Skip to content

Commit

Permalink
remove ts-morph, bump typescript version
Browse files Browse the repository at this point in the history
  • Loading branch information
mecirmartin committed Dec 21, 2021
1 parent d632078 commit f218fd6
Show file tree
Hide file tree
Showing 8 changed files with 3,703 additions and 290 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"jest": "^26.6.3",
"ts-jest": "^26.5.4",
"ts-morph": "^10.0.1",
"typescript": "^4.2.3",
"typescript": "4.4.4",
"typescript-pluralize": "^1.0.1"
}
}
101 changes: 0 additions & 101 deletions packages/browser-extension/source/react-lowcode/clone/source.ts

This file was deleted.

This file was deleted.

7 changes: 1 addition & 6 deletions packages/react-lowcode/src/ast/identifierLength.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@
import {
SourceLineCol,
startOfJsxIdentifier,
astFindStart,
} from "../ast/find"
import { SourceFile } from "ts-morph"
import { SourceLineCol, startOfJsxIdentifier, astFindStart } from "../ast/find"

export const getJsxIdentifierLength = (code: string, source: SourceLineCol) => {
const pos = startOfJsxIdentifier(code, source)
Expand Down
101 changes: 0 additions & 101 deletions packages/react-lowcode/src/clone/source.ts

This file was deleted.

130 changes: 75 additions & 55 deletions packages/react-lowcode/src/codegen/tests/helper.ts
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
// }
Loading

0 comments on commit f218fd6

Please sign in to comment.