UNPKG

@iobroker/create-adapter

Version:

Command line utility to create customized ioBroker adapters

63 lines 2.14 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.MigrationContextBase = void 0; /** * */ class MigrationContextBase { packageJson; ioPackageJson; /** * * @param packageName */ hasDevDependency(packageName) { if (this.packageJson.devDependencies) { return Object.prototype.hasOwnProperty.call(this.packageJson.devDependencies, packageName); } return false; } /** * */ async getMainFileContent() { if (!this.packageJson.main || !this.packageJson.main.endsWith(".js") || !(await this.fileExists(this.packageJson.main))) { // we don't have a main JavaScript file, it will be impossible to find code return ""; } try { const tsMains = [ this.joinPath("src", this.packageJson.main.replace(/\.js$/, ".ts")), this.packageJson.main.replace(/\.js$/, ".ts").replace(/^dist([\\/])/, "src$1"), this.packageJson.main.replace(/\.js$/, ".ts").replace(/^build([\\/])/, "src$1"), this.packageJson.main.replace(/\.js$/, ".ts").replace(/^(build|dist)[\\/]/, ""), ]; for (const tsMain of tsMains) { if (await this.fileExists(tsMain)) { // most probably TypeScript return await this.readTextFile(tsMain); } } return await this.readTextFile(this.packageJson.main); } catch { // we don't want this to crash, so just return an empty string return ""; } } /** * * @param either * @param or */ async analyzeCode(either, or) { const content = await this.getMainFileContent(); const eitherCount = (content.match(new RegExp(either, "g")) || []).length; const orCount = (content.match(new RegExp(or, "g")) || []).length; return eitherCount >= orCount; } } exports.MigrationContextBase = MigrationContextBase; //# sourceMappingURL=migrationContextBase.js.map