speedrun-cli 2.6.4 → 2.6.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/package.json +1 -1
- package/src/moduleGenerator.js +48 -3
package/package.json
CHANGED
package/src/moduleGenerator.js
CHANGED
|
@@ -386,6 +386,45 @@ export class ${pascalName}Module {}
|
|
|
386
386
|
`;
|
|
387
387
|
}
|
|
388
388
|
|
|
389
|
+
async function registerInAppModule(targetDir, pascalName, kebabName) {
|
|
390
|
+
try {
|
|
391
|
+
const appModulePath = path.join(targetDir, 'src', 'app.module.ts');
|
|
392
|
+
|
|
393
|
+
if (!(await fs.pathExists(appModulePath))) {
|
|
394
|
+
return false;
|
|
395
|
+
}
|
|
396
|
+
|
|
397
|
+
let content = await fs.readFile(appModulePath, 'utf8');
|
|
398
|
+
|
|
399
|
+
const moduleImport = `import { ${pascalName}Module } from './modules/${kebabName}/${kebabName}.module';`;
|
|
400
|
+
|
|
401
|
+
// Skip if already imported
|
|
402
|
+
if (content.includes(moduleImport) || content.includes(`${pascalName}Module`)) {
|
|
403
|
+
return true;
|
|
404
|
+
}
|
|
405
|
+
|
|
406
|
+
// 1. Add import statement at top
|
|
407
|
+
content = `${moduleImport}\n` + content;
|
|
408
|
+
|
|
409
|
+
// 2. Inject ${pascalName}Module into imports array
|
|
410
|
+
const importsArrayRegex = /(imports\s*:\s*\[)([^\]]*)/s;
|
|
411
|
+
if (importsArrayRegex.test(content)) {
|
|
412
|
+
content = content.replace(importsArrayRegex, (match, p1, p2) => {
|
|
413
|
+
const trimmedP2 = p2.trim();
|
|
414
|
+
const separator = trimmedP2 ? (trimmedP2.endsWith(',') ? '\n ' : ',\n ') : '\n ';
|
|
415
|
+
return `${p1}${p2}${separator}${pascalName}Module,`;
|
|
416
|
+
});
|
|
417
|
+
|
|
418
|
+
await fs.writeFile(appModulePath, content, 'utf8');
|
|
419
|
+
console.log(chalk.green(`✨ Automatically registered ${pascalName}Module in src/app.module.ts`));
|
|
420
|
+
return true;
|
|
421
|
+
}
|
|
422
|
+
} catch (error) {
|
|
423
|
+
console.warn(chalk.yellow(`⚠️ Could not auto-register ${pascalName}Module in app.module.ts: ${error.message}`));
|
|
424
|
+
}
|
|
425
|
+
return false;
|
|
426
|
+
}
|
|
427
|
+
|
|
389
428
|
async function generateModule(providedModuleName, targetDir = process.cwd(), specifiedOrm = null) {
|
|
390
429
|
try {
|
|
391
430
|
const options = await promptForModuleOptions(providedModuleName);
|
|
@@ -396,7 +435,7 @@ async function generateModule(providedModuleName, targetDir = process.cwd(), spe
|
|
|
396
435
|
// Detect ORM
|
|
397
436
|
const orm = specifiedOrm || await detectOrm(targetDir);
|
|
398
437
|
|
|
399
|
-
// Ensure
|
|
438
|
+
// Ensure inside a NestJS project structure
|
|
400
439
|
const srcDir = path.join(targetDir, 'src');
|
|
401
440
|
if (!(await fs.pathExists(srcDir))) {
|
|
402
441
|
console.warn(chalk.yellow('⚠️ Could not find "src" directory. Generating at current directory.'));
|
|
@@ -557,10 +596,15 @@ ${ops.create ? `
|
|
|
557
596
|
const moduleContent = getModuleContent(orm, pascalName, kebabName);
|
|
558
597
|
await fs.writeFile(path.join(moduleDir, `${kebabName}.module.ts`), moduleContent);
|
|
559
598
|
|
|
599
|
+
// 5. Auto-register in src/app.module.ts
|
|
600
|
+
const isAutoRegistered = await registerInAppModule(targetDir, pascalName, kebabName);
|
|
601
|
+
|
|
560
602
|
console.log(chalk.green(`\n✅ Module "${kebabName}" successfully generated in ${path.relative(process.cwd(), moduleDir)}`));
|
|
561
603
|
console.log(chalk.gray(` Detected ORM: ${orm}`));
|
|
562
|
-
|
|
563
|
-
|
|
604
|
+
|
|
605
|
+
if (!isAutoRegistered) {
|
|
606
|
+
console.log(chalk.yellow(`\n⚠️ Please manually register ${pascalName}Module in src/app.module.ts:`));
|
|
607
|
+
console.log(chalk.cyan(`
|
|
564
608
|
import { ${pascalName}Module } from './modules/${kebabName}/${kebabName}.module';
|
|
565
609
|
|
|
566
610
|
@Module({
|
|
@@ -571,6 +615,7 @@ import { ${pascalName}Module } from './modules/${kebabName}/${kebabName}.module'
|
|
|
571
615
|
})
|
|
572
616
|
export class AppModule {}
|
|
573
617
|
`));
|
|
618
|
+
}
|
|
574
619
|
|
|
575
620
|
return true;
|
|
576
621
|
} catch (error) {
|