From f4db805d84db1ca6e8fcb9a4ff3c88c579adeedc Mon Sep 17 00:00:00 2001 From: adrien2p Date: Mon, 18 Apr 2022 18:37:06 +0200 Subject: [PATCH] fix(cli): updateModuleImports method --- src/cli/commands/generate-component.ts | 2 +- src/cli/tests/commands/generate-component.spec.ts | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/cli/commands/generate-component.ts b/src/cli/commands/generate-component.ts index f9c5d120..cf2bf849 100644 --- a/src/cli/commands/generate-component.ts +++ b/src/cli/commands/generate-component.ts @@ -162,7 +162,7 @@ export function updateModuleImports(fullDestinationPath: string): void { const moduleContent = readFileSync(resolvedModulePath).toString(); - const shouldUpdateModuleImport = !moduleContent.match(`${componentClassName}`); + const shouldUpdateModuleImport = !moduleContent.match(`${parse(file.name).name}`); if (!shouldUpdateModuleImport) continue; const isComponentInSubDirectory = diff --git a/src/cli/tests/commands/generate-component.spec.ts b/src/cli/tests/commands/generate-component.spec.ts index e5341070..8f6100ca 100644 --- a/src/cli/tests/commands/generate-component.spec.ts +++ b/src/cli/tests/commands/generate-component.spec.ts @@ -127,7 +127,7 @@ describe('GenerateComponent', () => { it('should generate a module that includes other generated components automatically', () => { generateComponent(componentName, { middleware: true, service: true, path }); generateComponent(componentName, { module: true, path }); - generateComponent(componentName, { repository: true, router: true, path }); + generateComponent(componentName, { repository: true, router: true, entity: true, path }); const subDirectory = 'subDirectory'; generateComponent(componentName, { validator: true, path: path + '/' + subDirectory }); @@ -142,11 +142,12 @@ describe('GenerateComponent', () => { import { TestValidator } from './${subDirectory}/test.validator'; import { TestRouter } from './test.router'; import { TestRepository } from './test.repository'; + import { Test } from './test.entity'; import { TestService } from './test.service'; import { TestMiddleware } from './test.middleware'; @Module({ - imports: [TestMiddleware, TestService, TestRepository, TestRouter, TestValidator] + imports: [TestMiddleware, TestService, Test, TestRepository, TestRouter, TestValidator] }) export class TestModule {} `)