-
Notifications
You must be signed in to change notification settings - Fork 0
/
check.ts
65 lines (62 loc) · 1.86 KB
/
check.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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
import { parse, walk } from "./deps.ts";
// Async
async function printFilesNames({ skip }: { skip?: RegExp | RegExp[] }) {
console.log("type check start!");
const stack: string[] = [];
for await (
const entry of walk(".", {
includeFiles: true,
includeDirs: false,
exts: ["ts"],
skip: [/node_modules/, skip].flat().filter(Boolean) as RegExp[],
})
) {
console.log(entry.path);
if (stack.length < 15) {
stack.push(entry.path);
} else {
await runDenoCheck([...stack, entry.path]);
stack.length = 0;
// console.log({ status, stdout, stderr });
}
}
if (stack.length) {
await runDenoCheck(stack);
}
}
if (import.meta.main) {
/* deno run -A "check.ts" "--skip=npm|utils" */
await start();
// .catch(console.error);
}
async function start() {
const args = parse(Deno.args);
console.log(args);
const skip = typeof args.skip === "string"
? new RegExp(String(args.skip))
: Array.isArray(args.skip)
? args.skip.map((s) => new RegExp(s))
: undefined;
await printFilesNames({ skip }).then(() => console.log("type check Done!"));
}
async function runDenoCheck(stack: string[]) {
const cmd = ["deno", "check", "--unstable", "--remote", ...stack];
const process = Deno.run({
cmd: cmd,
stderr: "piped",
stdout: "piped",
});
const [status, stdout, stderr] = await Promise.all([
process.status(),
process.output(),
process.stderrOutput(),
]);
const decoder = new TextDecoder();
const out = decoder.decode(stdout);
const err = decoder.decode(stderr);
console.log(cmd, status, out, err);
process.close();
if (!status.success) {
throw new Error("type check failed:" + out + err);
}
}