Skip to content

Commit

Permalink
Merge pull request #66 from razroo/zeta-6800-standalone-effect-pipe
Browse files Browse the repository at this point in the history
standalone-pipe
  • Loading branch information
CharlieGreenman authored Nov 2, 2023
2 parents 83a0f55 + aa42527 commit 138abbb
Show file tree
Hide file tree
Showing 6 changed files with 97 additions and 2 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions src/rz/angular/angular-effects.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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:
Expand All @@ -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:
Expand Down Expand Up @@ -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;
Expand Down
Empty file.
71 changes: 71 additions & 0 deletions src/rz/angular/effects/standalone-pipe/standalone-pipe.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
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 = `export * from "./standalone-pipe";
`
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'
}]);
});
});
15 changes: 15 additions & 0 deletions src/rz/angular/effects/standalone-pipe/standalone-pipe.ts
Original file line number Diff line number Diff line change
@@ -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)
}
1 change: 1 addition & 0 deletions src/rz/angular/types/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down

0 comments on commit 138abbb

Please sign in to comment.