reciple 10.0.1-dev.8 → 10.0.2
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/README.md +69 -0
- package/assets/config/reciple.config.js +7 -0
- package/assets/config/reciple.config.ts +5 -0
- package/assets/global/nodemon.json +1 -0
- package/assets/templates/javascript/jsconfig.json +4 -0
- package/assets/templates/typescript/tsconfig.json +4 -0
- package/dist/_virtual/{_@oxc-project_runtime@0.99.0 → _@oxc-project_runtime@0.110.0}/helpers/decorate.mjs +1 -1
- package/dist/bin/commands/build.mjs +1 -1
- package/dist/bin/commands/build.mjs.map +1 -1
- package/dist/bin/commands/create.mjs +3 -2
- package/dist/bin/commands/create.mjs.map +1 -1
- package/dist/bin/commands/createModule.mjs +2 -2
- package/dist/bin/commands/createModule.mjs.map +1 -1
- package/dist/bin/commands/start.mjs +27 -26
- package/dist/bin/commands/start.mjs.map +1 -1
- package/dist/bin/commands/startSharding.d.mts +18 -0
- package/dist/bin/commands/startSharding.mjs +101 -0
- package/dist/bin/commands/startSharding.mjs.map +1 -0
- package/dist/bin/reciple.mjs +0 -0
- package/dist/classes/cli/CLI.d.mts +1 -1
- package/dist/classes/cli/CLI.mjs +6 -5
- package/dist/classes/cli/CLI.mjs.map +1 -1
- package/dist/classes/cli/ConfigReader.d.mts +24 -29
- package/dist/classes/cli/ConfigReader.mjs +46 -61
- package/dist/classes/cli/ConfigReader.mjs.map +1 -1
- package/dist/classes/cli/RuntimeEnvironment.mjs +1 -1
- package/dist/classes/cli/RuntimeEnvironment.mjs.map +1 -1
- package/dist/classes/client/EventListeners.mjs +3 -2
- package/dist/classes/client/EventListeners.mjs.map +1 -1
- package/dist/classes/client/ModuleLoader.d.mts +3 -3
- package/dist/classes/client/ModuleLoader.mjs +27 -25
- package/dist/classes/client/ModuleLoader.mjs.map +1 -1
- package/dist/classes/managers/ModuleManager.mjs +5 -5
- package/dist/classes/managers/ModuleManager.mjs.map +1 -1
- package/dist/classes/modules/BaseModule.d.mts +0 -3
- package/dist/classes/modules/BaseModule.mjs +2 -4
- package/dist/classes/modules/BaseModule.mjs.map +1 -1
- package/dist/classes/modules/PostconditionModule.d.mts +1 -1
- package/dist/classes/modules/PostconditionModule.mjs +5 -5
- package/dist/classes/modules/PostconditionModule.mjs.map +1 -1
- package/dist/classes/modules/PreconditionModule.d.mts +1 -1
- package/dist/classes/modules/PreconditionModule.mjs +5 -5
- package/dist/classes/modules/PreconditionModule.mjs.map +1 -1
- package/dist/classes/modules/commands/ContextMenuCommandModule.d.mts +1 -1
- package/dist/classes/modules/commands/ContextMenuCommandModule.mjs +5 -5
- package/dist/classes/modules/commands/ContextMenuCommandModule.mjs.map +1 -1
- package/dist/classes/modules/commands/MessageCommandModule.d.mts +1 -1
- package/dist/classes/modules/commands/MessageCommandModule.mjs +5 -5
- package/dist/classes/modules/commands/MessageCommandModule.mjs.map +1 -1
- package/dist/classes/modules/commands/SlashCommandModule.d.mts +1 -1
- package/dist/classes/modules/commands/SlashCommandModule.mjs +5 -5
- package/dist/classes/modules/commands/SlashCommandModule.mjs.map +1 -1
- package/dist/classes/modules/events/EventModule.d.mts +3 -4
- package/dist/classes/modules/events/EventModule.mjs +3 -4
- package/dist/classes/modules/events/EventModule.mjs.map +1 -1
- package/dist/classes/templates/ModuleTemplateBuilder.d.mts +1 -1
- package/dist/classes/templates/ModuleTemplateBuilder.mjs +22 -22
- package/dist/classes/templates/ModuleTemplateBuilder.mjs.map +1 -1
- package/dist/classes/templates/TemplateBuilder.mjs +31 -27
- package/dist/classes/templates/TemplateBuilder.mjs.map +1 -1
- package/dist/classes/validation/BaseModuleValidator.d.mts +11 -11
- package/dist/classes/validation/CommandModuleValidator.d.mts +17 -17
- package/dist/classes/validation/EventModuleValidator.d.mts +28 -12
- package/dist/classes/validation/PostconditionModule.d.mts +9 -9
- package/dist/classes/validation/PreconditionModule.d.mts +7 -7
- package/dist/helpers/constants.d.mts +2 -4
- package/dist/helpers/constants.mjs +8 -8
- package/dist/helpers/constants.mjs.map +1 -1
- package/dist/helpers/types.d.mts +3 -1
- package/dist/index.d.mts +4 -5
- package/dist/index.mjs +3 -4
- package/dist/index.mjs.map +1 -1
- package/dist/package.mjs +18 -16
- package/dist/package.mjs.map +1 -1
- package/package.json +16 -14
- package/LICENSE +0 -155
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SlashCommandModule.mjs","names":[
|
|
1
|
+
{"version":3,"file":"SlashCommandModule.mjs","names":[],"sources":["../../../../src/classes/modules/commands/SlashCommandModule.ts"],"sourcesContent":["import { BaseModule } from '../BaseModule.js';\nimport { ModuleType } from '../../../helpers/constants.js';\nimport { DiscordSnowflake } from '@sapphire/snowflake';\nimport { hasMixin, mix } from 'ts-mixer';\nimport { SlashCommand, type SlashCommandBuilder } from '@reciple/core';\nimport type { AnyCommandBuilderMethods } from '../../../helpers/types.js';\n\nexport interface SlashCommandModule extends Omit<BaseModule, 'moduleType'>, SlashCommandModule.SlashCommandWithoutBuilderMethods {}\n\n@mix(SlashCommand, BaseModule)\nexport abstract class SlashCommandModule implements SlashCommandModule {\n public readonly moduleType: ModuleType.Command = ModuleType.Command;\n public readonly id: string = DiscordSnowflake.generate().toString();\n\n public abstract data: SlashCommandBuilder.Data;\n\n public abstract execute(data: SlashCommand.ExecuteData): Promise<void>;\n\n public static from(data: SlashCommandModule.Resolvable): SlashCommandModule {\n if (hasMixin(data, SlashCommandModule)) return data;\n\n const ModuleInstance = class extends SlashCommandModule { data = data.data; execute = data.execute; };\n Object.assign(ModuleInstance.prototype, data);\n return new ModuleInstance();\n }\n}\n\nexport namespace SlashCommandModule {\n export type Resolvable = SlashCommandModule|SlashCommandModule.Data;\n\n export interface Data extends Omit<BaseModule.Data, 'moduleType'>, Omit<SlashCommand.Data, 'id'> {\n moduleType: ModuleType.Command;\n }\n\n export type SlashCommandWithoutBuilderMethods = Omit<SlashCommand, AnyCommandBuilderMethods>;\n}\n"],"mappings":";;;;;;;;;AAUO,qDAAe,mBAAiD;CACnE,AAAgB,aAAiC,WAAW;CAC5D,AAAgB,KAAa,iBAAiB,UAAU,CAAC,UAAU;CAMnE,OAAc,KAAK,MAAyD;AACxE,MAAI,SAAS,0BAAyB,CAAE,QAAO;EAE/C,MAAM,iBAAiB,kCAAiC;GAAE,OAAO,KAAK;GAAM,UAAU,KAAK;;AAC3F,SAAO,OAAO,eAAe,WAAW,KAAK;AAC7C,SAAO,IAAI,gBAAgB;;;uDAdlC,IAAI,cAAc,WAAW"}
|
|
@@ -1,11 +1,10 @@
|
|
|
1
|
-
import { ModuleType } from "../../../helpers/constants.mjs";
|
|
2
1
|
import { BaseModule } from "../BaseModule.mjs";
|
|
3
|
-
import {
|
|
2
|
+
import { ModuleType } from "../../../helpers/constants.mjs";
|
|
3
|
+
import { Awaitable } from "discord.js";
|
|
4
4
|
import { EventEmitter } from "node:events";
|
|
5
5
|
|
|
6
6
|
//#region src/classes/modules/events/EventModule.d.ts
|
|
7
|
-
declare
|
|
8
|
-
declare abstract class EventModule<Events extends EventModule.EventMap = EventModule.EventMap, Event extends keyof Events = keyof Events> extends base implements EventModule.Data<Events, Event> {
|
|
7
|
+
declare abstract class EventModule<Events extends EventModule.EventMap = EventModule.EventMap, Event extends keyof Events = keyof Events> extends BaseModule implements EventModule.Data<Events, Event> {
|
|
9
8
|
readonly moduleType: ModuleType.Event;
|
|
10
9
|
abstract emitter: EventEmitter;
|
|
11
10
|
abstract event: Event;
|
|
@@ -1,15 +1,14 @@
|
|
|
1
|
-
import { ModuleType } from "../../../helpers/constants.mjs";
|
|
2
1
|
import { BaseModule } from "../BaseModule.mjs";
|
|
2
|
+
import { ModuleType } from "../../../helpers/constants.mjs";
|
|
3
3
|
import { hasMixin } from "ts-mixer";
|
|
4
4
|
import { EventEmitter } from "node:events";
|
|
5
5
|
|
|
6
6
|
//#region src/classes/modules/events/EventModule.ts
|
|
7
|
-
|
|
8
|
-
var EventModule = class EventModule extends base {
|
|
7
|
+
var EventModule = class EventModule extends BaseModule {
|
|
9
8
|
moduleType = ModuleType.Event;
|
|
10
9
|
once = false;
|
|
11
10
|
static from(data) {
|
|
12
|
-
if (
|
|
11
|
+
if (hasMixin(data, EventModule)) return data;
|
|
13
12
|
const ModuleInstance = class extends EventModule {
|
|
14
13
|
emitter = data.emitter;
|
|
15
14
|
event = data.event;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"EventModule.mjs","names":[
|
|
1
|
+
{"version":3,"file":"EventModule.mjs","names":[],"sources":["../../../../src/classes/modules/events/EventModule.ts"],"sourcesContent":["import { EventEmitter } from 'node:events';\nimport { BaseModule } from '../BaseModule.js';\nimport { ModuleType } from '../../../helpers/constants.js';\nimport type { Awaitable } from 'discord.js';\nimport { hasMixin } from 'ts-mixer';\n\nexport abstract class EventModule<Events extends EventModule.EventMap = EventModule.EventMap, Event extends keyof Events = keyof Events> extends BaseModule implements EventModule.Data<Events, Event> {\n public readonly moduleType: ModuleType.Event = ModuleType.Event;\n public abstract emitter: EventEmitter;\n public abstract event: Event;\n\n public once?: boolean = false;\n\n public abstract onEvent(...args: Events[Event]): Awaitable<void>;\n\n public static from(data: EventModule.Resolvable): EventModule {\n if (hasMixin(data, EventModule)) return data;\n\n const ModuleInstance = class extends EventModule {\n emitter = data.emitter;\n event = data.event;\n once = data.once;\n onEvent = data.onEvent;\n };\n\n Object.assign(ModuleInstance.prototype, data);\n return new ModuleInstance();\n }\n}\n\nexport namespace EventModule {\n export type EventMap = Record<string|symbol, any>;\n export type Resolvable<Events extends EventModule.EventMap = EventModule.EventMap, Event extends keyof Events = keyof Events> = EventModule<Events, Event>|EventModule.Data<Events, Event>;\n\n export interface Data<Events extends EventModule.EventMap = EventModule.EventMap, Event extends keyof Events = keyof Events> extends Omit<BaseModule.Data, 'moduleType'> {\n moduleType: ModuleType.Event;\n emitter: EventEmitter;\n event: Event;\n once?: boolean;\n onEvent: (...args: Events[Event]) => Awaitable<void>;\n }\n}\n"],"mappings":";;;;;;AAMA,IAAsB,cAAtB,MAAsB,oBAA2H,WAAsD;CACnM,AAAgB,aAA+B,WAAW;CAI1D,AAAO,OAAiB;CAIxB,OAAc,KAAK,MAA2C;AAC1D,MAAI,SAAS,MAAM,YAAY,CAAE,QAAO;EAExC,MAAM,iBAAiB,cAAc,YAAY;GAC7C,UAAU,KAAK;GACf,QAAQ,KAAK;GACb,OAAO,KAAK;GACZ,UAAU,KAAK;;AAGnB,SAAO,OAAO,eAAe,WAAW,KAAK;AAC7C,SAAO,IAAI,gBAAgB"}
|
|
@@ -59,7 +59,7 @@ declare namespace ModuleTemplateBuilder {
|
|
|
59
59
|
CommandContextMenuType = "$COMMAND_CONTEXT_MENU_TYPE$",
|
|
60
60
|
EventEmitter = "$EVENT_EMITTER$",
|
|
61
61
|
EventName = "$EVENT_NAME$",
|
|
62
|
-
EventOnce = "$EVENT_ONCE$"
|
|
62
|
+
EventOnce = "$EVENT_ONCE$"
|
|
63
63
|
}
|
|
64
64
|
const PlaceholderDefaultValues: Record<Placeholder, string>;
|
|
65
65
|
const SourceDirectory: {
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { NotAnError } from "../NotAnError.mjs";
|
|
2
2
|
import { CLI } from "../cli/CLI.mjs";
|
|
3
3
|
import { ConfigReader } from "../cli/ConfigReader.mjs";
|
|
4
|
-
import { ModuleType } from "../../helpers/constants.mjs";
|
|
5
4
|
import { BaseModule } from "../modules/BaseModule.mjs";
|
|
5
|
+
import { ModuleType } from "../../helpers/constants.mjs";
|
|
6
6
|
import { PostconditionModule } from "../modules/PostconditionModule.mjs";
|
|
7
7
|
import { PreconditionModule } from "../modules/PreconditionModule.mjs";
|
|
8
8
|
import { EventModule } from "../modules/events/EventModule.mjs";
|
|
@@ -13,9 +13,9 @@ import { ModuleLoader } from "../client/ModuleLoader.mjs";
|
|
|
13
13
|
import { ClientEventModule } from "../modules/events/ClientEventModule.mjs";
|
|
14
14
|
import { RESTEventModule } from "../modules/events/RESTEventModule.mjs";
|
|
15
15
|
import path from "node:path";
|
|
16
|
-
import { colors } from "@reciple/utils";
|
|
17
16
|
import { mkdir, readFile, readdir, writeFile } from "node:fs/promises";
|
|
18
17
|
import { confirm, intro, isCancel, outro, select, text } from "@clack/prompts";
|
|
18
|
+
import { colors } from "@prtty/prtty";
|
|
19
19
|
import { readTSConfig } from "pkg-types";
|
|
20
20
|
import { ApplicationCommandType } from "discord.js";
|
|
21
21
|
import { existsSync } from "node:fs";
|
|
@@ -48,7 +48,7 @@ var ModuleTemplateBuilder = class ModuleTemplateBuilder {
|
|
|
48
48
|
this.defaultAll = options?.defaultAll ?? false;
|
|
49
49
|
}
|
|
50
50
|
async init() {
|
|
51
|
-
intro(colors.bold(
|
|
51
|
+
intro(colors.bold().black().bgCyan(` ${this.cli.command.name()} create module - v${this.cli.build} `));
|
|
52
52
|
return this;
|
|
53
53
|
}
|
|
54
54
|
async setupLanguage(options) {
|
|
@@ -71,11 +71,11 @@ var ModuleTemplateBuilder = class ModuleTemplateBuilder {
|
|
|
71
71
|
if (!template) {
|
|
72
72
|
const templateName = typeof options?.template === "string" ? options.template : void 0;
|
|
73
73
|
const templates = await ModuleTemplateBuilder.resolveModuleTemplates(this.typescript ? "ts" : "js");
|
|
74
|
-
const selectedTemplate = this.defaultAll ? templateName ? templates.find((template
|
|
74
|
+
const selectedTemplate = this.defaultAll ? templateName ? templates.find((template) => template.name === templateName) : templates.at(0) : await select({
|
|
75
75
|
message: "Select a module template",
|
|
76
|
-
options: templates.map((template
|
|
77
|
-
label: template
|
|
78
|
-
value: template
|
|
76
|
+
options: templates.map((template) => ({
|
|
77
|
+
label: template.name,
|
|
78
|
+
value: template
|
|
79
79
|
}))
|
|
80
80
|
});
|
|
81
81
|
if (isCancel(selectedTemplate)) throw new NotAnError("Operation cancelled");
|
|
@@ -102,9 +102,9 @@ var ModuleTemplateBuilder = class ModuleTemplateBuilder {
|
|
|
102
102
|
initialValue: defaultValue,
|
|
103
103
|
placeholder: defaultValue,
|
|
104
104
|
defaultValue,
|
|
105
|
-
validate: (value
|
|
106
|
-
if (!value
|
|
107
|
-
if (value
|
|
105
|
+
validate: (value) => {
|
|
106
|
+
if (!value) return "Please enter a value";
|
|
107
|
+
if (value.includes(" ")) return "Please enter a value without spaces";
|
|
108
108
|
}
|
|
109
109
|
});
|
|
110
110
|
break;
|
|
@@ -162,9 +162,9 @@ var ModuleTemplateBuilder = class ModuleTemplateBuilder {
|
|
|
162
162
|
});
|
|
163
163
|
const selectedDirectory = this.defaultAll ? directories.at(0) : await select({
|
|
164
164
|
message: "Select a directory",
|
|
165
|
-
options: directories.map((directory
|
|
166
|
-
label: path.relative(cwd, directory
|
|
167
|
-
value: directory
|
|
165
|
+
options: directories.map((directory) => ({
|
|
166
|
+
label: path.relative(cwd, directory),
|
|
167
|
+
value: directory
|
|
168
168
|
}))
|
|
169
169
|
});
|
|
170
170
|
if (isCancel(selectedDirectory)) throw new NotAnError("Operation cancelled");
|
|
@@ -203,15 +203,15 @@ var ModuleTemplateBuilder = class ModuleTemplateBuilder {
|
|
|
203
203
|
}
|
|
204
204
|
};
|
|
205
205
|
(function(_ModuleTemplateBuilder) {
|
|
206
|
-
let Placeholder = /* @__PURE__ */ function(Placeholder
|
|
207
|
-
Placeholder
|
|
208
|
-
Placeholder
|
|
209
|
-
Placeholder
|
|
210
|
-
Placeholder
|
|
211
|
-
Placeholder
|
|
212
|
-
Placeholder
|
|
213
|
-
Placeholder
|
|
214
|
-
return Placeholder
|
|
206
|
+
let Placeholder = /* @__PURE__ */ function(Placeholder) {
|
|
207
|
+
Placeholder["ModuleName"] = "$MODULE_NAME$";
|
|
208
|
+
Placeholder["CommandName"] = "$COMMAND_NAME$";
|
|
209
|
+
Placeholder["CommandDescription"] = "$COMMAND_DESCRIPTION$";
|
|
210
|
+
Placeholder["CommandContextMenuType"] = "$COMMAND_CONTEXT_MENU_TYPE$";
|
|
211
|
+
Placeholder["EventEmitter"] = "$EVENT_EMITTER$";
|
|
212
|
+
Placeholder["EventName"] = "$EVENT_NAME$";
|
|
213
|
+
Placeholder["EventOnce"] = "$EVENT_ONCE$";
|
|
214
|
+
return Placeholder;
|
|
215
215
|
}({});
|
|
216
216
|
_ModuleTemplateBuilder.Placeholder = Placeholder;
|
|
217
217
|
_ModuleTemplateBuilder.PlaceholderDefaultValues = {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ModuleTemplateBuilder.mjs","names":["template","value: string|symbol","value","directory","ModuleTypeClassName: Record<ModuleType, string[]>","files: string[]","templates: ModuleTemplateBuilder.Data[]"],"sources":["../../../src/classes/templates/ModuleTemplateBuilder.ts"],"sourcesContent":["import path from 'node:path';\nimport { CLI } from '../cli/CLI.js';\nimport { ModuleType } from '../../helpers/constants.js';\nimport { BaseModule } from '../modules/BaseModule.js';\nimport { MessageCommandModule } from '../modules/commands/MessageCommandModule.js';\nimport { SlashCommandModule } from '../modules/commands/SlashCommandModule.js';\nimport { ContextMenuCommandModule } from '../modules/commands/ContextMenuCommandModule.js';\nimport { ClientEventModule } from '../modules/events/ClientEventModule.js';\nimport { EventModule } from '../modules/events/EventModule.js';\nimport { RESTEventModule } from '../modules/events/RESTEventModule.js';\nimport { PostconditionModule } from '../modules/PostconditionModule.js';\nimport { PreconditionModule } from '../modules/PreconditionModule.js';\nimport { mkdir, readdir, readFile, writeFile } from 'node:fs/promises';\nimport { ConfigReader } from '../cli/ConfigReader.js';\nimport { confirm, intro, isCancel, outro, select, text } from '@clack/prompts';\nimport { NotAnError } from '../NotAnError.js';\nimport { ApplicationCommandType } from 'discord.js';\nimport { ModuleLoader } from '../client/ModuleLoader.js';\nimport { existsSync } from 'node:fs';\nimport { colors } from '@reciple/utils';\nimport { readTSConfig } from 'pkg-types';\n\nexport class ModuleTemplateBuilder {\n public _directory?: string;\n\n public readonly cli: CLI;\n public readonly config: ConfigReader;\n\n public template?: ModuleTemplateBuilder.Data;\n public typescript?: boolean;\n public filename?: string;\n public defaultAll: boolean;\n\n get content() {\n return this.template?.content ?? '';\n }\n\n get directory() {\n return this._directory ?? process.cwd();\n }\n\n get filepath() {\n return path.join(this.directory, this.filename ?? '');\n }\n\n constructor(options: ModuleTemplateBuilder.Options) {\n this.cli = options.cli;\n this.config = options.config;\n this.template = options?.template;\n this.typescript = options?.typescript;\n this._directory = options?.directory;\n this.filename = options?.filename;\n this.defaultAll = options?.defaultAll ?? false;\n }\n\n public async init(): Promise<this> {\n intro(colors.bold(colors.black(colors.bgCyan(` ${this.cli.command.name()} create module - v${this.cli.build} `))));\n return this;\n }\n\n public async setupLanguage(options?: ModuleTemplateBuilder.SetupLanguageOptions): Promise<this> {\n this.typescript = options?.typescript ?? this.typescript;\n\n if (!this.typescript) {\n const isTypeScriptDefault = (await ConfigReader.getProjectLang(this.directory)) === 'ts';\n const isTypeScript = this.defaultAll\n ? isTypeScriptDefault\n : await confirm({\n message: 'Would you like to use TypeScript?',\n active: 'Yes',\n inactive: 'No',\n initialValue: isTypeScriptDefault\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 setupTemplate(options?: ModuleTemplateBuilder.SetupTemplateOptions): Promise<this> {\n let template = typeof options?.template === 'object' ? options.template : undefined;\n\n if (!template) {\n const templateName = typeof options?.template === 'string' ? options.template : undefined;\n const templates = await ModuleTemplateBuilder.resolveModuleTemplates(this.typescript ? 'ts' : 'js');\n\n const selectedTemplate = this.defaultAll\n ? templateName ? templates.find(template => template.name === templateName) : templates.at(0)\n : await select({\n message: 'Select a module template',\n options: templates.map(template => ({\n label: template.name,\n value: template\n }))\n });\n\n if (isCancel(selectedTemplate)) throw new NotAnError('Operation cancelled');\n template = selectedTemplate;\n }\n\n this.template = template;\n if (!this.template) throw new NotAnError('No template selected');\n\n return this;\n }\n\n public async setupPlaceholders(): Promise<this> {\n const placeholders = Object.keys(ModuleTemplateBuilder.Placeholder).filter(k => !k.startsWith('$')) as (keyof typeof ModuleTemplateBuilder.Placeholder)[];\n\n for (const placeholderKey of placeholders) {\n if (!ModuleTemplateBuilder.hasPlaceholder(ModuleTemplateBuilder.Placeholder[placeholderKey], this.content)) continue;\n const placeholder = ModuleTemplateBuilder.Placeholder[placeholderKey];\n const defaultValue = ModuleTemplateBuilder.PlaceholderDefaultValues[placeholder];\n\n let value: string|symbol;\n\n if (this.defaultAll) {\n value = defaultValue;\n } else {\n switch (placeholder) {\n case ModuleTemplateBuilder.Placeholder.ModuleName:\n case ModuleTemplateBuilder.Placeholder.CommandName:\n case ModuleTemplateBuilder.Placeholder.EventName:\n value = this.defaultAll\n ? defaultValue\n : await text({\n message: `What would you like to name the ${placeholderKey.replace('Name', '').toLowerCase()}?`,\n initialValue: defaultValue,\n placeholder: defaultValue,\n defaultValue,\n validate: (value) => {\n if (!value) return 'Please enter a value';\n if (value.includes(' ')) return 'Please enter a value without spaces';\n }\n });\n break;\n case ModuleTemplateBuilder.Placeholder.CommandContextMenuType:\n const type = await select({\n message: 'Select a command context menu type',\n options: [\n { label: 'Message', value: ApplicationCommandType.Message },\n { label: 'User', value: ApplicationCommandType.User }\n ],\n initialValue: ApplicationCommandType.Message\n });\n\n value = isCancel(type) ? type : `${type}`;\n break;\n case ModuleTemplateBuilder.Placeholder.EventOnce:\n const once = await confirm({\n message: `Would you like to use the event once?`,\n active: 'Yes',\n inactive: 'No',\n initialValue: false\n });\n\n value = isCancel(once) ? once : `${once}`;\n break;\n case ModuleTemplateBuilder.Placeholder.EventEmitter:\n default:\n value = await text({\n message: `What would you like to use for the ${ModuleTemplateBuilder.toTextCase(placeholder)}?`,\n initialValue: defaultValue,\n placeholder: defaultValue,\n defaultValue\n });\n break;\n }\n }\n\n if (isCancel(value)) throw new NotAnError('Operation cancelled');\n if (!this.template) throw new NotAnError('No template selected');\n this.template.content = ModuleTemplateBuilder.removeExpectedErrorComments(this.content.replaceAll(placeholder, value));\n }\n\n return this;\n }\n\n public async setupDirectory(options?: ModuleTemplateBuilder.SetupDirectoryOptions): Promise<this> {\n let directory = options?.directory;\n\n if (!directory) {\n const cwd = process.cwd();\n const tsconfig = this.config.build.tsconfig\n ? await readTSConfig(typeof this.config.build.tsconfig == 'string' ? this.config.build.tsconfig : cwd, { try: true })\n : undefined;\n\n let directories = await ModuleLoader.scanForDirectories(this.config.config.modules);\n directories = await ModuleLoader.resolveSourceDirectories({\n directories,\n baseUrl: tsconfig?.compilerOptions?.baseUrl ?? '.',\n rootDir: tsconfig?.compilerOptions?.rootDir ?? 'src',\n outDir: tsconfig?.compilerOptions?.outDir ?? 'modules',\n cwd\n });\n\n const selectedDirectory = this.defaultAll\n ? directories.at(0)\n : await select({\n message: 'Select a directory',\n options: directories.map(directory => ({\n label: path.relative(cwd, directory),\n value: directory\n }))\n });\n\n if (isCancel(selectedDirectory)) throw new NotAnError('Operation cancelled');\n directory = selectedDirectory;\n }\n\n if (!directory) throw new NotAnError('No directory selected');\n this._directory = directory;\n\n return this;\n }\n\n public async setupFilename(options?: ModuleTemplateBuilder.SetupFilenameOptions): Promise<this> {\n let filename = options?.filename;\n\n if (!filename) {\n const defaultFilename = `${this.template?.name}.${this.typescript ? 'ts' : 'js'}`;\n const selectedFilename = this.defaultAll\n ? defaultFilename\n : await text({\n message: 'What would you like to name the module file?',\n initialValue: defaultFilename,\n placeholder: defaultFilename,\n defaultValue: defaultFilename,\n validate: (value) => {\n if (!value) return 'Please enter a value';\n if (existsSync(path.join(this.directory, value))) return 'File already exists';\n }\n });\n\n if (isCancel(selectedFilename)) throw new NotAnError('Operation cancelled');\n filename = selectedFilename;\n }\n\n if (!filename) throw new NotAnError('No filename selected');\n this.filename = filename;\n\n return this;\n }\n\n public async build({ overwrite, silent }: ModuleTemplateBuilder.BuildOptions = {}): Promise<this> {\n await mkdir(this.directory, { recursive: true });\n await writeFile(this.filepath, this.content, { flag: overwrite === false ? 'wx' : undefined });\n if (!silent) outro(`Module ${colors.green(this.template?.name!)} created in ${colors.cyan(path.relative(process.cwd(), this.filepath))}`);\n return this;\n }\n}\n\nexport namespace ModuleTemplateBuilder {\n export interface Options {\n cli: CLI;\n config: ConfigReader;\n template?: ModuleTemplateBuilder.Data;\n typescript?: boolean;\n directory?: string;\n filename?: string;\n defaultAll?: boolean;\n }\n\n export interface SetupLanguageOptions {\n typescript?: boolean;\n }\n\n export interface SetupTemplateOptions {\n template?: ModuleTemplateBuilder.Data|string;\n }\n\n export interface SetupDirectoryOptions {\n directory?: string;\n }\n\n export interface SetupFilenameOptions {\n filename?: string;\n }\n\n export interface BuildOptions {\n overwrite?: boolean;\n silent?: boolean;\n }\n\n export enum Placeholder {\n ModuleName = '$MODULE_NAME$',\n CommandName = '$COMMAND_NAME$',\n CommandDescription = '$COMMAND_DESCRIPTION$',\n CommandContextMenuType = '$COMMAND_CONTEXT_MENU_TYPE$',\n EventEmitter = '$EVENT_EMITTER$',\n EventName = '$EVENT_NAME$',\n EventOnce = '$EVENT_ONCE$'\n }\n\n export const PlaceholderDefaultValues: Record<Placeholder, string> = {\n [Placeholder.ModuleName]: 'MyModule',\n [Placeholder.CommandName]: 'my-command',\n [Placeholder.CommandDescription]: 'My command',\n [Placeholder.CommandContextMenuType]: `${ApplicationCommandType.Message}`,\n [Placeholder.EventEmitter]: 'null',\n [Placeholder.EventName]: 'my-event',\n [Placeholder.EventOnce]: 'false'\n }\n\n export const SourceDirectory = {\n js: path.join(CLI.root, './assets/modules/javascript'),\n ts: path.join(CLI.root, './assets/modules/typescript')\n };\n\n export const ModuleTypeClassName: Record<ModuleType, string[]> = {\n [ModuleType.Base]: [BaseModule.name],\n [ModuleType.Command]: [MessageCommandModule.name, SlashCommandModule.name, ContextMenuCommandModule.name],\n [ModuleType.Event]: [ClientEventModule.name, EventModule.name, RESTEventModule.name],\n [ModuleType.Postcondition]: [PostconditionModule.name],\n [ModuleType.Precondition]: [PreconditionModule.name]\n };\n\n export interface Data {\n src: string;\n name: string;\n content: string;\n moduleType: ModuleType|null;\n }\n\n export async function resolveModuleTemplates(source: keyof typeof SourceDirectory): Promise<ModuleTemplateBuilder.Data[]> {\n const src = ModuleTemplateBuilder.SourceDirectory[source];\n const files: string[] = await readdir(src);\n const templates: ModuleTemplateBuilder.Data[] = [];\n\n for (const file of files) {\n const filepath = path.join(src, file);\n const content = await readFile(filepath, 'utf-8');\n const moduleType = ModuleTemplateBuilder.getModuleTemplateContentType(content);\n\n templates.push({ src: filepath, name: path.parse(filepath).name, content, moduleType });\n }\n\n return templates;\n }\n\n export function getModuleTemplateContentType(content: string): ModuleType|null {\n const createExtendStatement = (name: string) => `export class ${Placeholder.ModuleName} extends ${name}`;\n\n for (const type of Object.keys(ModuleTypeClassName).map(Number) as ModuleType[]) {\n const statements = ModuleTypeClassName[type].map(createExtendStatement);\n\n for (const statement of statements) {\n if (content.includes(statement)) return type;\n }\n }\n\n return null;\n }\n\n export function hasPlaceholder(placeholder: Placeholder, content: string): boolean {\n return content.includes(placeholder);\n }\n\n export function removeExpectedErrorComments(content: string): string {\n const lines = content.split('\\n');\n\n return lines\n .filter(line => !line.trim().includes('// @ts-expect-error'))\n .join('\\n');\n }\n\n export function toTextCase(string: string): string {\n return String(string)\n .replace(/^[^A-Za-z0-9]*|[^A-Za-z0-9]*$/g, '')\n .replace(/([a-z])([A-Z])/g, (m, a, b) => a + '_' + b.toLowerCase())\n .replace(/[^A-Za-z0-9]+|_+/g, ' ')\n .toLowerCase();\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAsBA,IAAa,wBAAb,MAAa,sBAAsB;CAC/B,AAAO;CAEP,AAAgB;CAChB,AAAgB;CAEhB,AAAO;CACP,AAAO;CACP,AAAO;CACP,AAAO;CAEP,IAAI,UAAU;AACV,SAAO,KAAK,UAAU,WAAW;;CAGrC,IAAI,YAAY;AACZ,SAAO,KAAK,cAAc,QAAQ,KAAK;;CAG3C,IAAI,WAAW;AACX,SAAO,KAAK,KAAK,KAAK,WAAW,KAAK,YAAY,GAAG;;CAGzD,YAAY,SAAwC;AAChD,OAAK,MAAM,QAAQ;AACnB,OAAK,SAAS,QAAQ;AACtB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classes/templates/ModuleTemplateBuilder.ts"],"sourcesContent":["import path from 'node:path';\nimport { CLI } from '../cli/CLI.js';\nimport { ModuleType } from '../../helpers/constants.js';\nimport { BaseModule } from '../modules/BaseModule.js';\nimport { MessageCommandModule } from '../modules/commands/MessageCommandModule.js';\nimport { SlashCommandModule } from '../modules/commands/SlashCommandModule.js';\nimport { ContextMenuCommandModule } from '../modules/commands/ContextMenuCommandModule.js';\nimport { ClientEventModule } from '../modules/events/ClientEventModule.js';\nimport { EventModule } from '../modules/events/EventModule.js';\nimport { RESTEventModule } from '../modules/events/RESTEventModule.js';\nimport { PostconditionModule } from '../modules/PostconditionModule.js';\nimport { PreconditionModule } from '../modules/PreconditionModule.js';\nimport { mkdir, readdir, readFile, writeFile } from 'node:fs/promises';\nimport { ConfigReader } from '../cli/ConfigReader.js';\nimport { confirm, intro, isCancel, outro, select, text } from '@clack/prompts';\nimport { NotAnError } from '../NotAnError.js';\nimport { ApplicationCommandType } from 'discord.js';\nimport { ModuleLoader } from '../client/ModuleLoader.js';\nimport { existsSync } from 'node:fs';\nimport { readTSConfig } from 'pkg-types';\nimport { colors } from '@prtty/prtty';\n\nexport class ModuleTemplateBuilder {\n public _directory?: string;\n\n public readonly cli: CLI;\n public readonly config: ConfigReader;\n\n public template?: ModuleTemplateBuilder.Data;\n public typescript?: boolean;\n public filename?: string;\n public defaultAll: boolean;\n\n get content() {\n return this.template?.content ?? '';\n }\n\n get directory() {\n return this._directory ?? process.cwd();\n }\n\n get filepath() {\n return path.join(this.directory, this.filename ?? '');\n }\n\n constructor(options: ModuleTemplateBuilder.Options) {\n this.cli = options.cli;\n this.config = options.config;\n this.template = options?.template;\n this.typescript = options?.typescript;\n this._directory = options?.directory;\n this.filename = options?.filename;\n this.defaultAll = options?.defaultAll ?? false;\n }\n\n public async init(): Promise<this> {\n intro(colors.bold().black().bgCyan(` ${this.cli.command.name()} create module - v${this.cli.build} `));\n return this;\n }\n\n public async setupLanguage(options?: ModuleTemplateBuilder.SetupLanguageOptions): Promise<this> {\n this.typescript = options?.typescript ?? this.typescript;\n\n if (!this.typescript) {\n const isTypeScriptDefault = (await ConfigReader.getProjectLang(this.directory)) === 'ts';\n const isTypeScript = this.defaultAll\n ? isTypeScriptDefault\n : await confirm({\n message: 'Would you like to use TypeScript?',\n active: 'Yes',\n inactive: 'No',\n initialValue: isTypeScriptDefault\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 setupTemplate(options?: ModuleTemplateBuilder.SetupTemplateOptions): Promise<this> {\n let template = typeof options?.template === 'object' ? options.template : undefined;\n\n if (!template) {\n const templateName = typeof options?.template === 'string' ? options.template : undefined;\n const templates = await ModuleTemplateBuilder.resolveModuleTemplates(this.typescript ? 'ts' : 'js');\n\n const selectedTemplate = this.defaultAll\n ? templateName ? templates.find(template => template.name === templateName) : templates.at(0)\n : await select({\n message: 'Select a module template',\n options: templates.map(template => ({\n label: template.name,\n value: template\n }))\n });\n\n if (isCancel(selectedTemplate)) throw new NotAnError('Operation cancelled');\n template = selectedTemplate;\n }\n\n this.template = template;\n if (!this.template) throw new NotAnError('No template selected');\n\n return this;\n }\n\n public async setupPlaceholders(): Promise<this> {\n const placeholders = Object.keys(ModuleTemplateBuilder.Placeholder).filter(k => !k.startsWith('$')) as (keyof typeof ModuleTemplateBuilder.Placeholder)[];\n\n for (const placeholderKey of placeholders) {\n if (!ModuleTemplateBuilder.hasPlaceholder(ModuleTemplateBuilder.Placeholder[placeholderKey], this.content)) continue;\n const placeholder = ModuleTemplateBuilder.Placeholder[placeholderKey];\n const defaultValue = ModuleTemplateBuilder.PlaceholderDefaultValues[placeholder];\n\n let value: string|symbol;\n\n if (this.defaultAll) {\n value = defaultValue;\n } else {\n switch (placeholder) {\n case ModuleTemplateBuilder.Placeholder.ModuleName:\n case ModuleTemplateBuilder.Placeholder.CommandName:\n case ModuleTemplateBuilder.Placeholder.EventName:\n value = this.defaultAll\n ? defaultValue\n : await text({\n message: `What would you like to name the ${placeholderKey.replace('Name', '').toLowerCase()}?`,\n initialValue: defaultValue,\n placeholder: defaultValue,\n defaultValue,\n validate: (value) => {\n if (!value) return 'Please enter a value';\n if (value.includes(' ')) return 'Please enter a value without spaces';\n }\n });\n break;\n case ModuleTemplateBuilder.Placeholder.CommandContextMenuType:\n const type = await select({\n message: 'Select a command context menu type',\n options: [\n { label: 'Message', value: ApplicationCommandType.Message },\n { label: 'User', value: ApplicationCommandType.User }\n ],\n initialValue: ApplicationCommandType.Message\n });\n\n value = isCancel(type) ? type : `${type}`;\n break;\n case ModuleTemplateBuilder.Placeholder.EventOnce:\n const once = await confirm({\n message: `Would you like to use the event once?`,\n active: 'Yes',\n inactive: 'No',\n initialValue: false\n });\n\n value = isCancel(once) ? once : `${once}`;\n break;\n case ModuleTemplateBuilder.Placeholder.EventEmitter:\n default:\n value = await text({\n message: `What would you like to use for the ${ModuleTemplateBuilder.toTextCase(placeholder)}?`,\n initialValue: defaultValue,\n placeholder: defaultValue,\n defaultValue\n });\n break;\n }\n }\n\n if (isCancel(value)) throw new NotAnError('Operation cancelled');\n if (!this.template) throw new NotAnError('No template selected');\n this.template.content = ModuleTemplateBuilder.removeExpectedErrorComments(this.content.replaceAll(placeholder, value));\n }\n\n return this;\n }\n\n public async setupDirectory(options?: ModuleTemplateBuilder.SetupDirectoryOptions): Promise<this> {\n let directory = options?.directory;\n\n if (!directory) {\n const cwd = process.cwd();\n const tsconfig = this.config.build.tsconfig\n ? await readTSConfig(typeof this.config.build.tsconfig == 'string' ? this.config.build.tsconfig : cwd, { try: true })\n : undefined;\n\n let directories = await ModuleLoader.scanForDirectories(this.config.config.modules);\n directories = await ModuleLoader.resolveSourceDirectories({\n directories,\n baseUrl: tsconfig?.compilerOptions?.baseUrl ?? '.',\n rootDir: tsconfig?.compilerOptions?.rootDir ?? 'src',\n outDir: tsconfig?.compilerOptions?.outDir ?? 'modules',\n cwd\n });\n\n const selectedDirectory = this.defaultAll\n ? directories.at(0)\n : await select({\n message: 'Select a directory',\n options: directories.map(directory => ({\n label: path.relative(cwd, directory),\n value: directory\n }))\n });\n\n if (isCancel(selectedDirectory)) throw new NotAnError('Operation cancelled');\n directory = selectedDirectory;\n }\n\n if (!directory) throw new NotAnError('No directory selected');\n this._directory = directory;\n\n return this;\n }\n\n public async setupFilename(options?: ModuleTemplateBuilder.SetupFilenameOptions): Promise<this> {\n let filename = options?.filename;\n\n if (!filename) {\n const defaultFilename = `${this.template?.name}.${this.typescript ? 'ts' : 'js'}`;\n const selectedFilename = this.defaultAll\n ? defaultFilename\n : await text({\n message: 'What would you like to name the module file?',\n initialValue: defaultFilename,\n placeholder: defaultFilename,\n defaultValue: defaultFilename,\n validate: (value) => {\n if (!value) return 'Please enter a value';\n if (existsSync(path.join(this.directory, value))) return 'File already exists';\n }\n });\n\n if (isCancel(selectedFilename)) throw new NotAnError('Operation cancelled');\n filename = selectedFilename;\n }\n\n if (!filename) throw new NotAnError('No filename selected');\n this.filename = filename;\n\n return this;\n }\n\n public async build({ overwrite, silent }: ModuleTemplateBuilder.BuildOptions = {}): Promise<this> {\n await mkdir(this.directory, { recursive: true });\n await writeFile(this.filepath, this.content, { flag: overwrite === false ? 'wx' : undefined });\n if (!silent) outro(`Module ${colors.green(this.template?.name!)} created in ${colors.cyan(path.relative(process.cwd(), this.filepath))}`);\n return this;\n }\n}\n\nexport namespace ModuleTemplateBuilder {\n export interface Options {\n cli: CLI;\n config: ConfigReader;\n template?: ModuleTemplateBuilder.Data;\n typescript?: boolean;\n directory?: string;\n filename?: string;\n defaultAll?: boolean;\n }\n\n export interface SetupLanguageOptions {\n typescript?: boolean;\n }\n\n export interface SetupTemplateOptions {\n template?: ModuleTemplateBuilder.Data|string;\n }\n\n export interface SetupDirectoryOptions {\n directory?: string;\n }\n\n export interface SetupFilenameOptions {\n filename?: string;\n }\n\n export interface BuildOptions {\n overwrite?: boolean;\n silent?: boolean;\n }\n\n export enum Placeholder {\n ModuleName = '$MODULE_NAME$',\n CommandName = '$COMMAND_NAME$',\n CommandDescription = '$COMMAND_DESCRIPTION$',\n CommandContextMenuType = '$COMMAND_CONTEXT_MENU_TYPE$',\n EventEmitter = '$EVENT_EMITTER$',\n EventName = '$EVENT_NAME$',\n EventOnce = '$EVENT_ONCE$'\n }\n\n export const PlaceholderDefaultValues: Record<Placeholder, string> = {\n [Placeholder.ModuleName]: 'MyModule',\n [Placeholder.CommandName]: 'my-command',\n [Placeholder.CommandDescription]: 'My command',\n [Placeholder.CommandContextMenuType]: `${ApplicationCommandType.Message}`,\n [Placeholder.EventEmitter]: 'null',\n [Placeholder.EventName]: 'my-event',\n [Placeholder.EventOnce]: 'false'\n }\n\n export const SourceDirectory = {\n js: path.join(CLI.root, './assets/modules/javascript'),\n ts: path.join(CLI.root, './assets/modules/typescript')\n };\n\n export const ModuleTypeClassName: Record<ModuleType, string[]> = {\n [ModuleType.Base]: [BaseModule.name],\n [ModuleType.Command]: [MessageCommandModule.name, SlashCommandModule.name, ContextMenuCommandModule.name],\n [ModuleType.Event]: [ClientEventModule.name, EventModule.name, RESTEventModule.name],\n [ModuleType.Postcondition]: [PostconditionModule.name],\n [ModuleType.Precondition]: [PreconditionModule.name]\n };\n\n export interface Data {\n src: string;\n name: string;\n content: string;\n moduleType: ModuleType|null;\n }\n\n export async function resolveModuleTemplates(source: keyof typeof SourceDirectory): Promise<ModuleTemplateBuilder.Data[]> {\n const src = ModuleTemplateBuilder.SourceDirectory[source];\n const files: string[] = await readdir(src);\n const templates: ModuleTemplateBuilder.Data[] = [];\n\n for (const file of files) {\n const filepath = path.join(src, file);\n const content = await readFile(filepath, 'utf-8');\n const moduleType = ModuleTemplateBuilder.getModuleTemplateContentType(content);\n\n templates.push({ src: filepath, name: path.parse(filepath).name, content, moduleType });\n }\n\n return templates;\n }\n\n export function getModuleTemplateContentType(content: string): ModuleType|null {\n const createExtendStatement = (name: string) => `export class ${Placeholder.ModuleName} extends ${name}`;\n\n for (const type of Object.keys(ModuleTypeClassName).map(Number) as ModuleType[]) {\n const statements = ModuleTypeClassName[type].map(createExtendStatement);\n\n for (const statement of statements) {\n if (content.includes(statement)) return type;\n }\n }\n\n return null;\n }\n\n export function hasPlaceholder(placeholder: Placeholder, content: string): boolean {\n return content.includes(placeholder);\n }\n\n export function removeExpectedErrorComments(content: string): string {\n const lines = content.split('\\n');\n\n return lines\n .filter(line => !line.trim().includes('// @ts-expect-error'))\n .join('\\n');\n }\n\n export function toTextCase(string: string): string {\n return String(string)\n .replace(/^[^A-Za-z0-9]*|[^A-Za-z0-9]*$/g, '')\n .replace(/([a-z])([A-Z])/g, (m, a, b) => a + '_' + b.toLowerCase())\n .replace(/[^A-Za-z0-9]+|_+/g, ' ')\n .toLowerCase();\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAsBA,IAAa,wBAAb,MAAa,sBAAsB;CAC/B,AAAO;CAEP,AAAgB;CAChB,AAAgB;CAEhB,AAAO;CACP,AAAO;CACP,AAAO;CACP,AAAO;CAEP,IAAI,UAAU;AACV,SAAO,KAAK,UAAU,WAAW;;CAGrC,IAAI,YAAY;AACZ,SAAO,KAAK,cAAc,QAAQ,KAAK;;CAG3C,IAAI,WAAW;AACX,SAAO,KAAK,KAAK,KAAK,WAAW,KAAK,YAAY,GAAG;;CAGzD,YAAY,SAAwC;AAChD,OAAK,MAAM,QAAQ;AACnB,OAAK,SAAS,QAAQ;AACtB,OAAK,WAAW,SAAS;AACzB,OAAK,aAAa,SAAS;AAC3B,OAAK,aAAa,SAAS;AAC3B,OAAK,WAAW,SAAS;AACzB,OAAK,aAAa,SAAS,cAAc;;CAG7C,MAAa,OAAsB;AAC/B,QAAM,OAAO,MAAM,CAAC,OAAO,CAAC,OAAO,IAAI,KAAK,IAAI,QAAQ,MAAM,CAAC,oBAAoB,KAAK,IAAI,MAAM,GAAG,CAAC;AACtG,SAAO;;CAGX,MAAa,cAAc,SAAqE;AAC5F,OAAK,aAAa,SAAS,cAAc,KAAK;AAE9C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AAK;IAAE,KAAK;IAAU,MAAM,KAAK,MAAM,SAAS,CAAC;IAAM;IAAS;IAAY,CAAC;;AAG3F,SAAO;;;CAGJ,SAAS,6BAA6B,SAAkC;EAC3E,MAAM,yBAAyB,SAAiB,gBAAgB,YAAY,WAAW,WAAW;AAElG,OAAK,MAAM,QAAQ,OAAO,KAAK,oBAAoB,CAAC,IAAI,OAAO,EAAkB;GAC7E,MAAM,aAAa,oBAAoB,MAAM,IAAI,sBAAsB;AAEvE,QAAK,MAAM,aAAa,WACpB,KAAI,QAAQ,SAAS,UAAU,CAAE,QAAO;;AAIhD,SAAO;;;CAGJ,SAAS,eAAe,aAA0B,SAA0B;AAC/E,SAAO,QAAQ,SAAS,YAAY;;;CAGjC,SAAS,4BAA4B,SAAyB;AAGjE,SAFc,QAAQ,MAAM,KAAK,CAG5B,QAAO,SAAQ,CAAC,KAAK,MAAM,CAAC,SAAS,sBAAsB,CAAC,CAC5D,KAAK,KAAK;;;CAGZ,SAAS,WAAW,QAAwB;AAC/C,SAAO,OAAO,OAAO,CAChB,QAAQ,kCAAkC,GAAG,CAC7C,QAAQ,oBAAoB,GAAG,GAAG,MAAM,IAAI,MAAM,EAAE,aAAa,CAAC,CAClE,QAAQ,qBAAqB,IAAI,CACjC,aAAa"}
|
|
@@ -4,10 +4,11 @@ import { ConfigReader } from "../cli/ConfigReader.mjs";
|
|
|
4
4
|
import { packageJSON } from "../../helpers/constants.mjs";
|
|
5
5
|
import { ModuleTemplateBuilder } from "./ModuleTemplateBuilder.mjs";
|
|
6
6
|
import path from "node:path";
|
|
7
|
-
import { PackageJsonBuilder
|
|
7
|
+
import { PackageJsonBuilder } from "@reciple/utils";
|
|
8
8
|
import { parse } from "@dotenvx/dotenvx";
|
|
9
9
|
import { copyFile, mkdir, readFile, readdir, stat, writeFile } from "node:fs/promises";
|
|
10
10
|
import { confirm, intro, isCancel, log, outro, select, text } from "@clack/prompts";
|
|
11
|
+
import { colors } from "@prtty/prtty";
|
|
11
12
|
import micromatch from "micromatch";
|
|
12
13
|
import { existsSync, statSync } from "node:fs";
|
|
13
14
|
import { slug } from "github-slugger";
|
|
@@ -45,7 +46,7 @@ var TemplateBuilder = class TemplateBuilder {
|
|
|
45
46
|
this.token = options.token;
|
|
46
47
|
}
|
|
47
48
|
async init() {
|
|
48
|
-
intro(colors.bold(
|
|
49
|
+
intro(colors.bold().black().bgCyan(` ${this.cli.command.name()} create - v${this.cli.build} `));
|
|
49
50
|
return this;
|
|
50
51
|
}
|
|
51
52
|
async createDirectory(options) {
|
|
@@ -56,8 +57,8 @@ var TemplateBuilder = class TemplateBuilder {
|
|
|
56
57
|
placeholder: `Leave empty to use current directory`,
|
|
57
58
|
defaultValue: process.cwd(),
|
|
58
59
|
validate: (value) => {
|
|
59
|
-
const dir
|
|
60
|
-
if (existsSync(dir
|
|
60
|
+
const dir = path.resolve(value);
|
|
61
|
+
if (existsSync(dir) && !statSync(dir).isDirectory()) return "Invalid folder directory";
|
|
61
62
|
}
|
|
62
63
|
});
|
|
63
64
|
if (isCancel(dir)) throw new NotAnError("Operation cancelled");
|
|
@@ -129,9 +130,12 @@ var TemplateBuilder = class TemplateBuilder {
|
|
|
129
130
|
return this;
|
|
130
131
|
}
|
|
131
132
|
async createConfig(options) {
|
|
132
|
-
let filepath = options?.
|
|
133
|
-
if (!filepath) filepath = await ConfigReader.
|
|
134
|
-
|
|
133
|
+
let filepath = options?.path;
|
|
134
|
+
if (!filepath) filepath = await ConfigReader.find({
|
|
135
|
+
cwd: this.directory,
|
|
136
|
+
lang: this.typescript ? "ts" : this.typescript === false ? "js" : void 0
|
|
137
|
+
}) ?? path.join(this.directory, ConfigReader.createConfigFilename(this.typescript ? "ts" : "js"));
|
|
138
|
+
if (await ConfigReader.exists(filepath)) {
|
|
135
139
|
const overwrite = this.defaultAll ? false : await confirm({
|
|
136
140
|
message: `Config file already exists at ${colors.green(path.relative(process.cwd(), filepath))}. Would you like to overwrite it?`,
|
|
137
141
|
active: "Yes",
|
|
@@ -143,9 +147,10 @@ var TemplateBuilder = class TemplateBuilder {
|
|
|
143
147
|
}
|
|
144
148
|
this.config = await ConfigReader.create({
|
|
145
149
|
...options,
|
|
146
|
-
filepath,
|
|
150
|
+
path: filepath,
|
|
147
151
|
type: this.typescript ? "ts" : "js",
|
|
148
|
-
overwrite: true
|
|
152
|
+
overwrite: true,
|
|
153
|
+
readOptions: false
|
|
149
154
|
});
|
|
150
155
|
return this;
|
|
151
156
|
}
|
|
@@ -222,15 +227,14 @@ var TemplateBuilder = class TemplateBuilder {
|
|
|
222
227
|
this.packageJson = await PackageJsonBuilder.read(this.packageJsonPath, true);
|
|
223
228
|
this.packageJson.merge({
|
|
224
229
|
name: this.name,
|
|
225
|
-
|
|
230
|
+
private: true,
|
|
226
231
|
type: "module",
|
|
227
232
|
scripts: {
|
|
228
233
|
build: `reciple build`,
|
|
229
234
|
start: "reciple start",
|
|
230
235
|
dev: "nodemon"
|
|
231
236
|
},
|
|
232
|
-
...TemplateBuilder.createDependencyRecord(this.typescript ? "ts" : "js")
|
|
233
|
-
private: true
|
|
237
|
+
...TemplateBuilder.createDependencyRecord(this.typescript ? "ts" : "js")
|
|
234
238
|
});
|
|
235
239
|
return this;
|
|
236
240
|
}
|
|
@@ -253,9 +257,9 @@ var TemplateBuilder = class TemplateBuilder {
|
|
|
253
257
|
silent: true
|
|
254
258
|
}),
|
|
255
259
|
indicator: "timer",
|
|
256
|
-
errorMessage: `${colors.bold(
|
|
257
|
-
successMessage: `${colors.bold(
|
|
258
|
-
message: `${colors.bold(
|
|
260
|
+
errorMessage: `${colors.bold().red("✗")} Failed to install dependencies`,
|
|
261
|
+
successMessage: `${colors.bold().green("✔")} Dependencies installed successfully`,
|
|
262
|
+
message: `${colors.bold().dim("$")} Installing dependencies`
|
|
259
263
|
})[0];
|
|
260
264
|
this.dependenciesInstalled = true;
|
|
261
265
|
}
|
|
@@ -296,24 +300,24 @@ var TemplateBuilder = class TemplateBuilder {
|
|
|
296
300
|
}
|
|
297
301
|
async build(options) {
|
|
298
302
|
await this.packageJson?.write(this.packageJsonPath, true);
|
|
299
|
-
if (!options?.skipBuild) await CLI.createSpinnerPromise({
|
|
303
|
+
if (!options?.skipBuild && this.dependenciesInstalled) await CLI.createSpinnerPromise({
|
|
300
304
|
promise: runScript("build", {
|
|
301
305
|
cwd: this.directory,
|
|
302
306
|
packageManager: this.packageManager,
|
|
303
307
|
silent: true
|
|
304
308
|
}),
|
|
305
309
|
indicator: "timer",
|
|
306
|
-
errorMessage: `${colors.bold(
|
|
307
|
-
successMessage: `${colors.bold(
|
|
308
|
-
message: `${colors.bold(
|
|
310
|
+
errorMessage: `${colors.bold().red("✗")} Failed to build project`,
|
|
311
|
+
successMessage: `${colors.bold().green("✔")} Project built successfully`,
|
|
312
|
+
message: `${colors.bold().dim("$")} Building project`
|
|
309
313
|
})[0];
|
|
310
314
|
outro(`Project created in ${colors.cyan(this.relativeDirectory)}`);
|
|
311
|
-
console.log(`\n${colors.bold(
|
|
312
|
-
if (this.relativeDirectory !== "./") console.log(` • ${colors.cyan(
|
|
313
|
-
console.log(` • ${colors.cyan(
|
|
314
|
-
console.log(` • ${colors.cyan(
|
|
315
|
-
console.log(` • ${colors.cyan(
|
|
316
|
-
console.log(` • ${colors.cyan(
|
|
315
|
+
console.log(`\n${colors.bold().green("✔")} Start developing:`);
|
|
316
|
+
if (this.relativeDirectory !== "./") console.log(` • ${colors.cyan().bold(`cd ${this.relativeDirectory}`)}`);
|
|
317
|
+
console.log(` • ${colors.cyan().bold(installDependenciesCommand(this.packageManager ?? "npm"))} ${colors.dim("(Install dependencies)")}`);
|
|
318
|
+
console.log(` • ${colors.cyan().bold(runScriptCommand(this.packageManager ?? "npm", "build"))} ${colors.dim("(Build)")}`);
|
|
319
|
+
console.log(` • ${colors.cyan().bold(runScriptCommand(this.packageManager ?? "npm", "dev"))} ${colors.dim("(Development)")}`);
|
|
320
|
+
console.log(` • ${colors.cyan().bold(runScriptCommand(this.packageManager ?? "npm", "start"))} ${colors.dim("(Production)")}`);
|
|
317
321
|
return this;
|
|
318
322
|
}
|
|
319
323
|
};
|
|
@@ -354,12 +358,12 @@ var TemplateBuilder = class TemplateBuilder {
|
|
|
354
358
|
if (fromStats.isDirectory()) {
|
|
355
359
|
const files = await readdir(from);
|
|
356
360
|
for (const file of files) {
|
|
357
|
-
const data
|
|
361
|
+
const data = {
|
|
358
362
|
basename: file,
|
|
359
363
|
src: path.join(from, file),
|
|
360
364
|
dest: to
|
|
361
365
|
};
|
|
362
|
-
await copy(data
|
|
366
|
+
await copy(data.src, path.join(to, options?.rename ? options.rename(data) : file), options);
|
|
363
367
|
}
|
|
364
368
|
return;
|
|
365
369
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TemplateBuilder.mjs","names":["dir","parseDotenv","packageManager: PackageManagerName|symbol","moduleOptions: ModuleTemplateBuilder.Options","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, log } 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 public dependenciesInstalled: boolean = false;\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 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 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\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 ]),\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, true);\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 installDependencies(options?: TemplateBuilder.InstallDependenciesOptions): Promise<this> {\n if (options?.value !== false) {\n if (options?.value === undefined) {\n const install = this.defaultAll\n ? true\n : await confirm({\n message: `Would you like to install dependencies?`,\n active: 'Yes',\n inactive: 'No',\n initialValue: true\n });\n\n if (isCancel(install)) throw new NotAnError('Operation cancelled');\n if (!install) return this;\n }\n\n 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 this.dependenciesInstalled = true;\n }\n\n return this;\n }\n\n public async createModules(): Promise<this> {\n const modulesDirectory = path.join(this.directory, 'src');\n const moduleTemplates = await ModuleTemplateBuilder.resolveModuleTemplates(this.typescript ? 'ts' : 'js');\n\n await mkdir(modulesDirectory, { recursive: true });\n\n if (!this.dependenciesInstalled) {\n log.warn('Dependencies not installed. Skipping module creation.');\n return this;\n }\n\n const moduleOptions: ModuleTemplateBuilder.Options = {\n cli: this.cli,\n config: await this.config?.read()!,\n defaultAll: true,\n typescript: this.typescript,\n };\n\n const [template, loader] = CLI.createSpinnerPromise({\n promise: Promise.all([\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: 'Creating module templates',\n successMessage: 'Module templates created successfully',\n errorMessage: 'Failed to create module templates'\n });\n\n await template;\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?.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 console.log(` • ${colors.cyan(colors.bold(installDependenciesCommand(this.packageManager ?? 'npm')))} ${colors.dim('(Install dependencies)')}`);\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 '@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 typescript: packageJSON.devDependencies?.['typescript']!,\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 InstallDependenciesOptions {\n value?: boolean;\n }\n\n export interface CreateEnvFileOptions {\n envFile?: string;\n tokenKey?: string;\n env?: Record<string, string>;\n }\n\n export interface BuildOptions {\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;CACP,AAAO,wBAAiC;CAExC,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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AU,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"}
|
|
1
|
+
{"version":3,"file":"TemplateBuilder.mjs","names":["parseDotenv"],"sources":["../../../src/classes/templates/TemplateBuilder.ts"],"sourcesContent":["import { 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, log } 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';\nimport { colors } from '@prtty/prtty';\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 public dependenciesInstalled: boolean = false;\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().black().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 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 createConfig(options?: TemplateBuilder.CreateConfigOptions): Promise<this> {\n let filepath = options?.path;\n\n if (!filepath) {\n filepath = await ConfigReader.find({\n cwd: this.directory,\n lang: this.typescript\n ? 'ts'\n : this.typescript === false\n ? 'js'\n : undefined\n }) ?? path.join(\n this.directory,\n ConfigReader.createConfigFilename(this.typescript ? 'ts' : 'js')\n );\n }\n\n const exists = await ConfigReader.exists(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 path: filepath,\n type: this.typescript ? 'ts' : 'js',\n overwrite: true,\n readOptions: false\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\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 ]),\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, true);\n this.packageJson.merge({\n name: this.name,\n private: true,\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 });\n\n return this;\n }\n\n public async installDependencies(options?: TemplateBuilder.InstallDependenciesOptions): Promise<this> {\n if (options?.value !== false) {\n if (options?.value === undefined) {\n const install = this.defaultAll\n ? true\n : await confirm({\n message: `Would you like to install dependencies?`,\n active: 'Yes',\n inactive: 'No',\n initialValue: true\n });\n\n if (isCancel(install)) throw new NotAnError('Operation cancelled');\n if (!install) return this;\n }\n\n 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().red('✗')} Failed to install dependencies`,\n successMessage: `${colors.bold().green('✔')} Dependencies installed successfully`,\n message: `${colors.bold().dim('$')} Installing dependencies`\n })[0];\n\n this.dependenciesInstalled = true;\n }\n\n return this;\n }\n\n public async createModules(): Promise<this> {\n const modulesDirectory = path.join(this.directory, 'src');\n const moduleTemplates = await ModuleTemplateBuilder.resolveModuleTemplates(this.typescript ? 'ts' : 'js');\n\n await mkdir(modulesDirectory, { recursive: true });\n\n if (!this.dependenciesInstalled) {\n log.warn('Dependencies not installed. Skipping module creation.');\n return this;\n }\n\n const moduleOptions: ModuleTemplateBuilder.Options = {\n cli: this.cli,\n config: await this.config?.read()!,\n defaultAll: true,\n typescript: this.typescript,\n };\n\n const [template, loader] = CLI.createSpinnerPromise({\n promise: Promise.all([\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: 'Creating module templates',\n successMessage: 'Module templates created successfully',\n errorMessage: 'Failed to create module templates'\n });\n\n await template;\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?.skipBuild && this.dependenciesInstalled) 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().red('✗')} Failed to build project`,\n successMessage: `${colors.bold().green('✔')} Project built successfully`,\n message: `${colors.bold().dim('$')} Building project`\n })[0];\n\n outro(`Project created in ${colors.cyan(this.relativeDirectory)}`);\n\n console.log(`\\n${colors.bold().green('✔')} Start developing:`);\n\n if (this.relativeDirectory !== './') {\n console.log(` • ${colors.cyan().bold(`cd ${this.relativeDirectory}`)}`);\n }\n\n console.log(` • ${colors.cyan().bold(installDependenciesCommand(this.packageManager ?? 'npm'))} ${colors.dim('(Install dependencies)')}`);\n console.log(` • ${colors.cyan().bold(runScriptCommand(this.packageManager ?? 'npm', 'build'))} ${colors.dim('(Build)')}`);\n console.log(` • ${colors.cyan().bold(runScriptCommand(this.packageManager ?? 'npm', 'dev'))} ${colors.dim('(Development)')}`);\n console.log(` • ${colors.cyan().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 '@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 typescript: packageJSON.devDependencies?.['typescript']!,\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 InstallDependenciesOptions {\n value?: boolean;\n }\n\n export interface CreateEnvFileOptions {\n envFile?: string;\n tokenKey?: string;\n env?: Record<string, string>;\n }\n\n export interface BuildOptions {\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":";;;;;;;;;;;;;;;;;AAgBA,IAAa,kBAAb,MAAa,gBAAgB;CACzB,AAAQ;CAER,AAAO;CACP,AAAO;CACP,AAAO;CACP,AAAO;CAEP,AAAO;CACP,AAAO;CAEP,AAAO;CACP,AAAO,wBAAiC;CAExC,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,MAAM,CAAC,OAAO,CAAC,OAAO,IAAI,KAAK,IAAI,QAAQ,MAAM,CAAC,aAAa,KAAK,IAAI,MAAM,GAAG,CAAC;AAC/F,SAAO;;CAGX,MAAa,gBAAgB,SAAiE;AAC1F,OAAK,aAAa,SAAS,aAAa,KAAK;AAE7C,MAAI,CAAC,KA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AM,KAAK,QAAQ,GAAG,EAAE,EAAE,WAAW,MAAM,CAAC;AAClD,QAAM,SAAS,MAAM,GAAG"}
|
|
@@ -1,36 +1,36 @@
|
|
|
1
1
|
import { ModuleType } from "../../helpers/constants.mjs";
|
|
2
2
|
import { AnyModuleData } from "../../helpers/types.mjs";
|
|
3
3
|
import { Validator } from "@reciple/core";
|
|
4
|
-
import * as
|
|
4
|
+
import * as _sapphire_shapeshift0 from "@sapphire/shapeshift";
|
|
5
5
|
|
|
6
6
|
//#region src/classes/validation/BaseModuleValidator.d.ts
|
|
7
7
|
declare class BaseModuleValidator extends Validator {
|
|
8
|
-
static id:
|
|
9
|
-
static moduleType:
|
|
10
|
-
static onEnable:
|
|
11
|
-
static onReady:
|
|
12
|
-
static onDisable:
|
|
13
|
-
static object:
|
|
8
|
+
static id: _sapphire_shapeshift0.StringValidator<string>;
|
|
9
|
+
static moduleType: _sapphire_shapeshift0.NativeEnumValidator<typeof ModuleType>;
|
|
10
|
+
static onEnable: _sapphire_shapeshift0.UnionValidator<Function | undefined>;
|
|
11
|
+
static onReady: _sapphire_shapeshift0.UnionValidator<Function | undefined>;
|
|
12
|
+
static onDisable: _sapphire_shapeshift0.UnionValidator<Function | undefined>;
|
|
13
|
+
static object: _sapphire_shapeshift0.ObjectValidator<{
|
|
14
14
|
id: string | undefined;
|
|
15
15
|
moduleType: ModuleType | undefined;
|
|
16
16
|
onEnable: Function | undefined;
|
|
17
17
|
onReady: Function | undefined;
|
|
18
18
|
onDisable: Function | undefined;
|
|
19
|
-
},
|
|
19
|
+
}, _sapphire_shapeshift0.UndefinedToOptional<{
|
|
20
20
|
id: string | undefined;
|
|
21
21
|
moduleType: ModuleType | undefined;
|
|
22
22
|
onEnable: Function | undefined;
|
|
23
23
|
onReady: Function | undefined;
|
|
24
24
|
onDisable: Function | undefined;
|
|
25
25
|
}>>;
|
|
26
|
-
static resolvable:
|
|
27
|
-
toJSON: Function;
|
|
28
|
-
}> | _sapphire_shapeshift16.UndefinedToOptional<{
|
|
26
|
+
static resolvable: _sapphire_shapeshift0.UnionValidator<_sapphire_shapeshift0.UndefinedToOptional<{
|
|
29
27
|
id: string | undefined;
|
|
30
28
|
moduleType: ModuleType | undefined;
|
|
31
29
|
onEnable: Function | undefined;
|
|
32
30
|
onReady: Function | undefined;
|
|
33
31
|
onDisable: Function | undefined;
|
|
32
|
+
}> | _sapphire_shapeshift0.UndefinedToOptional<{
|
|
33
|
+
toJSON: Function;
|
|
34
34
|
}>>;
|
|
35
35
|
static isValidId(id: unknown): asserts id is string;
|
|
36
36
|
static isValidModuleType(moduleType: unknown): asserts moduleType is ModuleType;
|