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 +1 -1
- package/src/moduleGenerator.js +9 -12
package/package.json
CHANGED
package/src/moduleGenerator.js
CHANGED
|
@@ -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
|
-
//
|
|
400
|
+
// Cegah duplikasi import
|
|
402
401
|
if (content.includes(moduleImport) || content.includes(`${pascalName}Module`)) {
|
|
403
402
|
return true;
|
|
404
403
|
}
|
|
405
404
|
|
|
406
|
-
// 1.
|
|
405
|
+
// 1. Tambahkan baris import di paling atas file
|
|
407
406
|
content = `${moduleImport}\n` + content;
|
|
408
407
|
|
|
409
|
-
// 2. Inject ${pascalName}Module
|
|
410
|
-
const
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
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;
|