From 860faa72fe6a21994940e35332253229c3b01df3 Mon Sep 17 00:00:00 2001 From: Dcode22 Date: Thu, 2 Nov 2023 22:23:17 +0200 Subject: [PATCH 1/2] standalone-pipe --- package-lock.json | 4 +- src/rz/angular/angular-effects.ts | 8 +++ .../angular/effects/standalone-pipe/index.ts | 0 .../snapshots/index-output.ts.snap | 1 + .../standalone-pipe/standalone-pipe.spec.ts | 70 +++++++++++++++++++ .../standalone-pipe/standalone-pipe.ts | 15 ++++ src/rz/angular/types/types.ts | 1 + 7 files changed, 97 insertions(+), 2 deletions(-) create mode 100644 src/rz/angular/effects/standalone-pipe/index.ts create mode 100644 src/rz/angular/effects/standalone-pipe/snapshots/index-output.ts.snap create mode 100644 src/rz/angular/effects/standalone-pipe/standalone-pipe.spec.ts create mode 100644 src/rz/angular/effects/standalone-pipe/standalone-pipe.ts diff --git a/package-lock.json b/package-lock.json index 6d29b4a..e4269a7 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@codemorph/core", - "version": "1.5.0", + "version": "1.5.3", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "@codemorph/core", - "version": "1.5.0", + "version": "1.5.3", "license": "RAZROO", "workspaces": [ "src/rz/angular" diff --git a/src/rz/angular/angular-effects.ts b/src/rz/angular/angular-effects.ts index e8de8b6..be14b61 100644 --- a/src/rz/angular/angular-effects.ts +++ b/src/rz/angular/angular-effects.ts @@ -13,6 +13,7 @@ import { AngularTypeNames, AngularOptionalType } from "./types/types"; import { libraryEffects, returnRootTsConfig } from './effects/library/library'; import { exportPipeFile, pipeEffects } from "./effects/pipe/pipe"; import { moduleEffects } from "./effects/module/module"; +import { standalonePipeEffects } from "./effects/standalone-pipe/standalone-pipe"; export function angularFilesToAffect(filePathWithName: string, fileTree: string[], type: AngularTypeNames, optionalTypes: AngularOptionalType[]): string[] | NOT_SUPPORTED_TYPE { switch(type) { @@ -26,6 +27,8 @@ export function angularFilesToAffect(filePathWithName: string, fileTree: string[ return closestIndexFileToImportTo(filePathWithName, fileTree, optionalTypes) case AngularTypeNames.Pipe: return closestIndexFileToImportTo(filePathWithName, fileTree, optionalTypes) + case AngularTypeNames.StandalonePipe: + return closestIndexFileToImportTo(filePathWithName, fileTree, optionalTypes); case AngularTypeNames.Interface: return closestIndexFileToImportTo(filePathWithName, fileTree, optionalTypes) case AngularTypeNames.Graphql: @@ -51,6 +54,8 @@ export function angularStandaloneEffects(type: AngularTypeNames, fileEffects: Ed return directiveEffects(fileEffects); case AngularTypeNames.Pipe: return pipeEffects(fileEffects); + case AngularTypeNames.StandalonePipe: + return standalonePipeEffects(fileEffects); case AngularTypeNames.Library: return libraryEffects(fileEffects, parameters); case AngularTypeNames.Interface: @@ -78,6 +83,9 @@ export function angularEffects(filePathWithName: string, type: AngularTypeNames, case AngularTypeNames.Pipe: exportPipeFile(filePathWithName); break; + case AngularTypeNames.StandalonePipe: + exportPipeFile(filePathWithName); + break; case AngularTypeNames.Interface: exportInterfaceFile(filePathWithName) break; diff --git a/src/rz/angular/effects/standalone-pipe/index.ts b/src/rz/angular/effects/standalone-pipe/index.ts new file mode 100644 index 0000000..e69de29 diff --git a/src/rz/angular/effects/standalone-pipe/snapshots/index-output.ts.snap b/src/rz/angular/effects/standalone-pipe/snapshots/index-output.ts.snap new file mode 100644 index 0000000..a791b35 --- /dev/null +++ b/src/rz/angular/effects/standalone-pipe/snapshots/index-output.ts.snap @@ -0,0 +1 @@ +export * from "./standalone-pipe"; diff --git a/src/rz/angular/effects/standalone-pipe/standalone-pipe.spec.ts b/src/rz/angular/effects/standalone-pipe/standalone-pipe.spec.ts new file mode 100644 index 0000000..1206df6 --- /dev/null +++ b/src/rz/angular/effects/standalone-pipe/standalone-pipe.spec.ts @@ -0,0 +1,70 @@ +import { TemplateInputParameter } from './../../../utils/interfaces/template-parameters'; +import { writeFileSync, readFileSync } from 'fs'; +import { effects, filesToAffect, standaloneEffects } from "../../../morph"; +import { AngularTypeNames } from "../../types/types"; +import { EditFileEffect } from '../../../morph/interfaces/morph.interface'; + + +describe('exportPipeFile', () => { + afterEach(() => { + writeFileSync('src/rz/angular/effects/standalone-pipe/index.ts', ''); + }); + it('should export pipe file', () => { + const mockFilePath = 'src/rz/angular/effects/standalone-pipe/standalone-pipe.ts'; + const mockTemplateInputParameter: TemplateInputParameter = { + defaultValue: 'libs/{name}-dialog', + description: 'File path for name file(s)', + inputType: 'text', + name: 'nameFilePath', + optionalTypes: [{name: 'isExported', selected: true}], + paramType: 'filePath', + type: AngularTypeNames.StandalonePipe + } + + effects(mockFilePath, mockTemplateInputParameter, 'angular'); + const result = readFileSync('src/rz/angular/effects/standalone-pipe/index.ts').toString(); + const expected = readFileSync('src/rz/angular/effects/standalone-pipe/snapshots/index-output.ts.snap').toString(); + expect(result).toEqual(expected); + }); +}); + +describe('closestIndexFileToImportTo', () => { + it('should choose closest index file', () => { + const mockFilePath = 'path/to/another/src/hello.pipe.ts'; + const mockParameter = { + optionalTypes: {}, + type: AngularTypeNames.StandalonePipe + } as any; + + const fileTree = [ + "path/to/another/src", + "path/to/another/src/hello.pipe.ts", + "path/to/another/index.ts", + "path/to/another" + ]; + const fileToModify = filesToAffect(mockFilePath, fileTree, mockParameter, 'angular'); + expect(fileToModify).toEqual(['path/to/another/index.ts']); + }); +}); + +describe('standalonepipeEffects', () => { + it('should trigger standalone pipe effects', () => { + const programmingLanguage = 'angular'; + const mockParameter = { + type: AngularTypeNames.StandalonePipe + } as any; + const mockFileEffects: EditFileEffect[] = [{ + filePath: 'path/to/another/index.ts', + originFilePath: 'path/to/another/src/hello.pipe.ts', + content: `` + }]; + const result = standaloneEffects(programmingLanguage, mockParameter, mockFileEffects); + const indexContent = `export * from "./src/hello.pipe"; +`; + expect(result).toEqual([{ + content: indexContent, + originFilePath: "path/to/another/src/hello.pipe.ts", + filePath: 'path/to/another/index.ts' + }]); + }); +}); \ No newline at end of file diff --git a/src/rz/angular/effects/standalone-pipe/standalone-pipe.ts b/src/rz/angular/effects/standalone-pipe/standalone-pipe.ts new file mode 100644 index 0000000..92d1876 --- /dev/null +++ b/src/rz/angular/effects/standalone-pipe/standalone-pipe.ts @@ -0,0 +1,15 @@ +import { EditFileEffect } from "../../../morph/interfaces/morph.interface"; +import { exportTsFiles, isTsFile } from "../../../utils/add-export"; +import { findClosestFileUsingPaths } from "../../../utils/find-closest-file/find-closest-file"; +import { exportInIndex } from "../../export-in-index"; +import { AngularOptionalType } from "../../types/types"; + +export function exportPipeFile(filePathWithName: string): void { + if(isTsFile(filePathWithName)) { + exportTsFiles(filePathWithName); + } +} + +export function standalonePipeEffects(fileEffects: EditFileEffect[]): EditFileEffect[] { + return exportInIndex(fileEffects) +} \ No newline at end of file diff --git a/src/rz/angular/types/types.ts b/src/rz/angular/types/types.ts index ac10a84..1a1fd6e 100644 --- a/src/rz/angular/types/types.ts +++ b/src/rz/angular/types/types.ts @@ -15,6 +15,7 @@ export enum AngularTypeNames { NgrxFacade = 'ngrx-facade', NgrxReducer = 'ngrx-reducer', Pipe = 'pipe', + StandalonePipe = 'standalone-pipe', Resolver = 'resolver', Service = 'service', ServiceWorker = 'service-worker', From aa425270a45697f2b0b64dcc6694ab1307365d7b Mon Sep 17 00:00:00 2001 From: Dcode22 Date: Thu, 2 Nov 2023 23:16:55 +0200 Subject: [PATCH 2/2] removed snapshot replaced with string logic --- .../effects/standalone-pipe/snapshots/index-output.ts.snap | 1 - src/rz/angular/effects/standalone-pipe/standalone-pipe.spec.ts | 3 ++- 2 files changed, 2 insertions(+), 2 deletions(-) delete mode 100644 src/rz/angular/effects/standalone-pipe/snapshots/index-output.ts.snap diff --git a/src/rz/angular/effects/standalone-pipe/snapshots/index-output.ts.snap b/src/rz/angular/effects/standalone-pipe/snapshots/index-output.ts.snap deleted file mode 100644 index a791b35..0000000 --- a/src/rz/angular/effects/standalone-pipe/snapshots/index-output.ts.snap +++ /dev/null @@ -1 +0,0 @@ -export * from "./standalone-pipe"; diff --git a/src/rz/angular/effects/standalone-pipe/standalone-pipe.spec.ts b/src/rz/angular/effects/standalone-pipe/standalone-pipe.spec.ts index 1206df6..d07b3b8 100644 --- a/src/rz/angular/effects/standalone-pipe/standalone-pipe.spec.ts +++ b/src/rz/angular/effects/standalone-pipe/standalone-pipe.spec.ts @@ -23,7 +23,8 @@ describe('exportPipeFile', () => { effects(mockFilePath, mockTemplateInputParameter, 'angular'); const result = readFileSync('src/rz/angular/effects/standalone-pipe/index.ts').toString(); - const expected = readFileSync('src/rz/angular/effects/standalone-pipe/snapshots/index-output.ts.snap').toString(); + const expected = `export * from "./standalone-pipe"; +` expect(result).toEqual(expected); }); });