Add ability to generate interfaces
This commit is contained in:
parent
d06781277a
commit
1289913d06
@ -25,6 +25,7 @@ interface IClassProperty {
|
|||||||
|
|
||||||
interface IClassDefinition {
|
interface IClassDefinition {
|
||||||
name: string
|
name: string
|
||||||
|
type: ts.Type
|
||||||
typeParameters: ts.TypeParameter[]
|
typeParameters: ts.TypeParameter[]
|
||||||
relevantTypeParameters: ts.Type[]
|
relevantTypeParameters: ts.Type[]
|
||||||
allRelevantTypes: ts.Type[]
|
allRelevantTypes: ts.Type[]
|
||||||
@ -199,7 +200,11 @@ export function typecheck(...argv: string[]) {
|
|||||||
handleType(type)
|
handleType(type)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const typeDefinitions: Map<ts.Type, IClassDefinition> = new Map()
|
||||||
function handleType(type: ts.Type) {
|
function handleType(type: ts.Type) {
|
||||||
|
if (typeDefinitions.has(type)) {
|
||||||
|
return
|
||||||
|
}
|
||||||
const typeParameters: ts.TypeParameter[] = []
|
const typeParameters: ts.TypeParameter[] = []
|
||||||
const expandedTypeParameters: ts.Type[] = []
|
const expandedTypeParameters: ts.Type[] = []
|
||||||
const allRelevantTypes: ts.Type[] = []
|
const allRelevantTypes: ts.Type[] = []
|
||||||
@ -260,6 +265,7 @@ export function typecheck(...argv: string[]) {
|
|||||||
|
|
||||||
const classDef: IClassDefinition = {
|
const classDef: IClassDefinition = {
|
||||||
name: typeToString(type),
|
name: typeToString(type),
|
||||||
|
type,
|
||||||
// name: symbol.getName(),
|
// name: symbol.getName(),
|
||||||
typeParameters,
|
typeParameters,
|
||||||
allRelevantTypes: allRelevantTypes
|
allRelevantTypes: allRelevantTypes
|
||||||
@ -269,18 +275,22 @@ export function typecheck(...argv: string[]) {
|
|||||||
properties: classProperties,
|
properties: classProperties,
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log(classDef.name)
|
console.log(`interface ${classDef.name} {`)
|
||||||
console.log(' ',
|
console.log(' ',
|
||||||
classDef.properties
|
classDef.properties
|
||||||
.map(p => p.name + ': ' + typeToString(p.type) + ' {' +
|
.map(p => p.name + ': ' + typeToString(p.type)) // + ' {' +
|
||||||
p.relevantTypes.map(typeToString) + '}')
|
// p.relevantTypes.map(typeToString) + '}')
|
||||||
.join('\n '),
|
.join('\n '),
|
||||||
)
|
)
|
||||||
console.log('\n allRelevantTypes:\n ',
|
console.log('}')
|
||||||
classDef.allRelevantTypes.map(typeToString).join('\n '))
|
// console.log('\n allRelevantTypes:\n ',
|
||||||
|
// classDef.allRelevantTypes.map(typeToString).join('\n '))
|
||||||
console.log('\n')
|
console.log('\n')
|
||||||
|
|
||||||
classDefs.push(classDef)
|
classDefs.push(classDef)
|
||||||
|
typeDefinitions.set(type, classDef)
|
||||||
|
|
||||||
|
allRelevantTypes.map(handleType)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -317,15 +327,28 @@ export function typecheck(...argv: string[]) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const Vote = classDefs.find(c => c.name === 'Vote')
|
// const defs: Map<ts.Type, IClassDefinition> = new Map()
|
||||||
if (Vote) {
|
// classDefs.forEach(classDef => {
|
||||||
console.log('found vote')
|
// defs.set(classDef.type, classDef)
|
||||||
const U = Vote.allRelevantTypes.find(t => typeToString(t) === 'User')
|
// })
|
||||||
if (U) {
|
|
||||||
console.log('found user')
|
// classDefs.forEach(classDef => {
|
||||||
handleType(U)
|
// classDef.allRelevantTypes.forEach(type => {
|
||||||
}
|
// if (!defs.has(type)) {
|
||||||
}
|
// handleType(type)
|
||||||
|
// }
|
||||||
|
// })
|
||||||
|
// })
|
||||||
|
|
||||||
|
// const Vote = classDefs.find(c => c.name === 'Vote')
|
||||||
|
// if (Vote) {
|
||||||
|
// console.log('found vote')
|
||||||
|
// const U = Vote.allRelevantTypes.find(t => typeToString(t) === 'User')
|
||||||
|
// if (U) {
|
||||||
|
// console.log('found user')
|
||||||
|
// handleType(U)
|
||||||
|
// }
|
||||||
|
// }
|
||||||
}
|
}
|
||||||
|
|
||||||
generateInterfaces([args.file], {
|
generateInterfaces([args.file], {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user