@ifecodes/backend-template 1.4.0 ā 1.4.1
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/bin/cli.js +102 -84
- package/package.json +1 -1
package/bin/cli.js
CHANGED
|
@@ -125,7 +125,7 @@ This PR ...
|
|
|
125
125
|
|
|
126
126
|
fs.writeFileSync(
|
|
127
127
|
path.join(githubDir, "pull_request_template.md"),
|
|
128
|
-
prTemplateContent
|
|
128
|
+
prTemplateContent,
|
|
129
129
|
);
|
|
130
130
|
}
|
|
131
131
|
|
|
@@ -319,22 +319,22 @@ if (!isInMicroserviceProject && config.projectType === "microservice") {
|
|
|
319
319
|
if (isExistingProject) {
|
|
320
320
|
console.error(
|
|
321
321
|
`\n${pc.red("ā Error:")} Project ${pc.bold(
|
|
322
|
-
sanitizedName
|
|
323
|
-
)} already exists
|
|
322
|
+
sanitizedName,
|
|
323
|
+
)} already exists!`,
|
|
324
324
|
);
|
|
325
325
|
process.exit(1);
|
|
326
326
|
}
|
|
327
327
|
console.log(
|
|
328
328
|
`\n${pc.cyan("šļø Creating microservices:")} ${pc.bold(
|
|
329
|
-
servicesToCreate.join(", ")
|
|
330
|
-
)}...\n
|
|
329
|
+
servicesToCreate.join(", "),
|
|
330
|
+
)}...\n`,
|
|
331
331
|
);
|
|
332
332
|
} else if (!isInMicroserviceProject && config.projectType === "monolith") {
|
|
333
333
|
if (isExistingProject) {
|
|
334
334
|
console.error(
|
|
335
335
|
`\n${pc.red("ā Error:")} Project ${pc.bold(
|
|
336
|
-
sanitizedName
|
|
337
|
-
)} already exists
|
|
336
|
+
sanitizedName,
|
|
337
|
+
)} already exists!`,
|
|
338
338
|
);
|
|
339
339
|
process.exit(1);
|
|
340
340
|
}
|
|
@@ -355,7 +355,7 @@ if (!isInMicroserviceProject && config.projectType === "microservice") {
|
|
|
355
355
|
if (ext === "ts") {
|
|
356
356
|
indexContent = indexContent.replace(
|
|
357
357
|
'export { connectDB } from "./db";\n',
|
|
358
|
-
""
|
|
358
|
+
"",
|
|
359
359
|
);
|
|
360
360
|
// also remove any trailing references like `connectDB,` in exported objects
|
|
361
361
|
indexContent = indexContent.replace(/connectDB,?/g, "");
|
|
@@ -371,7 +371,7 @@ if (!isInMicroserviceProject && config.projectType === "microservice") {
|
|
|
371
371
|
// No TypeScript-to-JavaScript conversion ā templates include language-specific variants
|
|
372
372
|
} else if (isInMicroserviceProject) {
|
|
373
373
|
console.log(
|
|
374
|
-
`\n${pc.cyan("šļø Adding service:")} ${pc.bold(servicesToCreate[0])}...\n
|
|
374
|
+
`\n${pc.cyan("šļø Adding service:")} ${pc.bold(servicesToCreate[0])}...\n`,
|
|
375
375
|
);
|
|
376
376
|
}
|
|
377
377
|
|
|
@@ -382,7 +382,7 @@ if (isInMicroserviceProject || config.projectType === "microservice") {
|
|
|
382
382
|
const sharedDir = path.join(target, "shared");
|
|
383
383
|
if (!fs.existsSync(sharedDir)) {
|
|
384
384
|
console.log(
|
|
385
|
-
`\n${pc.cyan("š¦ Creating shared folder for config and utils...")}
|
|
385
|
+
`\n${pc.cyan("š¦ Creating shared folder for config and utils...")}`,
|
|
386
386
|
);
|
|
387
387
|
fs.mkdirSync(sharedDir, { recursive: true });
|
|
388
388
|
|
|
@@ -407,15 +407,15 @@ if (isInMicroserviceProject || config.projectType === "microservice") {
|
|
|
407
407
|
// Remove various export/import patterns referencing connectDB
|
|
408
408
|
idx = idx.replace(
|
|
409
409
|
/export\s*\{\s*connectDB\s*\}\s*from\s*["']\.\/db["'];?/g,
|
|
410
|
-
""
|
|
410
|
+
"",
|
|
411
411
|
);
|
|
412
412
|
idx = idx.replace(
|
|
413
413
|
/const\s*\{\s*connectDB\s*\}\s*=\s*require\(["']\.\/db["']\);?/g,
|
|
414
|
-
""
|
|
414
|
+
"",
|
|
415
415
|
);
|
|
416
416
|
idx = idx.replace(
|
|
417
417
|
/import\s*\{\s*connectDB\s*\}\s*from\s*["']\.\/db["'];?/g,
|
|
418
|
-
""
|
|
418
|
+
"",
|
|
419
419
|
);
|
|
420
420
|
idx = idx.replace(/\bconnectDB,?\b/g, "");
|
|
421
421
|
idx = idx.replace(/\n{3,}/g, "\n\n");
|
|
@@ -449,7 +449,7 @@ if (isInMicroserviceProject || config.projectType === "microservice") {
|
|
|
449
449
|
// Replace PORT with service-specific ports
|
|
450
450
|
envContent = envContent.replace(
|
|
451
451
|
" PORT: process.env.PORT!,",
|
|
452
|
-
portEnvVars
|
|
452
|
+
portEnvVars,
|
|
453
453
|
);
|
|
454
454
|
|
|
455
455
|
// Add ALLOWED_ORIGIN if CORS is selected
|
|
@@ -457,7 +457,7 @@ if (isInMicroserviceProject || config.projectType === "microservice") {
|
|
|
457
457
|
const assertion = config.language === "javascript" ? "" : "!";
|
|
458
458
|
envContent = envContent.replace(
|
|
459
459
|
"/*__ALLOWED_ORIGIN__*/",
|
|
460
|
-
`ALLOWED_ORIGIN: process.env.ALLOWED_ORIGIN${assertion}
|
|
460
|
+
`ALLOWED_ORIGIN: process.env.ALLOWED_ORIGIN${assertion},`,
|
|
461
461
|
);
|
|
462
462
|
} else {
|
|
463
463
|
envContent = envContent.replace("/*__ALLOWED_ORIGIN__*/", "");
|
|
@@ -468,11 +468,11 @@ if (isInMicroserviceProject || config.projectType === "microservice") {
|
|
|
468
468
|
const assertion = config.language === "javascript" ? "" : "!";
|
|
469
469
|
envContent = envContent.replace(
|
|
470
470
|
"/*__MONGO_URI__*/",
|
|
471
|
-
`MONGO_URI: process.env.MONGO_URI${assertion}
|
|
471
|
+
`MONGO_URI: process.env.MONGO_URI${assertion},`,
|
|
472
472
|
);
|
|
473
473
|
envContent = envContent.replace(
|
|
474
474
|
"/*__JWT_SECRET__*/",
|
|
475
|
-
`JWT_SECRET: process.env.JWT_SECRET${assertion}
|
|
475
|
+
`JWT_SECRET: process.env.JWT_SECRET${assertion},`,
|
|
476
476
|
);
|
|
477
477
|
} else {
|
|
478
478
|
envContent = envContent.replace("/*__MONGO_URI__*/", "");
|
|
@@ -490,7 +490,7 @@ if (isInMicroserviceProject || config.projectType === "microservice") {
|
|
|
490
490
|
if (ext === "ts") {
|
|
491
491
|
indexContent = indexContent.replace(
|
|
492
492
|
'export { connectDB } from "./db";\n',
|
|
493
|
-
""
|
|
493
|
+
"",
|
|
494
494
|
);
|
|
495
495
|
}
|
|
496
496
|
indexContent = indexContent
|
|
@@ -504,13 +504,13 @@ if (isInMicroserviceProject || config.projectType === "microservice") {
|
|
|
504
504
|
const sharedLoggerPath = path.join(sharedUtilsDir, `logger.${ext}`);
|
|
505
505
|
if (fs.existsSync(sharedLoggerPath)) {
|
|
506
506
|
console.log(
|
|
507
|
-
`\n${pc.cyan("š§ Updating shared logger to use shared config...")}
|
|
507
|
+
`\n${pc.cyan("š§ Updating shared logger to use shared config...")}`,
|
|
508
508
|
);
|
|
509
509
|
let loggerContent = fs.readFileSync(sharedLoggerPath, "utf8");
|
|
510
510
|
// Replace imports like: from '@/config'; or from "@/config" with relative import to shared config
|
|
511
511
|
loggerContent = loggerContent.replace(
|
|
512
512
|
/from\s+["']@\/config["'];?/g,
|
|
513
|
-
"from '../config';"
|
|
513
|
+
"from '../config';",
|
|
514
514
|
);
|
|
515
515
|
fs.writeFileSync(sharedLoggerPath, loggerContent);
|
|
516
516
|
}
|
|
@@ -527,7 +527,7 @@ if (isInMicroserviceProject || config.projectType === "microservice") {
|
|
|
527
527
|
};
|
|
528
528
|
fs.writeFileSync(
|
|
529
529
|
path.join(sharedDir, "package.json"),
|
|
530
|
-
JSON.stringify(sharedPackageJson, null, 2)
|
|
530
|
+
JSON.stringify(sharedPackageJson, null, 2),
|
|
531
531
|
);
|
|
532
532
|
}
|
|
533
533
|
}
|
|
@@ -574,7 +574,7 @@ if (isInMicroserviceProject || config.projectType === "microservice") {
|
|
|
574
574
|
fs.rmSync(conflictPath, { recursive: true, force: true });
|
|
575
575
|
} catch (e) {
|
|
576
576
|
console.error(
|
|
577
|
-
pc.red(`Failed to remove existing path: ${conflictPath}`)
|
|
577
|
+
pc.red(`Failed to remove existing path: ${conflictPath}`),
|
|
578
578
|
);
|
|
579
579
|
process.exit(1);
|
|
580
580
|
}
|
|
@@ -613,7 +613,7 @@ if (isInMicroserviceProject || config.projectType === "microservice") {
|
|
|
613
613
|
// Include services we're about to create so port computation and gateway routing
|
|
614
614
|
// are aware of newly added services when setting up files.
|
|
615
615
|
const allServices = Array.from(
|
|
616
|
-
new Set([...existingServices, ...servicesToSetup])
|
|
616
|
+
new Set([...existingServices, ...servicesToSetup]),
|
|
617
617
|
);
|
|
618
618
|
|
|
619
619
|
// Step 1: Setup all service files first (without installing dependencies)
|
|
@@ -631,7 +631,7 @@ if (isInMicroserviceProject || config.projectType === "microservice") {
|
|
|
631
631
|
serviceRoot,
|
|
632
632
|
shouldIncludeAuth,
|
|
633
633
|
allServices,
|
|
634
|
-
true // Skip install for now
|
|
634
|
+
true, // Skip install for now
|
|
635
635
|
);
|
|
636
636
|
serviceConfigs.push({
|
|
637
637
|
serviceName,
|
|
@@ -648,7 +648,7 @@ if (isInMicroserviceProject || config.projectType === "microservice") {
|
|
|
648
648
|
? fs
|
|
649
649
|
.readdirSync(servicesDirPath)
|
|
650
650
|
.filter((f) =>
|
|
651
|
-
fs.statSync(path.join(servicesDirPath, f)).isDirectory()
|
|
651
|
+
fs.statSync(path.join(servicesDirPath, f)).isDirectory(),
|
|
652
652
|
)
|
|
653
653
|
: [];
|
|
654
654
|
|
|
@@ -729,7 +729,7 @@ if (isInMicroserviceProject || config.projectType === "microservice") {
|
|
|
729
729
|
}
|
|
730
730
|
fs.writeFileSync(
|
|
731
731
|
rootPackageJsonPath,
|
|
732
|
-
JSON.stringify(rootPackageJson, null, 2) + "\n"
|
|
732
|
+
JSON.stringify(rootPackageJson, null, 2) + "\n",
|
|
733
733
|
);
|
|
734
734
|
}
|
|
735
735
|
|
|
@@ -782,7 +782,7 @@ if (isInMicroserviceProject || config.projectType === "microservice") {
|
|
|
782
782
|
const svcs = fs
|
|
783
783
|
.readdirSync(servicesDirPath)
|
|
784
784
|
.filter((f) =>
|
|
785
|
-
fs.statSync(path.join(servicesDirPath, f)).isDirectory()
|
|
785
|
+
fs.statSync(path.join(servicesDirPath, f)).isDirectory(),
|
|
786
786
|
);
|
|
787
787
|
for (const svc of svcs) {
|
|
788
788
|
for (const f of [...rootFiles, "eslint.config.js"]) {
|
|
@@ -861,7 +861,7 @@ if (isInMicroserviceProject || config.projectType === "microservice") {
|
|
|
861
861
|
};
|
|
862
862
|
fs.writeFileSync(
|
|
863
863
|
path.join(target, "tsconfig.json"),
|
|
864
|
-
JSON.stringify(rootTsConfigContent, null, 2) + "\n"
|
|
864
|
+
JSON.stringify(rootTsConfigContent, null, 2) + "\n",
|
|
865
865
|
);
|
|
866
866
|
}
|
|
867
867
|
|
|
@@ -890,7 +890,7 @@ if (isInMicroserviceProject || config.projectType === "microservice") {
|
|
|
890
890
|
// Remove any existing *_PORT lines to avoid duplication
|
|
891
891
|
envContent = envContent.replace(
|
|
892
892
|
/^[ \t]*[A-Z0-9_]+_PORT:\s*process\.env\.[A-Z0-9_]+!?\,?\s*$/gim,
|
|
893
|
-
""
|
|
893
|
+
"",
|
|
894
894
|
);
|
|
895
895
|
// Normalize multiple consecutive blank lines
|
|
896
896
|
envContent = envContent.replace(/\n{2,}/g, "\n\n");
|
|
@@ -901,7 +901,7 @@ if (isInMicroserviceProject || config.projectType === "microservice") {
|
|
|
901
901
|
if (envContent.includes("/*__PORTS__*/")) {
|
|
902
902
|
envContent = envContent.replace(
|
|
903
903
|
"/*__PORTS__*/",
|
|
904
|
-
"/*__PORTS__*/\n" + portEnvVars
|
|
904
|
+
"/*__PORTS__*/\n" + portEnvVars,
|
|
905
905
|
);
|
|
906
906
|
} else {
|
|
907
907
|
// Fallback: find the opening brace of the exported ENV object and insert after it
|
|
@@ -935,7 +935,7 @@ if (isInMicroserviceProject || config.projectType === "microservice") {
|
|
|
935
935
|
gatewayRoot,
|
|
936
936
|
config.auth,
|
|
937
937
|
allServices,
|
|
938
|
-
true
|
|
938
|
+
true,
|
|
939
939
|
);
|
|
940
940
|
}
|
|
941
941
|
|
|
@@ -946,7 +946,7 @@ if (isInMicroserviceProject || config.projectType === "microservice") {
|
|
|
946
946
|
? fs
|
|
947
947
|
.readdirSync(servicesDirPath)
|
|
948
948
|
.filter((f) =>
|
|
949
|
-
fs.statSync(path.join(servicesDirPath, f)).isDirectory()
|
|
949
|
+
fs.statSync(path.join(servicesDirPath, f)).isDirectory(),
|
|
950
950
|
)
|
|
951
951
|
: allServices;
|
|
952
952
|
|
|
@@ -1004,7 +1004,7 @@ if (isInMicroserviceProject || config.projectType === "microservice") {
|
|
|
1004
1004
|
if (nodeEnvRegex.test(exampleContent)) {
|
|
1005
1005
|
exampleContent = exampleContent.replace(
|
|
1006
1006
|
nodeEnvRegex,
|
|
1007
|
-
(m) => `${m}\n\n${portsBlock}\n
|
|
1007
|
+
(m) => `${m}\n\n${portsBlock}\n`,
|
|
1008
1008
|
);
|
|
1009
1009
|
} else {
|
|
1010
1010
|
// Prepend header and ports
|
|
@@ -1017,13 +1017,13 @@ if (isInMicroserviceProject || config.projectType === "microservice") {
|
|
|
1017
1017
|
// Inform the user about the new ports and remind them to update their runtime .env if needed
|
|
1018
1018
|
try {
|
|
1019
1019
|
console.log(
|
|
1020
|
-
pc.cyan("\nš§ Updated .env.example with service port entries:\n")
|
|
1020
|
+
pc.cyan("\nš§ Updated .env.example with service port entries:\n"),
|
|
1021
1021
|
);
|
|
1022
1022
|
console.log(pc.green(portsBlock));
|
|
1023
1023
|
console.log(
|
|
1024
1024
|
pc.dim(
|
|
1025
|
-
"If you keep a runtime .env with custom overrides, do NOT overwrite it.\nPlease copy any new *_PORT entries from .env.example into .env as appropriate."
|
|
1026
|
-
)
|
|
1025
|
+
"If you keep a runtime .env with custom overrides, do NOT overwrite it.\nPlease copy any new *_PORT entries from .env.example into .env as appropriate.",
|
|
1026
|
+
),
|
|
1027
1027
|
);
|
|
1028
1028
|
} catch (e) {
|
|
1029
1029
|
// non-fatal if logging fails
|
|
@@ -1046,7 +1046,7 @@ if (isInMicroserviceProject || config.projectType === "microservice") {
|
|
|
1046
1046
|
|
|
1047
1047
|
for (const { serviceName, serviceRoot, deps, devDeps } of serviceConfigs) {
|
|
1048
1048
|
console.log(
|
|
1049
|
-
pc.cyan(`\nš¦ Installing dependencies for ${serviceName}...\n`)
|
|
1049
|
+
pc.cyan(`\nš¦ Installing dependencies for ${serviceName}...\n`),
|
|
1050
1050
|
);
|
|
1051
1051
|
|
|
1052
1052
|
try {
|
|
@@ -1066,7 +1066,7 @@ if (isInMicroserviceProject || config.projectType === "microservice") {
|
|
|
1066
1066
|
} catch (error) {
|
|
1067
1067
|
allInstallsSucceeded = false;
|
|
1068
1068
|
console.error(
|
|
1069
|
-
pc.red(`\nā Failed to install dependencies for ${serviceName}`)
|
|
1069
|
+
pc.red(`\nā Failed to install dependencies for ${serviceName}`),
|
|
1070
1070
|
);
|
|
1071
1071
|
console.error(pc.dim(`\nYou can install them later by running:`));
|
|
1072
1072
|
console.error(pc.cyan(` cd services/${serviceName} && npm install\n`));
|
|
@@ -1076,8 +1076,42 @@ if (isInMicroserviceProject || config.projectType === "microservice") {
|
|
|
1076
1076
|
// Store for later use
|
|
1077
1077
|
config.allInstallsSucceeded = allInstallsSucceeded;
|
|
1078
1078
|
} else {
|
|
1079
|
-
|
|
1080
|
-
config.installSucceeded =
|
|
1079
|
+
config.monolithSetupResult = await setupService(config, null, target, true);
|
|
1080
|
+
config.installSucceeded = config.monolithSetupResult.installSucceeded;
|
|
1081
|
+
}
|
|
1082
|
+
|
|
1083
|
+
// Generate README.md for monolith (microservices already done above)
|
|
1084
|
+
if (!isInMicroserviceProject && config.projectType === "monolith") {
|
|
1085
|
+
console.log(`\n${pc.cyan("š Generating README.md...")}\n`);
|
|
1086
|
+
const readmeContent = generateReadme(config);
|
|
1087
|
+
fs.writeFileSync(path.join(target, "README.md"), readmeContent);
|
|
1088
|
+
writeStarterWorkflow(target, config);
|
|
1089
|
+
writePullRequestTemplate(target, config);
|
|
1090
|
+
writeContributingGuide(target, config);
|
|
1091
|
+
|
|
1092
|
+
// Rename gitignore to .gitignore (npm doesn't publish .gitignore files)
|
|
1093
|
+
const gitignorePath = path.join(target, "gitignore");
|
|
1094
|
+
const dotGitignorePath = path.join(target, ".gitignore");
|
|
1095
|
+
if (fs.existsSync(gitignorePath)) {
|
|
1096
|
+
fs.renameSync(gitignorePath, dotGitignorePath);
|
|
1097
|
+
}
|
|
1098
|
+
|
|
1099
|
+
// Generate .env from .env.example for monolith only
|
|
1100
|
+
console.log(`${pc.cyan("š Setting up environment files...")}\n`);
|
|
1101
|
+
try {
|
|
1102
|
+
const rootEnvExamplePath = path.join(target, ".env.example");
|
|
1103
|
+
const rootEnvPath = path.join(target, ".env");
|
|
1104
|
+
if (fs.existsSync(rootEnvExamplePath) && !fs.existsSync(rootEnvPath)) {
|
|
1105
|
+
fs.copyFileSync(rootEnvExamplePath, rootEnvPath);
|
|
1106
|
+
}
|
|
1107
|
+
} catch (err) {
|
|
1108
|
+
// Non-fatal; proceed even if we fail to write env files
|
|
1109
|
+
}
|
|
1110
|
+
}
|
|
1111
|
+
|
|
1112
|
+
// Install monolith dependencies last, after all files have been generated.
|
|
1113
|
+
if (!isInMicroserviceProject && config.projectType === "monolith") {
|
|
1114
|
+
const result = config.monolithSetupResult;
|
|
1081
1115
|
|
|
1082
1116
|
try {
|
|
1083
1117
|
if (result.deps && result.deps.length) {
|
|
@@ -1097,13 +1131,24 @@ if (isInMicroserviceProject || config.projectType === "microservice") {
|
|
|
1097
1131
|
console.error(pc.red("\nā Failed to install monolith dependencies"));
|
|
1098
1132
|
console.error(pc.dim(`\nYou can install them later by running:`));
|
|
1099
1133
|
console.error(pc.cyan(` cd ${target} && npm install\n`));
|
|
1134
|
+
|
|
1135
|
+
if (
|
|
1136
|
+
error?.code === "ENOSPC" ||
|
|
1137
|
+
/no space left on device/i.test(error?.message || "")
|
|
1138
|
+
) {
|
|
1139
|
+
console.error(
|
|
1140
|
+
pc.red(
|
|
1141
|
+
"\nš Generation stopped because the disk is full. Free up space and run the generator again.\n",
|
|
1142
|
+
),
|
|
1143
|
+
);
|
|
1144
|
+
process.exit(1);
|
|
1145
|
+
}
|
|
1100
1146
|
}
|
|
1101
1147
|
|
|
1102
1148
|
// Safety net: ensure eslint.config.js exists in generated monolith projects
|
|
1103
1149
|
const templateEslintConfig = path.join(base, "eslint.config.js");
|
|
1104
1150
|
const generatedEslintConfig = path.join(target, "eslint.config.js");
|
|
1105
1151
|
if (
|
|
1106
|
-
config.projectType === "monolith" &&
|
|
1107
1152
|
fs.existsSync(templateEslintConfig) &&
|
|
1108
1153
|
!fs.existsSync(generatedEslintConfig)
|
|
1109
1154
|
) {
|
|
@@ -1111,35 +1156,6 @@ if (isInMicroserviceProject || config.projectType === "microservice") {
|
|
|
1111
1156
|
}
|
|
1112
1157
|
}
|
|
1113
1158
|
|
|
1114
|
-
// Generate README.md for monolith (microservices already done above)
|
|
1115
|
-
if (!isInMicroserviceProject && config.projectType === "monolith") {
|
|
1116
|
-
console.log(`\n${pc.cyan("š Generating README.md...")}\n`);
|
|
1117
|
-
const readmeContent = generateReadme(config);
|
|
1118
|
-
fs.writeFileSync(path.join(target, "README.md"), readmeContent);
|
|
1119
|
-
writeStarterWorkflow(target, config);
|
|
1120
|
-
writePullRequestTemplate(target, config);
|
|
1121
|
-
writeContributingGuide(target, config);
|
|
1122
|
-
|
|
1123
|
-
// Rename gitignore to .gitignore (npm doesn't publish .gitignore files)
|
|
1124
|
-
const gitignorePath = path.join(target, "gitignore");
|
|
1125
|
-
const dotGitignorePath = path.join(target, ".gitignore");
|
|
1126
|
-
if (fs.existsSync(gitignorePath)) {
|
|
1127
|
-
fs.renameSync(gitignorePath, dotGitignorePath);
|
|
1128
|
-
}
|
|
1129
|
-
|
|
1130
|
-
// Generate .env from .env.example for monolith only
|
|
1131
|
-
console.log(`${pc.cyan("š Setting up environment files...")}\n`);
|
|
1132
|
-
try {
|
|
1133
|
-
const rootEnvExamplePath = path.join(target, ".env.example");
|
|
1134
|
-
const rootEnvPath = path.join(target, ".env");
|
|
1135
|
-
if (fs.existsSync(rootEnvExamplePath) && !fs.existsSync(rootEnvPath)) {
|
|
1136
|
-
fs.copyFileSync(rootEnvExamplePath, rootEnvPath);
|
|
1137
|
-
}
|
|
1138
|
-
} catch (err) {
|
|
1139
|
-
// Non-fatal; proceed even if we fail to write env files
|
|
1140
|
-
}
|
|
1141
|
-
}
|
|
1142
|
-
|
|
1143
1159
|
// Initialize git and Husky
|
|
1144
1160
|
if (!isInMicroserviceProject) {
|
|
1145
1161
|
execSync("git init", { cwd: target, stdio: "inherit" });
|
|
@@ -1162,13 +1178,13 @@ if (!isInMicroserviceProject) {
|
|
|
1162
1178
|
} catch (formatError) {
|
|
1163
1179
|
console.warn(
|
|
1164
1180
|
pc.yellow(
|
|
1165
|
-
"ā ļø Warning: Code formatting failed. You can run it manually later with: npm run format\n"
|
|
1166
|
-
)
|
|
1181
|
+
"ā ļø Warning: Code formatting failed. You can run it manually later with: npm run format\n",
|
|
1182
|
+
),
|
|
1167
1183
|
);
|
|
1168
1184
|
}
|
|
1169
1185
|
} else {
|
|
1170
1186
|
console.log(
|
|
1171
|
-
"\nā ļø Husky setup skipped (run 'npm install && npm run prepare' after fixing service dependencies)\n"
|
|
1187
|
+
"\nā ļø Husky setup skipped (run 'npm install && npm run prepare' after fixing service dependencies)\n",
|
|
1172
1188
|
);
|
|
1173
1189
|
}
|
|
1174
1190
|
} else if (config.projectType === "monolith") {
|
|
@@ -1180,15 +1196,15 @@ if (!isInMicroserviceProject) {
|
|
|
1180
1196
|
} catch (error) {
|
|
1181
1197
|
console.log(
|
|
1182
1198
|
`\n${pc.yellow("ā ļø Husky setup failed")} ${pc.dim(
|
|
1183
|
-
"(run 'npm run prepare' manually after fixing dependencies)"
|
|
1184
|
-
)}\n
|
|
1199
|
+
"(run 'npm run prepare' manually after fixing dependencies)",
|
|
1200
|
+
)}\n`,
|
|
1185
1201
|
);
|
|
1186
1202
|
}
|
|
1187
1203
|
} else {
|
|
1188
1204
|
console.log(
|
|
1189
1205
|
`\n${pc.yellow("ā ļø Husky setup skipped")} ${pc.dim(
|
|
1190
|
-
"(run 'npm install && npm run prepare' to set up git hooks)"
|
|
1191
|
-
)}\n
|
|
1206
|
+
"(run 'npm install && npm run prepare' to set up git hooks)",
|
|
1207
|
+
)}\n`,
|
|
1192
1208
|
);
|
|
1193
1209
|
}
|
|
1194
1210
|
}
|
|
@@ -1216,12 +1232,14 @@ if (isInMicroserviceProject) {
|
|
|
1216
1232
|
if (servicesToSetup.length > 0) {
|
|
1217
1233
|
console.log(
|
|
1218
1234
|
`\n${pc.green("ā
Service")} ${pc.bold(servicesToSetup[0])} ${pc.green(
|
|
1219
|
-
"added successfully!"
|
|
1220
|
-
)}
|
|
1235
|
+
"added successfully!",
|
|
1236
|
+
)}`,
|
|
1221
1237
|
);
|
|
1222
1238
|
} else {
|
|
1223
1239
|
console.log(
|
|
1224
|
-
pc.yellow(
|
|
1240
|
+
pc.yellow(
|
|
1241
|
+
"\nā ļø No new service was created (skipped by your selection).",
|
|
1242
|
+
),
|
|
1225
1243
|
);
|
|
1226
1244
|
}
|
|
1227
1245
|
console.log(`\n${pc.cyan("š¦ All services:")} ${allServices.join(", ")}`);
|
|
@@ -1230,7 +1248,7 @@ if (isInMicroserviceProject) {
|
|
|
1230
1248
|
} else if (config.projectType === "microservice") {
|
|
1231
1249
|
console.log(`\n${pc.green("ā
Microservice Backend created successfully!")}`);
|
|
1232
1250
|
console.log(
|
|
1233
|
-
`\n${pc.cyan("š¦ Created services:")} ${servicesToCreate.join(", ")}
|
|
1251
|
+
`\n${pc.cyan("š¦ Created services:")} ${servicesToCreate.join(", ")}`,
|
|
1234
1252
|
);
|
|
1235
1253
|
console.log(`\n${pc.blue("š” Next steps:")}`);
|
|
1236
1254
|
console.log(` ${pc.dim("1.")} cd ${pc.bold(sanitizedName)}`);
|
|
@@ -1253,15 +1271,15 @@ try {
|
|
|
1253
1271
|
// Remove various connectDB export/import patterns
|
|
1254
1272
|
idxContent = idxContent.replace(
|
|
1255
1273
|
/export\s*\{\s*connectDB\s*\}\s*from\s*["']\.\/db["'];?/g,
|
|
1256
|
-
""
|
|
1274
|
+
"",
|
|
1257
1275
|
);
|
|
1258
1276
|
idxContent = idxContent.replace(
|
|
1259
1277
|
/import\s*\{\s*connectDB\s*\}\s*from\s*["']\.\/db["'];?/g,
|
|
1260
|
-
""
|
|
1278
|
+
"",
|
|
1261
1279
|
);
|
|
1262
1280
|
idxContent = idxContent.replace(
|
|
1263
1281
|
/const\s*\{\s*connectDB\s*\}\s*=\s*require\(["']\.\/db["']\);?/g,
|
|
1264
|
-
""
|
|
1282
|
+
"",
|
|
1265
1283
|
);
|
|
1266
1284
|
// Remove any remaining connectDB identifiers (commas/newlines)
|
|
1267
1285
|
idxContent = idxContent.replace(/connectDB,?/g, "");
|
package/package.json
CHANGED