speedrun-cli 2.6.5 → 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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "speedrun-cli",
3
- "version": "2.6.5",
3
+ "version": "2.6.6",
4
4
  "description": "CLI tool to scaffold a production-ready NestJS authentication system with JWT, refresh tokens, and RBAC",
5
5
  "keywords": [
6
6
  "nestjs",
@@ -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 we are inside a NestJS project structure
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.'));
@@ -481,7 +520,7 @@ export class ${responseDtoName} {
481
520
  const serviceContent = getServiceContent(orm, pascalName, camelName, kebabName, createDtoName, updateDtoName, ops);
482
521
  await fs.writeFile(path.join(moduleDir, `${kebabName}.service.ts`), serviceContent);
483
522
 
484
- // 3. Generate Controller (FIXED: Swagger DTO Name & ExtraModels registration)
523
+ // 3. Generate Controller
485
524
  const controllerContent = `import { Controller${ops.findAll ? ', Query' : ''}${ops.findOne || ops.update || ops.remove ? ', Param, ParseUUIDPipe, HttpStatus' : ''}${ops.create ? ', Post, Body' : ''}${ops.findAll || ops.findOne ? ', Get' : ''}${ops.update ? ', Put' : ''}${ops.remove ? ', Delete' : ''}, Type } from '@nestjs/common';
486
525
  import { ApiTags, ApiBearerAuth, ApiExtraModels, ApiOperation, ApiResponse, ApiParam } from '@nestjs/swagger';
487
526
  import { BaseController } from '../../common/base/base.controller';
@@ -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
- console.log(chalk.yellow(`\n⚠️ Don't forget to register ${pascalName}Module in src/app.module.ts:`));
563
- console.log(chalk.cyan(`
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) {