UNPKG

@iobroker/create-adapter

Version:

Command line utility to create customized ioBroker adapters

125 lines 4.28 kB
"use strict"; const objects_1 = require("alcalzone-shared/objects"); const JSON5 = require("json5"); const questions_1 = require("../src/lib/questions"); const tools_1 = require("../src/lib/tools"); module.exports = (async (answers) => { const isAdapter = answers.features.indexOf("adapter") > -1; const isWidget = answers.features.indexOf("vis") > -1; const useTypeScript = answers.language === "TypeScript"; const supportCustom = answers.adminFeatures && answers.adminFeatures.indexOf("custom") > -1; const supportTab = answers.adminFeatures && answers.adminFeatures.indexOf("tab") > -1; const languages = ["en", "de", "ru", "pt", "nl", "fr", "it", "es", "pl", "zh-cn"]; const title = answers.title || answers.adapterName; const titleLang = JSON.stringify(objects_1.composeObject(await Promise.all(languages.map(async (lang) => [lang, await tools_1.translateText(title, lang)])))); const description = answers.description || answers.adapterName; const descriptionLang = JSON.stringify(objects_1.composeObject(await Promise.all(languages.map(async (lang) => [lang, await tools_1.translateText(description, lang)])))); const allSettings = answers.adapterSettings || questions_1.getDefaultAnswer("adapterSettings"); const adapterSettings = {}; for (const setting of allSettings) { adapterSettings[setting.key] = setting.defaultValue; } const template = ` { "common": { "name": "${answers.adapterName}", "version": "0.0.1", "news": { "0.0.1": { "en": "initial release", "de": "Erstveröffentlichung", "ru": "Начальная версия", "pt": "lançamento inicial", "nl": "Eerste uitgave", "fr": "Première version", "it": "Versione iniziale", "es": "Versión inicial", "pl": "Pierwsze wydanie", "zh-cn": "首次出版" } }, "title": "${answers.title || answers.adapterName}", "titleLang": ${titleLang}, "desc": ${descriptionLang}, "authors": [ "${answers.authorName} <${answers.authorEmail}>" ], "keywords": ${JSON.stringify(answers.keywords || questions_1.getDefaultAnswer("keywords"))}, "license": "${answers.license.id}", "platform": "Javascript/Node.js", "main": "${useTypeScript ? "build/" : ""}main.js", "icon": "${answers.adapterName}.png", "enabled": true, "extIcon": "https://raw.githubusercontent.com/${answers.authorGithub}/ioBroker.${answers.adapterName}/master/admin/${answers.adapterName}.png", "readme": "https://github.com/${answers.authorGithub}/ioBroker.${answers.adapterName}/blob/master/README.md", "loglevel": "info", ${isWidget ? (` "restartAdapters": ["vis"], "localLink": "%web_protocol%://%ip%:%web_port%/vis/edit.html", `) : ""} ${isAdapter ? (` "mode": "${answers.startMode || "daemon"}", ${answers.scheduleStartOnChange === "yes" ? (` "allowInit": true, `) : ""} "type": "${answers.type || "general"}", "compact": true, ${!!answers.connectionType ? (` "connectionType": "${answers.connectionType}", `) : ""} ${!!answers.dataSource ? (` "dataSource": "${answers.dataSource}", `) : ""} `) : isWidget ? (` "onlyWWW": true, "noConfig": true, "singleton": true, "type": "${answers.type || "visualization-widgets"}", "mode": "once", `) : ""} ${isAdapter ? `"materialize": true,` : ""} ${supportTab ? (` "materializeTab": true, "adminTab": { "singleton": true, "name": ${titleLang}, "link": "", "fa-icon": "info", }, `) : ""} ${supportCustom ? `"supportCustoms": true,` : ""} "dependencies": [ ${isAdapter ? `{ "js-controller": ">=1.4.2" },` : ""} ${isWidget ? `"vis",` : ""} ], }, "native": ${JSON.stringify(adapterSettings)}, "objects": [ ], "instanceObjects": [ ${answers.connectionIndicator === "yes" ? `{ "_id": "info", "type": "channel", "common": { "name": "Information" }, "native": {} }, { "_id": "info.connection", "type": "state", "common": { "role": "indicator.connected", "name": "Device or service connected", "type": "boolean", "read": true, "write": false, "def": false }, "native": {} },` : ""} ], }`; return JSON.stringify(JSON5.parse(template), null, 4); }); //# sourceMappingURL=io-package.json.js.map