Skip to content

Commit 138abbb

Browse files
Merge pull request #66 from razroo/zeta-6800-standalone-effect-pipe
standalone-pipe
2 parents 83a0f55 + aa42527 commit 138abbb

File tree

6 files changed

+97
-2
lines changed

6 files changed

+97
-2
lines changed

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/rz/angular/angular-effects.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import { AngularTypeNames, AngularOptionalType } from "./types/types";
1313
import { libraryEffects, returnRootTsConfig } from './effects/library/library';
1414
import { exportPipeFile, pipeEffects } from "./effects/pipe/pipe";
1515
import { moduleEffects } from "./effects/module/module";
16+
import { standalonePipeEffects } from "./effects/standalone-pipe/standalone-pipe";
1617

1718
export function angularFilesToAffect(filePathWithName: string, fileTree: string[], type: AngularTypeNames, optionalTypes: AngularOptionalType[]): string[] | NOT_SUPPORTED_TYPE {
1819
switch(type) {
@@ -26,6 +27,8 @@ export function angularFilesToAffect(filePathWithName: string, fileTree: string[
2627
return closestIndexFileToImportTo(filePathWithName, fileTree, optionalTypes)
2728
case AngularTypeNames.Pipe:
2829
return closestIndexFileToImportTo(filePathWithName, fileTree, optionalTypes)
30+
case AngularTypeNames.StandalonePipe:
31+
return closestIndexFileToImportTo(filePathWithName, fileTree, optionalTypes);
2932
case AngularTypeNames.Interface:
3033
return closestIndexFileToImportTo(filePathWithName, fileTree, optionalTypes)
3134
case AngularTypeNames.Graphql:
@@ -51,6 +54,8 @@ export function angularStandaloneEffects(type: AngularTypeNames, fileEffects: Ed
5154
return directiveEffects(fileEffects);
5255
case AngularTypeNames.Pipe:
5356
return pipeEffects(fileEffects);
57+
case AngularTypeNames.StandalonePipe:
58+
return standalonePipeEffects(fileEffects);
5459
case AngularTypeNames.Library:
5560
return libraryEffects(fileEffects, parameters);
5661
case AngularTypeNames.Interface:
@@ -78,6 +83,9 @@ export function angularEffects(filePathWithName: string, type: AngularTypeNames,
7883
case AngularTypeNames.Pipe:
7984
exportPipeFile(filePathWithName);
8085
break;
86+
case AngularTypeNames.StandalonePipe:
87+
exportPipeFile(filePathWithName);
88+
break;
8189
case AngularTypeNames.Interface:
8290
exportInterfaceFile(filePathWithName)
8391
break;

src/rz/angular/effects/standalone-pipe/index.ts

Whitespace-only changes.
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
import { TemplateInputParameter } from './../../../utils/interfaces/template-parameters';
2+
import { writeFileSync, readFileSync } from 'fs';
3+
import { effects, filesToAffect, standaloneEffects } from "../../../morph";
4+
import { AngularTypeNames } from "../../types/types";
5+
import { EditFileEffect } from '../../../morph/interfaces/morph.interface';
6+
7+
8+
describe('exportPipeFile', () => {
9+
afterEach(() => {
10+
writeFileSync('src/rz/angular/effects/standalone-pipe/index.ts', '');
11+
});
12+
it('should export pipe file', () => {
13+
const mockFilePath = 'src/rz/angular/effects/standalone-pipe/standalone-pipe.ts';
14+
const mockTemplateInputParameter: TemplateInputParameter = {
15+
defaultValue: 'libs/{name}-dialog',
16+
description: 'File path for name file(s)',
17+
inputType: 'text',
18+
name: 'nameFilePath',
19+
optionalTypes: [{name: 'isExported', selected: true}],
20+
paramType: 'filePath',
21+
type: AngularTypeNames.StandalonePipe
22+
}
23+
24+
effects(mockFilePath, mockTemplateInputParameter, 'angular');
25+
const result = readFileSync('src/rz/angular/effects/standalone-pipe/index.ts').toString();
26+
const expected = `export * from "./standalone-pipe";
27+
`
28+
expect(result).toEqual(expected);
29+
});
30+
});
31+
32+
describe('closestIndexFileToImportTo', () => {
33+
it('should choose closest index file', () => {
34+
const mockFilePath = 'path/to/another/src/hello.pipe.ts';
35+
const mockParameter = {
36+
optionalTypes: {},
37+
type: AngularTypeNames.StandalonePipe
38+
} as any;
39+
40+
const fileTree = [
41+
"path/to/another/src",
42+
"path/to/another/src/hello.pipe.ts",
43+
"path/to/another/index.ts",
44+
"path/to/another"
45+
];
46+
const fileToModify = filesToAffect(mockFilePath, fileTree, mockParameter, 'angular');
47+
expect(fileToModify).toEqual(['path/to/another/index.ts']);
48+
});
49+
});
50+
51+
describe('standalonepipeEffects', () => {
52+
it('should trigger standalone pipe effects', () => {
53+
const programmingLanguage = 'angular';
54+
const mockParameter = {
55+
type: AngularTypeNames.StandalonePipe
56+
} as any;
57+
const mockFileEffects: EditFileEffect[] = [{
58+
filePath: 'path/to/another/index.ts',
59+
originFilePath: 'path/to/another/src/hello.pipe.ts',
60+
content: ``
61+
}];
62+
const result = standaloneEffects(programmingLanguage, mockParameter, mockFileEffects);
63+
const indexContent = `export * from "./src/hello.pipe";
64+
`;
65+
expect(result).toEqual([{
66+
content: indexContent,
67+
originFilePath: "path/to/another/src/hello.pipe.ts",
68+
filePath: 'path/to/another/index.ts'
69+
}]);
70+
});
71+
});
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import { EditFileEffect } from "../../../morph/interfaces/morph.interface";
2+
import { exportTsFiles, isTsFile } from "../../../utils/add-export";
3+
import { findClosestFileUsingPaths } from "../../../utils/find-closest-file/find-closest-file";
4+
import { exportInIndex } from "../../export-in-index";
5+
import { AngularOptionalType } from "../../types/types";
6+
7+
export function exportPipeFile(filePathWithName: string): void {
8+
if(isTsFile(filePathWithName)) {
9+
exportTsFiles(filePathWithName);
10+
}
11+
}
12+
13+
export function standalonePipeEffects(fileEffects: EditFileEffect[]): EditFileEffect[] {
14+
return exportInIndex(fileEffects)
15+
}

src/rz/angular/types/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ export enum AngularTypeNames {
1515
NgrxFacade = 'ngrx-facade',
1616
NgrxReducer = 'ngrx-reducer',
1717
Pipe = 'pipe',
18+
StandalonePipe = 'standalone-pipe',
1819
Resolver = 'resolver',
1920
Service = 'service',
2021
ServiceWorker = 'service-worker',

0 commit comments

Comments
 (0)