-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
remove ts-morph, bump typescript version
- Loading branch information
1 parent
d632078
commit f218fd6
Showing
8 changed files
with
3,703 additions
and
290 deletions.
There are no files selected for viewing
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
101 changes: 0 additions & 101 deletions
101
packages/browser-extension/source/react-lowcode/clone/source.ts
This file was deleted.
Oops, something went wrong.
13 changes: 0 additions & 13 deletions
13
packages/browser-extension/source/react-lowcode/functions/rename.ts
This file was deleted.
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
This file was deleted.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,80 +1,100 @@ | ||
|
||
import { IntrospectionQuery } from "@iteria-app/graphql-lowcode/esm/generate" | ||
import { Project, SourceFile } from "ts-morph" | ||
import ts from "typescript" | ||
import { createEntityFromIntrospection, Entity, Property } from "../generation/entity" | ||
import { | ||
createEntityFromIntrospection, | ||
Entity, | ||
Property, | ||
} from "../generation/entity" | ||
|
||
export function createAst( | ||
code:string, | ||
scriptTarget = ts.ScriptTarget.ESNext, | ||
scriptKind = ts.ScriptKind.TSX, | ||
filePath = `/ts-ast-viewer.tsx` | ||
) { | ||
return ts.createSourceFile( | ||
filePath, | ||
code, | ||
scriptTarget, | ||
true, | ||
scriptKind | ||
) | ||
} | ||
|
||
export function sourceFileEntity(myClassFile: any/*SourceFile*/, typeName = "Customer") { | ||
const typeAlias = myClassFile.getTypeAlias(typeName) | ||
if (typeAlias) { | ||
const props = typeAlias?.getType()?.getProperties() ?? [] | ||
return { | ||
getName: () => typeName, | ||
getType: () => typeAlias, | ||
properties: props.map((prop: { getName: () => any; getTypeAtLocation: (arg0: any) => any; getDeclarations: () => { getText: () => any }[] }) => ({ | ||
code: string, | ||
scriptTarget = ts.ScriptTarget.ESNext, | ||
scriptKind = ts.ScriptKind.TSX, | ||
filePath = `/ts-ast-viewer.tsx` | ||
) { | ||
return ts.createSourceFile(filePath, code, scriptTarget, true, scriptKind) | ||
} | ||
|
||
export function sourceFileEntity( | ||
myClassFile: any /*SourceFile*/, | ||
typeName = "Customer" | ||
) { | ||
const typeAlias = myClassFile.getTypeAlias(typeName) | ||
if (typeAlias) { | ||
const props = typeAlias?.getType()?.getProperties() ?? [] | ||
return { | ||
getName: () => typeName, | ||
getType: () => typeAlias, | ||
properties: props.map( | ||
(prop: { | ||
getName: () => any | ||
getTypeAtLocation: (arg0: any) => any | ||
getDeclarations: () => { getText: () => any }[] | ||
}) => ({ | ||
getName: () => prop.getName(), | ||
getType: () => prop.getTypeAtLocation(myClassFile), | ||
getTypeText: () => prop.getDeclarations()[0].getText() | ||
})) | ||
} | ||
getTypeText: () => prop.getDeclarations()[0].getText(), | ||
}) | ||
), | ||
} | ||
} | ||
} | ||
|
||
export function getEntityProperty(typesSourceCode: string, name: string, typeName = "Utilization"): Property[] { | ||
const myClassFile = parseGraphqlTypes(typesSourceCode) | ||
const testEntity = sourceFileEntity(myClassFile, typeName) | ||
export function getEntityProperty( | ||
typesSourceCode: string, | ||
name: string, | ||
typeName = "Utilization" | ||
): Property[] { | ||
const myClassFile = parseGraphqlTypes(typesSourceCode) | ||
const testEntity = sourceFileEntity(myClassFile, typeName) | ||
|
||
let property = testEntity?.properties.filter(((prop: { getName: () => string })=> { | ||
let property = testEntity?.properties.filter( | ||
(prop: { getName: () => string }) => { | ||
return prop.getName().toLowerCase() === name.toLowerCase() | ||
})) | ||
} | ||
) | ||
|
||
return property ?? [] | ||
return property ?? [] | ||
} | ||
|
||
export function getEntityPropertyIntrospection(introspection: IntrospectionQuery, propertyName: string, typeName = "customer"): Property | undefined { | ||
const entity: Entity | undefined = createEntityFromIntrospection(introspection, typeName) | ||
export function getEntityPropertyIntrospection( | ||
introspection: IntrospectionQuery, | ||
propertyName: string, | ||
typeName = "customer" | ||
): Property | undefined { | ||
const entity: Entity | undefined = createEntityFromIntrospection( | ||
introspection, | ||
typeName | ||
) | ||
|
||
let property: Property | undefined = undefined | ||
|
||
if(entity){ | ||
let propertiesWithName = entity.properties.filter(((prop: { getName: () => string })=> { | ||
return prop.getName().toLowerCase() === propertyName | ||
})) | ||
if (entity) { | ||
let propertiesWithName = entity.properties.filter( | ||
(prop: { getName: () => string }) => { | ||
return prop.getName().toLowerCase() === propertyName | ||
} | ||
) | ||
|
||
if(propertiesWithName){ | ||
if (propertiesWithName) { | ||
property = propertiesWithName[0] | ||
} | ||
} | ||
|
||
return property | ||
} | ||
|
||
export function parseGraphqlTypes(sourceCode: string) { | ||
// initialize | ||
const project = new Project({ | ||
// Optionally specify compiler options, tsconfig.json, in-memory file system, and more here. | ||
// If you initialize with a tsconfig.json, then it will automatically populate the project | ||
// with the associated source files. | ||
// Read more: https://ts-morph.com/setup/ | ||
}) | ||
// add source files | ||
//project.addSourceFilesAtPaths("src/**/*.ts"); | ||
const myClassFile = project.createSourceFile("src/types.ts", sourceCode) | ||
return myClassFile | ||
} | ||
// export function parseGraphqlTypes(sourceCode: string) { | ||
// // initialize | ||
// const project = new Project({ | ||
// // Optionally specify compiler options, tsconfig.json, in-memory file system, and more here. | ||
// // If you initialize with a tsconfig.json, then it will automatically populate the project | ||
// // with the associated source files. | ||
// // Read more: https://ts-morph.com/setup/ | ||
// }) | ||
|
||
// // add source files | ||
// //project.addSourceFilesAtPaths("src/**/*.ts"); | ||
// const myClassFile = project.createSourceFile("src/types.ts", sourceCode) | ||
// return myClassFile | ||
// } |
Oops, something went wrong.