-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcli.ts
42 lines (36 loc) · 1.01 KB
/
cli.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
import { join, parse, colors } from "./deps.ts";
import { prepareEnv } from "./env.ts";
import { install } from "./install.ts";
import { cache } from "./runnable.ts";
if (import.meta.main) {
prepareEnv();
await cli();
}
async function cli() {
const args = parse(Deno.args);
const { _: [command, ...subCommands] } = args;
switch (command) {
case undefined:
await runTask("default");
break;
case "install":
const [name, url] = subCommands.map(s => s.toString());
const denoInstallArgs = Deno.args.slice(3);
await install({ name, url, denoInstallArgs });
break;
default:
await runTask(command.toString());
break;
}
}
async function runTask(task: string) {
await import(`file://${join(Deno.cwd(), "devo.ts")}`).catch(e => {
console.error(colors.red("Error loading devo.ts file"));
console.error(e);
});
if (!cache.has(task) && !cache.has("default")) {
console.log(`task not found: ${task}`);
Deno.exit();
}
cache.get(task)?.run();
}