Нет ts.ScriptTarget.TypeScript
, поэтому вам нужно использовать API компилятора.
Вот основная идея (не проверено, но должно помочь вам начать с этого):
import * as ts from "typescript";
// setup
const printer = ts.createPrinter();
const sourceFiles: ts.SourceFile[] = ...;
const transformerFactory: ts.TransformerFactory<ts.SourceFile> = ...;
// transform the source files
const transformationResult = ts.transform(sourceFiles, [transformerFactory]);
// log the diagnostics if they exist
if (transformationResult.diagnostics) {
// output diagnostics (ts.formatDiagnosticsWithColorAndContext is nice to use)
}
// print the transformed ASTs and write the result out to files
// note: replace fs.writeFile with something that actually works
const fileWrites = transformationResult.transformed
.map(file => fs.writeFile(file.fileName, printer.printFile(file));
Promise.all(fileWrites)
.then(() => console.log("finished"))
.catch(err => console.error(err));