diff --git a/src/rz/angular/angular-effects.ts b/src/rz/angular/angular-effects.ts index 2def41c..472a2f0 100644 --- a/src/rz/angular/angular-effects.ts +++ b/src/rz/angular/angular-effects.ts @@ -1,9 +1,9 @@ import { Parameters } from "../morph"; import { EditFileEffect, NOT_SUPPORTED, NOT_SUPPORTED_TYPE } from "../morph/interfaces/morph.interface"; import { addClassToDeclarationsAndImports, componentEffects, fileToAddClassToDeclarationsAndImports } from "./effects/component/component-effects"; +import { exportGraphqlFile, graphqlEffects } from "./effects/graphql/graphql"; +import { exportInterfaceFile, interfaceEffects } from "./effects/interface/interface"; import { directiveEffects, exportDirectiveFile } from "./effects/directive/directive"; -import { exportGraphqlFile } from "./effects/graphql/graphql"; -import { exportInterfaceFile } from "./effects/interface/interface"; import { addEffectToNgModule } from "./effects/ngrx/effects/ngrx-effects"; import { addFacadeToNgModule } from "./effects/ngrx/facade/ngrx-facade"; import { addReducerToNgModule } from "./effects/ngrx/reducer/ngrx-reducer"; @@ -25,6 +25,10 @@ export function angularFilesToAffect(filePathWithName: string, fileTree: string[ return closestIndexFileToImportTo(filePathWithName, fileTree, optionalTypes) case AngularTypeNames.Pipe: return closestIndexFileToImportTo(filePathWithName, fileTree, optionalTypes) + case AngularTypeNames.Interface: + return closestIndexFileToImportTo(filePathWithName, fileTree, optionalTypes) + case AngularTypeNames.Graphql: + return closestIndexFileToImportTo(filePathWithName, fileTree, optionalTypes) case AngularTypeNames.Directive: return closestIndexFileToImportTo(filePathWithName, fileTree, optionalTypes) default: @@ -46,6 +50,10 @@ export function angularStandaloneEffects(type: AngularTypeNames, fileEffects: Ed return pipeEffects(fileEffects); case AngularTypeNames.Library: return libraryEffects(fileEffects, parameters); + case AngularTypeNames.Interface: + return interfaceEffects(fileEffects); + case AngularTypeNames.Graphql: + return graphqlEffects(fileEffects); default: return []; } diff --git a/src/rz/angular/effects/graphql/graphql.spec.ts b/src/rz/angular/effects/graphql/graphql.spec.ts index 4997120..be13ab0 100644 --- a/src/rz/angular/effects/graphql/graphql.spec.ts +++ b/src/rz/angular/effects/graphql/graphql.spec.ts @@ -1,7 +1,9 @@ import { TemplateInputParameter } from './../../../utils/interfaces/template-parameters'; import { writeFileSync, readFileSync } from 'fs'; -import { effects } from "../../../morph"; +import { effects, filesToAffect } from "../../../morph"; import { AngularTypeNames } from "../../types/types"; +import { EditFileEffect } from '../../../morph/interfaces/morph.interface'; +import { graphqlEffects } from './graphql'; describe('exportGraphqlFile', () => { afterEach(() => { @@ -24,4 +26,36 @@ describe('exportGraphqlFile', () => { const expected = readFileSync('src/rz/angular/effects/graphql/snapshots/index-output.ts.snap').toString(); expect(result).toEqual(expected); }); + it('should trigger graphql effects', () => { + const mockFileEffects: EditFileEffect[] = [{ + filePath: 'path/to/another/index.ts', + originFilePath: 'path/to/another/src/hello.component.ts', + content: `` + }]; + const result = graphqlEffects(mockFileEffects); + const indexContent = `export * from "./src/hello.component"; +`; + expect(result).toEqual([{ + content: indexContent, + originFilePath: "path/to/another/src/hello.component.ts", + filePath: 'path/to/another/index.ts' + }]); + }); + + it('should choose closest index file', () => { + const mockFilePath = 'path/to/another/src/hello.graphql.ts'; + const mockParameter = { + optionalTypes: {}, + type: AngularTypeNames.Graphql + } as any; + + const fileTree = [ + "path/to/another/src", + "path/to/another/src/hello.component.ts", + "path/to/another/index.ts", + "path/to/another" + ]; + const fileToModify = filesToAffect(mockFilePath, fileTree, mockParameter, 'angular'); + expect(fileToModify).toEqual(['path/to/another/index.ts']); + }); }); \ No newline at end of file diff --git a/src/rz/angular/effects/graphql/graphql.ts b/src/rz/angular/effects/graphql/graphql.ts index 774f592..f7c09a8 100644 --- a/src/rz/angular/effects/graphql/graphql.ts +++ b/src/rz/angular/effects/graphql/graphql.ts @@ -1,7 +1,13 @@ +import { EditFileEffect } from "../../../morph/interfaces/morph.interface"; import { exportTsFiles, isTsFile } from "../../../utils/add-export"; +import { exportInIndex } from "../../export-in-index"; export function exportGraphqlFile(filePathWithName: string): void { if (isTsFile(filePathWithName)) { exportTsFiles(filePathWithName); } +} + +export function graphqlEffects(fileEffects: EditFileEffect[]): EditFileEffect[]{ + return exportInIndex(fileEffects) } \ No newline at end of file diff --git a/src/rz/angular/effects/interface/interface.spec.ts b/src/rz/angular/effects/interface/interface.spec.ts index 9fda629..4ca8894 100644 --- a/src/rz/angular/effects/interface/interface.spec.ts +++ b/src/rz/angular/effects/interface/interface.spec.ts @@ -1,13 +1,15 @@ import { TemplateInputParameter } from './../../../utils/interfaces/template-parameters'; import { writeFileSync, readFileSync } from 'fs'; -import { effects } from "../../../morph"; +import { effects, filesToAffect } from "../../../morph"; import { AngularTypeNames } from "../../types/types"; +import { EditFileEffect } from '../../../morph/interfaces/morph.interface'; +import { interfaceEffects } from './interface'; describe('exportInterfaceFile', () => { afterEach(() => { writeFileSync('src/rz/angular/effects/interface/index.ts', ''); }); - it('should export service file', () => { + it('should export interface file', () => { const mockFilePath = 'src/rz/angular/effects/interface/user.interface.ts'; const mockTemplateInputParameter: TemplateInputParameter = { defaultValue: 'libs/{name}-dialog', @@ -16,11 +18,44 @@ describe('exportInterfaceFile', () => { name: 'nameFilePath', optionalTypes: [{name: 'isExported', selected: true}], paramType: 'filePath', - type: AngularTypeNames.Service + type: AngularTypeNames.Interface }; effects(mockFilePath, mockTemplateInputParameter, 'angular'); const result = readFileSync('src/rz/angular/effects/interface/index.ts').toString(); const expected = readFileSync('src/rz/angular/effects/interface/snapshots/index-output.ts.snap').toString(); expect(result).toEqual(expected); }); + + it('should trigger interface effects', () => { + const mockFileEffects: EditFileEffect[] = [{ + filePath: 'path/to/another/index.ts', + originFilePath: 'path/to/another/src/hello.component.ts', + content: `` + }]; + const result = interfaceEffects(mockFileEffects); + const indexContent = `export * from "./src/hello.component"; +`; + expect(result).toEqual([{ + content: indexContent, + originFilePath: "path/to/another/src/hello.component.ts", + filePath: 'path/to/another/index.ts' + }]); + }); + + it('should choose closest index file', () => { + const mockFilePath = 'path/to/another/src/hello.interface.ts'; + const mockParameter = { + optionalTypes: {}, + type: AngularTypeNames.Interface + } as any; + + const fileTree = [ + "path/to/another/src", + "path/to/another/src/hello.component.ts", + "path/to/another/index.ts", + "path/to/another" + ]; + const fileToModify = filesToAffect(mockFilePath, fileTree, mockParameter, 'angular'); + expect(fileToModify).toEqual(['path/to/another/index.ts']); + }); }); \ No newline at end of file diff --git a/src/rz/angular/effects/interface/interface.ts b/src/rz/angular/effects/interface/interface.ts index 49452d2..e0dfbf3 100644 --- a/src/rz/angular/effects/interface/interface.ts +++ b/src/rz/angular/effects/interface/interface.ts @@ -1,7 +1,13 @@ +import { EditFileEffect } from "../../../morph/interfaces/morph.interface"; import { exportTsFiles, isTsFile } from "../../../utils/add-export"; +import { exportInIndex } from "../../export-in-index"; export function exportInterfaceFile(filePathWithName: string): void { if (isTsFile(filePathWithName)) { exportTsFiles(filePathWithName); } +} + +export function interfaceEffects(fileEffects: EditFileEffect[]): EditFileEffect[]{ + return exportInIndex(fileEffects) } \ No newline at end of file