nestcraftx 0.2.4 → 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/.gitattributes +6 -0
- package/.github/ISSUE_TEMPLATE/bug_report.md +33 -0
- package/.github/ISSUE_TEMPLATE/feature_request.md +19 -0
- package/.github/ISSUE_TEMPLATE/pull_request_template.md +24 -0
- package/CHANGELOG.fr.md +97 -97
- package/CHANGELOG.md +98 -98
- package/CLI_USAGE.fr.md +331 -331
- package/CLI_USAGE.md +364 -364
- package/DEMO.fr.md +292 -292
- package/DEMO.md +294 -294
- package/LICENSE +21 -21
- package/MIGRATION_GUIDE.fr.md +127 -127
- package/MIGRATION_GUIDE.md +124 -124
- package/QUICK_START.fr.md +152 -152
- package/QUICK_START.md +169 -169
- package/README.fr.md +653 -659
- package/SECURITY.md +10 -0
- 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/help.js +78 -78
- 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 +41 -41
- package/readme.md +638 -643
- package/utils/cliParser.js +133 -76
- package/utils/colors.js +62 -62
- package/utils/configs/configureDocker.js +120 -120
- package/utils/configs/setupCleanArchitecture.js +563 -557
- package/utils/configs/setupLightArchitecture.js +701 -660
- package/utils/envGenerator.js +122 -122
- package/utils/file-utils/packageJsonUtils.js +49 -55
- 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/lightModeInput.js +460 -460
- 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/projectSetup.js +46 -46
- package/utils/setups/setupAuth.js +973 -926
- package/utils/setups/setupDatabase.js +75 -75
- package/utils/setups/setupLogger.js +69 -59
- package/utils/setups/setupMongoose.js +377 -432
- package/utils/setups/setupPrisma.js +802 -630
- package/utils/setups/setupSwagger.js +97 -88
- 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 +2197 -1762
|
@@ -1,75 +1,75 @@
|
|
|
1
|
-
const { logInfo } = require("../loggers/logInfo");
|
|
2
|
-
const { runCommand } = require("../shell");
|
|
3
|
-
const { setupTypeORM } = require("./orms/typeOrmSetup");
|
|
4
|
-
const { setupMongoose } = require("./setupMongoose");
|
|
5
|
-
const { setupPrisma } = require("./setupPrisma");
|
|
6
|
-
|
|
7
|
-
async function setupDatabase(inputs) {
|
|
8
|
-
logInfo("🚀 Configuring the database...");
|
|
9
|
-
|
|
10
|
-
await runCommand(
|
|
11
|
-
"npm install dotenv",
|
|
12
|
-
"Error installing dotenv automatically, please run it manually now"
|
|
13
|
-
);
|
|
14
|
-
|
|
15
|
-
switch (inputs.selectedDB) {
|
|
16
|
-
case "postgresql":
|
|
17
|
-
await setupPostgres(inputs); // PostgreSQL Configuration
|
|
18
|
-
break;
|
|
19
|
-
case "mysql":
|
|
20
|
-
await setupMySQL(inputs); // MySQL Configuration
|
|
21
|
-
break;
|
|
22
|
-
case "mongodb":
|
|
23
|
-
await setupMongoDB(inputs); // MongoDB Configuration
|
|
24
|
-
break;
|
|
25
|
-
case "sqlite":
|
|
26
|
-
await setupSQLite(inputs); // SQLite Configuration
|
|
27
|
-
break;
|
|
28
|
-
case "firebase":
|
|
29
|
-
await setupFirebase(inputs); // Firebase Configuration
|
|
30
|
-
break;
|
|
31
|
-
case "redis":
|
|
32
|
-
await setupRedis(inputs); // Redis Configuration
|
|
33
|
-
break;
|
|
34
|
-
default:
|
|
35
|
-
throw new Error("Unsupported database.");
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
async function setupMongoDB(inputs) {
|
|
40
|
-
logInfo("Configuring MongoDB...");
|
|
41
|
-
await setupMongoose(inputs);
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
async function setupSQLite(inputs) {
|
|
45
|
-
logInfo("Configuring SQLite..."); // Calls a SQLite-specific script
|
|
46
|
-
await setupSQLiteConfig(inputs);
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
async function setupMySQL(inputs) {
|
|
50
|
-
logInfo("Configuring MySQL..."); // Calls a MySQL-specific script
|
|
51
|
-
await setupMySQLConfig(inputs);
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
async function setupFirebase(inputs) {
|
|
55
|
-
logInfo("Configuring Firebase..."); // Calls a Firebase-specific script
|
|
56
|
-
await setupFirebaseConfig(inputs);
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
async function setupPostgres(inputs) {
|
|
60
|
-
// Checks which ORM was chosen and calls the corresponding function
|
|
61
|
-
if (inputs.dbConfig.orm === "prisma") {
|
|
62
|
-
await setupPrisma(inputs);
|
|
63
|
-
} else if (inputs.dbConfig.orm === "typeorm") {
|
|
64
|
-
await setupTypeORM(inputs);
|
|
65
|
-
} else {
|
|
66
|
-
throw new Error("Unsupported ORM: " + inputs.dbConfig.orm);
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
async function setupRedis(inputs) {
|
|
71
|
-
logInfo("Configuring Redis..."); // Calls a Redis-specific script
|
|
72
|
-
await setupRedisConfig(inputs);
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
module.exports = { setupDatabase };
|
|
1
|
+
const { logInfo } = require("../loggers/logInfo");
|
|
2
|
+
const { runCommand } = require("../shell");
|
|
3
|
+
const { setupTypeORM } = require("./orms/typeOrmSetup");
|
|
4
|
+
const { setupMongoose } = require("./setupMongoose");
|
|
5
|
+
const { setupPrisma } = require("./setupPrisma");
|
|
6
|
+
|
|
7
|
+
async function setupDatabase(inputs) {
|
|
8
|
+
logInfo("🚀 Configuring the database...");
|
|
9
|
+
|
|
10
|
+
await runCommand(
|
|
11
|
+
"npm install dotenv",
|
|
12
|
+
"Error installing dotenv automatically, please run it manually now"
|
|
13
|
+
);
|
|
14
|
+
|
|
15
|
+
switch (inputs.selectedDB) {
|
|
16
|
+
case "postgresql":
|
|
17
|
+
await setupPostgres(inputs); // PostgreSQL Configuration
|
|
18
|
+
break;
|
|
19
|
+
case "mysql":
|
|
20
|
+
await setupMySQL(inputs); // MySQL Configuration
|
|
21
|
+
break;
|
|
22
|
+
case "mongodb":
|
|
23
|
+
await setupMongoDB(inputs); // MongoDB Configuration
|
|
24
|
+
break;
|
|
25
|
+
case "sqlite":
|
|
26
|
+
await setupSQLite(inputs); // SQLite Configuration
|
|
27
|
+
break;
|
|
28
|
+
case "firebase":
|
|
29
|
+
await setupFirebase(inputs); // Firebase Configuration
|
|
30
|
+
break;
|
|
31
|
+
case "redis":
|
|
32
|
+
await setupRedis(inputs); // Redis Configuration
|
|
33
|
+
break;
|
|
34
|
+
default:
|
|
35
|
+
throw new Error("Unsupported database.");
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
async function setupMongoDB(inputs) {
|
|
40
|
+
logInfo("Configuring MongoDB...");
|
|
41
|
+
await setupMongoose(inputs);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
async function setupSQLite(inputs) {
|
|
45
|
+
logInfo("Configuring SQLite..."); // Calls a SQLite-specific script
|
|
46
|
+
await setupSQLiteConfig(inputs);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
async function setupMySQL(inputs) {
|
|
50
|
+
logInfo("Configuring MySQL..."); // Calls a MySQL-specific script
|
|
51
|
+
await setupMySQLConfig(inputs);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
async function setupFirebase(inputs) {
|
|
55
|
+
logInfo("Configuring Firebase..."); // Calls a Firebase-specific script
|
|
56
|
+
await setupFirebaseConfig(inputs);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
async function setupPostgres(inputs) {
|
|
60
|
+
// Checks which ORM was chosen and calls the corresponding function
|
|
61
|
+
if (inputs.dbConfig.orm === "prisma") {
|
|
62
|
+
await setupPrisma(inputs);
|
|
63
|
+
} else if (inputs.dbConfig.orm === "typeorm") {
|
|
64
|
+
await setupTypeORM(inputs);
|
|
65
|
+
} else {
|
|
66
|
+
throw new Error("Unsupported ORM: " + inputs.dbConfig.orm);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
async function setupRedis(inputs) {
|
|
71
|
+
logInfo("Configuring Redis..."); // Calls a Redis-specific script
|
|
72
|
+
await setupRedisConfig(inputs);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
module.exports = { setupDatabase };
|
|
@@ -1,59 +1,69 @@
|
|
|
1
|
-
const fs = require("fs");
|
|
2
|
-
const { updateFile } = require("../userInput");
|
|
3
|
-
|
|
4
|
-
async function setupBootstrapLogger() {
|
|
5
|
-
// Modification de main.ts pour intégrer Swagger
|
|
6
|
-
const mainTsPath = "src/main.ts";
|
|
7
|
-
let mainTs = fs.readFileSync(mainTsPath, "utf8");
|
|
8
|
-
|
|
9
|
-
if (!mainTs.includes("await app.listen")) return mainTs;
|
|
10
|
-
|
|
11
|
-
// Injecte les imports si non présents
|
|
12
|
-
await updateFile({
|
|
13
|
-
path: mainTsPath,
|
|
14
|
-
pattern: "import { ValidationPipe } from '@nestjs/common';",
|
|
15
|
-
replacement: `import { Logger, ValidationPipe } from '@nestjs/common';`,
|
|
16
|
-
});
|
|
17
|
-
/* if (!mainTs.includes("Logger")) {
|
|
18
|
-
} */
|
|
19
|
-
|
|
20
|
-
if (!mainTs.includes("ConfigService")) {
|
|
21
|
-
await updateFile({
|
|
22
|
-
path: mainTsPath,
|
|
23
|
-
pattern: "import { NestFactory } from '@nestjs/core';",
|
|
24
|
-
replacement: `import { NestFactory } from '@nestjs/core';
|
|
25
|
-
import { ConfigService } from '@nestjs/config';`,
|
|
26
|
-
});
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
// Injecte la récupération des variables
|
|
30
|
-
if (!mainTs.includes("const host = configService.get<string>('HOST'")) {
|
|
31
|
-
await updateFile({
|
|
32
|
-
path: mainTsPath,
|
|
33
|
-
pattern: "const app = await NestFactory.create(AppModule);",
|
|
34
|
-
replacement: `const app = await NestFactory.create(AppModule);
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
1
|
+
const fs = require("fs");
|
|
2
|
+
const { updateFile } = require("../userInput");
|
|
3
|
+
|
|
4
|
+
async function setupBootstrapLogger() {
|
|
5
|
+
// Modification de main.ts pour intégrer Swagger
|
|
6
|
+
const mainTsPath = "src/main.ts";
|
|
7
|
+
let mainTs = fs.readFileSync(mainTsPath, "utf8");
|
|
8
|
+
|
|
9
|
+
if (!mainTs.includes("await app.listen")) return mainTs;
|
|
10
|
+
|
|
11
|
+
// Injecte les imports si non présents
|
|
12
|
+
await updateFile({
|
|
13
|
+
path: mainTsPath,
|
|
14
|
+
pattern: "import { ValidationPipe } from '@nestjs/common';",
|
|
15
|
+
replacement: `import { Logger, ValidationPipe } from '@nestjs/common';`,
|
|
16
|
+
});
|
|
17
|
+
/* if (!mainTs.includes("Logger")) {
|
|
18
|
+
} */
|
|
19
|
+
|
|
20
|
+
if (!mainTs.includes("ConfigService")) {
|
|
21
|
+
await updateFile({
|
|
22
|
+
path: mainTsPath,
|
|
23
|
+
pattern: "import { NestFactory } from '@nestjs/core';",
|
|
24
|
+
replacement: `import { NestFactory } from '@nestjs/core';
|
|
25
|
+
import { ConfigService } from '@nestjs/config';`,
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
// Injecte la récupération des variables
|
|
30
|
+
if (!mainTs.includes("const host = configService.get<string>('HOST'")) {
|
|
31
|
+
await updateFile({
|
|
32
|
+
path: mainTsPath,
|
|
33
|
+
pattern: "const app = await NestFactory.create(AppModule);",
|
|
34
|
+
replacement: `const app = await NestFactory.create(AppModule);
|
|
35
|
+
|
|
36
|
+
// Global validation & transformation
|
|
37
|
+
app.useGlobalPipes(
|
|
38
|
+
new ValidationPipe({
|
|
39
|
+
transform: true,
|
|
40
|
+
whitelist: true,
|
|
41
|
+
forbidNonWhitelisted: true,
|
|
42
|
+
}),
|
|
43
|
+
);
|
|
44
|
+
|
|
45
|
+
const configService = app.get(ConfigService);
|
|
46
|
+
const port = configService.get<number>('PORT', 3000);
|
|
47
|
+
const host = configService.get<string>('HOST', '0.0.0.0');`,
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
// Remplace le démarrage de l'app par le bloc stylisé
|
|
52
|
+
return await updateFile({
|
|
53
|
+
path: mainTsPath,
|
|
54
|
+
pattern: "await app.listen(process.env.PORT ?? 3000);",
|
|
55
|
+
replacement: `try {
|
|
56
|
+
await app.listen(port, host);
|
|
57
|
+
|
|
58
|
+
const logger = new Logger('Bootstrap');
|
|
59
|
+
logger.log(\`🚀 Application running on: \${await app.getUrl()}\`);
|
|
60
|
+
logger.log(\`🌐 Environment: \${process.env.NODE_ENV || 'development'}\`);
|
|
61
|
+
logger.log(\`📡 Listening on \${host}:\${port}\`);
|
|
62
|
+
} catch (error) {
|
|
63
|
+
const logger = new Logger('Bootstrap');
|
|
64
|
+
logger.error('❌ Failed to start the server', error);
|
|
65
|
+
process.exit(1);
|
|
66
|
+
}`,
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
module.exports = { setupBootstrapLogger };
|