@iobroker/create-adapter
Version:
Command line utility to create customized ioBroker adapters
204 lines • 7.06 kB
JavaScript
"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || (function () {
var ownKeys = function(o) {
ownKeys = Object.getOwnPropertyNames || function (o) {
var ar = [];
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
return ar;
};
return ownKeys(o);
};
return function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
__setModuleDefault(result, mod);
return result;
};
})();
const translate_1 = require("@iobroker/adapter-dev/build/translate");
const objects_1 = require("alcalzone-shared/objects");
const JSON5 = __importStar(require("json5"));
const licenses_1 = require("../src/lib/core/licenses");
const questions_1 = require("../src/lib/core/questions");
module.exports = (async (answers) => {
const isAdapter = answers.features.indexOf("adapter") > -1;
const isWidget = answers.features.indexOf("vis") > -1;
const widgetIsMainFunction = answers.widgetIsMainFunction === "main";
const useJsonConfig = answers.adminUi === "json";
const useAdminReact = answers.adminUi === "react";
const useTabReact = answers.tabReact === "yes";
const useReact = useAdminReact || useTabReact;
const supportCustom = answers.adminFeatures && answers.adminFeatures.indexOf("custom") > -1;
const supportTab = answers.adminFeatures && answers.adminFeatures.indexOf("tab") > -1;
const defaultBranch = answers.defaultBranch || "main";
const languages = ["en", "de", "ru", "pt", "nl", "fr", "it", "es", "pl", "uk", "zh-cn"];
const title = answers.title || answers.adapterName;
const titleLang = JSON.stringify((0, objects_1.composeObject)(await Promise.all(languages.map(async (lang) => [lang, await (0, translate_1.translateText)(title, lang)]))));
const description = answers.description || answers.adapterName;
const descriptionLang = JSON.stringify((0, objects_1.composeObject)(await Promise.all(languages.map(async (lang) => [lang, await (0, translate_1.translateText)(description, lang)]))));
const allSettings = answers.adapterSettings || (0, questions_1.getDefaultAnswer)("adapterSettings");
const adapterSettings = {};
for (const setting of allSettings) {
adapterSettings[setting.key] = setting.defaultValue;
}
// The "license" field is going to be replaced with "licenseInformation".
// For now keep both to be compatible
const licenseId = licenses_1.licenses[answers.license].id;
const licenseInformation = answers.licenseInformation || { type: "free" };
licenseInformation.license = licenseId;
let adminUiConfig;
switch (answers.adminUi) {
case "react":
case "html":
adminUiConfig = "materialize";
break;
case "json":
adminUiConfig = "json";
break;
default:
adminUiConfig = "none";
break;
}
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",
"uk": "Початкова версія",
"zh-cn": "首次出版"
}
},
"titleLang": ${titleLang},
"desc": ${descriptionLang},
"authors": [
"${answers.authorName} <${answers.authorEmail}>"
],
"keywords": ${JSON.stringify(answers.keywords || (0, questions_1.getDefaultAnswer)("keywords"))},
"licenseInformation": ${JSON.stringify(licenseInformation)},
"platform": "Javascript/Node.js",
"icon": "${(0, questions_1.getIconName)(answers)}",
"enabled": true,
"extIcon": "https://raw.githubusercontent.com/${answers.authorGithub}/ioBroker.${answers.adapterName}/${defaultBranch}/admin/${(0, questions_1.getIconName)(answers)}",
"readme": "https://github.com/${answers.authorGithub}/ioBroker.${answers.adapterName}/blob/${defaultBranch}/README.md",
"loglevel": "info",
"tier": 3,
${isWidget && widgetIsMainFunction
? `
"restartAdapters": ["vis"],
`
: ""}
${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,
"singleton": true,
"type": "${answers.type || "visualization-widgets"}",
"mode": "once",
`
: ""}
${isAdapter || answers.adminUi === "none" || isWidget
? `
"adminUI": {
"config": "${isAdapter ? adminUiConfig : "none"}",
${supportTab ? `"tab": "materialize",` : ""}
},`
: ""}
${supportTab
? `
"adminTab": {
"singleton": true,
"name": ${titleLang},
"link": "",
},
`
: ""}
${supportCustom ? `"supportCustoms": true,` : ""}
${useReact ? `"eraseOnUpload": true,` : ""}
"dependencies": [
${isAdapter ? `{ "js-controller": ">=6.0.11" },` : ""}
${isWidget && widgetIsMainFunction ? `"vis",` : ""}
],
"globalDependencies": [
${isAdapter ? `{ "admin": ">=7.0.23" },` : ""}
],
},
"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