forked from TheLartians/TypeScript2Python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.ts
More file actions
executable file
路36 lines (30 loc) 路 903 Bytes
/
Copy pathindex.ts
File metadata and controls
executable file
路36 lines (30 loc) 路 903 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#!/usr/bin/env node
import ts from "typescript";
import path from "path";
import { program } from "@commander-js/extra-typings";
import { typeScriptToPython } from "./typeScriptToPython";
const compile = (fileNames: string[]) => {
const program = ts.createProgram(fileNames, {
noEmit: true,
allowJs: true,
resolveJsonModule: true,
skipLibCheck: true,
});
const relevantSourceFiles = program
.getSourceFiles()
.filter((f) =>
fileNames
.map((fn) => path.relative(fn, f.fileName) === "")
.reduce((a, b) => a || b),
);
const transpiled = typeScriptToPython(program.getTypeChecker(), relevantSourceFiles)
console.log(transpiled);
}
program
.name("typescript2python")
.description("A program that converts TypeScript type definitions to Python")
.arguments("<input...>")
.action(args => {
compile(args)
})
.parse(process.argv)