node-ff
Version:
A CLI for creating NodeJs projects
160 lines (153 loc) • 5.25 kB
text/typescript
import { textHandling } from '../../utils';
import { sequeliseJav, sequeliseTyp } from './packages';
interface IOrmControl {
ormWithType?: boolean;
projectName: string;
content?: object;
}
class OrmControl {
public content?: object = [];
public projectName = '';
private ormWithType?: boolean = false;
constructor({ content, ormWithType, projectName }: IOrmControl) {
this.content = content;
this.projectName = projectName;
this.ormWithType = ormWithType;
this.dealings();
}
private dealings(): void {
if (this.ormWithType) {
this.content = {
directory_name: [
this.projectName,
this.projectName,
this.projectName,
`${this.projectName}/app`,
`${this.projectName}/app/api/controllers/user`,
`${this.projectName}/app/api/routes`,
`${this.projectName}/app/api/routes`,
`${this.projectName}/app/api/services`,
`${this.projectName}/app/db/config`,
`${this.projectName}/app/db/dal`,
`${this.projectName}/app/db/dto`,
`${this.projectName}/app/db/models`,
`${this.projectName}/app/db/models`,
`${this.projectName}/app/db`,
],
filename: [
'.sequelizerc',
'.env',
'tsc_eval.sh',
'server.ts',
'index.ts',
'index.ts',
'users.routes.ts',
'UserService.ts',
'database.ts',
'User.ts',
'user.dto.ts',
'index.ts',
'User.ts',
'init.ts',
],
text: [
textHandling.return_text(sequeliseTyp.sequelizercTyp, true),
textHandling.return_text(sequeliseTyp.envTyp, true),
textHandling.return_text(sequeliseTyp.tscEval, true),
textHandling.return_text(sequeliseTyp.severTyp, true),
textHandling.return_text(sequeliseTyp.controllerType, true),
textHandling.return_text(sequeliseTyp.indexRouter, true),
textHandling.return_text(sequeliseTyp.userRoutes, true),
textHandling.return_text(sequeliseTyp.userService, true),
textHandling.return_text(sequeliseTyp.databaseTyp, true),
textHandling.return_text(sequeliseTyp.dal, true),
textHandling.return_text(sequeliseTyp.dto, true),
textHandling.return_text(sequeliseTyp.indexModel, true),
textHandling.return_text(sequeliseTyp.userModel, true),
textHandling.return_text(sequeliseTyp.dbInit, true),
],
commands: `
cd ${this.projectName} &&
mv ./src ./app &&
cd app &&
mkdir api &&
mkdir db &&
cd db &&
mkdir config &&
mkdir dal &&
mkdir dto &&
mkdir migrations &&
mkdir seeders &&
mkdir models &&
cd .. &&
cd api &&
mkdir contracts &&
mkdir controllers &&
cd controllers &&
mkdir user &&
cd .. &&
mkdir routes &&
mkdir services
`,
};
} else {
this.content = {
directory_name: [
this.projectName,
this.projectName,
`${this.projectName}/app`,
`${this.projectName}/config`,
`${this.projectName}/app/controllers`,
`${this.projectName}/app/controllers`,
`${this.projectName}/app/models`,
`${this.projectName}/app/models`,
`${this.projectName}/app/routes`,
`${this.projectName}/app/routes`,
`${this.projectName}/app/services`,
`${this.projectName}/app/services`,
],
filename: [
'.sequelizerc',
'.env',
'server.js',
'database.js',
'index.js',
'users_controller.js',
'index.js',
'user.js',
'index.js',
'user_routes.js',
'index.js',
'user_services.js',
],
text: [
textHandling.return_text(sequeliseJav.sequelizerc, true),
textHandling.return_text(sequeliseJav.env, true),
textHandling.return_text(sequeliseJav.server, true),
textHandling.return_text(sequeliseJav.database, true),
textHandling.return_text(sequeliseJav.index_controller, true),
textHandling.return_text(sequeliseJav.user_controller, true),
textHandling.return_text(sequeliseJav.index_model, true),
textHandling.return_text(sequeliseJav.user_model, true),
textHandling.return_text(sequeliseJav.index_router, true),
textHandling.return_text(sequeliseJav.user_router, true),
textHandling.return_text(sequeliseJav.index_service, true),
textHandling.return_text(sequeliseJav.user_service, true),
],
commands: `
cd ${this.projectName} &&
npx sequelize init &&
mkdir database &&
rm -rf config/config.json &&
rm -rf models/index.js &&
mv ./migrations ./seeders ./database &&
mv ./src ./app &&
mv ./models ./app &&
cd app &&
mkdir controllers routes services
`,
};
}
}
}
export { OrmControl };