From 838dbdf36a92823fd2eceb28411d529050c951d7 Mon Sep 17 00:00:00 2001 From: Charlie Greenman Date: Mon, 21 Aug 2023 19:42:47 -0700 Subject: [PATCH 1/5] ZETA-6515: Add a not supported flag. --- src/rz/morph/index.ts | 2 +- src/rz/morph/interfaces/morph.interface.ts | 3 +++ src/rz/morph/morph.ts | 6 +++--- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/src/rz/morph/index.ts b/src/rz/morph/index.ts index f984df0..a4ba1d6 100644 --- a/src/rz/morph/index.ts +++ b/src/rz/morph/index.ts @@ -1,3 +1,3 @@ export { morphCode, filesToAffect, effects, standaloneEffects, Parameters, types } from "./morph"; -export { EditFile, EditInput} from "./interfaces/morph.interface"; +export { EditFile, EditInput, NOT_SUPPORTED_TYPE, NOT_SUPPORTED} from "./interfaces/morph.interface"; export { communityPaths, supportedCommunityPaths } from "./community-paths/community-paths"; \ No newline at end of file diff --git a/src/rz/morph/interfaces/morph.interface.ts b/src/rz/morph/interfaces/morph.interface.ts index 268cd94..8368d36 100644 --- a/src/rz/morph/interfaces/morph.interface.ts +++ b/src/rz/morph/interfaces/morph.interface.ts @@ -7,6 +7,9 @@ export interface EditInput { edits: EditFile[]; } +export type NOT_SUPPORTED_TYPE = 'NOT_SUPPORTED'; +export const NOT_SUPPORTED = 'NOT_SUPPORTED'; + export interface EditFile { nodeType?: 'import' | 'export' | 'classDeclaration' | 'classMethod' | 'addNgModuleImport' | 'addNgModuleImportToSpec' | 'addNgModuleProvider' | 'addNgModuleDeclaration' | 'addNgModuleProviderToSpec' | 'addToVariableObject' | 'editImport' | 'addConstructorMethod' | diff --git a/src/rz/morph/morph.ts b/src/rz/morph/morph.ts index 9ffdf30..2a6a34a 100644 --- a/src/rz/morph/morph.ts +++ b/src/rz/morph/morph.ts @@ -11,7 +11,7 @@ import { EditJsonInput } from '../json/interfaces/json-morph.interface'; import { angularEffects, angularFilesToAffect, angularStandaloneEffects } from '../angular/angular-effects'; import { reactTypes } from '../react'; import { TemplateInputParameter } from '../utils/interfaces/template-parameters'; -import { EditFileEffect } from './interfaces/morph.interface'; +import { EditFileEffect, NOT_SUPPORTED, NOT_SUPPORTED_TYPE } from './interfaces/morph.interface'; // takes in singular object and makes all edits to files // used when editing a file @@ -53,12 +53,12 @@ export function filesToAffect(filePathWithName: string, fileTree: string[], para // such as automatically exporting file in closes index ts file // type respresents component, guard, pipe etc, which is specific to programming language // allows effects to work in any environment e.g. backend, system, frontend thus standalone -export function standaloneEffects(programmingLanguage: string, parameter: TemplateInputParameter, fileEffects: EditFileEffect[]): EditFileEffect[] { +export function standaloneEffects(programmingLanguage: string, parameter: TemplateInputParameter, fileEffects: EditFileEffect[]): EditFileEffect[] | NOT_SUPPORTED_TYPE { switch(programmingLanguage) { case CommunityPaths.Angular: return angularStandaloneEffects((parameter.type) as AngularTypeNames, fileEffects) default: - return [] + return NOT_SUPPORTED } } From 1c784d137e55f952f4f57691b2f35dbfee91f411 Mon Sep 17 00:00:00 2001 From: Charlie Greenman Date: Mon, 21 Aug 2023 19:43:34 -0700 Subject: [PATCH 2/5] ZETA-6515: Wire up not support type. --- src/rz/angular/angular-effects.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/rz/angular/angular-effects.ts b/src/rz/angular/angular-effects.ts index 3702555..5b3bd2f 100644 --- a/src/rz/angular/angular-effects.ts +++ b/src/rz/angular/angular-effects.ts @@ -1,5 +1,5 @@ import { Parameters } from "../morph"; -import { EditFileEffect } from "../morph/interfaces/morph.interface"; +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 { exportGraphqlFile } from "./effects/graphql/graphql"; @@ -11,12 +11,12 @@ import { exportServiceFile } from "./effects/service/service"; import { exportComponentFile } from "./effects/standalone-component/standalone-component"; import { AngularType, AngularTypeNames, AngularOptionalType } from "./types/types"; -export function angularFilesToAffect(filePathWithName: string, fileTree: string[], type: AngularTypeNames, optionalTypes: AngularOptionalType[]): string[] { +export function angularFilesToAffect(filePathWithName: string, fileTree: string[], type: AngularTypeNames, optionalTypes: AngularOptionalType[]): string[] | NOT_SUPPORTED_TYPE { switch(type) { case AngularTypeNames.Component: return fileToAddClassToDeclarationsAndImports(filePathWithName, fileTree, optionalTypes); default: - return []; + return NOT_SUPPORTED; } } From 5e0e3375b46d8cd9b6a55fa5d7c0b8e8d0a7f146 Mon Sep 17 00:00:00 2001 From: Charlie Greenman Date: Mon, 21 Aug 2023 19:52:51 -0700 Subject: [PATCH 3/5] ZETA-6515: Now returns not supported if not supported. --- src/rz/angular/angular-effect.spec.ts | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 src/rz/angular/angular-effect.spec.ts diff --git a/src/rz/angular/angular-effect.spec.ts b/src/rz/angular/angular-effect.spec.ts new file mode 100644 index 0000000..4bfc61d --- /dev/null +++ b/src/rz/angular/angular-effect.spec.ts @@ -0,0 +1,13 @@ +import { NOT_SUPPORTED } from "../morph"; +import { angularFilesToAffect } from "./angular-effects"; + +describe('AngularEffects', () => { + it('should return NOT_SUPPORTED if not supported', () => { + const filePath = 'libs/hello.ts'; + const fileTree: string[] = []; + const type = 'zulu' as any; + + const result = angularFilesToAffect(filePath, fileTree, type, []); + expect(result).toEqual(NOT_SUPPORTED) + }) +}) \ No newline at end of file From f6c08991bd0e712012010c7a3f61c340f8f453c7 Mon Sep 17 00:00:00 2001 From: Charlie Greenman Date: Mon, 21 Aug 2023 19:57:01 -0700 Subject: [PATCH 4/5] ZETA-6515: Confirm not supported support. --- src/rz/morph/morph.spec.ts | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/src/rz/morph/morph.spec.ts b/src/rz/morph/morph.spec.ts index ff7abbe..050c4b8 100644 --- a/src/rz/morph/morph.spec.ts +++ b/src/rz/morph/morph.spec.ts @@ -1,8 +1,8 @@ import { EditScssInput } from './../scss/interfaces/morph-scss.interface'; import { readFileSync, writeFileSync } from 'fs'; import { EditHtmlFile, EditHtmlInput } from '../angular/interfaces/edit-html.interface'; -import { EditInput } from './interfaces/morph.interface'; -import { morphCode } from "./morph"; +import { EditInput, NOT_SUPPORTED } from './interfaces/morph.interface'; +import { filesToAffect, morphCode } from "./morph"; describe('morph', () => { const siblingCodeBlock = ` { expect(morphCode(editScssInput as EditScssInput)).toEqual(expected); }); + describe('NOT_SUPPORTED', () => { + it('should return NOT_SUPPORTED if not supported', () => { + const mockFilePath = 'path/to/another/src/hello.component.ts'; + const mockParameter = { + optionalTypes: {}, + type: 'yolo' as any + } as any; + + const fileTree = [ + "path/to/another/src", + "path/to/another/src/hello.component.ts", + "path/to/another/hello.module.ts", + "path/to/another" + ]; + const fileToModify = filesToAffect(mockFilePath, fileTree, mockParameter, 'angular'); + expect(fileToModify).toEqual(NOT_SUPPORTED); + }) + }) + describe('insertIntoHtmlTag', () => { it('should insert html into the specified tag if parent tag is div', () => { const fileToBeAddedTo = readFileSync('src/rz/angular/snapshots/insert-into-html-tag/insert-into-html-tag.html.snap').toString(); From ab6fa75c3f431798b3a8396f8d163790242080d6 Mon Sep 17 00:00:00 2001 From: Charlie Greenman Date: Mon, 21 Aug 2023 20:02:20 -0700 Subject: [PATCH 5/5] ZETA-6515: Fix unit test and add another. --- src/rz/morph/morph.spec.ts | 20 +++++++++++++++++++- src/rz/morph/morph.ts | 8 ++++---- 2 files changed, 23 insertions(+), 5 deletions(-) diff --git a/src/rz/morph/morph.spec.ts b/src/rz/morph/morph.spec.ts index 050c4b8..223ac83 100644 --- a/src/rz/morph/morph.spec.ts +++ b/src/rz/morph/morph.spec.ts @@ -107,7 +107,25 @@ describe('morph', () => { }); describe('NOT_SUPPORTED', () => { - it('should return NOT_SUPPORTED if not supported', () => { + + it('should return NOT_SUPPORTED if not language supported', () => { + const mockFilePath = 'path/to/another/src/hello.component.ts'; + const mockParameter = { + optionalTypes: {}, + type: 'component' as any + } as any; + + const fileTree = [ + "path/to/another/src", + "path/to/another/src/hello.component.ts", + "path/to/another/hello.module.ts", + "path/to/another" + ]; + const fileToModify = filesToAffect(mockFilePath, fileTree, mockParameter, 'felipe'); + expect(fileToModify).toEqual(NOT_SUPPORTED); + }); + + it('should return NOT_SUPPORTED if language supported but type is not', () => { const mockFilePath = 'path/to/another/src/hello.component.ts'; const mockParameter = { optionalTypes: {}, diff --git a/src/rz/morph/morph.ts b/src/rz/morph/morph.ts index 2a6a34a..8418ba2 100644 --- a/src/rz/morph/morph.ts +++ b/src/rz/morph/morph.ts @@ -38,12 +38,12 @@ export interface Parameters { // sister function to "effects" // This function happens first and then effects is called -export function filesToAffect(filePathWithName: string, fileTree: string[], parameter: TemplateInputParameter, programmingLanguage: string): string[] { +export function filesToAffect(filePathWithName: string, fileTree: string[], parameter: TemplateInputParameter, programmingLanguage: string): string[] | NOT_SUPPORTED_TYPE { switch(programmingLanguage) { case 'angular': return angularFilesToAffect(filePathWithName, fileTree, (parameter.type) as AngularTypeNames, (parameter.optionalTypes) as any as AngularOptionalType[]); default: - return []; + return NOT_SUPPORTED; } } @@ -53,12 +53,12 @@ export function filesToAffect(filePathWithName: string, fileTree: string[], para // such as automatically exporting file in closes index ts file // type respresents component, guard, pipe etc, which is specific to programming language // allows effects to work in any environment e.g. backend, system, frontend thus standalone -export function standaloneEffects(programmingLanguage: string, parameter: TemplateInputParameter, fileEffects: EditFileEffect[]): EditFileEffect[] | NOT_SUPPORTED_TYPE { +export function standaloneEffects(programmingLanguage: string, parameter: TemplateInputParameter, fileEffects: EditFileEffect[]): EditFileEffect[] { switch(programmingLanguage) { case CommunityPaths.Angular: return angularStandaloneEffects((parameter.type) as AngularTypeNames, fileEffects) default: - return NOT_SUPPORTED + return [] } }