-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #66 from razroo/zeta-6800-standalone-effect-pipe
standalone-pipe
- Loading branch information
Showing
6 changed files
with
97 additions
and
2 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
71 changes: 71 additions & 0 deletions
71
src/rz/angular/effects/standalone-pipe/standalone-pipe.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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' | ||
}]); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters