Skip to content

Commit

Permalink
Merge pull request #47 from razroo/zeta-6813-standalone-directive
Browse files Browse the repository at this point in the history
added directive standalone effects
  • Loading branch information
CharlieGreenman authored Sep 28, 2023
2 parents 74c9e61 + 35d1f36 commit 3b80622
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 2 deletions.
6 changes: 5 additions & 1 deletion src/rz/angular/angular-effects.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
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 { exportDirectiveFile } from "./effects/directive/directive";
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";
Expand All @@ -25,6 +25,8 @@ export function angularFilesToAffect(filePathWithName: string, fileTree: string[
return closestIndexFileToImportTo(filePathWithName, fileTree, optionalTypes)
case AngularTypeNames.Pipe:
return closestIndexFileToImportTo(filePathWithName, fileTree, optionalTypes)
case AngularTypeNames.Directive:
return closestIndexFileToImportTo(filePathWithName, fileTree, optionalTypes)
default:
return NOT_SUPPORTED;
}
Expand All @@ -38,6 +40,8 @@ export function angularStandaloneEffects(type: AngularTypeNames, fileEffects: Ed
return standaloneComponentEffects(fileEffects);
case AngularTypeNames.Service:
return serviceEffects(fileEffects);
case AngularTypeNames.Directive:
return directiveEffects(fileEffects);
case AngularTypeNames.Pipe:
return pipeEffects(fileEffects);
case AngularTypeNames.Library:
Expand Down
37 changes: 36 additions & 1 deletion src/rz/angular/effects/directive/directive.spec.ts
Original file line number Diff line number Diff line change
@@ -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 { directiveEffects } from './directive';
import { EditFileEffect } from '../../../morph/interfaces/morph.interface';

describe('exportDirectiveFile', () => {
afterEach(() => {
Expand All @@ -24,4 +26,37 @@ describe('exportDirectiveFile', () => {

expect(result).toEqual(expected);
});

it('should trigger directive effects', () => {
const mockFileEffects: EditFileEffect[] = [{
filePath: 'path/to/another/index.ts',
originFilePath: 'path/to/another/src/hello.component.ts',
content: ``
}];
const result = directiveEffects(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.directive.ts';
const mockParameter = {
optionalTypes: {},
type: AngularTypeNames.Directive
} 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']);
});
});
6 changes: 6 additions & 0 deletions src/rz/angular/effects/directive/directive.ts
Original file line number Diff line number Diff line change
@@ -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 exportDirectiveFile(filePathWithName: string): void {
if(isTsFile(filePathWithName)) {
exportTsFiles(filePathWithName);
}
}

export function directiveEffects(fileEffects: EditFileEffect[]): EditFileEffect[]{
return exportInIndex(fileEffects)
}

0 comments on commit 3b80622

Please sign in to comment.