Skip to content

Commit

Permalink
feat: add v2
Browse files Browse the repository at this point in the history
  • Loading branch information
Murzbul committed Nov 26, 2023
1 parent 07e007f commit caf605a
Show file tree
Hide file tree
Showing 16 changed files with 1,046 additions and 1,158 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ coverage
*.lcov
.idea
.nexp
node-experience

# nyc test coverage
.nyc_output
Expand Down
3 changes: 0 additions & 3 deletions .gitmodules

This file was deleted.

51 changes: 30 additions & 21 deletions bin/createProject.js
Original file line number Diff line number Diff line change
@@ -1,25 +1,21 @@
import inquirer from 'inquirer';
import { Listr } from 'listr2';
import * as url from 'url';

import welcomeBox from './welcome.js';
import copyIndexFiles from '../lib/createProject/copyIndexFiles.js';
import createFolders from '../lib/createProject/createFolders.js';
import copyRootFiles from '../lib/createProject/copyRootFiles.js';
import cleanDomains from '../lib/createProject/cleanDomains/cleanDomains.js';
import copyDomainFiles from '../lib/createProject/copyDomainFiles.js';
import getChoices from '../lib/createProject/getChoices.js';
import createPackageJson from '../lib/createProject/package.js';
import setEvnVar from '../lib/createProject/setEnvVar.js';
import simpleGit from 'simple-git';
import fs from 'fs-extra';

const createProject = async() =>
{
console.log(welcomeBox);

const rootPath = url.fileURLToPath(new URL('.', import.meta.url)).toString().replace('/bin', '');

const { orms, https } = await getChoices(rootPath);

inquirer
.prompt([
{
Expand All @@ -32,15 +28,8 @@ const createProject = async() =>
type: 'list',
name: 'orm',
message: 'Choose an ORM.',
choices: orms,
choices: ['Mongoose', 'MikroORM'],
default: 'Mongoose'
},
{
type: 'list',
name: 'http',
message: 'Choose an HTTP Library.',
choices: https,
default: 'Koa'
}
])
.then((answers) =>
Expand All @@ -49,25 +38,45 @@ const createProject = async() =>

console.log(answers);
const tasks = new Listr([
{
{
title: 'Clone Node Experience',
task: async() =>
{
const success = await fs.pathExists('node-experience');

if (!success)
{
const options = {
baseDir: process.cwd(),
binary: 'git',
maxConcurrentProcesses: 6,
trimmed: false
};

const git = simpleGit(options);
await git.clone('[email protected]:DigiChanges/node-experience.git');
}
}
},
{
title: 'Initialization',
task: async() =>
{
await createFolders(answers, rootPath);
await createFolders(answers, './');
}
},
{
title: 'Copy Index Files',
task: async() =>
{
await copyIndexFiles(answers, rootPath);
await copyIndexFiles(answers, './');
}
},
{
title: 'Copy Root Files',
task: async() =>
{
await copyRootFiles(answers, rootPath);
await copyRootFiles(answers, './');
}
},
{
Expand All @@ -81,21 +90,21 @@ const createProject = async() =>
title: 'Copy Domain Files',
task: async() =>
{
await copyDomainFiles(answers, rootPath);
await copyDomainFiles(answers, './');
}
},
{
title: 'Clean Domain Files',
task: async() =>
{
await cleanDomains(answers, rootPath);
await cleanDomains(answers, './');
}
},
{
title: 'Create Package JSON',
task: async() =>
{
await createPackageJson(answers, rootPath);
await createPackageJson(answers, './');
}
}
]);
Expand Down
4 changes: 1 addition & 3 deletions lib/createProject/cleanDomains/cleanDomains.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
import cleanOrm from './cleanOrm.js';
import cleanHttp from './cleanHttp.js';
import readInfoJsonNexp from '../readInfoJsonNexp.js';

const cleanDomains = async(vars, rootPath) =>
{
const { orm, http } = await readInfoJsonNexp(rootPath);
const { orm } = await readInfoJsonNexp(rootPath);

await cleanOrm(vars, orm);
await cleanHttp(vars, http);
};

export default cleanDomains;
80 changes: 0 additions & 80 deletions lib/createProject/cleanDomains/cleanHttp.js

This file was deleted.

36 changes: 16 additions & 20 deletions lib/createProject/cleanDomains/cleanOrm.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,44 +12,40 @@ const cleanFilesInfo = async(vars, httpMapper) =>
const ormChosen = last(mapperFilter);
const rootDestinyPath = join(resolve(), vars.projectName);

const ormFactoryFile = `import MainConfig from '../../Config/MainConfig';
import ${ormChosen}CreateConnection from '../Infrastructure/Database/Create${ormChosen}Connection';
import ICreateConnection from '../Infrastructure/Database/ICreateConnection';
const ormFactoryFile = `import MainConfig from '../../../Config/MainConfig';
import Create${ormChosen}Connection from '../Database/Create${ormChosen}Connection';
import ICreateConnection from '../Database/ICreateConnection';
type DbValueProp = typeof Create${ormChosen}Connection;
class DatabaseFactory
{
private dbDefault: string;
private readonly dbDefault: string;
private config = MainConfig.getInstance().getConfig();
constructor(dbDefault?: string)
{
this.dbDefault = dbDefault;
this.dbDefault = dbDefault ?? this.config.dbConfig.default;
}
create(): ICreateConnection
create(_db?: string): ICreateConnection
{
const mainConfig = MainConfig.getInstance();
if (!this.dbDefault)
{
this.dbDefault = mainConfig.getConfig().dbConfig.default;
}
const dbConfig: any = mainConfig.getConfig().dbConfig;
const config = dbConfig[this.dbDefault];
const db = _db ?? this.dbDefault;
const { dbConfig } = this.config;
const config = dbConfig[db];
const createConnections: Record<string, any> = {
${ormChosen}: ${ormChosen}CreateConnection
};
const strategy = new Map<string, DbValueProp>();
strategy.set('${ormChosen}', Create${ormChosen}Connection);
return new createConnections[this.dbDefault](config);
return new (strategy.get(db))(config);
}
}
export default DatabaseFactory;
`;

await writeFile(`${rootDestinyPath}/src/Shared/Factories/DatabaseFactory.ts`, ormFactoryFile, { flag: 'w' });
await writeFile(`${rootDestinyPath}/src/Main/Infrastructure/Factories/DatabaseFactory.ts`, ormFactoryFile, { flag: 'w' });
};

const cleanOrm = async(vars, ormMapper) =>
Expand Down
12 changes: 6 additions & 6 deletions lib/createProject/copyDomainFiles.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ const copyDomainFiles = async(vars, rootPath) =>
{
const projectPath = join(resolve(), `${vars.projectName}/src`);

await copyTemplate(vars, join(rootPath, 'templates/node-experience/src/Auth'), projectPath);
await copyTemplate(vars, join(rootPath, 'templates/node-experience/src/Config'), projectPath);
await copyTemplate(vars, join(rootPath, 'templates/node-experience/src/File'), projectPath);
await copyTemplate(vars, join(rootPath, 'templates/node-experience/src/Item'), projectPath);
await copyTemplate(vars, join(rootPath, 'templates/node-experience/src/Notification'), projectPath);
await copyTemplate(vars, join(rootPath, 'templates/node-experience/src/Shared'), projectPath);
await copyTemplate(vars, join(rootPath, '/node-experience/src/Auth'), projectPath);
await copyTemplate(vars, join(rootPath, '/node-experience/src/Config'), projectPath);
await copyTemplate(vars, join(rootPath, '/node-experience/src/Item'), projectPath);
await copyTemplate(vars, join(rootPath, '/node-experience/src/Main'), projectPath);
await copyTemplate(vars, join(rootPath, '/node-experience/src/Notification'), projectPath);
await copyTemplate(vars, join(rootPath, '/node-experience/src/Shared'), projectPath);
};

export default copyDomainFiles;
16 changes: 8 additions & 8 deletions lib/createProject/copyIndexFiles.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@ const copyIndexFiles = async(vars, rootPath) =>
{
const rootDestinyPath = join(resolve(), `${vars.projectName}/src`);

await copyTemplate(vars, join(rootPath, 'templates/indexFiles'), rootDestinyPath, false);
await copyTemplate(vars, join(rootPath, '/templates/node-experience/src/command.ts'), rootDestinyPath);
await copyTemplate(vars, join(rootPath, '/templates/node-experience/src/crons.ts'), rootDestinyPath);
await copyTemplate(vars, join(rootPath, '/templates/node-experience/src/exceptions.ts'), rootDestinyPath);
await copyTemplate(vars, join(rootPath, '/templates/node-experience/src/index.ts'), rootDestinyPath);
await copyTemplate(vars, join(rootPath, '/templates/node-experience/src/initCommand.ts'), rootDestinyPath);
await copyTemplate(vars, join(rootPath, '/templates/node-experience/src/seed.ts'), rootDestinyPath);
await copyTemplate(vars, join(rootPath, '/templates/node-experience/src/inversify.config.ts'), rootDestinyPath);
await copyTemplate(vars, join(rootPath, '/node-experience/src/closed.ts'), rootDestinyPath);
await copyTemplate(vars, join(rootPath, '/node-experience/src/command.ts'), rootDestinyPath);
await copyTemplate(vars, join(rootPath, '/node-experience/src/crons.ts'), rootDestinyPath);
await copyTemplate(vars, join(rootPath, '/node-experience/src/exceptions.ts'), rootDestinyPath);
await copyTemplate(vars, join(rootPath, '/node-experience/src/index.ts'), rootDestinyPath);
await copyTemplate(vars, join(rootPath, '/node-experience/src/initCommand.ts'), rootDestinyPath);
await copyTemplate(vars, join(rootPath, '/node-experience/src/initTestServer.ts'), rootDestinyPath);
await copyTemplate(vars, join(rootPath, '/node-experience/src/seed.ts'), rootDestinyPath);
};

export default copyIndexFiles;
60 changes: 31 additions & 29 deletions lib/createProject/copyRootFiles.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,35 +5,37 @@ const copyRootFiles = async(vars, rootPath) =>
{
const rootDestinyPath = join(resolve(), vars.projectName);

await copyTemplate(vars, join(rootPath, 'templates/node-experience/.circleci'), rootDestinyPath);
await copyTemplate(vars, join(rootPath, 'templates/node-experience/.husky'), rootDestinyPath);
await copyTemplate(vars, join(rootPath, 'templates/node-experience/config'), rootDestinyPath);
await copyTemplate(vars, join(rootPath, 'templates/node-experience/docker'), rootDestinyPath);
await copyTemplate(vars, join(rootPath, 'templates/node-experience/docs'), rootDestinyPath);
await copyTemplate(vars, join(rootPath, 'templates/node-experience/infrastructure'), rootDestinyPath);
await copyTemplate(vars, join(rootPath, 'templates/node-experience/tools'), rootDestinyPath);
await copyTemplate(vars, join(rootPath, 'templates/node-experience/.commitlintrc.json'), rootDestinyPath);
await copyTemplate(vars, join(rootPath, 'templates/node-experience/.env.dev'), rootDestinyPath);
await copyTemplate(vars, join(rootPath, 'templates/node-experience/.eslintrc.json'), rootDestinyPath);
await copyTemplate(vars, join(rootPath, 'templates/node-experience/.huskyrc'), rootDestinyPath);
await copyTemplate(vars, join(rootPath, 'templates/node-experience/.prettierignore'), rootDestinyPath);
await copyTemplate(vars, join(rootPath, 'templates/node-experience/.prettierrc'), rootDestinyPath);
await copyTemplate(vars, join(rootPath, 'templates/node-experience/dev.build.sh'), rootDestinyPath);
await copyTemplate(vars, join(rootPath, 'templates/node-experience/dev.init.sh'), rootDestinyPath);
await copyTemplate(vars, join(rootPath, 'templates/rootFiles/docker-compose.yml'), rootDestinyPath);
await copyTemplate(vars, join(rootPath, 'templates/node-experience/Dockerfile'), rootDestinyPath);
await copyTemplate(vars, join(rootPath, 'templates/node-experience/ecosystem.config.js'), rootDestinyPath);
await copyTemplate(vars, join(rootPath, 'templates/node-experience/etsc.config.js'), rootDestinyPath);
await copyTemplate(vars, join(rootPath, 'templates/node-experience/jest.config.js'), rootDestinyPath);
await copyTemplate(vars, join(rootPath, 'templates/node-experience/jest-mongodb-config.js'), rootDestinyPath);
await copyTemplate(vars, join(rootPath, 'templates/node-experience/LICENSE'), rootDestinyPath);
await copyTemplate(vars, join(rootPath, 'templates/node-experience/lint-staged.config.js'), rootDestinyPath);
await copyTemplate(vars, join(rootPath, 'templates/node-experience/Makefile'), rootDestinyPath);
await copyTemplate(vars, join(rootPath, 'templates/node-experience/nodemon.json'), rootDestinyPath);
await copyTemplate(vars, join(rootPath, 'templates/node-experience/prod.build.sh'), rootDestinyPath);
await copyTemplate(vars, join(rootPath, 'templates/node-experience/README.md'), rootDestinyPath);
await copyTemplate(vars, join(rootPath, 'templates/node-experience/tsconfig.json'), rootDestinyPath);
await copyTemplate(vars, join(rootPath, 'templates/node-experience/pnpm-lock.yaml'), rootDestinyPath);
await copyTemplate(vars, join(rootPath, '/node-experience/.github'), rootDestinyPath);
await copyTemplate(vars, join(rootPath, '/node-experience/.husky'), rootDestinyPath);
await copyTemplate(vars, join(rootPath, '/node-experience/config'), rootDestinyPath);
await copyTemplate(vars, join(rootPath, '/node-experience/docker'), rootDestinyPath);
await copyTemplate(vars, join(rootPath, '/node-experience/infrastructure'), rootDestinyPath);
await copyTemplate(vars, join(rootPath, '/node-experience/tools'), rootDestinyPath);
await copyTemplate(vars, join(rootPath, '/node-experience/.commitlintrc.json'), rootDestinyPath);
await copyTemplate(vars, join(rootPath, '/node-experience/.dockerignore'), rootDestinyPath);
await copyTemplate(vars, join(rootPath, '/node-experience/.env.dev'), rootDestinyPath);
await copyTemplate(vars, join(rootPath, '/node-experience/.env.test'), rootDestinyPath);
await copyTemplate(vars, join(rootPath, '/node-experience/.eslintrc'), rootDestinyPath);
await copyTemplate(vars, join(rootPath, '/node-experience/.gitignore'), rootDestinyPath);
await copyTemplate(vars, join(rootPath, '/node-experience/.huskyrc'), rootDestinyPath);
await copyTemplate(vars, join(rootPath, '/node-experience/.npmrc'), rootDestinyPath);
await copyTemplate(vars, join(rootPath, '/node-experience/dagger.mjs'), rootDestinyPath);
await copyTemplate(vars, join(rootPath, '/node-experience/Dockerfile'), rootDestinyPath);
await copyTemplate(vars, join(rootPath, '/node-experience/ecosystem.config.js'), rootDestinyPath);
await copyTemplate(vars, join(rootPath, '/node-experience/jest.config.js'), rootDestinyPath);
await copyTemplate(vars, join(rootPath, '/node-experience/jest-mongodb-config.js'), rootDestinyPath);
await copyTemplate(vars, join(rootPath, '/node-experience/LICENSE'), rootDestinyPath);
await copyTemplate(vars, join(rootPath, '/node-experience/lint-staged.config.js'), rootDestinyPath);
await copyTemplate(vars, join(rootPath, '/node-experience/Makefile'), rootDestinyPath);
await copyTemplate(vars, join(rootPath, '/node-experience/nexp.svg'), rootDestinyPath);
await copyTemplate(vars, join(rootPath, '/node-experience/nodemon.json'), rootDestinyPath);
await copyTemplate(vars, join(rootPath, '/node-experience/pnpm-lock.yaml'), rootDestinyPath);
await copyTemplate(vars, join(rootPath, '/node-experience/README.md'), rootDestinyPath);
await copyTemplate(vars, join(rootPath, '/node-experience/rimraf_cpy.mjs'), rootDestinyPath);
await copyTemplate(vars, join(rootPath, '/node-experience/sonar-project.properties'), rootDestinyPath);
await copyTemplate(vars, join(rootPath, '/node-experience/tsconfig.json'), rootDestinyPath);

await copyTemplate(vars, join(rootPath, '/templates/rootFiles/docker-compose.yml'), rootDestinyPath);
};

export default copyRootFiles;
Loading

0 comments on commit caf605a

Please sign in to comment.