node-ff
Version:
A CLI for creating NodeJs projects
134 lines • 6.6 kB
JavaScript
"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.Control = void 0;
const utils_1 = require("../../utils");
const ormControl_1 = require("./ormControl");
const packages_1 = require("./packages");
class Control {
constructor(project, typing, infos, orm, process) {
this.project = project;
this.typing = typing;
this.infos = infos;
this.orm = orm;
this.process = process;
this.eslintConf = new packages_1.eslintConfig(this.typing);
this.initial_data = {
directory_name: this.project,
filename: '',
text: '',
formate: false,
json: {},
};
this.data = {
git: Object.assign(Object.assign({}, this.initial_data), { filename: '.gitignore', text: utils_1.textHandling.return_text(packages_1.gitIgnore) }),
code: Object.assign(Object.assign({}, this.initial_data), { directory_name: `${this.project}/.vscode`, filename: 'settings.json', formate: true, json: packages_1.vcCodeSettings }),
initial: Object.assign(Object.assign({}, this.initial_data), { filename: ['.editorconfig', '.prettierrc.js', 'readme.md'], text: [
utils_1.textHandling.return_text(packages_1.editorconfig),
utils_1.textHandling.return_text(packages_1.prettierrc),
utils_1.textHandling.return_text(new packages_1.Readme(this.orm).content),
] }),
json: Object.assign(Object.assign({}, this.initial_data), { filename: 'package.json', formate: true, json: new packages_1.whichJSON(this.typing, this.orm).json }),
eslint: Object.assign(Object.assign({}, this.initial_data), { filename: ['.eslintrc.js', '.eslintignore'], text: [
utils_1.textHandling.return_text(this.eslintConf.configJs),
utils_1.textHandling.return_text(this.eslintConf.ignore),
] }),
with_typing: {
directory_name: [`${this.project}/src`, this.project],
filename: ['server.ts', 'tsconfig.json'],
text: [utils_1.textHandling.return_text(packages_1.serverTyp), ''],
formate: [false, true],
json: [{}, this.orm ? packages_1.tsconfigOrm : packages_1.tsconfig],
},
no_typing: {
directory_name: `${this.project}/src`,
filename: 'server.js',
text: utils_1.textHandling.return_text(packages_1.serverJav),
},
orms: {
sequelize: new ormControl_1.OrmControl({
projectName: this.project,
ormWithType: this.typing,
}).content,
},
};
}
exec({ initial_msg, final_msg, final_comands, }) {
return __awaiter(this, void 0, void 0, function* () {
console.log(initial_msg);
yield Promise.all(this.infos.map((item) => __awaiter(this, void 0, void 0, function* () {
yield this.process.execute(this.data[item]);
})));
final_comands === null || final_comands === void 0 ? void 0 : final_comands.execute({
commands: `cd ${this.project} && yarn`,
});
if (this.orm)
yield this.exec_orm({ final_comands });
console.log(final_msg);
});
}
exec_orm({ final_comands }) {
return __awaiter(this, void 0, void 0, function* () {
final_comands === null || final_comands === void 0 ? void 0 : final_comands.execute({
commands: this.data.orms[this.orm]['commands'],
});
setTimeout(() => __awaiter(this, void 0, void 0, function* () {
delete this.data.orms[this.orm]['commands'];
yield this.process.execute(this.data.orms[this.orm]);
}), 1000);
if (this.orm === 'sequelize') {
yield this.sequelize();
}
else {
yield this.prisma();
}
});
}
sequelize() {
return __awaiter(this, void 0, void 0, function* () {
const data = new Date();
const day = String(data.getDate()).padStart(2, '0');
const month = String(data.getMonth() + 1).padStart(2, '0');
const year = data.getFullYear();
const current_date = year + month + day;
if (this.typing) {
setTimeout(() => __awaiter(this, void 0, void 0, function* () {
yield this.process.execute({
directory_name: `${this.project}/app/db/migrations`,
filename: `${current_date}235103-create-user.js`,
text: packages_1.sequeliseTyp.userMigration,
});
}), 1000);
setTimeout(() => __awaiter(this, void 0, void 0, function* () {
yield this.process.execute({
directory_name: `${this.project}/app/db/seeders`,
filename: `${current_date}235103-demo-user.js`,
text: packages_1.sequeliseTyp.userDemo,
});
}), 1000);
}
else {
setTimeout(() => __awaiter(this, void 0, void 0, function* () {
yield this.process.execute({
directory_name: `${this.project}/database/migrations`,
filename: `${current_date}235103-create-user.js`,
text: packages_1.sequeliseJav.user_migration,
});
}), 1000);
}
});
}
prisma() {
return __awaiter(this, void 0, void 0, function* () { });
}
}
exports.Control = Control;
//# sourceMappingURL=control.js.map