-
Notifications
You must be signed in to change notification settings - Fork 13
/
cli.ts
71 lines (65 loc) · 1.81 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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
/**
* Copyright (c) Crew Dev.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
*/
import { CommandNotFound, HelpCommand } from "./src/shared/log.ts";
import { VERSION as cliVersion } from "./src/shared/version.ts";
import { flags, keyWords } from "./src/shared/utils.ts";
import { CreateProject } from "./src/cli/create.ts";
import { PromptConfig } from "./src/cli/prompt.ts";
import { showHelp } from "./src/shared/utils.ts";
import { colors } from "./imports/fmt.ts";
const { args: Args } = Deno;
type Command = "create";
const command = Args[0] as Command;
const instructs = {
// create a template project
async create() {
if (flags.help.includes(Args[1])) {
return HelpCommand({
command: {
alias: [keyWords.create],
description: "create a template project",
},
flags: [{ alias: flags.help, description: "show command help" }],
});
} else await CreateProject({ ...PromptConfig(), projectName: Args[1] });
},
};
async function Main() {
try {
// execute instructions
if (command === "create") {
return await instructs.create();
}
// show version
else if (flags.version.includes(Args[0])) {
console.log(
colors.green(
`snel: ${colors.yellow(cliVersion)}\ndeno: ${colors.yellow(
Deno.version.deno
)}`
)
);
}
// show help
else if (flags.help.includes(Args[0]) || !Args[0]) {
showHelp();
} else {
CommandNotFound({
commands: [keyWords.create],
flags: [...flags.help, ...flags.version],
});
}
} catch (error: any) {
if (!(error instanceof Deno.errors.NotFound)) {
console.log(error);
}
}
}
if (import.meta.main) {
await Main();
}