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.
Files changed (63) hide show
  1. package/.gitattributes +6 -0
  2. package/.github/ISSUE_TEMPLATE/bug_report.md +33 -0
  3. package/.github/ISSUE_TEMPLATE/feature_request.md +19 -0
  4. package/.github/ISSUE_TEMPLATE/pull_request_template.md +24 -0
  5. package/CHANGELOG.fr.md +97 -97
  6. package/CHANGELOG.md +98 -98
  7. package/CLI_USAGE.fr.md +331 -331
  8. package/CLI_USAGE.md +364 -364
  9. package/DEMO.fr.md +292 -292
  10. package/DEMO.md +294 -294
  11. package/LICENSE +21 -21
  12. package/MIGRATION_GUIDE.fr.md +127 -127
  13. package/MIGRATION_GUIDE.md +124 -124
  14. package/QUICK_START.fr.md +152 -152
  15. package/QUICK_START.md +169 -169
  16. package/README.fr.md +653 -659
  17. package/SECURITY.md +10 -0
  18. package/bin/nestcraft.js +84 -64
  19. package/commands/demo.js +333 -330
  20. package/commands/generate.js +93 -0
  21. package/commands/generateConf.js +91 -0
  22. package/commands/help.js +78 -78
  23. package/commands/info.js +48 -48
  24. package/commands/new.js +338 -335
  25. package/commands/start.js +19 -19
  26. package/commands/test.js +7 -7
  27. package/package.json +41 -41
  28. package/readme.md +638 -643
  29. package/utils/cliParser.js +133 -76
  30. package/utils/colors.js +62 -62
  31. package/utils/configs/configureDocker.js +120 -120
  32. package/utils/configs/setupCleanArchitecture.js +563 -557
  33. package/utils/configs/setupLightArchitecture.js +701 -660
  34. package/utils/envGenerator.js +122 -122
  35. package/utils/file-utils/packageJsonUtils.js +49 -55
  36. package/utils/file-utils/saveProjectConfig.js +36 -0
  37. package/utils/fullModeInput.js +607 -607
  38. package/utils/generators/application/dtoUpdater.js +54 -0
  39. package/utils/generators/cleanModuleGenerator.js +475 -0
  40. package/utils/generators/database/setupDatabase.js +31 -0
  41. package/utils/generators/domain/entityUpdater.js +78 -0
  42. package/utils/generators/infrastructure/mapperUpdater.js +65 -0
  43. package/utils/generators/lightModuleGenerator.js +131 -0
  44. package/utils/generators/relation/relation.engine.js +64 -0
  45. package/utils/interactive/askEntityInputs.js +165 -0
  46. package/utils/lightModeInput.js +460 -460
  47. package/utils/loggers/logError.js +7 -7
  48. package/utils/loggers/logInfo.js +7 -7
  49. package/utils/loggers/logSuccess.js +7 -7
  50. package/utils/loggers/logWarning.js +7 -7
  51. package/utils/setups/orms/typeOrmSetup.js +630 -630
  52. package/utils/setups/projectSetup.js +46 -46
  53. package/utils/setups/setupAuth.js +973 -926
  54. package/utils/setups/setupDatabase.js +75 -75
  55. package/utils/setups/setupLogger.js +69 -59
  56. package/utils/setups/setupMongoose.js +377 -432
  57. package/utils/setups/setupPrisma.js +802 -630
  58. package/utils/setups/setupSwagger.js +97 -88
  59. package/utils/shell.js +32 -32
  60. package/utils/spinner.js +57 -57
  61. package/utils/systemCheck.js +124 -124
  62. package/utils/userInput.js +421 -421
  63. package/utils/utils.js +2197 -1762
@@ -1,88 +1,97 @@
1
- const fs = require("fs");
2
- const { execSync } = require("child_process");
3
- const { logInfo } = require("../loggers/logInfo");
4
- const { logSuccess } = require("../loggers/logSuccess");
5
-
6
- async function setupSwagger(inputs) {
7
- logInfo("Installation et Configuration de Swagger...");
8
-
9
- // installation de swagger
10
- try {
11
- execSync("npm install @nestjs/swagger swagger-ui-express", {
12
- stdio: "inherit",
13
- });
14
- } catch (error) {
15
- console.error("❌ Échec de l'installation de Swagger :", error);
16
- process.exit(1);
17
- }
18
-
19
- // Modification de main.ts pour intégrer Swagger
20
- const mainTsPath = "src/main.ts";
21
- let mainTs = fs.readFileSync(mainTsPath, "utf8");
22
-
23
- if (!mainTs.includes("DocumentBuilder")) {
24
- // Ajout des imports Swagger et Logger si nécessaires
25
- mainTs = mainTs.replace(
26
- "import { NestFactory",
27
- "import { DocumentBuilder, SwaggerModule } from '@nestjs/swagger';\nimport { ConfigService } from '@nestjs/config';\nimport { Logger } from '@nestjs/common';\nimport { NestFactory"
28
- );
29
-
30
- // retirer
31
- // Configuration de Swagger directement dans bootstrap
32
- mainTs = mainTs.replace(
33
- "const app = await NestFactory.create(AppModule);",
34
- ""
35
- );
36
-
37
- // Configuration de Swagger directement dans bootstrap
38
- mainTs = mainTs.replace(
39
- "async function bootstrap() {",
40
- `async function bootstrap() {
41
- const app = await NestFactory.create(AppModule);
42
-
43
- // Configuration Swagger
44
- const config = new DocumentBuilder()
45
- .setTitle('${inputs.title}')
46
- .setDescription('${inputs.description}')
47
- .setVersion('${inputs.version}')
48
- .addBearerAuth()
49
- .build();
50
-
51
- const document = SwaggerModule.createDocument(app, config);
52
- SwaggerModule.setup('${inputs.endpoint}', app, document,{
53
- swaggerOptions: {
54
- persistAuthorization: true,
55
- },
56
- });
57
-
58
- const configService = app.get(ConfigService);
59
- const port = configService.get<number>('PORT', 3000);
60
- const host = configService.get<string>('HOST', '0.0.0.0');
61
- `
62
- );
63
-
64
- // Ajout du bloc try/catch pour le démarrage de l'application
65
- if (mainTs.includes("await app.listen")) {
66
- mainTs = mainTs.replace(
67
- "await app.listen(process.env.PORT ?? 3000);",
68
- `try {
69
- await app.listen(port, host);
70
-
71
- const logger = new Logger('Bootstrap');
72
- logger.log(\`🚀 Application running on: \${await app.getUrl()}/${inputs.endpoint}\`);
73
- logger.log(\`🌐 Environment: \${process.env.NODE_ENV || 'development'}\`);
74
- logger.log(\`📡 Listening on \${host}:\${port}\`);
75
- } catch (error) {
76
- const logger = new Logger('Bootstrap');
77
- logger.error('❌ Failed to start the server', error);
78
- process.exit(1);
79
- }`
80
- );
81
- }
82
- }
83
-
84
- fs.writeFileSync(mainTsPath, mainTs);
85
- logSuccess(" Swagger configuré avec succès !");
86
- }
87
-
88
- module.exports = { setupSwagger };
1
+ const fs = require("fs");
2
+ const { execSync } = require("child_process");
3
+ const { logInfo } = require("../loggers/logInfo");
4
+ const { logSuccess } = require("../loggers/logSuccess");
5
+
6
+ async function setupSwagger(inputs) {
7
+ logInfo("Installation et Configuration de Swagger...");
8
+
9
+ // installation de swagger
10
+ try {
11
+ execSync("npm install @nestjs/swagger swagger-ui-express", {
12
+ stdio: "inherit",
13
+ });
14
+ } catch (error) {
15
+ console.error("❌ Échec de l'installation de Swagger :", error);
16
+ process.exit(1);
17
+ }
18
+
19
+ // Modification de main.ts pour intégrer Swagger
20
+ const mainTsPath = "src/main.ts";
21
+ let mainTs = fs.readFileSync(mainTsPath, "utf8");
22
+
23
+ if (!mainTs.includes("DocumentBuilder")) {
24
+ // Ajout des imports Swagger et Logger si nécessaires
25
+ mainTs = mainTs.replace(
26
+ "import { NestFactory",
27
+ "import { DocumentBuilder, SwaggerModule } from '@nestjs/swagger';\nimport { ConfigService } from '@nestjs/config';\nimport { Logger } from '@nestjs/common';\nimport { NestFactory"
28
+ );
29
+
30
+ // retirer
31
+ // Configuration de Swagger directement dans bootstrap
32
+ mainTs = mainTs.replace(
33
+ "const app = await NestFactory.create(AppModule);",
34
+ ""
35
+ );
36
+
37
+ // Configuration de Swagger directement dans bootstrap
38
+ mainTs = mainTs.replace(
39
+ "async function bootstrap() {",
40
+ `async function bootstrap() {
41
+ const app = await NestFactory.create(AppModule);
42
+
43
+ // Global validation & transformation
44
+ app.useGlobalPipes(
45
+ new ValidationPipe({
46
+ transform: true,
47
+ whitelist: true,
48
+ forbidNonWhitelisted: true,
49
+ }),
50
+ );
51
+
52
+ // Configuration Swagger
53
+ const config = new DocumentBuilder()
54
+ .setTitle('${inputs.title}')
55
+ .setDescription('${inputs.description}')
56
+ .setVersion('${inputs.version}')
57
+ .addBearerAuth()
58
+ .build();
59
+
60
+ const document = SwaggerModule.createDocument(app, config);
61
+ SwaggerModule.setup('${inputs.endpoint}', app, document,{
62
+ swaggerOptions: {
63
+ persistAuthorization: true,
64
+ },
65
+ });
66
+
67
+ const configService = app.get(ConfigService);
68
+ const port = configService.get<number>('PORT', 3000);
69
+ const host = configService.get<string>('HOST', '0.0.0.0');
70
+ `
71
+ );
72
+
73
+ // Ajout du bloc try/catch pour le démarrage de l'application
74
+ if (mainTs.includes("await app.listen")) {
75
+ mainTs = mainTs.replace(
76
+ "await app.listen(process.env.PORT ?? 3000);",
77
+ `try {
78
+ await app.listen(port, host);
79
+
80
+ const logger = new Logger('Bootstrap');
81
+ logger.log(\`🚀 Application running on: \${await app.getUrl()}/${inputs.endpoint}\`);
82
+ logger.log(\`🌐 Environment: \${process.env.NODE_ENV || 'development'}\`);
83
+ logger.log(\`📡 Listening on \${host}:\${port}\`);
84
+ } catch (error) {
85
+ const logger = new Logger('Bootstrap');
86
+ logger.error('❌ Failed to start the server', error);
87
+ process.exit(1);
88
+ }`
89
+ );
90
+ }
91
+ }
92
+
93
+ fs.writeFileSync(mainTsPath, mainTs);
94
+ logSuccess(" Swagger configuré avec succès !");
95
+ }
96
+
97
+ module.exports = { setupSwagger };
package/utils/shell.js CHANGED
@@ -1,32 +1,32 @@
1
- const { execSync } = require("child_process");
2
- const fs = require("fs");
3
- const { logError } = require("./loggers/logError");
4
- const { spinner } = require("./spinner");
5
-
6
- async function runCommand(command, errorMessage, spinnerText = null) {
7
- const spin = spinnerText ? spinner(spinnerText) : null;
8
-
9
- try {
10
- if (spin) spin.start();
11
- execSync(command, { stdio: spinnerText ? "pipe" : "inherit" });
12
- if (spin) spin.succeed(spinnerText);
13
- } catch (error) {
14
- if (spin) spin.fail(errorMessage);
15
- logError(errorMessage);
16
- fs.appendFileSync(
17
- "setup.log",
18
- `[Erreur] ${errorMessage}: ${error.message}\n`
19
- );
20
- process.exit(1);
21
- }
22
- }
23
-
24
- async function runCommandSilent(command) {
25
- try {
26
- return execSync(command, { stdio: "pipe" }).toString();
27
- } catch (error) {
28
- return null;
29
- }
30
- }
31
-
32
- module.exports = { runCommand, runCommandSilent };
1
+ const { execSync } = require("child_process");
2
+ const fs = require("fs");
3
+ const { logError } = require("./loggers/logError");
4
+ const { spinner } = require("./spinner");
5
+
6
+ async function runCommand(command, errorMessage, spinnerText = null) {
7
+ const spin = spinnerText ? spinner(spinnerText) : null;
8
+
9
+ try {
10
+ if (spin) spin.start();
11
+ execSync(command, { stdio: spinnerText ? "pipe" : "inherit" });
12
+ if (spin) spin.succeed(spinnerText);
13
+ } catch (error) {
14
+ if (spin) spin.fail(errorMessage);
15
+ logError(errorMessage);
16
+ fs.appendFileSync(
17
+ "setup.log",
18
+ `[Erreur] ${errorMessage}: ${error.message}\n`,
19
+ );
20
+ process.exit(1);
21
+ }
22
+ }
23
+
24
+ async function runCommandSilent(command) {
25
+ try {
26
+ return execSync(command, { stdio: "pipe" }).toString();
27
+ } catch (error) {
28
+ return null;
29
+ }
30
+ }
31
+
32
+ module.exports = { runCommand, runCommandSilent };
package/utils/spinner.js CHANGED
@@ -1,57 +1,57 @@
1
- const { info, success, error: errorColor } = require('./colors');
2
-
3
- class Spinner {
4
- constructor(text = 'Loading...') {
5
- this.text = text;
6
- this.frames = ['⠋', '⠙', '⠹', '⠸', '⠼', '⠴', '⠦', '⠧', '⠇', '⠏'];
7
- this.currentFrame = 0;
8
- this.intervalId = null;
9
- this.isSpinning = false;
10
- }
11
-
12
- start() {
13
- if (this.isSpinning) return;
14
-
15
- this.isSpinning = true;
16
- this.currentFrame = 0;
17
-
18
- process.stdout.write('\n');
19
-
20
- this.intervalId = setInterval(() => {
21
- const frame = this.frames[this.currentFrame];
22
- process.stdout.write(`\r${info(frame)} ${this.text}`);
23
- this.currentFrame = (this.currentFrame + 1) % this.frames.length;
24
- }, 80);
25
- }
26
-
27
- stop() {
28
- if (!this.isSpinning) return;
29
-
30
- this.isSpinning = false;
31
- if (this.intervalId) {
32
- clearInterval(this.intervalId);
33
- this.intervalId = null;
34
- }
35
- process.stdout.write('\r' + ' '.repeat(this.text.length + 10) + '\r');
36
- }
37
-
38
- succeed(text) {
39
- this.stop();
40
- console.log(success('✓') + ` ${text || this.text}`);
41
- }
42
-
43
- fail(text) {
44
- this.stop();
45
- console.log(errorColor('✗') + ` ${text || this.text}`);
46
- }
47
-
48
- update(text) {
49
- this.text = text;
50
- }
51
- }
52
-
53
- function spinner(text) {
54
- return new Spinner(text);
55
- }
56
-
57
- module.exports = { Spinner, spinner };
1
+ const { info, success, error: errorColor } = require('./colors');
2
+
3
+ class Spinner {
4
+ constructor(text = 'Loading...') {
5
+ this.text = text;
6
+ this.frames = ['⠋', '⠙', '⠹', '⠸', '⠼', '⠴', '⠦', '⠧', '⠇', '⠏'];
7
+ this.currentFrame = 0;
8
+ this.intervalId = null;
9
+ this.isSpinning = false;
10
+ }
11
+
12
+ start() {
13
+ if (this.isSpinning) return;
14
+
15
+ this.isSpinning = true;
16
+ this.currentFrame = 0;
17
+
18
+ process.stdout.write('\n');
19
+
20
+ this.intervalId = setInterval(() => {
21
+ const frame = this.frames[this.currentFrame];
22
+ process.stdout.write(`\r${info(frame)} ${this.text}`);
23
+ this.currentFrame = (this.currentFrame + 1) % this.frames.length;
24
+ }, 80);
25
+ }
26
+
27
+ stop() {
28
+ if (!this.isSpinning) return;
29
+
30
+ this.isSpinning = false;
31
+ if (this.intervalId) {
32
+ clearInterval(this.intervalId);
33
+ this.intervalId = null;
34
+ }
35
+ process.stdout.write('\r' + ' '.repeat(this.text.length + 10) + '\r');
36
+ }
37
+
38
+ succeed(text) {
39
+ this.stop();
40
+ console.log(success('✓') + ` ${text || this.text}`);
41
+ }
42
+
43
+ fail(text) {
44
+ this.stop();
45
+ console.log(errorColor('✗') + ` ${text || this.text}`);
46
+ }
47
+
48
+ update(text) {
49
+ this.text = text;
50
+ }
51
+ }
52
+
53
+ function spinner(text) {
54
+ return new Spinner(text);
55
+ }
56
+
57
+ module.exports = { Spinner, spinner };
@@ -1,124 +1,124 @@
1
- const { execSync } = require("child_process");
2
- const fs = require("fs");
3
-
4
- function checkCommand(cmd) {
5
- try {
6
- execSync(`${cmd} --version`, { stdio: "pipe" });
7
- return true;
8
- } catch {
9
- return false;
10
- }
11
- }
12
-
13
- function getVersion(cmd) {
14
- try {
15
- const output = execSync(`${cmd} --version`, {
16
- encoding: "utf8",
17
- stdio: "pipe",
18
- });
19
- return output.trim().split("\n")[0];
20
- } catch {
21
- return "not installed";
22
- }
23
- }
24
-
25
- function checkSystemRequirements() {
26
- const checks = {
27
- node: {
28
- installed: checkCommand("node"),
29
- version: getVersion("node"),
30
- },
31
- npm: {
32
- installed: checkCommand("npm"),
33
- version: getVersion("npm"),
34
- },
35
- nestCli: {
36
- installed: checkCommand("nest"),
37
- version: getVersion("nest"),
38
- },
39
- git: {
40
- installed: checkCommand("git"),
41
- version: getVersion("git"),
42
- },
43
- docker: {
44
- installed: checkCommand("docker"),
45
- version: getVersion("docker"),
46
- },
47
- npx: {
48
- installed: checkCommand("npx"),
49
- version: "npx available",
50
- },
51
- };
52
-
53
- const envExists = fs.existsSync(".env");
54
-
55
- let postgresStatus = "not detected locally";
56
- if (envExists) {
57
- try {
58
- const envContent = fs.readFileSync(".env", "utf8");
59
- if (
60
- envContent.includes("POSTGRES_") ||
61
- envContent.includes("DATABASE_URL")
62
- ) {
63
- postgresStatus = "configured in .env";
64
- }
65
- } catch {}
66
- }
67
-
68
- checks.postgres = {
69
- installed: false,
70
- version: postgresStatus,
71
- };
72
-
73
- return checks;
74
- }
75
-
76
- function displaySystemCheck() {
77
- console.log("\n🔍 NestCraftX System Check");
78
- console.log("--------------------------------");
79
-
80
- const checks = checkSystemRequirements();
81
- let successCount = 0;
82
- let totalCount = 0;
83
-
84
- Object.entries(checks).forEach(([name, info]) => {
85
- totalCount++;
86
- const displayName =
87
- name.charAt(0).toUpperCase() + name.slice(1).replace(/([A-Z])/g, " $1");
88
-
89
- if (info.installed || info.version.includes("configured")) {
90
- console.log(`✅ ${displayName}: ${info.version}`);
91
- successCount++;
92
- } else {
93
- console.log(`⚠️ ${displayName}: ${info.version}`);
94
- }
95
- });
96
-
97
- console.log("--------------------------------");
98
-
99
- const status =
100
- successCount === totalCount
101
- ? "✅ Ready"
102
- : successCount >= totalCount - 2
103
- ? "⚠️ Almost Ready"
104
- : "❌ Missing Requirements";
105
-
106
- console.log(`System status: ${status} (${successCount}/${totalCount} OK)`);
107
-
108
- if (successCount < totalCount) {
109
- console.log("\n💡 Tips:");
110
- if (!checks.nestCli.installed) {
111
- console.log(" - Install Nest CLI: npm install -g @nestjs/cli");
112
- }
113
- if (!checks.docker.installed) {
114
- console.log(" - Install Docker: https://docs.docker.com/get-docker/");
115
- }
116
- if (!checks.git.installed) {
117
- console.log(" - Install Git: https://git-scm.com/downloads");
118
- }
119
- }
120
-
121
- console.log("");
122
- }
123
-
124
- module.exports = { checkSystemRequirements, displaySystemCheck };
1
+ const { execSync } = require("child_process");
2
+ const fs = require("fs");
3
+
4
+ function checkCommand(cmd) {
5
+ try {
6
+ execSync(`${cmd} --version`, { stdio: "pipe" });
7
+ return true;
8
+ } catch {
9
+ return false;
10
+ }
11
+ }
12
+
13
+ function getVersion(cmd) {
14
+ try {
15
+ const output = execSync(`${cmd} --version`, {
16
+ encoding: "utf8",
17
+ stdio: "pipe",
18
+ });
19
+ return output.trim().split("\n")[0];
20
+ } catch {
21
+ return "not installed";
22
+ }
23
+ }
24
+
25
+ function checkSystemRequirements() {
26
+ const checks = {
27
+ node: {
28
+ installed: checkCommand("node"),
29
+ version: getVersion("node"),
30
+ },
31
+ npm: {
32
+ installed: checkCommand("npm"),
33
+ version: getVersion("npm"),
34
+ },
35
+ nestCli: {
36
+ installed: checkCommand("nest"),
37
+ version: getVersion("nest"),
38
+ },
39
+ git: {
40
+ installed: checkCommand("git"),
41
+ version: getVersion("git"),
42
+ },
43
+ docker: {
44
+ installed: checkCommand("docker"),
45
+ version: getVersion("docker"),
46
+ },
47
+ npx: {
48
+ installed: checkCommand("npx"),
49
+ version: "npx available",
50
+ },
51
+ };
52
+
53
+ const envExists = fs.existsSync(".env");
54
+
55
+ let postgresStatus = "not detected locally";
56
+ if (envExists) {
57
+ try {
58
+ const envContent = fs.readFileSync(".env", "utf8");
59
+ if (
60
+ envContent.includes("POSTGRES_") ||
61
+ envContent.includes("DATABASE_URL")
62
+ ) {
63
+ postgresStatus = "configured in .env";
64
+ }
65
+ } catch {}
66
+ }
67
+
68
+ checks.postgres = {
69
+ installed: false,
70
+ version: postgresStatus,
71
+ };
72
+
73
+ return checks;
74
+ }
75
+
76
+ function displaySystemCheck() {
77
+ console.log("\n🔍 NestCraftX System Check");
78
+ console.log("--------------------------------");
79
+
80
+ const checks = checkSystemRequirements();
81
+ let successCount = 0;
82
+ let totalCount = 0;
83
+
84
+ Object.entries(checks).forEach(([name, info]) => {
85
+ totalCount++;
86
+ const displayName =
87
+ name.charAt(0).toUpperCase() + name.slice(1).replace(/([A-Z])/g, " $1");
88
+
89
+ if (info.installed || info.version.includes("configured")) {
90
+ console.log(`✅ ${displayName}: ${info.version}`);
91
+ successCount++;
92
+ } else {
93
+ console.log(`⚠️ ${displayName}: ${info.version}`);
94
+ }
95
+ });
96
+
97
+ console.log("--------------------------------");
98
+
99
+ const status =
100
+ successCount === totalCount
101
+ ? "✅ Ready"
102
+ : successCount >= totalCount - 2
103
+ ? "⚠️ Almost Ready"
104
+ : "❌ Missing Requirements";
105
+
106
+ console.log(`System status: ${status} (${successCount}/${totalCount} OK)`);
107
+
108
+ if (successCount < totalCount) {
109
+ console.log("\n💡 Tips:");
110
+ if (!checks.nestCli.installed) {
111
+ console.log(" - Install Nest CLI: npm install -g @nestjs/cli");
112
+ }
113
+ if (!checks.docker.installed) {
114
+ console.log(" - Install Docker: https://docs.docker.com/get-docker/");
115
+ }
116
+ if (!checks.git.installed) {
117
+ console.log(" - Install Git: https://git-scm.com/downloads");
118
+ }
119
+ }
120
+
121
+ console.log("");
122
+ }
123
+
124
+ module.exports = { checkSystemRequirements, displaySystemCheck };