ts-meta-extract v0.7.3
Example
In the following example we defined a custom function to serilize ts files.
import {
serializeTsFiles,
serializeVueFiles,
customEntryFilters,
customDecoratorSerilize
} from "ts-meta-extract";
export function customSerializeTsFiles(entries: string[]) {
const output = serializeTsFiles(entries, {
classEntryFilter: customEntryFilters.isDecoratedBy(["Component"]),
serializeDecorator: customDecoratorSerilize.serializeLiteralDecorator(["Component", "Prop", "Inject"])
});
return output;
}The function provide a custom serialization which meets two conditions:
Only serialize classes decorated by decorator named by
"Component"; (by definingclassEntryFilter)Serialize all decorators named by
"Component","Prop"and"Inject". (by definingserializeDecorator)
Interface
serializeTsFiles(files, [config])recieves a dozens of entry files of typescript and extract all classes meta data into json string.The first parameter files is a string array for entry file names. And the second parameter config is an optional object contains hooks for some custom process.
The custom hooks includes:
classEntryFilter
(node)accepts a class declaration node of typets.ClassDeclaration, and returntrueif this class should be serialized. If no function was provided, all classes included in files will be serialized.serializeDecorator
(node)accepts a node of typets.Decorator, and should return astringtype. If a function is provided, the function will be use to serialize decorators.compilerHostGenerator
(compilerOptions)accepts a object of typets.CompilerOptions, and return a object of typets.CompilerHost. This is for some occasions that customising a compiler host for program generation is needed for some purpose like changing source file getter or customising module resolver.
serializeVueFiles(files, [config])is the same as serializeTsFiles except adding support of ".vue" vue single file components like files.