-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmod.ts
212 lines (194 loc) · 6.14 KB
/
mod.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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
import {
blue,
Checkbox,
Command,
Confirm,
gray,
Input,
red,
Secret,
Select,
Table,
yellow,
} from "./deps.ts";
import addBase from "./src/add-base.ts";
import addFramework from "./src/add-framework.ts";
import addPlugin from "./src/add-plugin.ts";
import initGit from "./src/init-git.ts";
// Stolen from https://github.com/discordeno/discordeno/blob/main/template/minimal/src/utils/helpers.ts
function humanizeMilliseconds(milliseconds: number) {
// Gets ms into seconds
const time = milliseconds / 1000;
if (time < 1) return "1s";
const days = Math.floor(time / 86400);
const hours = Math.floor((time % 86400) / 3600);
const minutes = Math.floor(((time % 86400) % 3600) / 60);
const seconds = Math.floor(((time % 86400) % 3600) % 60);
const dayString = days ? `${days}d ` : "";
const hourString = hours ? `${hours}h ` : "";
const minuteString = minutes ? `${minutes}m ` : "";
const secondString = seconds ? `${seconds}s ` : "";
return `${dayString}${hourString}${minuteString}${secondString}`.trim();
}
await new Command()
.name("create-discordeno-bot")
.version("1.0.0")
.description("A quick CLI to create a Discordeno Bot.")
.action(async () => {
console.log(`${blue(">")} Hey there 👋, thanks for using discordeno.`);
console.log(
`${
yellow("!")
} This CLI is WIP, please send bugs to: https://github.com/Reboot-Codes/create-discordeno-bot/issues\n${
yellow("!")
} Working configuration:`,
);
const worksTable = new Table(
["botType", "gateway"],
["approach", "functional"],
["framework", "none"],
["plugins", "[]"],
["botName", "any"],
["botToken", "any"],
["projectDir", "any"],
["initializeGit", "any"],
);
worksTable.border(true).render();
const botType = await Select.prompt({
indent: "",
listPointer: blue(">"),
pointer: blue(">"),
message: "What type of bot do you want to create?",
options: [
{ name: "Gateway Bot", value: "gateway" },
{ name: "HTTP Bot", value: "http" },
],
});
const approach = await Select.prompt({
indent: "",
listPointer: blue(">"),
pointer: blue(">"),
message: "Do you prefer a functional or Object-Oriented approach?",
options: [
{ name: "Functional", value: "functional" },
{ name: "Object-Oriented", value: "oop" },
],
});
let framework = "none";
if (approach == "oop") {
framework = await Select.prompt({
indent: "",
listPointer: blue(">"),
pointer: blue(">"),
message: "Which Object-Oriented framework would you like to use?",
options: [
{ name: "Natico", value: "natico" },
{ name: "Amethyst", value: "amethyst" },
{ name: "Oasis", value: "oasis" },
],
});
}
let plugins: string[] = [];
if (framework == "none") {
plugins = await Checkbox.prompt({
indent: "",
listPointer: blue(">"),
pointer: blue(">"),
message: "What plugins would you like to use?",
searchLabel: blue(">"),
options: [
{ name: "Cache Plugin", value: "cache" },
{ name: "Fileloader Plugin", value: "fileloader" },
{ name: "Permissions Plugin", value: "permissions" },
{ name: "Helpers Plugin", value: "helpers" },
],
});
}
console.log(
`\n${blue(">")} Okay, we're going to create a ${blue(botType)} bot.\n${
blue(">")
} ${
framework == "none"
? (
plugins.length > 0
? (`With the ${
plugins.length > 1
? `following plugins: ${blue(plugins.join(", "))}`
: `${blue(plugins[0])} plugin.`
}`)
: `Without any discordeno plugins.`
)
: `With the ${blue(framework)} framework.`
}\n`,
);
const denoVersion = Deno.version.deno;
if (!(Number(denoVersion.split(".")[0]) >= 1)) {
console.log(
`${
red("!")
} The version of deno you have installed (v${denoVersion}) is too old!\n${
red("!")
} Please upgrade to a version at or greater than v1`,
);
Deno.exit(1);
}
console.log(
`${blue(">")} You have ${
blue(`deno v${denoVersion}`)
} installed, great!\n`,
);
const botName = await Input.prompt({
indent: "",
listPointer: blue(">"),
pointer: blue(">"),
message: `What would you like to call your bot? ${
gray('(e.g. "Awesome Bot")')
}`,
minLength: 3,
});
const botToken = await Secret.prompt({
indent: "",
pointer: blue(">"),
message: "What is your bot's API token?",
});
const projectDir = await Input.prompt({
indent: "",
listPointer: blue(">"),
pointer: blue(">"),
message: "Where would you like to initialize the bot?",
default: `./${botName.toLowerCase().split(" ").join("-")}`,
});
const initializeGit = await Confirm.prompt({
indent: "",
pointer: blue(">"),
message: "Would you like to initialize a git repository?",
default: true,
});
console.log(
`\n${blue(">")} Amazing! Creating a bot in ${blue(projectDir)} using ${
framework == "none" ? blue(`discordeno v13.0.0-rc35`) : blue(framework)
}...\n`,
);
const startTime = performance.now();
if (framework == "none") {
// Framework-less Setup Steps
await addBase(projectDir, botType, botToken == "" ? undefined : botToken);
if (plugins.length > 0) {
for (const plugin of plugins) {
await addPlugin(projectDir, plugin);
}
}
} else {
// Framework Setup, they require different setup steps.
await addFramework(projectDir, framework);
}
// Although git init is the same for either Functional or OOP
if (initializeGit) await initGit(projectDir);
const endTime = performance.now();
console.log(
`\n${blue(">")} Created ${blue(botName)} in ${blue(projectDir)}, took ${
blue(humanizeMilliseconds(endTime - startTime))
}.`,
);
})
.parse(Deno.args);