@webresto/cli
Version:
Webresto command line interface
57 lines (56 loc) • 2.56 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.update = void 0;
const fs_1 = __importDefault(require("fs"));
const { readdirSync } = require('fs');
const async_shelljs_1 = require("async-shelljs");
const update = async (module) => {
// if (debug) {
async_shelljs_1.config.silent = false;
// } else {
// config.silent = true;
// }
let modulesPath = process.cwd() + '/modules/';
if (!fs_1.default.existsSync(modulesPath))
throw `Dirrectory ${modulesPath} not found`;
if (module) {
let currentModulePath = process.cwd() + '/modules/' + module;
if (fs_1.default.existsSync(currentModulePath)) {
await (0, async_shelljs_1.exec)(` mv ${currentModulePath} /tmp/${module}_${Date.now()}`);
}
await (0, async_shelljs_1.exec)(` mkdir -p ${currentModulePath}`);
if ((await (0, async_shelljs_1.exec)('curl --version').code) !== 0) {
throw 'curl not found';
}
if ((await (0, async_shelljs_1.exec)('tar --version').code) !== 0) {
throw 'tar not found';
}
await (0, async_shelljs_1.exec)(`curl ${process.env.MODULE_STORAGE_URL}/${module}/${module}.tar | tar -xv -C ${currentModulePath}`);
}
else {
const installedModules = readdirSync(modulesPath, {
withFileTypes: true
})
.filter(dirent => dirent.isDirectory())
.map(dirent => dirent.name);
for await (let module of installedModules) {
let currentModulePath = process.cwd() + '/modules/' + module;
if (fs_1.default.existsSync(currentModulePath)) {
await (0, async_shelljs_1.exec)(` mv ${currentModulePath} /tmp/${module}_${Date.now()}`);
}
await (0, async_shelljs_1.exec)(` mkdir -p ${currentModulePath}`);
if ((await (0, async_shelljs_1.exec)('curl --version').code) !== 0) {
throw 'curl not found';
}
if ((await (0, async_shelljs_1.exec)('tar --version').code) !== 0) {
throw 'tar not found';
}
await (0, async_shelljs_1.exec)(` curl ${process.env.MODULE_STORAGE_URL}/${module}/${module}.tar | tar -xv -C ${currentModulePath} && cd ${currentModulePath} && npm install --only=prod`);
}
}
console.log(process.cwd(), module);
};
exports.update = update;