UNPKG

@iobroker/create-adapter

Version:

Command line utility to create customized ioBroker adapters

72 lines (66 loc) 2.45 kB
"use strict"; const questions_1 = require("../../src/lib/core/questions"); function generateSettingsProperty(settings) { if (settings.inputType === "select" && settings.options) { return ` ${settings.key}: (${settings.options.map(opt => `"${opt.value}"`).join(" | ")});`; } else if (settings.inputType === "checkbox") { return ` ${settings.key}: boolean;`; } else if (settings.inputType === "number") { return ` ${settings.key}: number;`; } return ` ${settings.key}: string;`; } const templateFunction = answers => { const isAdapter = answers.features.indexOf("adapter") > -1; if (!isAdapter) { return; } const useTypeScript = answers.language === "TypeScript"; const useTSWithoutBuild = answers.language === "TypeScript (without build)"; const useTypeChecking = answers.tools && answers.tools.indexOf("type checking") > -1; let template; if ((useTypeScript || useTSWithoutBuild) && !useTypeChecking) { const adapterSettings = answers.adapterSettings ?? (0, questions_1.getDefaultAnswer)("adapterSettings"); template = ` // This file extends the AdapterConfig type from "@iobroker/types" // Augment the globally declared type ioBroker.AdapterConfig declare global { namespace ioBroker { interface AdapterConfig {${adapterSettings.map(generateSettingsProperty).join("")} } } } // this is required so the above AdapterConfig is found by TypeScript / type checking export {}; `; } else { template = ` // This file extends the AdapterConfig type from "@iobroker/types" // using the actual properties present in io-package.json // in order to provide typings for adapter.config properties import { native } from "${useTypeScript || useTSWithoutBuild ? "../" : ""}../io-package.json"; type _AdapterConfig = typeof native; // Augment the globally declared type ioBroker.AdapterConfig declare global { namespace ioBroker { interface AdapterConfig extends _AdapterConfig { // Do not enter anything here! } } } // this is required so the above AdapterConfig is found by TypeScript / type checking export {}; `; } return template.trim(); }; templateFunction.customPath = answers => `${answers.language === "TypeScript" || answers.language === "TypeScript (without build)" ? "src/" : ""}lib/adapter-config.d.ts`; module.exports = templateFunction; //# sourceMappingURL=adapter-config.dts.js.map