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
@@ -0,0 +1,93 @@
1
+ const fs = require("fs");
2
+ const path = require("path");
3
+ const { logError } = require("../utils/loggers/logError");
4
+ const { logInfo } = require("../utils/loggers/logInfo");
5
+ const { logWarning } = require("../utils/loggers/logWarning");
6
+ const generateCleanModule = require("../utils/generators/cleanModuleGenerator");
7
+ const { askEntityInputs } = require("../utils/interactive/askEntityInputs");
8
+ const lightModuleGenerator = require("../utils/generators/lightModuleGenerator");
9
+
10
+ async function generate(subCommand, targetName, flags) {
11
+ // 1. Localisation of config file
12
+ const configPath = path.join(process.cwd(), ".nestcraftx", ".nestcraftxrc");
13
+
14
+ // 2. Existing Vérification
15
+ if (!fs.existsSync(configPath)) {
16
+ logError("Aucun fichier de configuration NestcraftX trouvé.");
17
+ logInfo(
18
+ "Assurez-vous d'être à la racine du projet ou lancez 'nestcraftx g-conf' ou 'nestcraftx generate-conf' pour le restaurer.",
19
+ );
20
+ return;
21
+ }
22
+
23
+ // 3. Lecture et parsing de la configuration complète
24
+ let projectConfig;
25
+ try {
26
+ const rawData = fs.readFileSync(configPath, "utf8");
27
+ projectConfig = JSON.parse(rawData);
28
+ } catch (err) {
29
+ logError(
30
+ "Erreur lors de la lecture du fichier .nestcraftxrc. Le JSON est peut-être corrompu.\nlancez 'nestcraftx generate-conf' ou 'nestcraftx g-conf' pour le restaurer",
31
+ );
32
+ return;
33
+ }
34
+
35
+ // 4. Extraction des infos clés pour les passer aux générateurs
36
+ const { mode, orm, auth, swagger, database } = projectConfig;
37
+
38
+ // 5. Dispatcher vers les implémentations
39
+ switch (subCommand) {
40
+ case "module":
41
+ if (!targetName) {
42
+ logWarning(
43
+ "⚠️ Veuillez préciser le nom du module (ex: nestcraftx g module Product)",
44
+ );
45
+ return;
46
+ }
47
+
48
+ // Ici, on passera projectConfig complet pour avoir accès à swagger, auth, etc.
49
+ await handleModuleGeneration(targetName, projectConfig);
50
+ break;
51
+
52
+ case "auth":
53
+ if (auth) {
54
+ logWarning("L'authentification est déjà configurée dans ce projet.");
55
+ return;
56
+ }
57
+ // Logique pour ajouter l'auth après coup
58
+ await handleAuthGeneration(projectConfig);
59
+ break;
60
+
61
+ default:
62
+ logError(`Sous-commande inconnue : ${subCommand}`);
63
+ console.log("\nUtilisations possibles :");
64
+ console.log(" nestcraftx g module <name>");
65
+ console.log(" nestcraftx g auth");
66
+ break;
67
+ }
68
+ }
69
+
70
+ // --- Fonctions de redirection (prochainement implémentées) ---
71
+
72
+ async function handleModuleGeneration(name, config) {
73
+ logInfo(
74
+ `🚀 Générating module '${name}' (${config.mode.toUpperCase()} | ${config.orm.toUpperCase()})...`,
75
+ );
76
+ // 1. Demander les champs de l'entité interactivement
77
+ const entityData = await askEntityInputs(name);
78
+
79
+ if (config.mode === "full") {
80
+ await generateCleanModule(name, config, entityData);
81
+ } else {
82
+ await lightModuleGenerator(entityData, config);
83
+ }
84
+ }
85
+
86
+ async function handleAuthGeneration(config) {
87
+ // On réutilisera ton script setupAuth corrigé
88
+ // await require('../utils/setups/setupAuth')(config);
89
+
90
+ logInfo("🚀 Generating module auth...");
91
+ }
92
+
93
+ module.exports = generate;
@@ -0,0 +1,91 @@
1
+ const fs = require("fs");
2
+ const path = require("path");
3
+ const { logSuccess } = require("../utils/loggers/logSuccess");
4
+ const { logInfo } = require("../utils/loggers/logInfo");
5
+ const { logError } = require("../utils/loggers/logError");
6
+
7
+ async function generateConf() {
8
+ logInfo("🔍 Analyse du projet pour reconstruire la configuration...");
9
+
10
+ const root = process.cwd();
11
+ const pkgPath = path.join(root, "package.json");
12
+
13
+ if (!fs.existsSync(pkgPath)) {
14
+ logError(
15
+ "❌ Erreur : Aucun package.json trouvé. Es-tu à la racine d'un projet NestJS ?",
16
+ );
17
+ return;
18
+ }
19
+
20
+ const pkg = JSON.parse(fs.readFileSync(pkgPath, "utf8"));
21
+ const deps = { ...pkg.dependencies, ...pkg.devDependencies };
22
+
23
+ // 1. Détecter le Mode (Architecture)
24
+ // On vérifie si la structure Clean Arch existe
25
+ const isFull =
26
+ fs.existsSync(path.join(root, "src", "auth", "application")) ||
27
+ fs.existsSync(path.join(root, "src", "common", "domain"));
28
+ const mode = isFull ? "full" : "light";
29
+
30
+ // 2. Détecter l'ORM
31
+ let orm = "prisma"; // par défaut
32
+ if (deps["@nestjs/mongoose"] || deps["mongoose"]) {
33
+ orm = "mongoose";
34
+ } else if (deps["@nestjs/typeorm"] || deps["typeorm"]) {
35
+ orm = "typeorm";
36
+ } else if (fs.existsSync(path.join(root, "prisma"))) {
37
+ orm = "prisma";
38
+ }
39
+
40
+ // 3. Détecter les options
41
+ const hasAuth = !!(
42
+ deps["@nestjs/passport"] || fs.existsSync(path.join(root, "src", "auth"))
43
+ );
44
+ const hasSwagger = !!deps["@nestjs/swagger"];
45
+ const hasDocker =
46
+ fs.existsSync(path.join(root, "Dockerfile")) ||
47
+ fs.existsSync(path.join(root, "docker-compose.yml"));
48
+
49
+ // 4. Déterminer le Gestionnaire de paquets
50
+ const packageManager = fs.existsSync(path.join(root, "yarn.lock"))
51
+ ? "yarn"
52
+ : "npm";
53
+
54
+ // 5. Détecter la DB (Approximation basée sur l'ORM ou les drivers)
55
+ let selectedDB = "postgresql";
56
+ if (orm === "mongoose") selectedDB = "mongodb";
57
+ if (deps["mysql2"]) selectedDB = "mysql";
58
+
59
+ // Construction de l'objet de configuration
60
+ const configData = {
61
+ name: pkg.name || "restored-project",
62
+ mode: mode,
63
+ orm: orm,
64
+ database: selectedDB,
65
+ auth: hasAuth,
66
+ swagger: hasSwagger,
67
+ packageManager: packageManager,
68
+ docker: hasDocker,
69
+ restoredAt: new Date().toISOString(),
70
+ };
71
+
72
+ // 6. Sauvegarde du fichier
73
+ const configDir = path.join(root, ".nestcraftx");
74
+ const configFile = path.join(configDir, ".nestcraftxrc");
75
+
76
+ try {
77
+ if (!fs.existsSync(configDir)) {
78
+ fs.mkdirSync(configDir, { recursive: true });
79
+ }
80
+ fs.writeFileSync(configFile, JSON.stringify(configData, null, 2));
81
+
82
+ logSuccess("✅ Fichier .nestcraftxrc reconstruit avec succès !");
83
+ console.table(configData);
84
+ } catch (error) {
85
+ logError(
86
+ `❌ Impossible de sauvegarder la configuration : ${error.message}`,
87
+ );
88
+ }
89
+ }
90
+
91
+ module.exports = generateConf;
package/commands/help.js CHANGED
@@ -1,78 +1,78 @@
1
- async function helpCommand() {
2
- console.log(`
3
- ╔═══════════════════════════════════════════════════════════╗
4
- ║ ║
5
- ║ 🌟 NestCraftX CLI v0.2.4 🌟 ║
6
- ║ Clean Architecture Generator for NestJS ║
7
- ║ ║
8
- ╚═══════════════════════════════════════════════════════════╝
9
-
10
- 📦 MAIN COMMANDS:
11
-
12
- nestcraftx new <project-name> [options]
13
- Creates a new NestJS project with Clean Architecture
14
-
15
- Options:
16
- --light Quick Mode (minimal configuration)
17
- --orm <name> Select the ORM (prisma|typeorm|mongoose)
18
- --auth Add JWT authentication
19
- --swagger Add Swagger UI
20
- --docker Generate Docker files
21
-
22
- Examples:
23
- nestcraftx new my-app
24
- nestcraftx new blog-api --light --orm prisma --auth --swagger
25
- nestcraftx new shop --orm typeorm --auth
26
-
27
- nestcraftx demo [options]
28
- Generates a full demo project (blog with users, posts, comments)
29
- Options:
30
- --light Simplified MVP Mode
31
- --docker Adds Docker
32
- --auth Adds JWT Auth
33
- --swagger Adds Swagger UI
34
-
35
- nestcraftx test
36
- Checks system environment (Node, npm, Nest CLI, Docker, etc.)
37
-
38
- nestcraftx info
39
- Displays CLI information and features
40
-
41
- nestcraftx start
42
- Launches the interactive generator (legacy mode)
43
-
44
- 📚 OTHER COMMANDS:
45
-
46
- nestcraftx --version, -v CLI Version
47
- nestcraftx --help, -h Displays this help guide
48
-
49
- 🎯 MODES:
50
-
51
- Light Mode - Quick configuration for POCs and small projects
52
- Full Mode - Complete configuration with all options
53
-
54
- 🛠️ SUPPORTED ORMS:
55
-
56
- • Prisma - Modern and type-safe ORM (recommended)
57
- • TypeORM - Full-featured ORM with decorators
58
- • Mongoose - ODM for MongoDB
59
-
60
- ✨ FEATURES:
61
-
62
- ✅ Clean Architecture with DDD
63
- ✅ Repository Pattern & Use Cases
64
- ✅ Integrated JWT Auth
65
- ✅ Automatic Swagger Documentation
66
- ✅ Docker & Docker Compose
67
- ✅ Entity and Relationship Generation
68
- ✅ Automatic DTO Validation
69
- ✅ Structured Logging
70
-
71
- 📖 Full Documentation:
72
- https://github.com/august-dev-pro/NestCraftX
73
-
74
- 💬 Need help? Open an issue on GitHub!
75
- `);
76
- }
77
-
78
- module.exports = helpCommand;
1
+ async function helpCommand() {
2
+ console.log(`
3
+ ╔═══════════════════════════════════════════════════════════╗
4
+ ║ ║
5
+ ║ 🌟 NestCraftX CLI v0.2.5 🌟 ║
6
+ ║ Clean Architecture Generator for NestJS ║
7
+ ║ ║
8
+ ╚═══════════════════════════════════════════════════════════╝
9
+
10
+ 📦 MAIN COMMANDS:
11
+
12
+ nestcraftx new <project-name> [options]
13
+ Creates a new NestJS project with Clean Architecture
14
+
15
+ Options:
16
+ --light Quick Mode (minimal configuration)
17
+ --orm <name> Select the ORM (prisma|typeorm|mongoose)
18
+ --auth Add JWT authentication
19
+ --swagger Add Swagger UI
20
+ --docker Generate Docker files
21
+
22
+ Examples:
23
+ nestcraftx new my-app
24
+ nestcraftx new blog-api --light --orm prisma --auth --swagger
25
+ nestcraftx new shop --orm typeorm --auth
26
+
27
+ nestcraftx demo [options]
28
+ Generates a full demo project (blog with users, posts, comments)
29
+ Options:
30
+ --light Simplified MVP Mode
31
+ --docker Adds Docker
32
+ --auth Adds JWT Auth
33
+ --swagger Adds Swagger UI
34
+
35
+ nestcraftx test
36
+ Checks system environment (Node, npm, Nest CLI, Docker, etc.)
37
+
38
+ nestcraftx info
39
+ Displays CLI information and features
40
+
41
+ nestcraftx start
42
+ Launches the interactive generator (legacy mode)
43
+
44
+ 📚 OTHER COMMANDS:
45
+
46
+ nestcraftx --version, -v CLI Version
47
+ nestcraftx --help, -h Displays this help guide
48
+
49
+ 🎯 MODES:
50
+
51
+ Light Mode - Quick configuration for POCs and small projects
52
+ Full Mode - Complete configuration with all options
53
+
54
+ 🛠️ SUPPORTED ORMS:
55
+
56
+ • Prisma - Modern and type-safe ORM (recommended)
57
+ • TypeORM - Full-featured ORM with decorators
58
+ • Mongoose - ODM for MongoDB
59
+
60
+ ✨ FEATURES:
61
+
62
+ ✅ Clean Architecture with DDD
63
+ ✅ Repository Pattern & Use Cases
64
+ ✅ Integrated JWT Auth
65
+ ✅ Automatic Swagger Documentation
66
+ ✅ Docker & Docker Compose
67
+ ✅ Entity and Relationship Generation
68
+ ✅ Automatic DTO Validation
69
+ ✅ Structured Logging
70
+
71
+ 📖 Full Documentation:
72
+ https://github.com/august-dev-pro/NestCraftX
73
+
74
+ 💬 Need help? Open an issue on GitHub!
75
+ `);
76
+ }
77
+
78
+ module.exports = helpCommand;
package/commands/info.js CHANGED
@@ -1,48 +1,48 @@
1
- const packageJson = require("../package.json");
2
-
3
- async function infoCommand() {
4
- console.log("\n🧱 NestCraftX v" + packageJson.version);
5
- console.log("Clean Architecture Generator for NestJS");
6
- console.log("─".repeat(50));
7
-
8
- console.log("\n✅ Supported ORMs:");
9
- console.log(" • Prisma - Modern and type-safe ORM");
10
- console.log(" • TypeORM - Full-featured ORM with decorators");
11
- console.log(" • Mongoose - ODM for MongoDB");
12
-
13
- console.log("\n✅ Available Modes:");
14
- console.log(" • Light - Quick setup for POCs");
15
- console.log(" • Full - Complete and customized configuration");
16
-
17
- console.log("\n✅ Key Features:");
18
- console.log(" • Clean Architecture with DDD");
19
- console.log(" • Integrated JWT Auth");
20
- console.log(" • Swagger Documentation");
21
- console.log(" • Docker & Docker Compose");
22
- console.log(" • Automatic Entity Generation");
23
- console.log(" • Use Cases pattern");
24
- console.log(" • Repository pattern");
25
-
26
- console.log("\n📦 GitHub:");
27
- console.log(" " + packageJson.repository.url);
28
-
29
- console.log("\n📅 Upcoming:");
30
- console.log(" • Custom Middlewares");
31
- console.log(" • Microservices support");
32
- console.log(" • CI/CD Templates");
33
- console.log(" • GraphQL integration");
34
- console.log(" • Automated Tests");
35
-
36
- console.log("\n💡 Available Commands:");
37
- console.log(" nestcraftx new <name> [options] Create a project");
38
- console.log(" nestcraftx demo Generate a demo project");
39
- console.log(" nestcraftx test Check environment status");
40
- console.log(" nestcraftx info Display this information");
41
- console.log(" nestcraftx --help Complete help guide");
42
-
43
- console.log("\n👤 Author: " + packageJson.author);
44
- console.log("📄 License: " + packageJson.license);
45
- console.log("");
46
- }
47
-
48
- module.exports = infoCommand;
1
+ const packageJson = require("../package.json");
2
+
3
+ async function infoCommand() {
4
+ console.log("\n🧱 NestCraftX v" + packageJson.version);
5
+ console.log("Clean Architecture Generator for NestJS");
6
+ console.log("─".repeat(50));
7
+
8
+ console.log("\n✅ Supported ORMs:");
9
+ console.log(" • Prisma - Modern and type-safe ORM");
10
+ console.log(" • TypeORM - Full-featured ORM with decorators");
11
+ console.log(" • Mongoose - ODM for MongoDB");
12
+
13
+ console.log("\n✅ Available Modes:");
14
+ console.log(" • Light - Quick setup for POCs");
15
+ console.log(" • Full - Complete and customized configuration");
16
+
17
+ console.log("\n✅ Key Features:");
18
+ console.log(" • Clean Architecture with DDD");
19
+ console.log(" • Integrated JWT Auth");
20
+ console.log(" • Swagger Documentation");
21
+ console.log(" • Docker & Docker Compose");
22
+ console.log(" • Automatic Entity Generation");
23
+ console.log(" • Use Cases pattern");
24
+ console.log(" • Repository pattern");
25
+
26
+ console.log("\n📦 GitHub:");
27
+ console.log(" " + packageJson.repository.url);
28
+
29
+ console.log("\n📅 Upcoming:");
30
+ console.log(" • Custom Middlewares");
31
+ console.log(" • Microservices support");
32
+ console.log(" • CI/CD Templates");
33
+ console.log(" • GraphQL integration");
34
+ console.log(" • Automated Tests");
35
+
36
+ console.log("\n💡 Available Commands:");
37
+ console.log(" nestcraftx new <name> [options] Create a project");
38
+ console.log(" nestcraftx demo Generate a demo project");
39
+ console.log(" nestcraftx test Check environment status");
40
+ console.log(" nestcraftx info Display this information");
41
+ console.log(" nestcraftx --help Complete help guide");
42
+
43
+ console.log("\n👤 Author: " + packageJson.author);
44
+ console.log("📄 License: " + packageJson.license);
45
+ console.log("");
46
+ }
47
+
48
+ module.exports = infoCommand;