nestcraftx 0.2.5 → 0.2.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CLI_USAGE.fr.md +331 -331
- package/CLI_USAGE.md +364 -364
- package/LICENSE +21 -21
- package/bin/nestcraft.js +84 -64
- package/commands/demo.js +333 -330
- package/commands/generate.js +93 -0
- package/commands/generateConf.js +91 -0
- package/commands/info.js +48 -48
- package/commands/new.js +338 -335
- package/commands/start.js +19 -19
- package/commands/test.js +7 -7
- package/package.json +1 -1
- package/utils/cliParser.js +133 -76
- package/utils/colors.js +62 -62
- package/utils/configs/configureDocker.js +120 -120
- package/utils/configs/setupCleanArchitecture.js +15 -13
- package/utils/configs/setupLightArchitecture.js +15 -9
- package/utils/file-utils/saveProjectConfig.js +36 -0
- package/utils/fullModeInput.js +607 -607
- package/utils/generators/application/dtoUpdater.js +54 -0
- package/utils/generators/cleanModuleGenerator.js +475 -0
- package/utils/generators/database/setupDatabase.js +31 -0
- package/utils/generators/domain/entityUpdater.js +78 -0
- package/utils/generators/infrastructure/mapperUpdater.js +65 -0
- package/utils/generators/lightModuleGenerator.js +131 -0
- package/utils/generators/relation/relation.engine.js +64 -0
- package/utils/interactive/askEntityInputs.js +165 -0
- package/utils/loggers/logError.js +7 -7
- package/utils/loggers/logInfo.js +7 -7
- package/utils/loggers/logSuccess.js +7 -7
- package/utils/loggers/logWarning.js +7 -7
- package/utils/setups/orms/typeOrmSetup.js +630 -630
- package/utils/setups/setupAuth.js +28 -15
- package/utils/setups/setupDatabase.js +75 -75
- package/utils/setups/setupPrisma.js +802 -630
- package/utils/shell.js +32 -32
- package/utils/spinner.js +57 -57
- package/utils/systemCheck.js +124 -124
- package/utils/userInput.js +421 -421
- package/utils/utils.js +27 -27
|
@@ -79,7 +79,7 @@ async function setupCleanArchitecture(inputs) {
|
|
|
79
79
|
const mongooseSchemaContent = await generateMongooseSchemaFileContent(
|
|
80
80
|
entity,
|
|
81
81
|
entitiesData,
|
|
82
|
-
mode
|
|
82
|
+
mode,
|
|
83
83
|
);
|
|
84
84
|
|
|
85
85
|
const schemaPath = `src/${entity.name}/infrastructure/persistence/mongoose`;
|
|
@@ -141,7 +141,7 @@ async function setupCleanArchitecture(inputs) {
|
|
|
141
141
|
|
|
142
142
|
import { Inject, Logger } from '@nestjs/common';
|
|
143
143
|
import { Create${entityName}Dto } from 'src/${entity.name}/application/dtos/${entity.name}.dto';
|
|
144
|
-
import { I${entityName}RepositoryName, I${entityName}Repository } from 'src/${entity.name}/domain/interfaces/${entity.name}.repository.interface';
|
|
144
|
+
import { I${entityName}RepositoryName, type I${entityName}Repository } from 'src/${entity.name}/domain/interfaces/${entity.name}.repository.interface';
|
|
145
145
|
import { ${entityName}Entity } from 'src/${entity.name}/domain/entities/${entityNameLower}.entity';
|
|
146
146
|
|
|
147
147
|
export class Create${entityName}UseCase {
|
|
@@ -168,7 +168,7 @@ export class Create${entityName}UseCase {
|
|
|
168
168
|
*/
|
|
169
169
|
|
|
170
170
|
import { Inject, Logger, NotFoundException } from '@nestjs/common';
|
|
171
|
-
import { I${entityName}RepositoryName, I${entityName}Repository } from 'src/${entity.name}/domain/interfaces/${entity.name}.repository.interface';
|
|
171
|
+
import { I${entityName}RepositoryName, type I${entityName}Repository } from 'src/${entity.name}/domain/interfaces/${entity.name}.repository.interface';
|
|
172
172
|
import { ${entityName}Entity } from 'src/${entity.name}/domain/entities/${entityNameLower}.entity';
|
|
173
173
|
|
|
174
174
|
export class GetById${entityName}UseCase {
|
|
@@ -201,7 +201,7 @@ export class GetById${entityName}UseCase {
|
|
|
201
201
|
*/
|
|
202
202
|
|
|
203
203
|
import { Inject, Logger } from '@nestjs/common';
|
|
204
|
-
import { I${entityName}RepositoryName, I${entityName}Repository } from 'src/${entity.name}/domain/interfaces/${entity.name}.repository.interface';
|
|
204
|
+
import { I${entityName}RepositoryName, type I${entityName}Repository } from 'src/${entity.name}/domain/interfaces/${entity.name}.repository.interface';
|
|
205
205
|
import { ${entityName}Entity } from 'src/${entity.name}/domain/entities/${entityNameLower}.entity';
|
|
206
206
|
|
|
207
207
|
export class GetAll${entityName}UseCase {
|
|
@@ -229,7 +229,7 @@ export class GetAll${entityName}UseCase {
|
|
|
229
229
|
|
|
230
230
|
import { Inject, Logger, NotFoundException } from '@nestjs/common';
|
|
231
231
|
import { Update${entityName}Dto } from 'src/${entity.name}/application/dtos/${entity.name}.dto';
|
|
232
|
-
import { I${entityName}RepositoryName, I${entityName}Repository } from 'src/${entity.name}/domain/interfaces/${entity.name}.repository.interface';
|
|
232
|
+
import { I${entityName}RepositoryName, type I${entityName}Repository } from 'src/${entity.name}/domain/interfaces/${entity.name}.repository.interface';
|
|
233
233
|
import { ${entityName}Entity } from 'src/${entity.name}/domain/entities/${entityNameLower}.entity';
|
|
234
234
|
|
|
235
235
|
export class Update${entityName}UseCase {
|
|
@@ -269,7 +269,7 @@ export class Update${entityName}UseCase {
|
|
|
269
269
|
*/
|
|
270
270
|
|
|
271
271
|
import { Inject, Logger, NotFoundException } from '@nestjs/common';
|
|
272
|
-
import { I${entityName}RepositoryName, I${entityName}Repository } from 'src/${entity.name}/domain/interfaces/${entity.name}.repository.interface';
|
|
272
|
+
import { I${entityName}RepositoryName, type I${entityName}Repository } from 'src/${entity.name}/domain/interfaces/${entity.name}.repository.interface';
|
|
273
273
|
|
|
274
274
|
export class Delete${entityName}UseCase {
|
|
275
275
|
private readonly logger = new Logger(Delete${entityName}UseCase.name);
|
|
@@ -419,7 +419,7 @@ export class ${entityNameCapitalized}Adapter {
|
|
|
419
419
|
const controllerContente = await generateController(
|
|
420
420
|
entity.name,
|
|
421
421
|
entityPath,
|
|
422
|
-
useSwagger
|
|
422
|
+
useSwagger,
|
|
423
423
|
);
|
|
424
424
|
await createFile({
|
|
425
425
|
path: `${entityPath}/presentation/controllers/${entityNameLower}.controller.ts`,
|
|
@@ -438,13 +438,13 @@ export class ${entityNameCapitalized}Adapter {
|
|
|
438
438
|
} else if (dbConfig.orm === "typeorm") {
|
|
439
439
|
extraImports = `import { ${entityNameCapitalized} } from 'src/entities/${entityNameCapitalized}.entity';\nimport { TypeOrmModule } from '@nestjs/typeorm';`;
|
|
440
440
|
importsBlock.push(
|
|
441
|
-
`TypeOrmModule.forFeature([${entityNameCapitalized}])
|
|
441
|
+
`TypeOrmModule.forFeature([${entityNameCapitalized}])`,
|
|
442
442
|
);
|
|
443
443
|
} else if (dbConfig.orm === "mongoose") {
|
|
444
444
|
extraImports = `import { MongooseModule } from '@nestjs/mongoose';
|
|
445
445
|
import { ${entityNameCapitalized}, ${entityNameCapitalized}Schema } from '${entityPath}/infrastructure/persistence/mongoose/${entityNameLower}.schema';`;
|
|
446
446
|
importsBlock.push(
|
|
447
|
-
`MongooseModule.forFeature([{ name: ${entityNameCapitalized}.name, schema: ${entityNameCapitalized}Schema }])
|
|
447
|
+
`MongooseModule.forFeature([{ name: ${entityNameCapitalized}.name, schema: ${entityNameCapitalized}Schema }])`,
|
|
448
448
|
);
|
|
449
449
|
}
|
|
450
450
|
|
|
@@ -460,7 +460,7 @@ import { ${entityNameCapitalized}, ${entityNameCapitalized}Schema } from '${enti
|
|
|
460
460
|
// Always necessary providers
|
|
461
461
|
providersBlock.push(
|
|
462
462
|
`{
|
|
463
|
-
provide:
|
|
463
|
+
provide: I${entityNameCapitalized}RepositoryName,
|
|
464
464
|
useClass: ${entityNameCapitalized}Repository,
|
|
465
465
|
}`,
|
|
466
466
|
`${entityNameCapitalized}Service`,
|
|
@@ -469,7 +469,7 @@ import { ${entityNameCapitalized}, ${entityNameCapitalized}Schema } from '${enti
|
|
|
469
469
|
`GetById${entityNameCapitalized}UseCase`,
|
|
470
470
|
`GetAll${entityNameCapitalized}UseCase`,
|
|
471
471
|
`Delete${entityNameCapitalized}UseCase`,
|
|
472
|
-
`${entityNameCapitalized}Mapper
|
|
472
|
+
`${entityNameCapitalized}Mapper`,
|
|
473
473
|
);
|
|
474
474
|
|
|
475
475
|
await createFile({
|
|
@@ -494,6 +494,8 @@ import { GetById${entityNameCapitalized}UseCase } from '${entityPath}/applicatio
|
|
|
494
494
|
import { GetAll${entityNameCapitalized}UseCase } from '${entityPath}/application/use-cases/getAll-${entityNameLower}.use-case';
|
|
495
495
|
import { Delete${entityNameCapitalized}UseCase } from '${entityPath}/application/use-cases/delete-${entityNameLower}.use-case';
|
|
496
496
|
import { ${entityNameCapitalized}Mapper } from '${entityPath}/infrastructure/mappers/${entityNameLower}.mapper';
|
|
497
|
+
import { I${entityNameCapitalized}RepositoryName } from './domain/interfaces/${entityNameLower}.repository.interface';
|
|
498
|
+
|
|
497
499
|
|
|
498
500
|
@Module({
|
|
499
501
|
imports: [
|
|
@@ -506,7 +508,7 @@ import { ${entityNameCapitalized}Mapper } from '${entityPath}/infrastructure/map
|
|
|
506
508
|
${providersBlock.join(",\n ")}
|
|
507
509
|
],
|
|
508
510
|
exports: [
|
|
509
|
-
${entityNameCapitalized}Service,
|
|
511
|
+
${entityNameCapitalized}Service, I${entityNameCapitalized}RepositoryName
|
|
510
512
|
]
|
|
511
513
|
})
|
|
512
514
|
export class ${entityNameCapitalized}Module {}
|
|
@@ -544,7 +546,7 @@ import { APP_INTERCEPTOR } from '@nestjs/core';`,
|
|
|
544
546
|
logSuccess(`Structure generated successfully!`);
|
|
545
547
|
} catch (error) {
|
|
546
548
|
logError(
|
|
547
|
-
`Process encountered an error during Clean Architecture setup: ${error}
|
|
549
|
+
`Process encountered an error during Clean Architecture setup: ${error}`,
|
|
548
550
|
);
|
|
549
551
|
throw error;
|
|
550
552
|
}
|
|
@@ -32,7 +32,7 @@ async function setupLightArchitecture(inputs) {
|
|
|
32
32
|
|
|
33
33
|
// Générer l'enum Role si l'entité User existe
|
|
34
34
|
const hasUserEntity = entitiesData.entities.some(
|
|
35
|
-
(entity) => entity.name.toLowerCase() === "user"
|
|
35
|
+
(entity) => entity.name.toLowerCase() === "user",
|
|
36
36
|
);
|
|
37
37
|
|
|
38
38
|
if (hasUserEntity) {
|
|
@@ -80,7 +80,7 @@ async function setupLightArchitecture(inputs) {
|
|
|
80
80
|
const mongooseSchemaContent = await generateMongooseSchemaFileContent(
|
|
81
81
|
entity,
|
|
82
82
|
entitiesData,
|
|
83
|
-
mode
|
|
83
|
+
mode,
|
|
84
84
|
);
|
|
85
85
|
await createFile({
|
|
86
86
|
path: `${entityPath}/entities/${entityNameLower}.schema.ts`,
|
|
@@ -104,7 +104,7 @@ async function setupLightArchitecture(inputs) {
|
|
|
104
104
|
entityNameCapitalized,
|
|
105
105
|
entityNameLower,
|
|
106
106
|
dbConfig.orm,
|
|
107
|
-
entity
|
|
107
|
+
entity,
|
|
108
108
|
);
|
|
109
109
|
await createFile({
|
|
110
110
|
path: `${entityPath}/repositories/${entityNameLower}.repository.ts`,
|
|
@@ -113,7 +113,7 @@ async function setupLightArchitecture(inputs) {
|
|
|
113
113
|
|
|
114
114
|
const serviceContent = generateLightService(
|
|
115
115
|
entityNameCapitalized,
|
|
116
|
-
entityNameLower
|
|
116
|
+
entityNameLower,
|
|
117
117
|
);
|
|
118
118
|
await createFile({
|
|
119
119
|
path: `${entityPath}/services/${entityNameLower}.service.ts`,
|
|
@@ -123,7 +123,7 @@ async function setupLightArchitecture(inputs) {
|
|
|
123
123
|
const controllerContent = generateLightController(
|
|
124
124
|
entityNameCapitalized,
|
|
125
125
|
entityNameLower,
|
|
126
|
-
useSwagger
|
|
126
|
+
useSwagger,
|
|
127
127
|
);
|
|
128
128
|
await createFile({
|
|
129
129
|
path: `${entityPath}/controllers/${entityNameLower}.controller.ts`,
|
|
@@ -135,7 +135,7 @@ async function setupLightArchitecture(inputs) {
|
|
|
135
135
|
entityNameLower,
|
|
136
136
|
entityPath,
|
|
137
137
|
dbConfig.orm,
|
|
138
|
-
useAuth
|
|
138
|
+
useAuth,
|
|
139
139
|
);
|
|
140
140
|
await createFile({
|
|
141
141
|
path: `${entityPath}/${entityNameLower}.module.ts`,
|
|
@@ -641,7 +641,7 @@ function generateLightModule(
|
|
|
641
641
|
entityLower,
|
|
642
642
|
entityPath,
|
|
643
643
|
orm,
|
|
644
|
-
useAuth = false
|
|
644
|
+
useAuth = false,
|
|
645
645
|
) {
|
|
646
646
|
let importsBlock = [];
|
|
647
647
|
let providersBlock = [`${entityName}Service`, `${entityName}Repository`];
|
|
@@ -659,7 +659,7 @@ import { TypeOrmModule } from '@nestjs/typeorm';`;
|
|
|
659
659
|
extraImports = `import { MongooseModule } from '@nestjs/mongoose';
|
|
660
660
|
import { ${entityName}, ${entityName}Schema } from '${entityPath}/entities/${entityLower}.schema';`;
|
|
661
661
|
importsBlock.push(
|
|
662
|
-
`MongooseModule.forFeature([{ name: ${entityName}.name, schema: ${entityName}Schema }])
|
|
662
|
+
`MongooseModule.forFeature([{ name: ${entityName}.name, schema: ${entityName}Schema }])`,
|
|
663
663
|
);
|
|
664
664
|
}
|
|
665
665
|
|
|
@@ -692,4 +692,10 @@ function decapitalize(str) {
|
|
|
692
692
|
return str.charAt(0).toLowerCase() + str.slice(1);
|
|
693
693
|
}
|
|
694
694
|
|
|
695
|
-
module.exports = {
|
|
695
|
+
module.exports = {
|
|
696
|
+
setupLightArchitecture,
|
|
697
|
+
generateLightRepository,
|
|
698
|
+
generateLightService,
|
|
699
|
+
generateLightController,
|
|
700
|
+
generateLightModule,
|
|
701
|
+
};
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
const fs = require("fs");
|
|
2
|
+
const path = require("path");
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Lit le package.json, fusionne les scripts et les dépendances, et réécrit le fichier.
|
|
6
|
+
*
|
|
7
|
+
* @param {object} inputs Les inputs du CLI (pour le chemin du projet et le nom)
|
|
8
|
+
*
|
|
9
|
+
*/
|
|
10
|
+
async function saveProjectConfig(inputs) {
|
|
11
|
+
const configDir = path.join(process.cwd(), ".nestcraftx");
|
|
12
|
+
const configFile = path.join(configDir, ".nestcraftxrc");
|
|
13
|
+
|
|
14
|
+
const configData = {
|
|
15
|
+
name: inputs.projectName,
|
|
16
|
+
mode: inputs.mode,
|
|
17
|
+
orm: inputs.dbConfig.orm,
|
|
18
|
+
database: inputs.selectedDB,
|
|
19
|
+
auth: inputs.useAuth,
|
|
20
|
+
swagger: inputs.useSwagger,
|
|
21
|
+
packageManager: inputs.packageManager,
|
|
22
|
+
docker: inputs.useDocker,
|
|
23
|
+
generatedAt: new Date().toISOString(),
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
try {
|
|
27
|
+
if (!fs.existsSync(configDir)) {
|
|
28
|
+
fs.mkdirSync(configDir, { recursive: true });
|
|
29
|
+
}
|
|
30
|
+
fs.writeFileSync(configFile, JSON.stringify(configData, null, 2));
|
|
31
|
+
} catch (error) {
|
|
32
|
+
logWarning("Could not save project configuration file.");
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
module.exports = { saveProjectConfig };
|