lina-infratech-cli
Version:
A CLI tool for Lina Infratech Developers
50 lines (49 loc) • 2.25 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.projectInitAction = void 0;
const tslib_1 = require("tslib");
const child_process_1 = require("child_process");
const shelljs_1 = require("shelljs");
const commit_and_lint_1 = require("../utils/commit-and-lint");
const generator_1 = require("../generator");
const messages_1 = require("../ui/messages");
const colors_1 = require("../utils/chalk/colors");
const constants_1 = require("../utils/constants");
function installDependencies() {
const deps = constants_1.expressDependencies.join(' ');
const devDeps = constants_1.expressDevDependencies.join(' ');
console.log(messages_1.MESSAGES.DEPS_INSTALL);
(0, child_process_1.execSync)(`npm i ${deps}`);
(0, colors_1.logSuccess)(messages_1.MESSAGES.DEPS_OK);
console.log(messages_1.MESSAGES.DEV_DEPS_INSTALL);
(0, child_process_1.execSync)(`npm i -D ${devDeps}`);
(0, colors_1.logSuccess)(messages_1.MESSAGES.DEV_DEPS_OK);
}
function projectInitAction(projectName, options) {
return tslib_1.__awaiter(this, void 0, void 0, function* () {
(0, colors_1.logSuccess)(`Creating project: ${projectName}...`);
console.log('options:', options);
if (options.express) {
try {
(0, shelljs_1.mkdir)(`${process.cwd()}/${projectName}`);
(0, shelljs_1.cd)(`${process.cwd()}/${projectName}`);
console.log(messages_1.MESSAGES.NPM_START);
(0, child_process_1.execSync)('npm init -y');
(0, colors_1.logSuccess)(messages_1.MESSAGES.NPM_OK);
installDependencies();
(0, generator_1.generatePackageJson)();
yield (0, generator_1.generateConfigFiles)();
(0, generator_1.generateProjectStructure)();
(0, commit_and_lint_1.commitAndLint)('Initial commit - generated by Lina CLI');
}
catch (error) {
(0, colors_1.logError)(messages_1.MESSAGES.GENERIC_ERROR, error);
process.exit(1);
}
}
else {
(0, colors_1.logError)('Please inform a init option');
}
});
}
exports.projectInitAction = projectInitAction;