create-bot-ts 1.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of create-bot-ts might be problematic. Click here for more details.
- package/.prettierrc +8 -0
- package/README.md +20 -0
- package/index.js +287 -0
- package/package.json +14 -0
package/.prettierrc
ADDED
package/README.md
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
# create-bot-ts
|
|
2
|
+
|
|
3
|
+
This is a package that I use as some sort of starter template for Discord bots in typescript.
|
|
4
|
+
|
|
5
|
+
#### Its main features are
|
|
6
|
+
|
|
7
|
+
- Yarn Berry
|
|
8
|
+
- Git
|
|
9
|
+
- Typescript
|
|
10
|
+
- yarn version
|
|
11
|
+
- yarn upgrade-interactive
|
|
12
|
+
- husky
|
|
13
|
+
- list-staged
|
|
14
|
+
- eslit & prettier
|
|
15
|
+
|
|
16
|
+
After installation run:
|
|
17
|
+
|
|
18
|
+
```sh
|
|
19
|
+
yarn create @eslint/config
|
|
20
|
+
```
|
package/index.js
ADDED
|
@@ -0,0 +1,287 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
const cp = require("child_process");
|
|
3
|
+
const fs = require("fs");
|
|
4
|
+
const path = require("path");
|
|
5
|
+
const outdent = require("outdent");
|
|
6
|
+
const { createSpinner } = require("nanospinner");
|
|
7
|
+
|
|
8
|
+
// Start the spinner
|
|
9
|
+
const spinner = createSpinner(
|
|
10
|
+
"Creating template! Do not exit the process..."
|
|
11
|
+
).start({
|
|
12
|
+
color: "green",
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
const NS_PER_SEC = 1e9;
|
|
16
|
+
const MS_PER_NS = 1e-6;
|
|
17
|
+
const time = process.hrtime();
|
|
18
|
+
|
|
19
|
+
// Make the src and child directories
|
|
20
|
+
fs.mkdirSync(path.join(process.cwd(), "src"));
|
|
21
|
+
fs.mkdirSync(path.join(process.cwd(), "src", "client"));
|
|
22
|
+
fs.mkdirSync(path.join(process.cwd(), "src", "commands"));
|
|
23
|
+
fs.mkdirSync(path.join(process.cwd(), "src", "events"));
|
|
24
|
+
fs.mkdirSync(path.join(process.cwd(), "src", "utils"));
|
|
25
|
+
fs.mkdirSync(path.join(process.cwd(), "src", "interfaces"));
|
|
26
|
+
fs.mkdirSync(path.join(process.cwd(), "src", "models"));
|
|
27
|
+
|
|
28
|
+
// Make index.ts in src and client.ts
|
|
29
|
+
fs.writeFileSync(path.join(process.cwd(), "src", "index.ts"), "");
|
|
30
|
+
fs.writeFileSync(path.join(process.cwd(), "src", "client", "index.ts"), "");
|
|
31
|
+
|
|
32
|
+
// Declare function that writes files
|
|
33
|
+
const writeFiles = (files) => {
|
|
34
|
+
files.map((f) => {
|
|
35
|
+
fs.writeFileSync(
|
|
36
|
+
path.join(process.cwd(), f.path),
|
|
37
|
+
outdent`${f.content}`
|
|
38
|
+
);
|
|
39
|
+
});
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
// Use the declared function above here.
|
|
43
|
+
writeFiles([
|
|
44
|
+
{
|
|
45
|
+
path: "tsconfig.json",
|
|
46
|
+
content: `{
|
|
47
|
+
"compilerOptions": {
|
|
48
|
+
"lib": ["ESNext"],
|
|
49
|
+
"module": "commonjs",
|
|
50
|
+
"moduleResolution": "node",
|
|
51
|
+
"target": "ESNext",
|
|
52
|
+
"sourceMap": true,
|
|
53
|
+
"esModuleInterop": true,
|
|
54
|
+
"experimentalDecorators": true,
|
|
55
|
+
"emitDecoratorMetadata": true,
|
|
56
|
+
"allowSyntheticDefaultImports": true,
|
|
57
|
+
"skipLibCheck": true,
|
|
58
|
+
"skipDefaultLibCheck": true,
|
|
59
|
+
"declaration": true,
|
|
60
|
+
"resolveJsonModule": true
|
|
61
|
+
},
|
|
62
|
+
"include": ["src"]
|
|
63
|
+
}
|
|
64
|
+
`,
|
|
65
|
+
},
|
|
66
|
+
{
|
|
67
|
+
path: ".prettierrc",
|
|
68
|
+
content: `{
|
|
69
|
+
"semi": true,
|
|
70
|
+
"singleQuote": false,
|
|
71
|
+
"tabWidth": 4,
|
|
72
|
+
"printWidth": 80,
|
|
73
|
+
"useTabs": false,
|
|
74
|
+
"endOfLine": "lf"
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
`,
|
|
78
|
+
},
|
|
79
|
+
{
|
|
80
|
+
path: ".gitignore",
|
|
81
|
+
content: `# @see https://git-scm.com/docs/gitignore
|
|
82
|
+
|
|
83
|
+
# \`.DS_Store\` is a file that stores custom attributes of its containing folder
|
|
84
|
+
.DS_Store
|
|
85
|
+
|
|
86
|
+
# Logs
|
|
87
|
+
logs
|
|
88
|
+
*.log
|
|
89
|
+
|
|
90
|
+
# Dependencies
|
|
91
|
+
node_modules
|
|
92
|
+
bower_components
|
|
93
|
+
vendor
|
|
94
|
+
|
|
95
|
+
# yarn v2
|
|
96
|
+
.yarn/*
|
|
97
|
+
!.yarn/cache
|
|
98
|
+
!.yarn/patches
|
|
99
|
+
!.yarn/plugins
|
|
100
|
+
!.yarn/releases
|
|
101
|
+
!.yarn/sdks
|
|
102
|
+
!.yarn/versions
|
|
103
|
+
|
|
104
|
+
# Envs
|
|
105
|
+
.env
|
|
106
|
+
|
|
107
|
+
# Databases
|
|
108
|
+
*.db
|
|
109
|
+
|
|
110
|
+
# Caches
|
|
111
|
+
.cache
|
|
112
|
+
.npm
|
|
113
|
+
.eslintcache
|
|
114
|
+
|
|
115
|
+
# Temporaries
|
|
116
|
+
.tmp
|
|
117
|
+
.temp
|
|
118
|
+
|
|
119
|
+
# Built
|
|
120
|
+
dist
|
|
121
|
+
target
|
|
122
|
+
built
|
|
123
|
+
output
|
|
124
|
+
out
|
|
125
|
+
|
|
126
|
+
# Editor directories and files
|
|
127
|
+
.idea
|
|
128
|
+
.templates
|
|
129
|
+
template.config.js
|
|
130
|
+
*.suo
|
|
131
|
+
*.ntvs*
|
|
132
|
+
*.njsproj
|
|
133
|
+
*.sln
|
|
134
|
+
*.sw?
|
|
135
|
+
|
|
136
|
+
# Push Scripts
|
|
137
|
+
push.bat
|
|
138
|
+
push.sh
|
|
139
|
+
|
|
140
|
+
`,
|
|
141
|
+
},
|
|
142
|
+
]);
|
|
143
|
+
|
|
144
|
+
spinner.update({
|
|
145
|
+
text: "Initializing npm package...",
|
|
146
|
+
});
|
|
147
|
+
|
|
148
|
+
// Initialize the npm package with -y to default to yes to all prompts
|
|
149
|
+
cp.exec("npm init -y", { cwd: process.cwd() }, () => {
|
|
150
|
+
spinner.update({
|
|
151
|
+
text: "Initializing Yarn Berry...",
|
|
152
|
+
color: "blue",
|
|
153
|
+
});
|
|
154
|
+
// Set yarn version to berry
|
|
155
|
+
cp.exec("yarn set version berry", { cwd: process.cwd() }, () => {
|
|
156
|
+
spinner.update({
|
|
157
|
+
text: "Adding git...",
|
|
158
|
+
color: "red",
|
|
159
|
+
});
|
|
160
|
+
|
|
161
|
+
// Synchronize git
|
|
162
|
+
cp.execSync("git init", { cwd: process.cwd() });
|
|
163
|
+
|
|
164
|
+
spinner.update({
|
|
165
|
+
text: "Installing yarn plugins...",
|
|
166
|
+
color: "blue",
|
|
167
|
+
});
|
|
168
|
+
|
|
169
|
+
// Install yarn plugins
|
|
170
|
+
cp.execSync("yarn plugin import version", { cwd: process.cwd() });
|
|
171
|
+
cp.execSync("yarn plugin import interactive-tools", {
|
|
172
|
+
cwd: process.cwd(),
|
|
173
|
+
});
|
|
174
|
+
|
|
175
|
+
cp.exec("yarn", { cwd: process.cwd() }, () => {
|
|
176
|
+
cp.exec(
|
|
177
|
+
"yarn add discord.js bufferutil erlpack zlib-sync utf-8-validate",
|
|
178
|
+
{ cwd: process.cwd() },
|
|
179
|
+
() => {
|
|
180
|
+
spinner.update({
|
|
181
|
+
text: "Adding discord dependencies",
|
|
182
|
+
color: "blue",
|
|
183
|
+
});
|
|
184
|
+
cp.exec(
|
|
185
|
+
"yarn plugin import typescript",
|
|
186
|
+
{ cwd: process.cwd() },
|
|
187
|
+
() => {
|
|
188
|
+
spinner.update({
|
|
189
|
+
text: "Adding necessary devDependencies",
|
|
190
|
+
color: "yellow",
|
|
191
|
+
});
|
|
192
|
+
cp.exec(
|
|
193
|
+
`yarn add --dev eslint eslint-config-airbnb-base eslint-config-prettier eslint-import-resolver-node eslint-plugin-import eslint-plugin-prettier @typescript-eslint/eslint-plugin @typescript-eslint/parser husky lint-staged node-notifier prettier ts-node ts-node-dev`,
|
|
194
|
+
{ cwd: process.cwd() },
|
|
195
|
+
() => {
|
|
196
|
+
spinner.update({
|
|
197
|
+
text: "Setting up husky...",
|
|
198
|
+
color: "cyan",
|
|
199
|
+
});
|
|
200
|
+
cp.execSync("yarn dlx husky-init --yarn2", {
|
|
201
|
+
cwd: process.cwd(),
|
|
202
|
+
});
|
|
203
|
+
spinner.update({
|
|
204
|
+
text: "Adding scripts...",
|
|
205
|
+
color: "magenta",
|
|
206
|
+
});
|
|
207
|
+
const package = JSON.parse(
|
|
208
|
+
fs.readFileSync(
|
|
209
|
+
path.join(
|
|
210
|
+
process.cwd(),
|
|
211
|
+
"package.json"
|
|
212
|
+
),
|
|
213
|
+
{ encoding: "utf-8" }
|
|
214
|
+
)
|
|
215
|
+
);
|
|
216
|
+
package.scripts = {
|
|
217
|
+
test: "yarn eslint",
|
|
218
|
+
prod: "ts-node --transpile-only ./src/index.ts",
|
|
219
|
+
dev: "ts-node-dev --respawn --transpile-only --notify --rs ./src/index.ts",
|
|
220
|
+
prettier: "prettier ./src/**/*.ts",
|
|
221
|
+
"prettier:fix":
|
|
222
|
+
"prettier --write ./src/**/*.ts",
|
|
223
|
+
eslint: "eslint ./src/**/*.ts",
|
|
224
|
+
"eslint:fix":
|
|
225
|
+
"eslint --fix ./src/**/*.ts",
|
|
226
|
+
};
|
|
227
|
+
package["lint-staged"] = {
|
|
228
|
+
"./src/**/*.ts": ["eslint --fix"],
|
|
229
|
+
};
|
|
230
|
+
|
|
231
|
+
fs.writeFileSync(
|
|
232
|
+
path.join(
|
|
233
|
+
process.cwd(),
|
|
234
|
+
"package.json"
|
|
235
|
+
),
|
|
236
|
+
JSON.stringify(package, null, 4)
|
|
237
|
+
);
|
|
238
|
+
|
|
239
|
+
spinner.update({
|
|
240
|
+
text: "Generating README.md...",
|
|
241
|
+
color: "magenta",
|
|
242
|
+
});
|
|
243
|
+
|
|
244
|
+
fs.writeFileSync(
|
|
245
|
+
path.join(process.cwd(), "README.md"),
|
|
246
|
+
outdent`
|
|
247
|
+
# ${package.name}
|
|
248
|
+
|
|
249
|
+
Created with created with [create-bot-ts](https://github.com/MahoMuri/create-bot-ts)
|
|
250
|
+
|
|
251
|
+
Based from [create-ts-pro](https://github.com/Milo123456789/create-ts-pro)
|
|
252
|
+
|
|
253
|
+
Features:
|
|
254
|
+
- Yarn PnP
|
|
255
|
+
- Husky
|
|
256
|
+
- ESlint and prettier
|
|
257
|
+
- TypeScript
|
|
258
|
+
- Version Plugin
|
|
259
|
+
- Upgrade-interactive plugin
|
|
260
|
+
|
|
261
|
+
Next Steps, run:
|
|
262
|
+
\`\`\`sh
|
|
263
|
+
yarn create @eslint/config
|
|
264
|
+
\`\`\`
|
|
265
|
+
|
|
266
|
+
to fully initialize eslint.
|
|
267
|
+
`
|
|
268
|
+
);
|
|
269
|
+
const diff = process.hrtime(time);
|
|
270
|
+
const seconds =
|
|
271
|
+
(diff[0] * NS_PER_SEC +
|
|
272
|
+
diff[1] * MS_PER_NS) /
|
|
273
|
+
NS_PER_SEC;
|
|
274
|
+
spinner.success({
|
|
275
|
+
text: `Sucessfully Generated ${
|
|
276
|
+
package.name
|
|
277
|
+
} template in ${seconds.toFixed(3)}s`,
|
|
278
|
+
});
|
|
279
|
+
}
|
|
280
|
+
);
|
|
281
|
+
}
|
|
282
|
+
);
|
|
283
|
+
}
|
|
284
|
+
);
|
|
285
|
+
});
|
|
286
|
+
});
|
|
287
|
+
});
|
package/package.json
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "create-bot-ts",
|
|
3
|
+
"version": "1.0.3",
|
|
4
|
+
"description": "\"MahoMuri's personal template for Discord Bots\"",
|
|
5
|
+
"main": "index.js",
|
|
6
|
+
"author": "MahoMuri",
|
|
7
|
+
"license": "MIT",
|
|
8
|
+
"bin": "index.js",
|
|
9
|
+
"private": false,
|
|
10
|
+
"dependencies": {
|
|
11
|
+
"nanospinner": "^1.0.0",
|
|
12
|
+
"outdent": "^0.8.0"
|
|
13
|
+
}
|
|
14
|
+
}
|