-
Notifications
You must be signed in to change notification settings - Fork 4
/
Taskfile.ts
38 lines (31 loc) · 1.06 KB
/
Taskfile.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
/* To use Taskfile, it's recommended that you alias this to your shell:
Unix: alias deno-task='deno run --allow-run $(git rev-parse --show-toplevel)/Taskfile.ts'
Windows PowerShell: Set-Alias -Name deno-task -Value deno run --allow-run ./Taskfile.ts
Thanks to https://dev.to/vonheikemen/a-simple-way-to-replace-npm-scripts-in-deno-4j0g for this idea.
*/
type DenoTask = (...args: any[]) => Promise<Deno.ProcessStatus>;
function run([name, ...args]: string[], tasks: Record<string, DenoTask>): void {
if (tasks[name]) {
tasks[name](...args);
} else {
console.log(`Task "${name}" not found`);
}
}
async function exec(args: string[]): Promise<Deno.ProcessStatus> {
const proc = await Deno.run({ cmd: args }).status();
if (proc.success == false) {
Deno.exit(proc.code);
}
return proc;
}
run(Deno.args, {
test: () => exec(`deno test --allow-env`.split(" ")),
docs: () =>
exec(
`deno run --allow-read --allow-write documentation/createDocumentation.ts`
.split(
" ",
),
),
fmt: () => exec(`deno fmt`.split(" ")),
});