@webresto/cli
Version:
Webresto command line interface
65 lines (64 loc) • 2.69 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.install = void 0;
const fs_1 = __importDefault(require("fs"));
const async_shelljs_1 = require("async-shelljs");
const download_1 = __importDefault(require("module-registry-client-lib/lib/download"));
const install = async (module, options) => {
let modulesPath = process.cwd() + '/modules/';
let channel = options.channel ?? "main";
if (module) {
// if (debug) {
async_shelljs_1.config.silent = false;
// } else {
// config.silent = true;
// }
if (!fs_1.default.existsSync(modulesPath))
throw `Dirrectory ${modulesPath} not found`;
let currentModulePath = process.cwd() + '/modules/' + module;
if (fs_1.default.existsSync(currentModulePath)) {
throw `Module path exist ${currentModulePath}`;
}
// if (process.env.WEBRESTO_LICENSE === "undefined") {
// throw "you must set webresto license"
// }
let version = 'latest';
const moduleAndVersion = module.split('@');
if (moduleAndVersion.length === 2) {
module = moduleAndVersion[0];
version = moduleAndVersion[1];
}
await (0, download_1.default)(module, version, channel, process.env.WEBRESTO_LICENSE, modulesPath);
}
else {
let webrestoListFile = `${process.cwd()}/webresto-modules.list`;
if (fs_1.default.existsSync(webrestoListFile)) {
const modulesList = fs_1.default
.readFileSync(`${process.cwd()}/webresto-modules.list`, {
encoding: 'utf8',
flag: 'r'
})
.split('\n');
for await (let module of modulesList) {
if (!module)
continue;
let version = 'latest';
const moduleAndVersion = module.split('@');
if (moduleAndVersion.length === 2) {
module = moduleAndVersion[0];
version = moduleAndVersion[1];
}
let currentModulePath = process.cwd() + '/modules/' + module;
if (fs_1.default.existsSync(currentModulePath)) {
console.info('DIRECTORY EXIST ' + currentModulePath);
continue;
}
await (0, download_1.default)(module, version, channel, process.env.WEBRESTO_LICENSE, modulesPath);
}
}
}
};
exports.install = install;