speedrun-cli 2.6.6 → 2.6.7

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.6",
3
+ "version": "2.6.7",
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",
@@ -395,26 +395,23 @@ async function registerInAppModule(targetDir, pascalName, kebabName) {
395
395
  }
396
396
 
397
397
  let content = await fs.readFile(appModulePath, 'utf8');
398
-
399
398
  const moduleImport = `import { ${pascalName}Module } from './modules/${kebabName}/${kebabName}.module';`;
400
399
 
401
- // Skip if already imported
400
+ // Cegah duplikasi import
402
401
  if (content.includes(moduleImport) || content.includes(`${pascalName}Module`)) {
403
402
  return true;
404
403
  }
405
404
 
406
- // 1. Add import statement at top
405
+ // 1. Tambahkan baris import di paling atas file
407
406
  content = `${moduleImport}\n` + content;
408
407
 
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
-
408
+ // 2. Inject ${pascalName}Module tepat di dalam decorator @Module({ imports: [ ... ] })
409
+ const importsKeywordIndex = content.indexOf('imports: [');
410
+
411
+ if (importsKeywordIndex !== -1) {
412
+ const insertPosition = importsKeywordIndex + 'imports: ['.length;
413
+ content = content.slice(0, insertPosition) + `\n ${pascalName}Module,` + content.slice(insertPosition);
414
+
418
415
  await fs.writeFile(appModulePath, content, 'utf8');
419
416
  console.log(chalk.green(`✨ Automatically registered ${pascalName}Module in src/app.module.ts`));
420
417
  return true;