/
raw-runner.ts
34 lines (28 loc) · 1.01 KB
/
raw-runner.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
#!/usr/bin/env node
import { drop, last, filter } from "lodash"
async function main(useAsyncAwait: boolean, files: string[]) {
let cwd = process.cwd()
let tasks = files.map(file => [file, require(cwd + "/" + file).run])
if (useAsyncAwait) {
tasks.forEach(async ([file, run]: [string, Function]) => {
let name = last(file.split("/"))!.replace(".js", "")
console.time(name)
console.log(name, await run())
console.timeEnd(name)
console.log(" ")
})
} else {
tasks.forEach(([file, run]: [string, Function]) => {
let name = last(file.split("/"))!.replace(".js", "")
console.time(name)
console.log(name, run())
console.timeEnd(name)
})
}
}
let args: string[] = drop(process.argv, 2)
let asyncAwaitIndex = args.indexOf("--await")
let useAsyncAwait = asyncAwaitIndex !== -1
let files = filter(args, a => a !== "--await")
main(useAsyncAwait, files)
.catch(e => console.log(e))