reciple 9.9.0 → 10.0.1-dev.0
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.
- package/LICENSE +155 -674
- package/assets/config/reciple.config.js +87 -0
- package/assets/config/reciple.config.ts +80 -0
- package/assets/global/README.md +1 -0
- package/assets/global/gitignore +121 -0
- package/assets/global/nodemon.json +13 -0
- package/assets/modules/javascript/Base.js +21 -0
- package/assets/modules/javascript/ClientEvent.js +14 -0
- package/assets/modules/javascript/ContextMenuCommand.js +17 -0
- package/assets/modules/javascript/Event.js +17 -0
- package/assets/modules/javascript/MessageCommand.js +16 -0
- package/assets/modules/javascript/RESTEvent.js +14 -0
- package/assets/modules/javascript/SlashCommand.js +16 -0
- package/assets/modules/typescript/Base.ts +17 -0
- package/assets/modules/typescript/ClientEvent.ts +15 -0
- package/assets/modules/typescript/ContextMenuCommand.ts +15 -0
- package/assets/modules/typescript/Event.ts +16 -0
- package/assets/modules/typescript/MessageCommand.ts +14 -0
- package/assets/modules/typescript/RESTEvent.ts +15 -0
- package/assets/modules/typescript/SlashCommand.ts +14 -0
- package/assets/templates/javascript/jsconfig.json +17 -0
- package/assets/templates/typescript/tsconfig.json +17 -0
- package/dist/_virtual/_@oxc-project_runtime@0.99.0/helpers/decorate.mjs +10 -0
- package/dist/bin/commands/build.d.mts +16 -0
- package/dist/bin/commands/build.mjs +24 -0
- package/dist/bin/commands/build.mjs.map +1 -0
- package/dist/bin/commands/create.d.mts +23 -0
- package/dist/bin/commands/create.mjs +48 -0
- package/dist/bin/commands/create.mjs.map +1 -0
- package/dist/bin/commands/createModule.d.mts +21 -0
- package/dist/bin/commands/createModule.mjs +40 -0
- package/dist/bin/commands/createModule.mjs.map +1 -0
- package/dist/bin/commands/start.d.mts +18 -0
- package/dist/bin/commands/start.mjs +104 -0
- package/dist/bin/commands/start.mjs.map +1 -0
- package/dist/bin/reciple.d.mts +1 -0
- package/dist/bin/reciple.mjs +9 -0
- package/dist/bin/reciple.mjs.map +1 -0
- package/dist/classes/NotAnError.d.mts +7 -0
- package/dist/classes/NotAnError.mjs +11 -0
- package/dist/classes/NotAnError.mjs.map +1 -0
- package/dist/classes/cli/CLI.d.mts +54 -0
- package/dist/classes/cli/CLI.mjs +156 -0
- package/dist/classes/cli/CLI.mjs.map +1 -0
- package/dist/classes/cli/CLISubcommand.d.mts +27 -0
- package/dist/classes/cli/CLISubcommand.mjs +23 -0
- package/dist/classes/cli/CLISubcommand.mjs.map +1 -0
- package/dist/classes/cli/ConfigReader.d.mts +81 -0
- package/dist/classes/cli/ConfigReader.mjs +141 -0
- package/dist/classes/cli/ConfigReader.mjs.map +1 -0
- package/dist/classes/cli/RuntimeEnvironment.d.mts +14 -0
- package/dist/classes/cli/RuntimeEnvironment.mjs +36 -0
- package/dist/classes/cli/RuntimeEnvironment.mjs.map +1 -0
- package/dist/classes/client/EventListeners.d.mts +26 -0
- package/dist/classes/client/EventListeners.mjs +103 -0
- package/dist/classes/client/EventListeners.mjs.map +1 -0
- package/dist/classes/client/ModuleLoader.d.mts +55 -0
- package/dist/classes/client/ModuleLoader.mjs +152 -0
- package/dist/classes/client/ModuleLoader.mjs.map +1 -0
- package/dist/classes/managers/ModuleManager.d.mts +55 -0
- package/dist/classes/managers/ModuleManager.mjs +107 -0
- package/dist/classes/managers/ModuleManager.mjs.map +1 -0
- package/dist/classes/modules/BaseModule.d.mts +34 -0
- package/dist/classes/modules/BaseModule.mjs +33 -0
- package/dist/classes/modules/BaseModule.mjs.map +1 -0
- package/dist/classes/modules/PostconditionModule.d.mts +20 -0
- package/dist/classes/modules/PostconditionModule.mjs +24 -0
- package/dist/classes/modules/PostconditionModule.mjs.map +1 -0
- package/dist/classes/modules/PreconditionModule.d.mts +20 -0
- package/dist/classes/modules/PreconditionModule.mjs +24 -0
- package/dist/classes/modules/PreconditionModule.mjs.map +1 -0
- package/dist/classes/modules/commands/ContextMenuCommandModule.d.mts +24 -0
- package/dist/classes/modules/commands/ContextMenuCommandModule.mjs +27 -0
- package/dist/classes/modules/commands/ContextMenuCommandModule.mjs.map +1 -0
- package/dist/classes/modules/commands/MessageCommandModule.d.mts +24 -0
- package/dist/classes/modules/commands/MessageCommandModule.mjs +27 -0
- package/dist/classes/modules/commands/MessageCommandModule.mjs.map +1 -0
- package/dist/classes/modules/commands/SlashCommandModule.d.mts +24 -0
- package/dist/classes/modules/commands/SlashCommandModule.mjs +27 -0
- package/dist/classes/modules/commands/SlashCommandModule.mjs.map +1 -0
- package/dist/classes/modules/events/ClientEventModule.d.mts +11 -0
- package/dist/classes/modules/events/ClientEventModule.mjs +10 -0
- package/dist/classes/modules/events/ClientEventModule.mjs.map +1 -0
- package/dist/classes/modules/events/EventModule.d.mts +29 -0
- package/dist/classes/modules/events/EventModule.mjs +26 -0
- package/dist/classes/modules/events/EventModule.mjs.map +1 -0
- package/dist/classes/modules/events/RESTEventModule.d.mts +11 -0
- package/dist/classes/modules/events/RESTEventModule.mjs +10 -0
- package/dist/classes/modules/events/RESTEventModule.mjs.map +1 -0
- package/dist/classes/templates/ModuleTemplateBuilder.d.mts +84 -0
- package/dist/classes/templates/ModuleTemplateBuilder.mjs +288 -0
- package/dist/classes/templates/ModuleTemplateBuilder.mjs.map +1 -0
- package/dist/classes/templates/TemplateBuilder.d.mts +78 -0
- package/dist/classes/templates/TemplateBuilder.mjs +351 -0
- package/dist/classes/templates/TemplateBuilder.mjs.map +1 -0
- package/dist/classes/validation/BaseModuleValidator.d.mts +44 -0
- package/dist/classes/validation/BaseModuleValidator.mjs +46 -0
- package/dist/classes/validation/BaseModuleValidator.mjs.map +1 -0
- package/dist/classes/validation/CommandModuleValidator.d.mts +117 -0
- package/dist/classes/validation/CommandModuleValidator.mjs +16 -0
- package/dist/classes/validation/CommandModuleValidator.mjs.map +1 -0
- package/dist/classes/validation/EventModuleValidator.d.mts +59 -0
- package/dist/classes/validation/EventModuleValidator.mjs +42 -0
- package/dist/classes/validation/EventModuleValidator.mjs.map +1 -0
- package/dist/classes/validation/PostconditionModule.d.mts +30 -0
- package/dist/classes/validation/PostconditionModule.mjs +34 -0
- package/dist/classes/validation/PostconditionModule.mjs.map +1 -0
- package/dist/classes/validation/PreconditionModule.d.mts +28 -0
- package/dist/classes/validation/PreconditionModule.mjs +29 -0
- package/dist/classes/validation/PreconditionModule.mjs.map +1 -0
- package/dist/helpers/constants.d.mts +20 -0
- package/dist/helpers/constants.mjs +28 -0
- package/dist/helpers/constants.mjs.map +1 -0
- package/dist/helpers/types.d.mts +20 -0
- package/dist/helpers/types.mjs +1 -0
- package/dist/index.d.mts +39 -0
- package/dist/index.mjs +39 -0
- package/dist/index.mjs.map +1 -0
- package/dist/package.mjs +80 -0
- package/dist/package.mjs.map +1 -0
- package/package.json +61 -46
- package/README.md +0 -206
- package/dist/bin.d.ts +0 -2
- package/dist/bin.js +0 -4
- package/dist/bin.js.map +0 -1
- package/dist/classes/CLI.d.ts +0 -55
- package/dist/classes/CLI.js +0 -191
- package/dist/classes/CLI.js.map +0 -1
- package/dist/classes/Config.d.ts +0 -26
- package/dist/classes/Config.js +0 -73
- package/dist/classes/Config.js.map +0 -1
- package/dist/classes/EventHandlers.d.ts +0 -9
- package/dist/classes/EventHandlers.js +0 -71
- package/dist/classes/EventHandlers.js.map +0 -1
- package/dist/classes/ModuleLoader.d.ts +0 -25
- package/dist/classes/ModuleLoader.js +0 -91
- package/dist/classes/ModuleLoader.js.map +0 -1
- package/dist/commands/init.d.ts +0 -7
- package/dist/commands/init.js +0 -10
- package/dist/commands/init.js.map +0 -1
- package/dist/commands/modules.d.ts +0 -9
- package/dist/commands/modules.js +0 -33
- package/dist/commands/modules.js.map +0 -1
- package/dist/commands/shard.d.ts +0 -9
- package/dist/commands/shard.js +0 -102
- package/dist/commands/shard.js.map +0 -1
- package/dist/commands/start.d.ts +0 -9
- package/dist/commands/start.js +0 -95
- package/dist/commands/start.js.map +0 -1
- package/dist/exports.d.ts +0 -6
- package/dist/exports.js +0 -7
- package/dist/exports.js.map +0 -1
- package/dist/index.d.ts +0 -15
- package/dist/index.js +0 -8
- package/dist/index.js.map +0 -1
- package/dist/types/constants.d.ts +0 -6
- package/dist/types/constants.js +0 -29
- package/dist/types/constants.js.map +0 -1
- package/dist/types/structures.d.ts +0 -36
- package/dist/types/structures.js +0 -2
- package/dist/types/structures.js.map +0 -1
- package/static/config.d.mts +0 -5
- package/static/config.mjs +0 -105
|
@@ -0,0 +1,351 @@
|
|
|
1
|
+
import { NotAnError } from "../NotAnError.mjs";
|
|
2
|
+
import { CLI } from "../cli/CLI.mjs";
|
|
3
|
+
import { ConfigReader } from "../cli/ConfigReader.mjs";
|
|
4
|
+
import { packageJSON } from "../../helpers/constants.mjs";
|
|
5
|
+
import { ModuleTemplateBuilder } from "./ModuleTemplateBuilder.mjs";
|
|
6
|
+
import path from "node:path";
|
|
7
|
+
import { PackageJsonBuilder, colors } from "@reciple/utils";
|
|
8
|
+
import { parse } from "@dotenvx/dotenvx";
|
|
9
|
+
import { copyFile, mkdir, readFile, readdir, stat, writeFile } from "node:fs/promises";
|
|
10
|
+
import { confirm, intro, isCancel, outro, select, text } from "@clack/prompts";
|
|
11
|
+
import micromatch from "micromatch";
|
|
12
|
+
import { existsSync, statSync } from "node:fs";
|
|
13
|
+
import { slug } from "github-slugger";
|
|
14
|
+
import { detectPackageManager, installDependencies, installDependenciesCommand, runScript, runScriptCommand } from "nypm";
|
|
15
|
+
|
|
16
|
+
//#region src/classes/templates/TemplateBuilder.ts
|
|
17
|
+
var TemplateBuilder = class TemplateBuilder {
|
|
18
|
+
_directory;
|
|
19
|
+
cli;
|
|
20
|
+
typescript;
|
|
21
|
+
token;
|
|
22
|
+
defaultAll;
|
|
23
|
+
config;
|
|
24
|
+
packageJson;
|
|
25
|
+
packageManager;
|
|
26
|
+
get directory() {
|
|
27
|
+
return this._directory ?? process.cwd();
|
|
28
|
+
}
|
|
29
|
+
get relativeDirectory() {
|
|
30
|
+
return path.relative(process.cwd(), this.directory) || "./";
|
|
31
|
+
}
|
|
32
|
+
get packageJsonPath() {
|
|
33
|
+
return path.join(this.directory, "package.json");
|
|
34
|
+
}
|
|
35
|
+
get name() {
|
|
36
|
+
return slug(path.basename(this.directory));
|
|
37
|
+
}
|
|
38
|
+
constructor(options) {
|
|
39
|
+
this.cli = options.cli;
|
|
40
|
+
this._directory = options.directory;
|
|
41
|
+
this.typescript = options.typescript;
|
|
42
|
+
this.defaultAll = options.defaultAll ?? false;
|
|
43
|
+
this.packageManager = options.packageManager;
|
|
44
|
+
this.token = options.token;
|
|
45
|
+
}
|
|
46
|
+
async init() {
|
|
47
|
+
intro(colors.bold(colors.black(colors.bgCyan(` ${this.cli.command.name()} create - v${this.cli.build} `))));
|
|
48
|
+
return this;
|
|
49
|
+
}
|
|
50
|
+
async createDirectory(options) {
|
|
51
|
+
this._directory = options?.directory ?? this._directory;
|
|
52
|
+
if (!this._directory) {
|
|
53
|
+
const dir = this.defaultAll ? process.cwd() : await text({
|
|
54
|
+
message: `Enter project directory`,
|
|
55
|
+
placeholder: `Leave empty to use current directory`,
|
|
56
|
+
defaultValue: process.cwd(),
|
|
57
|
+
validate: (value) => {
|
|
58
|
+
const dir$1 = path.resolve(value);
|
|
59
|
+
if (existsSync(dir$1) && !statSync(dir$1).isDirectory()) return "Invalid folder directory";
|
|
60
|
+
}
|
|
61
|
+
});
|
|
62
|
+
if (isCancel(dir)) throw new NotAnError("Operation cancelled");
|
|
63
|
+
this._directory = dir;
|
|
64
|
+
}
|
|
65
|
+
this._directory = path.resolve(this._directory);
|
|
66
|
+
if (await stat(this.directory).catch(() => void 0)) {
|
|
67
|
+
let files = await readdir(this.directory);
|
|
68
|
+
files = micromatch.not(files, options?.ignoredFiles ?? TemplateBuilder.ignoredDirectoryFiles, { dot: true });
|
|
69
|
+
if (files.length) switch (options?.onNotEmpty) {
|
|
70
|
+
case "throw": throw new NotAnError(`Directory ${colors.cyan(this.relativeDirectory)} is not empty`);
|
|
71
|
+
case "ignore": return this;
|
|
72
|
+
default:
|
|
73
|
+
const overwrite = this.defaultAll ? false : await confirm({
|
|
74
|
+
message: `Directory ${colors.cyan(this.relativeDirectory)} is not empty. Would you like to continue?`,
|
|
75
|
+
active: "Yes",
|
|
76
|
+
inactive: "No",
|
|
77
|
+
initialValue: false
|
|
78
|
+
});
|
|
79
|
+
if (!overwrite) throw new NotAnError(`Directory ${colors.cyan(this.relativeDirectory)} is not empty`);
|
|
80
|
+
if (isCancel(overwrite)) throw new NotAnError("Operation cancelled");
|
|
81
|
+
break;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
await mkdir(this.directory, { recursive: true });
|
|
85
|
+
return this;
|
|
86
|
+
}
|
|
87
|
+
async setupLanguage(options) {
|
|
88
|
+
this.typescript = options?.typescript ?? this.typescript;
|
|
89
|
+
if (!this.typescript) {
|
|
90
|
+
const isTypeScript = this.defaultAll ? false : await confirm({
|
|
91
|
+
message: "Would you like to use TypeScript?",
|
|
92
|
+
active: "Yes",
|
|
93
|
+
inactive: "No",
|
|
94
|
+
initialValue: false
|
|
95
|
+
});
|
|
96
|
+
if (isCancel(isTypeScript)) throw new NotAnError("Operation cancelled");
|
|
97
|
+
this.typescript = isTypeScript;
|
|
98
|
+
}
|
|
99
|
+
return this;
|
|
100
|
+
}
|
|
101
|
+
async createConfig(options) {
|
|
102
|
+
let filepath = options?.filepath;
|
|
103
|
+
if (!filepath) filepath = await ConfigReader.findConfig(this.directory, this.typescript ? "ts" : this.typescript === false ? "js" : void 0) ?? path.join(this.directory, ConfigReader.createConfigFilename(this.typescript ? "ts" : "js"));
|
|
104
|
+
if (await ConfigReader.hasFile(filepath)) {
|
|
105
|
+
const overwrite = this.defaultAll ? false : await confirm({
|
|
106
|
+
message: `Config file already exists at ${colors.green(path.relative(process.cwd(), filepath))}. Would you like to overwrite it?`,
|
|
107
|
+
active: "Yes",
|
|
108
|
+
inactive: "No",
|
|
109
|
+
initialValue: false
|
|
110
|
+
});
|
|
111
|
+
if (!overwrite) return this;
|
|
112
|
+
if (isCancel(overwrite)) throw new NotAnError("Operation cancelled");
|
|
113
|
+
}
|
|
114
|
+
this.config = await ConfigReader.create({
|
|
115
|
+
...options,
|
|
116
|
+
filepath,
|
|
117
|
+
type: this.typescript ? "ts" : "js",
|
|
118
|
+
overwrite: true
|
|
119
|
+
});
|
|
120
|
+
return this;
|
|
121
|
+
}
|
|
122
|
+
async createTemplate(options) {
|
|
123
|
+
const source = path.join(CLI.root, "./assets/templates/", this.typescript ? "typescript" : "javascript");
|
|
124
|
+
const globals = path.join(CLI.root, "./assets/global/");
|
|
125
|
+
const modulesDirectory = path.join(this.directory, "src");
|
|
126
|
+
const moduleTemplates = await ModuleTemplateBuilder.resolveModuleTemplates(this.typescript ? "ts" : "js");
|
|
127
|
+
const moduleOptions = {
|
|
128
|
+
cli: this.cli,
|
|
129
|
+
config: this.config,
|
|
130
|
+
defaultAll: true,
|
|
131
|
+
typescript: this.typescript
|
|
132
|
+
};
|
|
133
|
+
function rename(data) {
|
|
134
|
+
switch (data.basename) {
|
|
135
|
+
case "gitignore": return ".gitignore";
|
|
136
|
+
default: return options?.rename?.(data) ?? data.basename;
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
function overwrite(data) {
|
|
140
|
+
switch (data.basename) {
|
|
141
|
+
case "gitignore": return false;
|
|
142
|
+
case "tsconfig.json":
|
|
143
|
+
case "jsconfig.json": return true;
|
|
144
|
+
default: return (typeof options?.overwrite === "boolean" ? options.overwrite : options?.overwrite?.(data)) ?? true;
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
const [template, loader] = CLI.createSpinnerPromise({
|
|
148
|
+
promise: Promise.all([
|
|
149
|
+
TemplateBuilder.copy(source, this.directory, {
|
|
150
|
+
...options,
|
|
151
|
+
rename,
|
|
152
|
+
overwrite
|
|
153
|
+
}),
|
|
154
|
+
TemplateBuilder.copy(globals, this.directory, {
|
|
155
|
+
...options,
|
|
156
|
+
rename,
|
|
157
|
+
overwrite
|
|
158
|
+
}),
|
|
159
|
+
new ModuleTemplateBuilder({
|
|
160
|
+
...moduleOptions,
|
|
161
|
+
directory: path.join(modulesDirectory, "commands"),
|
|
162
|
+
filename: `SlashCommand.${this.typescript ? "ts" : "js"}`,
|
|
163
|
+
template: moduleTemplates.find((t) => t.name === "SlashCommand")
|
|
164
|
+
}).setupPlaceholders().then((m) => m.build({ silent: true })),
|
|
165
|
+
new ModuleTemplateBuilder({
|
|
166
|
+
...moduleOptions,
|
|
167
|
+
directory: path.join(modulesDirectory, "events"),
|
|
168
|
+
filename: `ClientEvent.${this.typescript ? "ts" : "js"}`,
|
|
169
|
+
template: moduleTemplates.find((t) => t.name === "ClientEvent")
|
|
170
|
+
}).setupPlaceholders().then((m) => m.build({ silent: true }))
|
|
171
|
+
]),
|
|
172
|
+
message: "Copying template files",
|
|
173
|
+
successMessage: "Files copied successfully",
|
|
174
|
+
errorMessage: "Failed to copy files"
|
|
175
|
+
});
|
|
176
|
+
await template;
|
|
177
|
+
return this;
|
|
178
|
+
}
|
|
179
|
+
async setPackageManager(options) {
|
|
180
|
+
this.packageManager = options?.packageManager ?? this.packageManager;
|
|
181
|
+
if (!this.packageManager) {
|
|
182
|
+
const defaultPackageManager = await detectPackageManager(this.directory).then((pm) => pm?.name ?? "npm");
|
|
183
|
+
const packageManager = this.defaultAll ? defaultPackageManager : await select({
|
|
184
|
+
message: "Select package manager",
|
|
185
|
+
options: [{
|
|
186
|
+
value: defaultPackageManager,
|
|
187
|
+
label: defaultPackageManager
|
|
188
|
+
}, ...[
|
|
189
|
+
{
|
|
190
|
+
value: "npm",
|
|
191
|
+
label: "npm"
|
|
192
|
+
},
|
|
193
|
+
{
|
|
194
|
+
value: "yarn",
|
|
195
|
+
label: "yarn"
|
|
196
|
+
},
|
|
197
|
+
{
|
|
198
|
+
value: "pnpm",
|
|
199
|
+
label: "pnpm"
|
|
200
|
+
},
|
|
201
|
+
{
|
|
202
|
+
value: "bun",
|
|
203
|
+
label: "bun"
|
|
204
|
+
},
|
|
205
|
+
{
|
|
206
|
+
value: "deno",
|
|
207
|
+
label: "deno"
|
|
208
|
+
}
|
|
209
|
+
].filter((o) => o.value !== defaultPackageManager)],
|
|
210
|
+
initialValue: defaultPackageManager
|
|
211
|
+
});
|
|
212
|
+
if (isCancel(packageManager)) throw new NotAnError("Operation cancelled");
|
|
213
|
+
this.packageManager = packageManager;
|
|
214
|
+
}
|
|
215
|
+
this.packageJson = await PackageJsonBuilder.read(this.packageJsonPath);
|
|
216
|
+
this.packageJson.merge({
|
|
217
|
+
name: this.name,
|
|
218
|
+
version: "0.0.1",
|
|
219
|
+
type: "module",
|
|
220
|
+
scripts: {
|
|
221
|
+
build: `reciple build`,
|
|
222
|
+
start: "reciple start",
|
|
223
|
+
dev: "nodemon"
|
|
224
|
+
},
|
|
225
|
+
...TemplateBuilder.createDependencyRecord(this.typescript ? "ts" : "js"),
|
|
226
|
+
private: true
|
|
227
|
+
});
|
|
228
|
+
return this;
|
|
229
|
+
}
|
|
230
|
+
async createEnvFile(options) {
|
|
231
|
+
const tokenKey = options?.tokenKey ?? "DISCORD_TOKEN";
|
|
232
|
+
const envFile = options?.envFile ? path.resolve(options.envFile) : path.join(this.directory, ".env");
|
|
233
|
+
const stats = await stat(envFile).catch(() => void 0);
|
|
234
|
+
let env = options?.env ?? {};
|
|
235
|
+
env = stats ? parse(await readFile(envFile, "utf-8"), { processEnv: env }) : env;
|
|
236
|
+
if (env[tokenKey]) {
|
|
237
|
+
const skip = this.defaultAll || await confirm({
|
|
238
|
+
message: "Discord bot token already exists in .env file, do you want to skip?",
|
|
239
|
+
initialValue: true,
|
|
240
|
+
active: "Yes",
|
|
241
|
+
inactive: "No"
|
|
242
|
+
});
|
|
243
|
+
if (isCancel(skip)) throw new NotAnError("Operation cancelled");
|
|
244
|
+
if (skip) return this;
|
|
245
|
+
}
|
|
246
|
+
const token = await text({
|
|
247
|
+
message: "Enter Discord Bot Token",
|
|
248
|
+
placeholder: "Bot Token from Discord Developer Portal",
|
|
249
|
+
defaultValue: env[tokenKey]
|
|
250
|
+
});
|
|
251
|
+
if (isCancel(token)) throw new NotAnError("Operation cancelled");
|
|
252
|
+
env[tokenKey] = token;
|
|
253
|
+
await writeFile(envFile, `\n${tokenKey}="${token}"\n`, {
|
|
254
|
+
encoding: "utf-8",
|
|
255
|
+
flag: "a"
|
|
256
|
+
});
|
|
257
|
+
return this;
|
|
258
|
+
}
|
|
259
|
+
async build(options) {
|
|
260
|
+
await this.packageJson?.write(this.packageJsonPath, true);
|
|
261
|
+
if (!options?.skipInstallDependencies) await CLI.createSpinnerPromise({
|
|
262
|
+
promise: installDependencies({
|
|
263
|
+
cwd: this.directory,
|
|
264
|
+
packageManager: this.packageManager,
|
|
265
|
+
silent: true
|
|
266
|
+
}),
|
|
267
|
+
indicator: "timer",
|
|
268
|
+
errorMessage: `${colors.bold(colors.red("✗"))} Failed to install dependencies`,
|
|
269
|
+
successMessage: `${colors.bold(colors.green("✔"))} Dependencies installed successfully`,
|
|
270
|
+
message: `${colors.bold(colors.dim("$"))} Installing dependencies`
|
|
271
|
+
})[0];
|
|
272
|
+
if (!options?.skipBuild) await CLI.createSpinnerPromise({
|
|
273
|
+
promise: runScript("build", {
|
|
274
|
+
cwd: this.directory,
|
|
275
|
+
packageManager: this.packageManager,
|
|
276
|
+
silent: true
|
|
277
|
+
}),
|
|
278
|
+
indicator: "timer",
|
|
279
|
+
errorMessage: `${colors.bold(colors.red("✗"))} Failed to build project`,
|
|
280
|
+
successMessage: `${colors.bold(colors.green("✔"))} Project built successfully`,
|
|
281
|
+
message: `${colors.bold(colors.dim("$"))} Building project`
|
|
282
|
+
})[0];
|
|
283
|
+
outro(`Project created in ${colors.cyan(this.relativeDirectory)}`);
|
|
284
|
+
console.log(`\n${colors.bold(colors.green("✔"))} Start developing:`);
|
|
285
|
+
if (this.relativeDirectory !== "./") console.log(` • ${colors.cyan(colors.bold(`cd ${this.relativeDirectory}`))}`);
|
|
286
|
+
if (options?.skipInstallDependencies) console.log(` • ${colors.cyan(colors.bold(installDependenciesCommand(this.packageManager ?? "npm")))}`);
|
|
287
|
+
console.log(` • ${colors.cyan(colors.bold(runScriptCommand(this.packageManager ?? "npm", "build")))} ${colors.dim("(Build)")}`);
|
|
288
|
+
console.log(` • ${colors.cyan(colors.bold(runScriptCommand(this.packageManager ?? "npm", "dev")))} ${colors.dim("(Development)")}`);
|
|
289
|
+
console.log(` • ${colors.cyan(colors.bold(runScriptCommand(this.packageManager ?? "npm", "start")))} ${colors.dim("(Production)")}`);
|
|
290
|
+
return this;
|
|
291
|
+
}
|
|
292
|
+
};
|
|
293
|
+
(function(_TemplateBuilder) {
|
|
294
|
+
_TemplateBuilder.ignoredDirectoryFiles = [".*", "LICENSE"];
|
|
295
|
+
const dependencies = _TemplateBuilder.dependencies = {
|
|
296
|
+
both: {
|
|
297
|
+
dependencies: { "@reciple/jsx": packageJSON.dependencies?.["@reciple/jsx"] },
|
|
298
|
+
devDependencies: {
|
|
299
|
+
"@types/node": packageJSON.devDependencies?.["@types/node"],
|
|
300
|
+
nodemon: packageJSON.devDependencies?.nodemon
|
|
301
|
+
}
|
|
302
|
+
},
|
|
303
|
+
ts: {},
|
|
304
|
+
js: {}
|
|
305
|
+
};
|
|
306
|
+
function createDependencyRecord(type) {
|
|
307
|
+
const record = type === "ts" ? dependencies.ts : type === "js" ? dependencies.js : {};
|
|
308
|
+
record.dependencies = {
|
|
309
|
+
...record.dependencies,
|
|
310
|
+
...dependencies.both.dependencies
|
|
311
|
+
};
|
|
312
|
+
record.devDependencies = {
|
|
313
|
+
...record.devDependencies,
|
|
314
|
+
...dependencies.both.devDependencies
|
|
315
|
+
};
|
|
316
|
+
return record;
|
|
317
|
+
}
|
|
318
|
+
_TemplateBuilder.createDependencyRecord = createDependencyRecord;
|
|
319
|
+
async function copy(from, to, options) {
|
|
320
|
+
const fromStats = await stat(from).catch(() => void 0);
|
|
321
|
+
if (!fromStats) return;
|
|
322
|
+
if (fromStats.isDirectory()) {
|
|
323
|
+
const files = await readdir(from);
|
|
324
|
+
for (const file of files) {
|
|
325
|
+
const data$1 = {
|
|
326
|
+
basename: file,
|
|
327
|
+
src: path.join(from, file),
|
|
328
|
+
dest: to
|
|
329
|
+
};
|
|
330
|
+
await copy(data$1.src, path.join(to, options?.rename ? options.rename(data$1) : file), options);
|
|
331
|
+
}
|
|
332
|
+
return;
|
|
333
|
+
}
|
|
334
|
+
const data = {
|
|
335
|
+
basename: path.basename(from),
|
|
336
|
+
src: from,
|
|
337
|
+
dest: to
|
|
338
|
+
};
|
|
339
|
+
if (options?.filter && !options.filter(data)) return;
|
|
340
|
+
const toStats = await stat(to).catch(() => void 0);
|
|
341
|
+
const overwrite = typeof options?.overwrite === "function" ? options.overwrite(data) : options?.overwrite ?? true;
|
|
342
|
+
if (toStats && overwrite) return;
|
|
343
|
+
await mkdir(path.dirname(to), { recursive: true });
|
|
344
|
+
await copyFile(from, to);
|
|
345
|
+
}
|
|
346
|
+
_TemplateBuilder.copy = copy;
|
|
347
|
+
})(TemplateBuilder || (TemplateBuilder = {}));
|
|
348
|
+
|
|
349
|
+
//#endregion
|
|
350
|
+
export { TemplateBuilder };
|
|
351
|
+
//# sourceMappingURL=TemplateBuilder.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"TemplateBuilder.mjs","names":["dir","packageManager: PackageManagerName|symbol","parseDotenv","dependencies: Record<'ts'|'js'|'both', Partial<Record<'dependencies'|'devDependencies', Record<string, string>>>>","data: CopyMetadata","data"],"sources":["../../../src/classes/templates/TemplateBuilder.ts"],"sourcesContent":["import { colors, PackageJsonBuilder } from '@reciple/utils';\nimport { ConfigReader } from '../cli/ConfigReader.js';\nimport { copyFile, mkdir, readdir, readFile, stat, writeFile } from 'node:fs/promises';\nimport { confirm, intro, isCancel, outro, select, text } from '@clack/prompts';\nimport micromatch from 'micromatch';\nimport { CLI } from '../cli/CLI.js';\nimport path from 'node:path';\nimport { existsSync, statSync } from 'node:fs';\nimport { NotAnError } from '../NotAnError.js';\nimport { slug } from 'github-slugger';\nimport { packageJSON } from '../../helpers/constants.js';\nimport { parse as parseDotenv } from '@dotenvx/dotenvx';\nimport { ModuleTemplateBuilder } from './ModuleTemplateBuilder.js';\nimport { detectPackageManager, installDependencies, installDependenciesCommand, runScript, runScriptCommand, type PackageManagerName } from 'nypm';\n\nexport class TemplateBuilder {\n private _directory?: string;\n\n public cli: CLI;\n public typescript?: boolean;\n public token?: string;\n public defaultAll: boolean;\n\n public config?: ConfigReader;\n public packageJson?: PackageJsonBuilder;\n\n public packageManager?: PackageManagerName;\n\n get directory() {\n return this._directory ?? process.cwd();\n }\n\n get relativeDirectory() {\n return path.relative(process.cwd(), this.directory) || './';\n }\n\n get packageJsonPath() {\n return path.join(this.directory, 'package.json');\n }\n\n get name() {\n return slug(path.basename(this.directory));\n }\n\n constructor(options: TemplateBuilder.Options) {\n this.cli = options.cli;\n this._directory = options.directory;\n this.typescript = options.typescript;\n this.defaultAll = options.defaultAll ?? false;\n this.packageManager = options.packageManager;\n this.token = options.token;\n }\n\n public async init(): Promise<this> {\n intro(colors.bold(colors.black(colors.bgCyan(` ${this.cli.command.name()} create - v${this.cli.build} `))));\n return this;\n }\n\n public async createDirectory(options?: TemplateBuilder.CreateDirectoryOptions): Promise<this> {\n this._directory = options?.directory ?? this._directory;\n\n if (!this._directory) {\n const dir = this.defaultAll\n ? process.cwd()\n : await text({\n message: `Enter project directory`,\n placeholder: `Leave empty to use current directory`,\n defaultValue: process.cwd(),\n validate: value => {\n const dir = path.resolve(value);\n if (existsSync(dir) && !statSync(dir).isDirectory()) return 'Invalid folder directory';\n }\n });\n\n if (isCancel(dir)) throw new NotAnError('Operation cancelled');\n this._directory = dir;\n }\n\n this._directory = path.resolve(this._directory);\n\n const stats = await stat(this.directory).catch(() => undefined);\n\n if (stats) {\n let files = await readdir(this.directory);\n files = micromatch.not(files, options?.ignoredFiles ?? TemplateBuilder.ignoredDirectoryFiles, { dot: true });\n\n if (files.length) {\n switch (options?.onNotEmpty) {\n case 'throw':\n throw new NotAnError(`Directory ${colors.cyan(this.relativeDirectory)} is not empty`);\n case 'ignore':\n return this;\n default:\n const overwrite = this.defaultAll\n ? false\n : await confirm({\n message: `Directory ${colors.cyan(this.relativeDirectory)} is not empty. Would you like to continue?`,\n active: 'Yes',\n inactive: 'No',\n initialValue: false\n });\n\n if (!overwrite) throw new NotAnError(`Directory ${colors.cyan(this.relativeDirectory)} is not empty`);\n if (isCancel(overwrite)) throw new NotAnError('Operation cancelled');\n break;\n }\n }\n }\n\n await mkdir(this.directory, { recursive: true });\n return this;\n }\n\n public async setupLanguage(options?: TemplateBuilder.SetupLanguageOptions): Promise<this> {\n this.typescript = options?.typescript ?? this.typescript;\n\n if (!this.typescript) {\n const isTypeScript = this.defaultAll\n ? false\n : await confirm({\n message: 'Would you like to use TypeScript?',\n active: 'Yes',\n inactive: 'No',\n initialValue: false\n });\n\n if (isCancel(isTypeScript)) throw new NotAnError('Operation cancelled');\n this.typescript = isTypeScript;\n }\n\n return this;\n }\n\n public async createConfig(options?: TemplateBuilder.CreateConfigOptions): Promise<this> {\n let filepath = options?.filepath;\n\n if (!filepath) {\n filepath = await ConfigReader.findConfig(\n this.directory,\n this.typescript\n ? 'ts'\n : this.typescript === false\n ? 'js'\n : undefined\n )\n ?? path.join(\n this.directory,\n ConfigReader.createConfigFilename(this.typescript ? 'ts' : 'js')\n );\n }\n\n const exists = await ConfigReader.hasFile(filepath);\n\n if (exists) {\n const overwrite = this.defaultAll\n ? false\n : await confirm({\n message: `Config file already exists at ${colors.green(path.relative(process.cwd(), filepath))}. Would you like to overwrite it?`,\n active: 'Yes',\n inactive: 'No',\n initialValue: false\n });\n\n if (!overwrite) return this;\n if (isCancel(overwrite)) throw new NotAnError('Operation cancelled');\n }\n\n this.config = await ConfigReader.create({\n ...options,\n filepath,\n type: this.typescript ? 'ts' : 'js',\n overwrite: true\n });\n\n return this;\n }\n\n public async createTemplate(options?: TemplateBuilder.CreateModulesOptions): Promise<this> {\n const source = path.join(CLI.root, './assets/templates/', this.typescript ? 'typescript' : 'javascript');\n const globals = path.join(CLI.root, './assets/global/');\n const modulesDirectory = path.join(this.directory, 'src');\n const moduleTemplates = await ModuleTemplateBuilder.resolveModuleTemplates(this.typescript ? 'ts' : 'js');\n const moduleOptions = {\n cli: this.cli,\n config: this.config!,\n defaultAll: true,\n typescript: this.typescript,\n };\n\n function rename(data: TemplateBuilder.CopyMetadata) {\n switch (data.basename) {\n case 'gitignore':\n return '.gitignore';\n default:\n return options?.rename?.(data) ?? data.basename;\n }\n }\n\n function overwrite(data: TemplateBuilder.CopyMetadata) {\n switch (data.basename) {\n case 'gitignore':\n return false;\n case 'tsconfig.json':\n case 'jsconfig.json':\n return true;\n default:\n return (typeof options?.overwrite === 'boolean' ? options.overwrite : options?.overwrite?.(data)) ?? true;\n }\n }\n\n const [template, loader] = CLI.createSpinnerPromise({\n promise: Promise.all([\n TemplateBuilder.copy(source, this.directory, { ...options, rename, overwrite }),\n TemplateBuilder.copy(globals, this.directory, { ...options, rename, overwrite }),\n new ModuleTemplateBuilder({\n ...moduleOptions,\n directory: path.join(modulesDirectory, 'commands'),\n filename: `SlashCommand.${this.typescript ? 'ts' : 'js'}`,\n template: moduleTemplates.find(t => t.name === 'SlashCommand')\n })\n .setupPlaceholders()\n .then(m => m.build({ silent: true })),\n new ModuleTemplateBuilder({\n ...moduleOptions,\n directory: path.join(modulesDirectory, 'events'),\n filename: `ClientEvent.${this.typescript ? 'ts' : 'js'}`,\n template: moduleTemplates.find(t => t.name === 'ClientEvent')\n })\n .setupPlaceholders()\n .then(m => m.build({ silent: true }))\n ]),\n message: 'Copying template files',\n successMessage: 'Files copied successfully',\n errorMessage: 'Failed to copy files'\n });\n\n await template;\n return this;\n }\n\n public async setPackageManager(options?: TemplateBuilder.SetPackageManagerOptions) {\n this.packageManager = options?.packageManager ?? this.packageManager;\n\n if (!this.packageManager) {\n const defaultPackageManager = await detectPackageManager(this.directory).then(pm => pm?.name ?? 'npm');\n const packageManager: PackageManagerName|symbol = this.defaultAll\n ? defaultPackageManager\n : await select({\n message: 'Select package manager',\n options: [\n { value: defaultPackageManager, label: defaultPackageManager },\n ...[\n { value: 'npm', label: 'npm' },\n { value: 'yarn', label: 'yarn' },\n { value: 'pnpm', label: 'pnpm' },\n { value: 'bun', label: 'bun' },\n { value: 'deno', label: 'deno' }\n ].filter(o => o.value !== defaultPackageManager) as { value: PackageManagerName; label: string; }[]\n ],\n initialValue: defaultPackageManager\n });\n\n if (isCancel(packageManager)) throw new NotAnError('Operation cancelled');\n this.packageManager = packageManager;\n }\n\n this.packageJson = await PackageJsonBuilder.read(this.packageJsonPath);\n this.packageJson.merge({\n name: this.name,\n version: '0.0.1',\n type: 'module',\n scripts: {\n build: `reciple build`,\n start: 'reciple start',\n dev: 'nodemon',\n },\n ...TemplateBuilder.createDependencyRecord(this.typescript ? 'ts' : 'js'),\n private: true\n });\n\n return this;\n }\n\n public async createEnvFile(options?: TemplateBuilder.CreateEnvFileOptions): Promise<this> {\n const tokenKey = options?.tokenKey ?? 'DISCORD_TOKEN';\n const envFile = options?.envFile ? path.resolve(options.envFile) : path.join(this.directory, '.env');\n const stats = await stat(envFile).catch(() => undefined);\n\n let env = options?.env ?? {};\n env = stats\n ? parseDotenv(await readFile(envFile, 'utf-8'), {\n processEnv: env\n })\n : env;\n\n if (env[tokenKey]) {\n const skip = this.defaultAll || await confirm({\n message: 'Discord bot token already exists in .env file, do you want to skip?',\n initialValue: true,\n active: 'Yes',\n inactive: 'No'\n });\n\n if (isCancel(skip)) throw new NotAnError('Operation cancelled');\n if (skip) return this;\n }\n\n const token = await text({\n message: 'Enter Discord Bot Token',\n placeholder: 'Bot Token from Discord Developer Portal',\n defaultValue: env[tokenKey]\n });\n\n if (isCancel(token)) throw new NotAnError('Operation cancelled');\n env[tokenKey] = token;\n\n await writeFile(envFile, `\\n${tokenKey}=\"${token}\"\\n`, {\n encoding: 'utf-8',\n flag: 'a'\n });\n\n return this;\n }\n\n public async build(options?: TemplateBuilder.BuildOptions): Promise<this> {\n await this.packageJson?.write(this.packageJsonPath, true);\n\n if (!options?.skipInstallDependencies) await CLI.createSpinnerPromise({\n promise: installDependencies({\n cwd: this.directory,\n packageManager: this.packageManager,\n silent: true\n }),\n indicator: 'timer',\n errorMessage: `${colors.bold(colors.red('✗'))} Failed to install dependencies`,\n successMessage: `${colors.bold(colors.green('✔'))} Dependencies installed successfully`,\n message: `${colors.bold(colors.dim('$'))} Installing dependencies`\n })[0];\n\n if (!options?.skipBuild) await CLI.createSpinnerPromise({\n promise: runScript('build', {\n cwd: this.directory,\n packageManager: this.packageManager,\n silent: true\n }),\n indicator: 'timer',\n errorMessage: `${colors.bold(colors.red('✗'))} Failed to build project`,\n successMessage: `${colors.bold(colors.green('✔'))} Project built successfully`,\n message: `${colors.bold(colors.dim('$'))} Building project`\n })[0];\n\n outro(`Project created in ${colors.cyan(this.relativeDirectory)}`);\n\n console.log(`\\n${colors.bold(colors.green('✔'))} Start developing:`);\n\n if (this.relativeDirectory !== './') {\n console.log(` • ${colors.cyan(colors.bold(`cd ${this.relativeDirectory}`))}`);\n }\n\n if (options?.skipInstallDependencies) {\n console.log(` • ${colors.cyan(colors.bold(installDependenciesCommand(this.packageManager ?? 'npm')))}`);\n }\n\n console.log(` • ${colors.cyan(colors.bold(runScriptCommand(this.packageManager ?? 'npm', 'build')))} ${colors.dim('(Build)')}`);\n console.log(` • ${colors.cyan(colors.bold(runScriptCommand(this.packageManager ?? 'npm', 'dev')))} ${colors.dim('(Development)')}`);\n console.log(` • ${colors.cyan(colors.bold(runScriptCommand(this.packageManager ?? 'npm', 'start')))} ${colors.dim('(Production)')}`);\n\n\n return this;\n }\n}\n\nexport namespace TemplateBuilder {\n export interface Options {\n cli: CLI;\n directory?: string;\n typescript?: boolean;\n packageManager?: PackageManagerName;\n defaultAll?: boolean;\n token?: string;\n }\n\n export const ignoredDirectoryFiles = ['.*', 'LICENSE'];\n\n export const dependencies: Record<'ts'|'js'|'both', Partial<Record<'dependencies'|'devDependencies', Record<string, string>>>> = {\n both: {\n dependencies: {\n // TODO: Uncomment when ready\n // '@reciple/core': packageJSON.dependencies?.['@reciple/core'],\n '@reciple/jsx': packageJSON.dependencies?.['@reciple/jsx']!,\n // 'reciple': `^${packageJSON.version}`,\n },\n devDependencies: {\n '@types/node': packageJSON.devDependencies?.['@types/node']!,\n nodemon: packageJSON.devDependencies?.nodemon!\n }\n },\n ts: {},\n js: {}\n };\n\n export function createDependencyRecord(type: 'ts'|'js'): Partial<Record<'dependencies'|'devDependencies', Record<string, string>>> {\n const record = type === 'ts'\n ? dependencies.ts\n : type === 'js'\n ? dependencies.js\n : {};\n\n record.dependencies = { ...record.dependencies, ...dependencies.both.dependencies };\n record.devDependencies = { ...record.devDependencies, ...dependencies.both.devDependencies };\n\n return record;\n }\n\n export interface CreateDirectoryOptions {\n directory?: string;\n ignoredFiles?: string[];\n onNotEmpty?: 'prompt'|'throw'|'ignore';\n }\n\n export interface SetupLanguageOptions {\n typescript?: boolean;\n }\n\n export interface CreateConfigOptions extends Partial<ConfigReader.CreateOptions> {}\n\n export interface CreateModulesOptions extends Partial<CopyOptions> {}\n\n export interface SetPackageManagerOptions {\n packageManager?: PackageManagerName;\n }\n\n export interface CreateEnvFileOptions {\n envFile?: string;\n tokenKey?: string;\n env?: Record<string, string>;\n }\n\n export interface BuildOptions {\n skipInstallDependencies?: boolean;\n skipBuild?: boolean;\n }\n\n export interface CopyOptions {\n overwrite?: boolean|((data: CopyMetadata) => boolean);\n filter?: (data: CopyMetadata) => boolean;\n rename?: (data: CopyMetadata) => string;\n }\n\n export interface CopyMetadata {\n basename: string;\n src: string;\n dest: string;\n }\n\n export async function copy(from: string, to: string, options?: CopyOptions): Promise<void> {\n const fromStats = await stat(from).catch(() => undefined);\n if (!fromStats) return;\n\n if (fromStats.isDirectory()) {\n const files = await readdir(from);\n\n for (const file of files) {\n const data: CopyMetadata = {\n basename: file,\n src: path.join(from, file),\n dest: to\n };\n\n await copy(\n data.src,\n path.join(to,\n options?.rename\n ? options.rename(data)\n : file\n ),\n options\n );\n }\n return;\n }\n\n const data: CopyMetadata = {\n basename: path.basename(from),\n src: from,\n dest: to\n };\n\n if (options?.filter && !options.filter(data)) return;\n\n const toStats = await stat(to).catch(() => undefined);\n const overwrite = typeof options?.overwrite === 'function'\n ? options.overwrite(data)\n : options?.overwrite ?? true;\n\n if (toStats && overwrite) return;\n\n await mkdir(path.dirname(to), { recursive: true });\n await copyFile(from, to);\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;AAeA,IAAa,kBAAb,MAAa,gBAAgB;CACzB,AAAQ;CAER,AAAO;CACP,AAAO;CACP,AAAO;CACP,AAAO;CAEP,AAAO;CACP,AAAO;CAEP,AAAO;CAEP,IAAI,YAAY;AACZ,SAAO,KAAK,cAAc,QAAQ,KAAK;;CAG3C,IAAI,oBAAoB;AACpB,SAAO,KAAK,SAAS,QAAQ,KAAK,EAAE,KAAK,UAAU,IAAI;;CAG3D,IAAI,kBAAkB;AAClB,SAAO,KAAK,KAAK,KAAK,WAAW,eAAe;;CAGpD,IAAI,OAAO;AACP,SAAO,KAAK,KAAK,SAAS,KAAK,UAAU,CAAC;;CAG9C,YAAY,SAAkC;AAC1C,OAAK,MAAM,QAAQ;AACnB,OAAK,aAAa,QAAQ;AAC1B,OAAK,aAAa,QAAQ;AAC1B,OAAK,aAAa,QAAQ,cAAc;AACxC,OAAK,iBAAiB,QAAQ;AAC9B,OAAK,QAAQ,QAAQ;;CAGzB,MAAa,OAAsB;AAC/B,QAAM,OAAO,KAAK,OAAO,MAAM,OAAO,OAAO,IAAI,KAAK,IAAI,QAAQ,MAAM,CAAC,aAAa,KAAK,IAAI,MAAM,GAAG,CAAC,CAAC,CAAC;AAC3G,SAAO;;CAGX,MAAa,gBAAgB,SAAiE;AAC1F,OAAK,aAAa,SAAS,aAAa,KAAK;AAE7C,MAAI,CAAC,KAAK,YAAY;GAClB,MAAM,MAAM,KAAK,aACX,QAAQ,KAAK,GACb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MAAMC,SAAqB;KACvB,UAAU;KACV,KAAK,KAAK,KAAK,MAAM,KAAK;KAC1B,MAAM;KACT;AAED,UAAM,KACFC,OAAK,KACL,KAAK,KAAK,IACN,SAAS,SACH,QAAQ,OAAOA,OAAK,GACpB,KACT,EACD,QACH;;AAEL;;EAGJ,MAAMD,OAAqB;GACvB,UAAU,KAAK,SAAS,KAAK;GAC7B,KAAK;GACL,MAAM;GACT;AAED,MAAI,SAAS,UAAU,CAAC,QAAQ,OAAO,KAAK,CAAE;EAE9C,MAAM,UAAU,MAAM,KAAK,GAAG,CAAC,YAAY,OAAU;EACrD,MAAM,YAAY,OAAO,SAAS,cAAc,aAC1C,QAAQ,UAAU,KAAK,GACvB,SAAS,aAAa;AAE5B,MAAI,WAAW,UAAW;AAE1B,QAAM,MAAM,KAAK,QAAQ,GAAG,EAAE,EAAE,WAAW,MAAM,CAAC;AAClD,QAAM,SAAS,MAAM,GAAG"}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { ModuleType } from "../../helpers/constants.mjs";
|
|
2
|
+
import { AnyModuleData } from "../../helpers/types.mjs";
|
|
3
|
+
import { Validator } from "@reciple/core";
|
|
4
|
+
import * as _sapphire_shapeshift16 from "@sapphire/shapeshift";
|
|
5
|
+
|
|
6
|
+
//#region src/classes/validation/BaseModuleValidator.d.ts
|
|
7
|
+
declare class BaseModuleValidator extends Validator {
|
|
8
|
+
static id: _sapphire_shapeshift16.StringValidator<string>;
|
|
9
|
+
static moduleType: _sapphire_shapeshift16.NativeEnumValidator<typeof ModuleType>;
|
|
10
|
+
static onEnable: _sapphire_shapeshift16.UnionValidator<Function | undefined>;
|
|
11
|
+
static onReady: _sapphire_shapeshift16.UnionValidator<Function | undefined>;
|
|
12
|
+
static onDisable: _sapphire_shapeshift16.UnionValidator<Function | undefined>;
|
|
13
|
+
static object: _sapphire_shapeshift16.ObjectValidator<{
|
|
14
|
+
id: string | undefined;
|
|
15
|
+
moduleType: ModuleType | undefined;
|
|
16
|
+
onEnable: Function | undefined;
|
|
17
|
+
onReady: Function | undefined;
|
|
18
|
+
onDisable: Function | undefined;
|
|
19
|
+
}, _sapphire_shapeshift16.UndefinedToOptional<{
|
|
20
|
+
id: string | undefined;
|
|
21
|
+
moduleType: ModuleType | undefined;
|
|
22
|
+
onEnable: Function | undefined;
|
|
23
|
+
onReady: Function | undefined;
|
|
24
|
+
onDisable: Function | undefined;
|
|
25
|
+
}>>;
|
|
26
|
+
static resolvable: _sapphire_shapeshift16.UnionValidator<_sapphire_shapeshift16.UndefinedToOptional<{
|
|
27
|
+
id: string | undefined;
|
|
28
|
+
moduleType: ModuleType | undefined;
|
|
29
|
+
onEnable: Function | undefined;
|
|
30
|
+
onReady: Function | undefined;
|
|
31
|
+
onDisable: Function | undefined;
|
|
32
|
+
}> | _sapphire_shapeshift16.UndefinedToOptional<{
|
|
33
|
+
toJSON: Function;
|
|
34
|
+
}>>;
|
|
35
|
+
static isValidId(id: unknown): asserts id is string;
|
|
36
|
+
static isValidModuleType(moduleType: unknown): asserts moduleType is ModuleType;
|
|
37
|
+
static isValidOnEnable(onEnable: unknown): asserts onEnable is () => Promise<void>;
|
|
38
|
+
static isValidOnReady(onReady: unknown): asserts onReady is () => Promise<void>;
|
|
39
|
+
static isValidOnDisable(onDisable: unknown): asserts onDisable is () => Promise<void>;
|
|
40
|
+
static isValid(value: unknown): asserts value is AnyModuleData;
|
|
41
|
+
}
|
|
42
|
+
//#endregion
|
|
43
|
+
export { BaseModuleValidator };
|
|
44
|
+
//# sourceMappingURL=BaseModuleValidator.d.mts.map
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { ModuleType } from "../../helpers/constants.mjs";
|
|
2
|
+
import { Validator } from "@reciple/core";
|
|
3
|
+
|
|
4
|
+
//#region src/classes/validation/BaseModuleValidator.ts
|
|
5
|
+
var BaseModuleValidator = class BaseModuleValidator extends Validator {
|
|
6
|
+
static id = BaseModuleValidator.s.string().lengthGreaterThan(0);
|
|
7
|
+
static moduleType = BaseModuleValidator.s.nativeEnum(ModuleType);
|
|
8
|
+
static onEnable = BaseModuleValidator.s.instance(Function).optional();
|
|
9
|
+
static onReady = BaseModuleValidator.s.instance(Function).optional();
|
|
10
|
+
static onDisable = BaseModuleValidator.s.instance(Function).optional();
|
|
11
|
+
static object = BaseModuleValidator.s.object({
|
|
12
|
+
id: BaseModuleValidator.id.optional(),
|
|
13
|
+
moduleType: BaseModuleValidator.moduleType.optional(),
|
|
14
|
+
onEnable: BaseModuleValidator.onEnable,
|
|
15
|
+
onReady: BaseModuleValidator.onReady,
|
|
16
|
+
onDisable: BaseModuleValidator.onDisable
|
|
17
|
+
});
|
|
18
|
+
static resolvable = BaseModuleValidator.s.union([BaseModuleValidator.object, BaseModuleValidator.jsonEncodable]);
|
|
19
|
+
static isValidId(id) {
|
|
20
|
+
BaseModuleValidator.id.setValidationEnabled(BaseModuleValidator.isValidationEnabled).parse(id);
|
|
21
|
+
}
|
|
22
|
+
static isValidModuleType(moduleType) {
|
|
23
|
+
BaseModuleValidator.moduleType.setValidationEnabled(BaseModuleValidator.isValidationEnabled).parse(moduleType);
|
|
24
|
+
}
|
|
25
|
+
static isValidOnEnable(onEnable) {
|
|
26
|
+
BaseModuleValidator.onEnable.setValidationEnabled(BaseModuleValidator.isValidationEnabled).parse(onEnable);
|
|
27
|
+
}
|
|
28
|
+
static isValidOnReady(onReady) {
|
|
29
|
+
BaseModuleValidator.onReady.setValidationEnabled(BaseModuleValidator.isValidationEnabled).parse(onReady);
|
|
30
|
+
}
|
|
31
|
+
static isValidOnDisable(onDisable) {
|
|
32
|
+
BaseModuleValidator.onDisable.setValidationEnabled(BaseModuleValidator.isValidationEnabled).parse(onDisable);
|
|
33
|
+
}
|
|
34
|
+
static isValid(value) {
|
|
35
|
+
const data = value;
|
|
36
|
+
if ("id" in data) BaseModuleValidator.isValidId(data.id);
|
|
37
|
+
if ("moduleType" in data) BaseModuleValidator.isValidModuleType(data.moduleType);
|
|
38
|
+
BaseModuleValidator.isValidOnEnable(data.onEnable);
|
|
39
|
+
BaseModuleValidator.isValidOnReady(data.onReady);
|
|
40
|
+
BaseModuleValidator.isValidOnDisable(data.onDisable);
|
|
41
|
+
}
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
//#endregion
|
|
45
|
+
export { BaseModuleValidator };
|
|
46
|
+
//# sourceMappingURL=BaseModuleValidator.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"BaseModuleValidator.mjs","names":[],"sources":["../../../src/classes/validation/BaseModuleValidator.ts"],"sourcesContent":["import { Validator } from '@reciple/core';\nimport { ModuleType } from '../../helpers/constants.js';\nimport type { AnyModuleData } from '../../helpers/types.js';\n\nexport class BaseModuleValidator extends Validator {\n public static id = BaseModuleValidator.s.string().lengthGreaterThan(0);\n public static moduleType = BaseModuleValidator.s.nativeEnum(ModuleType);\n public static onEnable = BaseModuleValidator.s.instance(Function).optional();\n public static onReady = BaseModuleValidator.s.instance(Function).optional();\n public static onDisable = BaseModuleValidator.s.instance(Function).optional();\n\n public static object = BaseModuleValidator.s.object({\n id: BaseModuleValidator.id.optional(),\n moduleType: BaseModuleValidator.moduleType.optional(),\n onEnable: BaseModuleValidator.onEnable,\n onReady: BaseModuleValidator.onReady,\n onDisable: BaseModuleValidator.onDisable\n });\n\n public static resolvable = BaseModuleValidator.s.union([\n BaseModuleValidator.object,\n BaseModuleValidator.jsonEncodable\n ]);\n\n public static isValidId(id: unknown): asserts id is string {\n BaseModuleValidator.id.setValidationEnabled(BaseModuleValidator.isValidationEnabled).parse(id);\n }\n\n public static isValidModuleType(moduleType: unknown): asserts moduleType is ModuleType {\n BaseModuleValidator.moduleType.setValidationEnabled(BaseModuleValidator.isValidationEnabled).parse(moduleType);\n }\n\n public static isValidOnEnable(onEnable: unknown): asserts onEnable is () => Promise<void> {\n BaseModuleValidator.onEnable.setValidationEnabled(BaseModuleValidator.isValidationEnabled).parse(onEnable);\n }\n\n public static isValidOnReady(onReady: unknown): asserts onReady is () => Promise<void> {\n BaseModuleValidator.onReady.setValidationEnabled(BaseModuleValidator.isValidationEnabled).parse(onReady);\n }\n\n public static isValidOnDisable(onDisable: unknown): asserts onDisable is () => Promise<void> {\n BaseModuleValidator.onDisable.setValidationEnabled(BaseModuleValidator.isValidationEnabled).parse(onDisable);\n }\n\n public static isValid(value: unknown): asserts value is AnyModuleData {\n const data = value as AnyModuleData;\n\n if ('id' in data) BaseModuleValidator.isValidId(data.id);\n if ('moduleType' in data) BaseModuleValidator.isValidModuleType(data.moduleType);\n\n BaseModuleValidator.isValidOnEnable(data.onEnable);\n BaseModuleValidator.isValidOnReady(data.onReady);\n BaseModuleValidator.isValidOnDisable(data.onDisable);\n }\n}\n"],"mappings":";;;;AAIA,IAAa,sBAAb,MAAa,4BAA4B,UAAU;CAC/C,OAAc,KAAK,oBAAoB,EAAE,QAAQ,CAAC,kBAAkB,EAAE;CACtE,OAAc,aAAa,oBAAoB,EAAE,WAAW,WAAW;CACvE,OAAc,WAAW,oBAAoB,EAAE,SAAS,SAAS,CAAC,UAAU;CAC5E,OAAc,UAAU,oBAAoB,EAAE,SAAS,SAAS,CAAC,UAAU;CAC3E,OAAc,YAAY,oBAAoB,EAAE,SAAS,SAAS,CAAC,UAAU;CAE7E,OAAc,SAAS,oBAAoB,EAAE,OAAO;EAChD,IAAI,oBAAoB,GAAG,UAAU;EACrC,YAAY,oBAAoB,WAAW,UAAU;EACrD,UAAU,oBAAoB;EAC9B,SAAS,oBAAoB;EAC7B,WAAW,oBAAoB;EAClC,CAAC;CAEF,OAAc,aAAa,oBAAoB,EAAE,MAAM,CACnD,oBAAoB,QACpB,oBAAoB,cACvB,CAAC;CAEF,OAAc,UAAU,IAAmC;AACvD,sBAAoB,GAAG,qBAAqB,oBAAoB,oBAAoB,CAAC,MAAM,GAAG;;CAGlG,OAAc,kBAAkB,YAAuD;AACnF,sBAAoB,WAAW,qBAAqB,oBAAoB,oBAAoB,CAAC,MAAM,WAAW;;CAGlH,OAAc,gBAAgB,UAA4D;AACtF,sBAAoB,SAAS,qBAAqB,oBAAoB,oBAAoB,CAAC,MAAM,SAAS;;CAG9G,OAAc,eAAe,SAA0D;AACnF,sBAAoB,QAAQ,qBAAqB,oBAAoB,oBAAoB,CAAC,MAAM,QAAQ;;CAG5G,OAAc,iBAAiB,WAA8D;AACzF,sBAAoB,UAAU,qBAAqB,oBAAoB,oBAAoB,CAAC,MAAM,UAAU;;CAGhH,OAAc,QAAQ,OAAgD;EAClE,MAAM,OAAO;AAEb,MAAI,QAAQ,KAAM,qBAAoB,UAAU,KAAK,GAAG;AACxD,MAAI,gBAAgB,KAAM,qBAAoB,kBAAkB,KAAK,WAAW;AAEhF,sBAAoB,gBAAgB,KAAK,SAAS;AAClD,sBAAoB,eAAe,KAAK,QAAQ;AAChD,sBAAoB,iBAAiB,KAAK,UAAU"}
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
import { ModuleType } from "../../helpers/constants.mjs";
|
|
2
|
+
import { AnyCommandModuleData } from "../../helpers/types.mjs";
|
|
3
|
+
import "../../index.mjs";
|
|
4
|
+
import * as _reciple_core0 from "@reciple/core";
|
|
5
|
+
import { Validator } from "@reciple/core";
|
|
6
|
+
import * as _sapphire_shapeshift0 from "@sapphire/shapeshift";
|
|
7
|
+
|
|
8
|
+
//#region src/classes/validation/CommandModuleValidator.d.ts
|
|
9
|
+
declare class CommandModuleValidator extends Validator {
|
|
10
|
+
static object: _sapphire_shapeshift0.ObjectValidator<{
|
|
11
|
+
id: string | undefined;
|
|
12
|
+
moduleType: ModuleType | undefined;
|
|
13
|
+
onEnable: Function | undefined;
|
|
14
|
+
onReady: Function | undefined;
|
|
15
|
+
onDisable: Function | undefined;
|
|
16
|
+
} & {
|
|
17
|
+
id: string;
|
|
18
|
+
type: _reciple_core0.CommandType;
|
|
19
|
+
data: _sapphire_shapeshift0.UndefinedToOptional<{
|
|
20
|
+
name: any;
|
|
21
|
+
description: any;
|
|
22
|
+
aliases: any;
|
|
23
|
+
options: any;
|
|
24
|
+
flags: any;
|
|
25
|
+
}> | _sapphire_shapeshift0.UndefinedToOptional<{
|
|
26
|
+
type: any;
|
|
27
|
+
name: any;
|
|
28
|
+
}>;
|
|
29
|
+
cooldown: number | undefined;
|
|
30
|
+
preconditions: _sapphire_shapeshift0.UndefinedToOptional<{
|
|
31
|
+
id: any;
|
|
32
|
+
scope: any;
|
|
33
|
+
execute: any;
|
|
34
|
+
}>[] | undefined;
|
|
35
|
+
postconditions: _sapphire_shapeshift0.UndefinedToOptional<{
|
|
36
|
+
id: any;
|
|
37
|
+
scope: any;
|
|
38
|
+
execute: any;
|
|
39
|
+
}>[] | undefined;
|
|
40
|
+
disabledPreconditions: string[] | undefined;
|
|
41
|
+
disabledPostconditions: string[] | undefined;
|
|
42
|
+
execute: Function;
|
|
43
|
+
}, _sapphire_shapeshift0.UndefinedToOptional<{
|
|
44
|
+
id: string | undefined;
|
|
45
|
+
moduleType: ModuleType | undefined;
|
|
46
|
+
onEnable: Function | undefined;
|
|
47
|
+
onReady: Function | undefined;
|
|
48
|
+
onDisable: Function | undefined;
|
|
49
|
+
} & {
|
|
50
|
+
id: string;
|
|
51
|
+
type: _reciple_core0.CommandType;
|
|
52
|
+
data: _sapphire_shapeshift0.UndefinedToOptional<{
|
|
53
|
+
name: any;
|
|
54
|
+
description: any;
|
|
55
|
+
aliases: any;
|
|
56
|
+
options: any;
|
|
57
|
+
flags: any;
|
|
58
|
+
}> | _sapphire_shapeshift0.UndefinedToOptional<{
|
|
59
|
+
type: any;
|
|
60
|
+
name: any;
|
|
61
|
+
}>;
|
|
62
|
+
cooldown: number | undefined;
|
|
63
|
+
preconditions: _sapphire_shapeshift0.UndefinedToOptional<{
|
|
64
|
+
id: any;
|
|
65
|
+
scope: any;
|
|
66
|
+
execute: any;
|
|
67
|
+
}>[] | undefined;
|
|
68
|
+
postconditions: _sapphire_shapeshift0.UndefinedToOptional<{
|
|
69
|
+
id: any;
|
|
70
|
+
scope: any;
|
|
71
|
+
execute: any;
|
|
72
|
+
}>[] | undefined;
|
|
73
|
+
disabledPreconditions: string[] | undefined;
|
|
74
|
+
disabledPostconditions: string[] | undefined;
|
|
75
|
+
execute: Function;
|
|
76
|
+
}>>;
|
|
77
|
+
static resolvable: _sapphire_shapeshift0.UnionValidator<_sapphire_shapeshift0.UndefinedToOptional<{
|
|
78
|
+
id: string | undefined;
|
|
79
|
+
moduleType: ModuleType | undefined;
|
|
80
|
+
onEnable: Function | undefined;
|
|
81
|
+
onReady: Function | undefined;
|
|
82
|
+
onDisable: Function | undefined;
|
|
83
|
+
} & {
|
|
84
|
+
id: string;
|
|
85
|
+
type: _reciple_core0.CommandType;
|
|
86
|
+
data: _sapphire_shapeshift0.UndefinedToOptional<{
|
|
87
|
+
name: any;
|
|
88
|
+
description: any;
|
|
89
|
+
aliases: any;
|
|
90
|
+
options: any;
|
|
91
|
+
flags: any;
|
|
92
|
+
}> | _sapphire_shapeshift0.UndefinedToOptional<{
|
|
93
|
+
type: any;
|
|
94
|
+
name: any;
|
|
95
|
+
}>;
|
|
96
|
+
cooldown: number | undefined;
|
|
97
|
+
preconditions: _sapphire_shapeshift0.UndefinedToOptional<{
|
|
98
|
+
id: any;
|
|
99
|
+
scope: any;
|
|
100
|
+
execute: any;
|
|
101
|
+
}>[] | undefined;
|
|
102
|
+
postconditions: _sapphire_shapeshift0.UndefinedToOptional<{
|
|
103
|
+
id: any;
|
|
104
|
+
scope: any;
|
|
105
|
+
execute: any;
|
|
106
|
+
}>[] | undefined;
|
|
107
|
+
disabledPreconditions: string[] | undefined;
|
|
108
|
+
disabledPostconditions: string[] | undefined;
|
|
109
|
+
execute: Function;
|
|
110
|
+
}> | _sapphire_shapeshift0.UndefinedToOptional<{
|
|
111
|
+
toJSON: Function;
|
|
112
|
+
}>>;
|
|
113
|
+
static isValid(value: unknown): asserts value is AnyCommandModuleData;
|
|
114
|
+
}
|
|
115
|
+
//#endregion
|
|
116
|
+
export { CommandModuleValidator };
|
|
117
|
+
//# sourceMappingURL=CommandModuleValidator.d.mts.map
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { BaseModuleValidator } from "./BaseModuleValidator.mjs";
|
|
2
|
+
import { BaseCommandValidator, Validator } from "@reciple/core";
|
|
3
|
+
|
|
4
|
+
//#region src/classes/validation/CommandModuleValidator.ts
|
|
5
|
+
var CommandModuleValidator = class CommandModuleValidator extends Validator {
|
|
6
|
+
static object = BaseModuleValidator.object.extend(BaseCommandValidator.object);
|
|
7
|
+
static resolvable = Validator.s.union([CommandModuleValidator.object, Validator.jsonEncodable]);
|
|
8
|
+
static isValid(value) {
|
|
9
|
+
BaseModuleValidator.isValid(value);
|
|
10
|
+
BaseCommandValidator.isValid(value);
|
|
11
|
+
}
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
//#endregion
|
|
15
|
+
export { CommandModuleValidator };
|
|
16
|
+
//# sourceMappingURL=CommandModuleValidator.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"CommandModuleValidator.mjs","names":[],"sources":["../../../src/classes/validation/CommandModuleValidator.ts"],"sourcesContent":["import { BaseModuleValidator } from './BaseModuleValidator.js';\nimport { BaseCommandValidator, Validator } from '@reciple/core';\nimport type { AnyCommandModuleData } from '../../helpers/types.js';\n\nexport class CommandModuleValidator extends Validator {\n public static object = BaseModuleValidator.object.extend(BaseCommandValidator.object);\n public static resolvable = Validator.s.union([CommandModuleValidator.object, Validator.jsonEncodable]);\n\n public static isValid(value: unknown): asserts value is AnyCommandModuleData {\n BaseModuleValidator.isValid(value);\n BaseCommandValidator.isValid(value);\n }\n}\n"],"mappings":";;;;AAIA,IAAa,yBAAb,MAAa,+BAA+B,UAAU;CAClD,OAAc,SAAS,oBAAoB,OAAO,OAAO,qBAAqB,OAAO;CACrF,OAAc,aAAa,UAAU,EAAE,MAAM,CAAC,uBAAuB,QAAQ,UAAU,cAAc,CAAC;CAEtG,OAAc,QAAQ,OAAuD;AACzE,sBAAoB,QAAQ,MAAM;AAClC,uBAAqB,QAAQ,MAAM"}
|