Skip to content

Commit

Permalink
Merge pull request #48 from razroo/zeta-6827-standalone-interface
Browse files Browse the repository at this point in the history
standalone effects for graphql and interface
  • Loading branch information
CharlieGreenman authored Sep 28, 2023
2 parents 3b80622 + 9eeb797 commit b9bc143
Show file tree
Hide file tree
Showing 5 changed files with 95 additions and 6 deletions.
12 changes: 10 additions & 2 deletions src/rz/angular/angular-effects.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
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 { exportGraphqlFile, graphqlEffects } from "./effects/graphql/graphql";
import { exportInterfaceFile, interfaceEffects } from "./effects/interface/interface";
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";
import { addFacadeToNgModule } from "./effects/ngrx/facade/ngrx-facade";
import { addReducerToNgModule } from "./effects/ngrx/reducer/ngrx-reducer";
Expand All @@ -25,6 +25,10 @@ export function angularFilesToAffect(filePathWithName: string, fileTree: string[
return closestIndexFileToImportTo(filePathWithName, fileTree, optionalTypes)
case AngularTypeNames.Pipe:
return closestIndexFileToImportTo(filePathWithName, fileTree, optionalTypes)
case AngularTypeNames.Interface:
return closestIndexFileToImportTo(filePathWithName, fileTree, optionalTypes)
case AngularTypeNames.Graphql:
return closestIndexFileToImportTo(filePathWithName, fileTree, optionalTypes)
case AngularTypeNames.Directive:
return closestIndexFileToImportTo(filePathWithName, fileTree, optionalTypes)
default:
Expand All @@ -46,6 +50,10 @@ export function angularStandaloneEffects(type: AngularTypeNames, fileEffects: Ed
return pipeEffects(fileEffects);
case AngularTypeNames.Library:
return libraryEffects(fileEffects, parameters);
case AngularTypeNames.Interface:
return interfaceEffects(fileEffects);
case AngularTypeNames.Graphql:
return graphqlEffects(fileEffects);
default:
return [];
}
Expand Down
36 changes: 35 additions & 1 deletion src/rz/angular/effects/graphql/graphql.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 { EditFileEffect } from '../../../morph/interfaces/morph.interface';
import { graphqlEffects } from './graphql';

describe('exportGraphqlFile', () => {
afterEach(() => {
Expand All @@ -24,4 +26,36 @@ describe('exportGraphqlFile', () => {
const expected = readFileSync('src/rz/angular/effects/graphql/snapshots/index-output.ts.snap').toString();
expect(result).toEqual(expected);
});
it('should trigger graphql effects', () => {
const mockFileEffects: EditFileEffect[] = [{
filePath: 'path/to/another/index.ts',
originFilePath: 'path/to/another/src/hello.component.ts',
content: ``
}];
const result = graphqlEffects(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.graphql.ts';
const mockParameter = {
optionalTypes: {},
type: AngularTypeNames.Graphql
} 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/graphql/graphql.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 exportGraphqlFile(filePathWithName: string): void {
if (isTsFile(filePathWithName)) {
exportTsFiles(filePathWithName);
}
}

export function graphqlEffects(fileEffects: EditFileEffect[]): EditFileEffect[]{
return exportInIndex(fileEffects)
}
41 changes: 38 additions & 3 deletions src/rz/angular/effects/interface/interface.spec.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
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 { EditFileEffect } from '../../../morph/interfaces/morph.interface';
import { interfaceEffects } from './interface';

describe('exportInterfaceFile', () => {
afterEach(() => {
writeFileSync('src/rz/angular/effects/interface/index.ts', '');
});
it('should export service file', () => {
it('should export interface file', () => {
const mockFilePath = 'src/rz/angular/effects/interface/user.interface.ts';
const mockTemplateInputParameter: TemplateInputParameter = {
defaultValue: 'libs/{name}-dialog',
Expand All @@ -16,11 +18,44 @@ describe('exportInterfaceFile', () => {
name: 'nameFilePath',
optionalTypes: [{name: 'isExported', selected: true}],
paramType: 'filePath',
type: AngularTypeNames.Service
type: AngularTypeNames.Interface
};
effects(mockFilePath, mockTemplateInputParameter, 'angular');
const result = readFileSync('src/rz/angular/effects/interface/index.ts').toString();
const expected = readFileSync('src/rz/angular/effects/interface/snapshots/index-output.ts.snap').toString();
expect(result).toEqual(expected);
});

it('should trigger interface effects', () => {
const mockFileEffects: EditFileEffect[] = [{
filePath: 'path/to/another/index.ts',
originFilePath: 'path/to/another/src/hello.component.ts',
content: ``
}];
const result = interfaceEffects(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.interface.ts';
const mockParameter = {
optionalTypes: {},
type: AngularTypeNames.Interface
} 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/interface/interface.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 exportInterfaceFile(filePathWithName: string): void {
if (isTsFile(filePathWithName)) {
exportTsFiles(filePathWithName);
}
}

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

0 comments on commit b9bc143

Please sign in to comment.