@webresto/cli
Version:
Webresto command line interface
41 lines (40 loc) • 1.8 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.generate = void 0;
const fs_1 = __importDefault(require("fs"));
const async_shelljs_1 = require("async-shelljs");
const generate = async (what, name) => {
// 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`;
let currentModulePath = process.cwd() + '/modules/' + name;
if (fs_1.default.existsSync(currentModulePath))
throw `Dirrectory ${currentModulePath} was found`;
switch (what) {
case 'module':
let gitExist = (await (0, async_shelljs_1.exec)('git --version').code) === 0 ? true : false;
if (gitExist) {
await (0, async_shelljs_1.exec)(`git clone https://github.com/webresto/module-starter.git ${currentModulePath}`);
await (0, async_shelljs_1.exec)(`rm -rf ${currentModulePath}/.git`);
}
else {
// await exec(`wget https://github.com/webresto/module-starter/archive/refs/heads/main.zip -O ${currentModulePathTMP} ..... `)
console.log('git is not exist');
}
await (0, async_shelljs_1.exec)(`cd ${currentModulePath}/.factory && npm i && cd ${currentModulePath} && .factory/module_init ${name} && npm i`);
break;
default:
throw `Generate ${what} not known`;
break;
}
console.log(process.cwd(), what, name);
};
exports.generate = generate;