UNPKG

@iobroker/create-adapter

Version:

Command line utility to create customized ioBroker adapters

78 lines 2.14 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.LocalMigrationContext = void 0; const fs_extra_1 = require("fs-extra"); const migrationContextBase_1 = require("./core/migrationContextBase"); const path = require("path"); /** * */ class LocalMigrationContext extends migrationContextBase_1.MigrationContextBase { baseDir; /** * * @param baseDir */ constructor(baseDir) { super(); this.baseDir = baseDir; } /** * */ async load() { this.packageJson = await this.readJsonFile("package.json"); this.ioPackageJson = await this.readJsonFile("io-package.json"); } /** * * @param parts */ joinPath(...parts) { return path.join(...parts); } /** * * @param fileName */ readTextFile(fileName) { return (0, fs_extra_1.readFile)(path.join(this.baseDir, fileName), { encoding: "utf8", }); } /** * * @param fileName */ async readJsonFile(fileName) { return (0, fs_extra_1.readJson)(path.join(this.baseDir, fileName)); } /** * * @param dirName */ async directoryExists(dirName) { const fullPath = path.join(this.baseDir, dirName); return (0, fs_extra_1.existsSync)(fullPath) && (await (0, fs_extra_1.stat)(fullPath)).isDirectory(); } /** * * @param dirName */ async fileExists(dirName) { const fullPath = path.join(this.baseDir, dirName); return (0, fs_extra_1.existsSync)(fullPath) && (await (0, fs_extra_1.stat)(fullPath)).isFile(); } /** * * @param dirName * @param extension * @param filter */ async hasFilesWithExtension(dirName, extension, filter) { return ((await this.directoryExists(dirName)) && (await (0, fs_extra_1.readdir)(path.join(this.baseDir, dirName))).some(f => (!filter || filter(f)) && f.toLowerCase().endsWith(extension.toLowerCase()))); } } exports.LocalMigrationContext = LocalMigrationContext; //# sourceMappingURL=localMigrationContext.js.map