-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.ts
30 lines (25 loc) · 1021 Bytes
/
index.ts
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
import { readdirSync, readFileSync, writeFileSync } from "fs";
import { resolve, basename } from "path";
import { transform } from "@mistlog/typetype";
import { exit } from "process";
const exampleDirs = readdirSync("./examples")
.map(name => resolve(__dirname, "./examples/", name));
exampleDirs.forEach(dir => {
const examples = readdirSync(dir)
.map(name => resolve(dir, name))
.filter(each => each.endsWith(".type"));
examples.forEach(example => {
const source = readFileSync(example, "utf8");
const name = basename(example).replace(".type", "");
try {
const code = transform(source, { debug: true }).code;
writeFileSync(resolve(dir, `${name}.ts`), code, "utf8");
} catch (error) {
console.log(`failed: ${name}.ts`);
console.log(error.message);
console.log(error.backtrace);
exit(-1)
}
})
})
console.log(`generate ts type file succeed`);