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.
Files changed (163) hide show
  1. package/LICENSE +155 -674
  2. package/assets/config/reciple.config.js +87 -0
  3. package/assets/config/reciple.config.ts +80 -0
  4. package/assets/global/README.md +1 -0
  5. package/assets/global/gitignore +121 -0
  6. package/assets/global/nodemon.json +13 -0
  7. package/assets/modules/javascript/Base.js +21 -0
  8. package/assets/modules/javascript/ClientEvent.js +14 -0
  9. package/assets/modules/javascript/ContextMenuCommand.js +17 -0
  10. package/assets/modules/javascript/Event.js +17 -0
  11. package/assets/modules/javascript/MessageCommand.js +16 -0
  12. package/assets/modules/javascript/RESTEvent.js +14 -0
  13. package/assets/modules/javascript/SlashCommand.js +16 -0
  14. package/assets/modules/typescript/Base.ts +17 -0
  15. package/assets/modules/typescript/ClientEvent.ts +15 -0
  16. package/assets/modules/typescript/ContextMenuCommand.ts +15 -0
  17. package/assets/modules/typescript/Event.ts +16 -0
  18. package/assets/modules/typescript/MessageCommand.ts +14 -0
  19. package/assets/modules/typescript/RESTEvent.ts +15 -0
  20. package/assets/modules/typescript/SlashCommand.ts +14 -0
  21. package/assets/templates/javascript/jsconfig.json +17 -0
  22. package/assets/templates/typescript/tsconfig.json +17 -0
  23. package/dist/_virtual/_@oxc-project_runtime@0.99.0/helpers/decorate.mjs +10 -0
  24. package/dist/bin/commands/build.d.mts +16 -0
  25. package/dist/bin/commands/build.mjs +24 -0
  26. package/dist/bin/commands/build.mjs.map +1 -0
  27. package/dist/bin/commands/create.d.mts +23 -0
  28. package/dist/bin/commands/create.mjs +48 -0
  29. package/dist/bin/commands/create.mjs.map +1 -0
  30. package/dist/bin/commands/createModule.d.mts +21 -0
  31. package/dist/bin/commands/createModule.mjs +40 -0
  32. package/dist/bin/commands/createModule.mjs.map +1 -0
  33. package/dist/bin/commands/start.d.mts +18 -0
  34. package/dist/bin/commands/start.mjs +104 -0
  35. package/dist/bin/commands/start.mjs.map +1 -0
  36. package/dist/bin/reciple.d.mts +1 -0
  37. package/dist/bin/reciple.mjs +9 -0
  38. package/dist/bin/reciple.mjs.map +1 -0
  39. package/dist/classes/NotAnError.d.mts +7 -0
  40. package/dist/classes/NotAnError.mjs +11 -0
  41. package/dist/classes/NotAnError.mjs.map +1 -0
  42. package/dist/classes/cli/CLI.d.mts +54 -0
  43. package/dist/classes/cli/CLI.mjs +156 -0
  44. package/dist/classes/cli/CLI.mjs.map +1 -0
  45. package/dist/classes/cli/CLISubcommand.d.mts +27 -0
  46. package/dist/classes/cli/CLISubcommand.mjs +23 -0
  47. package/dist/classes/cli/CLISubcommand.mjs.map +1 -0
  48. package/dist/classes/cli/ConfigReader.d.mts +81 -0
  49. package/dist/classes/cli/ConfigReader.mjs +141 -0
  50. package/dist/classes/cli/ConfigReader.mjs.map +1 -0
  51. package/dist/classes/cli/RuntimeEnvironment.d.mts +14 -0
  52. package/dist/classes/cli/RuntimeEnvironment.mjs +36 -0
  53. package/dist/classes/cli/RuntimeEnvironment.mjs.map +1 -0
  54. package/dist/classes/client/EventListeners.d.mts +26 -0
  55. package/dist/classes/client/EventListeners.mjs +103 -0
  56. package/dist/classes/client/EventListeners.mjs.map +1 -0
  57. package/dist/classes/client/ModuleLoader.d.mts +55 -0
  58. package/dist/classes/client/ModuleLoader.mjs +152 -0
  59. package/dist/classes/client/ModuleLoader.mjs.map +1 -0
  60. package/dist/classes/managers/ModuleManager.d.mts +55 -0
  61. package/dist/classes/managers/ModuleManager.mjs +107 -0
  62. package/dist/classes/managers/ModuleManager.mjs.map +1 -0
  63. package/dist/classes/modules/BaseModule.d.mts +34 -0
  64. package/dist/classes/modules/BaseModule.mjs +33 -0
  65. package/dist/classes/modules/BaseModule.mjs.map +1 -0
  66. package/dist/classes/modules/PostconditionModule.d.mts +20 -0
  67. package/dist/classes/modules/PostconditionModule.mjs +24 -0
  68. package/dist/classes/modules/PostconditionModule.mjs.map +1 -0
  69. package/dist/classes/modules/PreconditionModule.d.mts +20 -0
  70. package/dist/classes/modules/PreconditionModule.mjs +24 -0
  71. package/dist/classes/modules/PreconditionModule.mjs.map +1 -0
  72. package/dist/classes/modules/commands/ContextMenuCommandModule.d.mts +24 -0
  73. package/dist/classes/modules/commands/ContextMenuCommandModule.mjs +27 -0
  74. package/dist/classes/modules/commands/ContextMenuCommandModule.mjs.map +1 -0
  75. package/dist/classes/modules/commands/MessageCommandModule.d.mts +24 -0
  76. package/dist/classes/modules/commands/MessageCommandModule.mjs +27 -0
  77. package/dist/classes/modules/commands/MessageCommandModule.mjs.map +1 -0
  78. package/dist/classes/modules/commands/SlashCommandModule.d.mts +24 -0
  79. package/dist/classes/modules/commands/SlashCommandModule.mjs +27 -0
  80. package/dist/classes/modules/commands/SlashCommandModule.mjs.map +1 -0
  81. package/dist/classes/modules/events/ClientEventModule.d.mts +11 -0
  82. package/dist/classes/modules/events/ClientEventModule.mjs +10 -0
  83. package/dist/classes/modules/events/ClientEventModule.mjs.map +1 -0
  84. package/dist/classes/modules/events/EventModule.d.mts +29 -0
  85. package/dist/classes/modules/events/EventModule.mjs +26 -0
  86. package/dist/classes/modules/events/EventModule.mjs.map +1 -0
  87. package/dist/classes/modules/events/RESTEventModule.d.mts +11 -0
  88. package/dist/classes/modules/events/RESTEventModule.mjs +10 -0
  89. package/dist/classes/modules/events/RESTEventModule.mjs.map +1 -0
  90. package/dist/classes/templates/ModuleTemplateBuilder.d.mts +84 -0
  91. package/dist/classes/templates/ModuleTemplateBuilder.mjs +288 -0
  92. package/dist/classes/templates/ModuleTemplateBuilder.mjs.map +1 -0
  93. package/dist/classes/templates/TemplateBuilder.d.mts +78 -0
  94. package/dist/classes/templates/TemplateBuilder.mjs +351 -0
  95. package/dist/classes/templates/TemplateBuilder.mjs.map +1 -0
  96. package/dist/classes/validation/BaseModuleValidator.d.mts +44 -0
  97. package/dist/classes/validation/BaseModuleValidator.mjs +46 -0
  98. package/dist/classes/validation/BaseModuleValidator.mjs.map +1 -0
  99. package/dist/classes/validation/CommandModuleValidator.d.mts +117 -0
  100. package/dist/classes/validation/CommandModuleValidator.mjs +16 -0
  101. package/dist/classes/validation/CommandModuleValidator.mjs.map +1 -0
  102. package/dist/classes/validation/EventModuleValidator.d.mts +59 -0
  103. package/dist/classes/validation/EventModuleValidator.mjs +42 -0
  104. package/dist/classes/validation/EventModuleValidator.mjs.map +1 -0
  105. package/dist/classes/validation/PostconditionModule.d.mts +30 -0
  106. package/dist/classes/validation/PostconditionModule.mjs +34 -0
  107. package/dist/classes/validation/PostconditionModule.mjs.map +1 -0
  108. package/dist/classes/validation/PreconditionModule.d.mts +28 -0
  109. package/dist/classes/validation/PreconditionModule.mjs +29 -0
  110. package/dist/classes/validation/PreconditionModule.mjs.map +1 -0
  111. package/dist/helpers/constants.d.mts +20 -0
  112. package/dist/helpers/constants.mjs +28 -0
  113. package/dist/helpers/constants.mjs.map +1 -0
  114. package/dist/helpers/types.d.mts +20 -0
  115. package/dist/helpers/types.mjs +1 -0
  116. package/dist/index.d.mts +39 -0
  117. package/dist/index.mjs +39 -0
  118. package/dist/index.mjs.map +1 -0
  119. package/dist/package.mjs +80 -0
  120. package/dist/package.mjs.map +1 -0
  121. package/package.json +61 -46
  122. package/README.md +0 -206
  123. package/dist/bin.d.ts +0 -2
  124. package/dist/bin.js +0 -4
  125. package/dist/bin.js.map +0 -1
  126. package/dist/classes/CLI.d.ts +0 -55
  127. package/dist/classes/CLI.js +0 -191
  128. package/dist/classes/CLI.js.map +0 -1
  129. package/dist/classes/Config.d.ts +0 -26
  130. package/dist/classes/Config.js +0 -73
  131. package/dist/classes/Config.js.map +0 -1
  132. package/dist/classes/EventHandlers.d.ts +0 -9
  133. package/dist/classes/EventHandlers.js +0 -71
  134. package/dist/classes/EventHandlers.js.map +0 -1
  135. package/dist/classes/ModuleLoader.d.ts +0 -25
  136. package/dist/classes/ModuleLoader.js +0 -91
  137. package/dist/classes/ModuleLoader.js.map +0 -1
  138. package/dist/commands/init.d.ts +0 -7
  139. package/dist/commands/init.js +0 -10
  140. package/dist/commands/init.js.map +0 -1
  141. package/dist/commands/modules.d.ts +0 -9
  142. package/dist/commands/modules.js +0 -33
  143. package/dist/commands/modules.js.map +0 -1
  144. package/dist/commands/shard.d.ts +0 -9
  145. package/dist/commands/shard.js +0 -102
  146. package/dist/commands/shard.js.map +0 -1
  147. package/dist/commands/start.d.ts +0 -9
  148. package/dist/commands/start.js +0 -95
  149. package/dist/commands/start.js.map +0 -1
  150. package/dist/exports.d.ts +0 -6
  151. package/dist/exports.js +0 -7
  152. package/dist/exports.js.map +0 -1
  153. package/dist/index.d.ts +0 -15
  154. package/dist/index.js +0 -8
  155. package/dist/index.js.map +0 -1
  156. package/dist/types/constants.d.ts +0 -6
  157. package/dist/types/constants.js +0 -29
  158. package/dist/types/constants.js.map +0 -1
  159. package/dist/types/structures.d.ts +0 -36
  160. package/dist/types/structures.js +0 -2
  161. package/dist/types/structures.js.map +0 -1
  162. package/static/config.d.mts +0 -5
  163. package/static/config.mjs +0 -105
@@ -0,0 +1,29 @@
1
+ import { ModuleType } from "../../../helpers/constants.mjs";
2
+ import { BaseModule } from "../BaseModule.mjs";
3
+ import { Awaitable, Constructable } from "discord.js";
4
+ import { EventEmitter } from "node:events";
5
+
6
+ //#region src/classes/modules/events/EventModule.d.ts
7
+ declare const base: Constructable<Omit<BaseModule, 'moduleType'>>;
8
+ declare abstract class EventModule<Events extends EventModule.EventMap = EventModule.EventMap, Event extends keyof Events = keyof Events> extends base implements EventModule.Data<Events, Event> {
9
+ readonly moduleType: ModuleType.Event;
10
+ abstract emitter: EventEmitter;
11
+ abstract event: Event;
12
+ once?: boolean;
13
+ abstract onEvent(...args: Events[Event]): Awaitable<void>;
14
+ static from(data: EventModule.Resolvable): EventModule;
15
+ }
16
+ declare namespace EventModule {
17
+ type EventMap = Record<string | symbol, any>;
18
+ type Resolvable<Events extends EventModule.EventMap = EventModule.EventMap, Event extends keyof Events = keyof Events> = EventModule<Events, Event> | EventModule.Data<Events, Event>;
19
+ interface Data<Events extends EventModule.EventMap = EventModule.EventMap, Event extends keyof Events = keyof Events> extends Omit<BaseModule.Data, 'moduleType'> {
20
+ moduleType: ModuleType.Event;
21
+ emitter: EventEmitter;
22
+ event: Event;
23
+ once?: boolean;
24
+ onEvent: (...args: Events[Event]) => Awaitable<void>;
25
+ }
26
+ }
27
+ //#endregion
28
+ export { EventModule };
29
+ //# sourceMappingURL=EventModule.d.mts.map
@@ -0,0 +1,26 @@
1
+ import { ModuleType } from "../../../helpers/constants.mjs";
2
+ import { BaseModule } from "../BaseModule.mjs";
3
+ import { hasMixin } from "ts-mixer";
4
+ import { EventEmitter } from "node:events";
5
+
6
+ //#region src/classes/modules/events/EventModule.ts
7
+ const base = BaseModule;
8
+ var EventModule = class EventModule extends base {
9
+ moduleType = ModuleType.Event;
10
+ once = false;
11
+ static from(data) {
12
+ if (data instanceof EventModule || hasMixin(data, EventModule)) return data;
13
+ const ModuleInstance = class extends EventModule {
14
+ emitter = data.emitter;
15
+ event = data.event;
16
+ once = data.once;
17
+ onEvent = data.onEvent;
18
+ };
19
+ Object.assign(ModuleInstance.prototype, data);
20
+ return new ModuleInstance();
21
+ }
22
+ };
23
+
24
+ //#endregion
25
+ export { EventModule };
26
+ //# sourceMappingURL=EventModule.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"EventModule.mjs","names":["base: Constructable<Omit<BaseModule, 'moduleType'>>"],"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, Constructable } from 'discord.js';\nimport { hasMixin } from 'ts-mixer';\n\nconst base: Constructable<Omit<BaseModule, 'moduleType'>> = BaseModule;\n\nexport abstract class EventModule<Events extends EventModule.EventMap = EventModule.EventMap, Event extends keyof Events = keyof Events> extends base 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 (data instanceof EventModule || 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,MAAMA,OAAsD;AAE5D,IAAsB,cAAtB,MAAsB,oBAA2H,KAAgD;CAC7L,AAAgB,aAA+B,WAAW;CAI1D,AAAO,OAAiB;CAIxB,OAAc,KAAK,MAA2C;AAC1D,MAAI,gBAAgB,eAAe,SAAS,MAAM,YAAY,CAAE,QAAO;EAEvE,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"}
@@ -0,0 +1,11 @@
1
+ import { EventModule } from "./EventModule.mjs";
2
+ import { REST, RestEventsMap } from "discord.js";
3
+
4
+ //#region src/classes/modules/events/RESTEventModule.d.ts
5
+ declare abstract class RESTEventModule<Event extends keyof RestEventsMap> extends EventModule<RestEventsMap, Event> {
6
+ emitter: REST;
7
+ abstract event: Event;
8
+ }
9
+ //#endregion
10
+ export { RESTEventModule };
11
+ //# sourceMappingURL=RESTEventModule.d.mts.map
@@ -0,0 +1,10 @@
1
+ import { EventModule } from "./EventModule.mjs";
2
+
3
+ //#region src/classes/modules/events/RESTEventModule.ts
4
+ var RESTEventModule = class extends EventModule {
5
+ emitter = useClient().rest;
6
+ };
7
+
8
+ //#endregion
9
+ export { RESTEventModule };
10
+ //# sourceMappingURL=RESTEventModule.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"RESTEventModule.mjs","names":[],"sources":["../../../../src/classes/modules/events/RESTEventModule.ts"],"sourcesContent":["import { EventModule } from './EventModule.js';\nimport type { REST, RestEventsMap } from 'discord.js';\n\nexport abstract class RESTEventModule<Event extends keyof RestEventsMap> extends EventModule<RestEventsMap, Event> {\n public emitter: REST = useClient().rest;\n public abstract event: Event;\n}\n"],"mappings":";;;AAGA,IAAsB,kBAAtB,cAAiF,YAAkC;CAC/G,AAAO,UAAgB,WAAW,CAAC"}
@@ -0,0 +1,84 @@
1
+ import { CLI } from "../cli/CLI.mjs";
2
+ import { ModuleType } from "../../helpers/constants.mjs";
3
+ import { ConfigReader } from "../cli/ConfigReader.mjs";
4
+
5
+ //#region src/classes/templates/ModuleTemplateBuilder.d.ts
6
+ declare class ModuleTemplateBuilder {
7
+ _directory?: string;
8
+ readonly cli: CLI;
9
+ readonly config: ConfigReader;
10
+ template?: ModuleTemplateBuilder.Data;
11
+ typescript?: boolean;
12
+ filename?: string;
13
+ defaultAll: boolean;
14
+ get content(): string;
15
+ get directory(): string;
16
+ get filepath(): string;
17
+ constructor(options: ModuleTemplateBuilder.Options);
18
+ init(): Promise<this>;
19
+ setupLanguage(options?: ModuleTemplateBuilder.SetupLanguageOptions): Promise<this>;
20
+ setupTemplate(options?: ModuleTemplateBuilder.SetupTemplateOptions): Promise<this>;
21
+ setupPlaceholders(): Promise<this>;
22
+ setupDirectory(options?: ModuleTemplateBuilder.SetupDirectoryOptions): Promise<this>;
23
+ setupFilename(options?: ModuleTemplateBuilder.SetupFilenameOptions): Promise<this>;
24
+ build({
25
+ overwrite,
26
+ silent
27
+ }?: ModuleTemplateBuilder.BuildOptions): Promise<this>;
28
+ }
29
+ declare namespace ModuleTemplateBuilder {
30
+ interface Options {
31
+ cli: CLI;
32
+ config: ConfigReader;
33
+ template?: ModuleTemplateBuilder.Data;
34
+ typescript?: boolean;
35
+ directory?: string;
36
+ filename?: string;
37
+ defaultAll?: boolean;
38
+ }
39
+ interface SetupLanguageOptions {
40
+ typescript?: boolean;
41
+ }
42
+ interface SetupTemplateOptions {
43
+ template?: ModuleTemplateBuilder.Data | string;
44
+ }
45
+ interface SetupDirectoryOptions {
46
+ directory?: string;
47
+ }
48
+ interface SetupFilenameOptions {
49
+ filename?: string;
50
+ }
51
+ interface BuildOptions {
52
+ overwrite?: boolean;
53
+ silent?: boolean;
54
+ }
55
+ enum Placeholder {
56
+ ModuleName = "$MODULE_NAME$",
57
+ CommandName = "$COMMAND_NAME$",
58
+ CommandDescription = "$COMMAND_DESCRIPTION$",
59
+ CommandContextMenuType = "$COMMAND_CONTEXT_MENU_TYPE$",
60
+ EventEmitter = "$EVENT_EMITTER$",
61
+ EventName = "$EVENT_NAME$",
62
+ EventOnce = "$EVENT_ONCE$",
63
+ }
64
+ const PlaceholderDefaultValues: Record<Placeholder, string>;
65
+ const SourceDirectory: {
66
+ js: string;
67
+ ts: string;
68
+ };
69
+ const ModuleTypeClassName: Record<ModuleType, string[]>;
70
+ interface Data {
71
+ src: string;
72
+ name: string;
73
+ content: string;
74
+ moduleType: ModuleType | null;
75
+ }
76
+ function resolveModuleTemplates(source: keyof typeof SourceDirectory): Promise<ModuleTemplateBuilder.Data[]>;
77
+ function getModuleTemplateContentType(content: string): ModuleType | null;
78
+ function hasPlaceholder(placeholder: Placeholder, content: string): boolean;
79
+ function removeExpectedErrorComments(content: string): string;
80
+ function toTextCase(string: string): string;
81
+ }
82
+ //#endregion
83
+ export { ModuleTemplateBuilder };
84
+ //# sourceMappingURL=ModuleTemplateBuilder.d.mts.map
@@ -0,0 +1,288 @@
1
+ import { NotAnError } from "../NotAnError.mjs";
2
+ import { CLI } from "../cli/CLI.mjs";
3
+ import { ConfigReader } from "../cli/ConfigReader.mjs";
4
+ import { ModuleType } from "../../helpers/constants.mjs";
5
+ import { BaseModule } from "../modules/BaseModule.mjs";
6
+ import { PostconditionModule } from "../modules/PostconditionModule.mjs";
7
+ import { PreconditionModule } from "../modules/PreconditionModule.mjs";
8
+ import { EventModule } from "../modules/events/EventModule.mjs";
9
+ import { MessageCommandModule } from "../modules/commands/MessageCommandModule.mjs";
10
+ import { SlashCommandModule } from "../modules/commands/SlashCommandModule.mjs";
11
+ import { ContextMenuCommandModule } from "../modules/commands/ContextMenuCommandModule.mjs";
12
+ import { ModuleLoader } from "../client/ModuleLoader.mjs";
13
+ import { ClientEventModule } from "../modules/events/ClientEventModule.mjs";
14
+ import { RESTEventModule } from "../modules/events/RESTEventModule.mjs";
15
+ import path from "node:path";
16
+ import { colors } from "@reciple/utils";
17
+ import { mkdir, readFile, readdir, writeFile } from "node:fs/promises";
18
+ import { confirm, intro, isCancel, outro, select, text } from "@clack/prompts";
19
+ import { readTSConfig } from "pkg-types";
20
+ import { ApplicationCommandType } from "discord.js";
21
+ import { existsSync } from "node:fs";
22
+
23
+ //#region src/classes/templates/ModuleTemplateBuilder.ts
24
+ var ModuleTemplateBuilder = class ModuleTemplateBuilder {
25
+ _directory;
26
+ cli;
27
+ config;
28
+ template;
29
+ typescript;
30
+ filename;
31
+ defaultAll;
32
+ get content() {
33
+ return this.template?.content ?? "";
34
+ }
35
+ get directory() {
36
+ return this._directory ?? process.cwd();
37
+ }
38
+ get filepath() {
39
+ return path.join(this.directory, this.filename ?? "");
40
+ }
41
+ constructor(options) {
42
+ this.cli = options.cli;
43
+ this.config = options.config;
44
+ this.template = options?.template;
45
+ this.typescript = options?.typescript;
46
+ this._directory = options?.directory;
47
+ this.filename = options?.filename;
48
+ this.defaultAll = options?.defaultAll ?? false;
49
+ }
50
+ async init() {
51
+ intro(colors.bold(colors.black(colors.bgCyan(` ${this.cli.command.name()} create module - v${this.cli.build} `))));
52
+ return this;
53
+ }
54
+ async setupLanguage(options) {
55
+ this.typescript = options?.typescript ?? this.typescript;
56
+ if (!this.typescript) {
57
+ const isTypeScriptDefault = await ConfigReader.getProjectLang(this.directory) === "ts";
58
+ const isTypeScript = this.defaultAll ? isTypeScriptDefault : await confirm({
59
+ message: "Would you like to use TypeScript?",
60
+ active: "Yes",
61
+ inactive: "No",
62
+ initialValue: isTypeScriptDefault
63
+ });
64
+ if (isCancel(isTypeScript)) throw new NotAnError("Operation cancelled");
65
+ this.typescript = isTypeScript;
66
+ }
67
+ return this;
68
+ }
69
+ async setupTemplate(options) {
70
+ let template = typeof options?.template === "object" ? options.template : void 0;
71
+ if (!template) {
72
+ const templateName = typeof options?.template === "string" ? options.template : void 0;
73
+ const templates = await ModuleTemplateBuilder.resolveModuleTemplates(this.typescript ? "ts" : "js");
74
+ const selectedTemplate = this.defaultAll ? templateName ? templates.find((template$1) => template$1.name === templateName) : templates.at(0) : await select({
75
+ message: "Select a module template",
76
+ options: templates.map((template$1) => ({
77
+ label: template$1.name,
78
+ value: template$1
79
+ }))
80
+ });
81
+ if (isCancel(selectedTemplate)) throw new NotAnError("Operation cancelled");
82
+ template = selectedTemplate;
83
+ }
84
+ this.template = template;
85
+ if (!this.template) throw new NotAnError("No template selected");
86
+ return this;
87
+ }
88
+ async setupPlaceholders() {
89
+ const placeholders = Object.keys(ModuleTemplateBuilder.Placeholder).filter((k) => !k.startsWith("$"));
90
+ for (const placeholderKey of placeholders) {
91
+ if (!ModuleTemplateBuilder.hasPlaceholder(ModuleTemplateBuilder.Placeholder[placeholderKey], this.content)) continue;
92
+ const placeholder = ModuleTemplateBuilder.Placeholder[placeholderKey];
93
+ const defaultValue = ModuleTemplateBuilder.PlaceholderDefaultValues[placeholder];
94
+ let value;
95
+ if (this.defaultAll) value = defaultValue;
96
+ else switch (placeholder) {
97
+ case ModuleTemplateBuilder.Placeholder.ModuleName:
98
+ case ModuleTemplateBuilder.Placeholder.CommandName:
99
+ case ModuleTemplateBuilder.Placeholder.EventName:
100
+ value = this.defaultAll ? defaultValue : await text({
101
+ message: `What would you like to name the ${placeholderKey.replace("Name", "").toLowerCase()}?`,
102
+ initialValue: defaultValue,
103
+ placeholder: defaultValue,
104
+ defaultValue,
105
+ validate: (value$1) => {
106
+ if (!value$1) return "Please enter a value";
107
+ if (value$1.includes(" ")) return "Please enter a value without spaces";
108
+ }
109
+ });
110
+ break;
111
+ case ModuleTemplateBuilder.Placeholder.CommandContextMenuType:
112
+ const type = await select({
113
+ message: "Select a command context menu type",
114
+ options: [{
115
+ label: "Message",
116
+ value: ApplicationCommandType.Message
117
+ }, {
118
+ label: "User",
119
+ value: ApplicationCommandType.User
120
+ }],
121
+ initialValue: ApplicationCommandType.Message
122
+ });
123
+ value = isCancel(type) ? type : `${type}`;
124
+ break;
125
+ case ModuleTemplateBuilder.Placeholder.EventOnce:
126
+ const once = await confirm({
127
+ message: `Would you like to use the event once?`,
128
+ active: "Yes",
129
+ inactive: "No",
130
+ initialValue: false
131
+ });
132
+ value = isCancel(once) ? once : `${once}`;
133
+ break;
134
+ case ModuleTemplateBuilder.Placeholder.EventEmitter:
135
+ default:
136
+ value = await text({
137
+ message: `What would you like to use for the ${ModuleTemplateBuilder.toTextCase(placeholder)}?`,
138
+ initialValue: defaultValue,
139
+ placeholder: defaultValue,
140
+ defaultValue
141
+ });
142
+ break;
143
+ }
144
+ if (isCancel(value)) throw new NotAnError("Operation cancelled");
145
+ if (!this.template) throw new NotAnError("No template selected");
146
+ this.template.content = ModuleTemplateBuilder.removeExpectedErrorComments(this.content.replaceAll(placeholder, value));
147
+ }
148
+ return this;
149
+ }
150
+ async setupDirectory(options) {
151
+ let directory = options?.directory;
152
+ if (!directory) {
153
+ const cwd = process.cwd();
154
+ const tsconfig = this.config.build.tsconfig ? await readTSConfig(typeof this.config.build.tsconfig == "string" ? this.config.build.tsconfig : cwd, { try: true }) : void 0;
155
+ let directories = await ModuleLoader.scanForDirectories(this.config.config.modules);
156
+ directories = await ModuleLoader.resolveSourceDirectories({
157
+ directories,
158
+ baseUrl: tsconfig?.compilerOptions?.baseUrl ?? ".",
159
+ rootDir: tsconfig?.compilerOptions?.rootDir ?? "src",
160
+ outDir: tsconfig?.compilerOptions?.outDir ?? "modules",
161
+ cwd
162
+ });
163
+ const selectedDirectory = this.defaultAll ? directories.at(0) : await select({
164
+ message: "Select a directory",
165
+ options: directories.map((directory$1) => ({
166
+ label: path.relative(cwd, directory$1),
167
+ value: directory$1
168
+ }))
169
+ });
170
+ if (isCancel(selectedDirectory)) throw new NotAnError("Operation cancelled");
171
+ directory = selectedDirectory;
172
+ }
173
+ if (!directory) throw new NotAnError("No directory selected");
174
+ this._directory = directory;
175
+ return this;
176
+ }
177
+ async setupFilename(options) {
178
+ let filename = options?.filename;
179
+ if (!filename) {
180
+ const defaultFilename = `${this.template?.name}.${this.typescript ? "ts" : "js"}`;
181
+ const selectedFilename = this.defaultAll ? defaultFilename : await text({
182
+ message: "What would you like to name the module file?",
183
+ initialValue: defaultFilename,
184
+ placeholder: defaultFilename,
185
+ defaultValue: defaultFilename,
186
+ validate: (value) => {
187
+ if (!value) return "Please enter a value";
188
+ if (existsSync(path.join(this.directory, value))) return "File already exists";
189
+ }
190
+ });
191
+ if (isCancel(selectedFilename)) throw new NotAnError("Operation cancelled");
192
+ filename = selectedFilename;
193
+ }
194
+ if (!filename) throw new NotAnError("No filename selected");
195
+ this.filename = filename;
196
+ return this;
197
+ }
198
+ async build({ overwrite, silent } = {}) {
199
+ await mkdir(this.directory, { recursive: true });
200
+ await writeFile(this.filepath, this.content, { flag: overwrite === false ? "wx" : void 0 });
201
+ if (!silent) outro(`Module ${colors.green(this.template?.name)} created in ${colors.cyan(path.relative(process.cwd(), this.filepath))}`);
202
+ return this;
203
+ }
204
+ };
205
+ (function(_ModuleTemplateBuilder) {
206
+ let Placeholder = /* @__PURE__ */ function(Placeholder$1) {
207
+ Placeholder$1["ModuleName"] = "$MODULE_NAME$";
208
+ Placeholder$1["CommandName"] = "$COMMAND_NAME$";
209
+ Placeholder$1["CommandDescription"] = "$COMMAND_DESCRIPTION$";
210
+ Placeholder$1["CommandContextMenuType"] = "$COMMAND_CONTEXT_MENU_TYPE$";
211
+ Placeholder$1["EventEmitter"] = "$EVENT_EMITTER$";
212
+ Placeholder$1["EventName"] = "$EVENT_NAME$";
213
+ Placeholder$1["EventOnce"] = "$EVENT_ONCE$";
214
+ return Placeholder$1;
215
+ }({});
216
+ _ModuleTemplateBuilder.Placeholder = Placeholder;
217
+ _ModuleTemplateBuilder.PlaceholderDefaultValues = {
218
+ [Placeholder.ModuleName]: "MyModule",
219
+ [Placeholder.CommandName]: "my-command",
220
+ [Placeholder.CommandDescription]: "My command",
221
+ [Placeholder.CommandContextMenuType]: `${ApplicationCommandType.Message}`,
222
+ [Placeholder.EventEmitter]: "null",
223
+ [Placeholder.EventName]: "my-event",
224
+ [Placeholder.EventOnce]: "false"
225
+ };
226
+ _ModuleTemplateBuilder.SourceDirectory = {
227
+ js: path.join(CLI.root, "./assets/modules/javascript"),
228
+ ts: path.join(CLI.root, "./assets/modules/typescript")
229
+ };
230
+ const ModuleTypeClassName = _ModuleTemplateBuilder.ModuleTypeClassName = {
231
+ [ModuleType.Base]: [BaseModule.name],
232
+ [ModuleType.Command]: [
233
+ MessageCommandModule.name,
234
+ SlashCommandModule.name,
235
+ ContextMenuCommandModule.name
236
+ ],
237
+ [ModuleType.Event]: [
238
+ ClientEventModule.name,
239
+ EventModule.name,
240
+ RESTEventModule.name
241
+ ],
242
+ [ModuleType.Postcondition]: [PostconditionModule.name],
243
+ [ModuleType.Precondition]: [PreconditionModule.name]
244
+ };
245
+ async function resolveModuleTemplates(source) {
246
+ const src = ModuleTemplateBuilder.SourceDirectory[source];
247
+ const files = await readdir(src);
248
+ const templates = [];
249
+ for (const file of files) {
250
+ const filepath = path.join(src, file);
251
+ const content = await readFile(filepath, "utf-8");
252
+ const moduleType = ModuleTemplateBuilder.getModuleTemplateContentType(content);
253
+ templates.push({
254
+ src: filepath,
255
+ name: path.parse(filepath).name,
256
+ content,
257
+ moduleType
258
+ });
259
+ }
260
+ return templates;
261
+ }
262
+ _ModuleTemplateBuilder.resolveModuleTemplates = resolveModuleTemplates;
263
+ function getModuleTemplateContentType(content) {
264
+ const createExtendStatement = (name) => `export class ${Placeholder.ModuleName} extends ${name}`;
265
+ for (const type of Object.keys(ModuleTypeClassName).map(Number)) {
266
+ const statements = ModuleTypeClassName[type].map(createExtendStatement);
267
+ for (const statement of statements) if (content.includes(statement)) return type;
268
+ }
269
+ return null;
270
+ }
271
+ _ModuleTemplateBuilder.getModuleTemplateContentType = getModuleTemplateContentType;
272
+ function hasPlaceholder(placeholder, content) {
273
+ return content.includes(placeholder);
274
+ }
275
+ _ModuleTemplateBuilder.hasPlaceholder = hasPlaceholder;
276
+ function removeExpectedErrorComments(content) {
277
+ return content.split("\n").filter((line) => !line.trim().includes("// @ts-expect-error")).join("\n");
278
+ }
279
+ _ModuleTemplateBuilder.removeExpectedErrorComments = removeExpectedErrorComments;
280
+ function toTextCase(string) {
281
+ return String(string).replace(/^[^A-Za-z0-9]*|[^A-Za-z0-9]*$/g, "").replace(/([a-z])([A-Z])/g, (m, a, b) => a + "_" + b.toLowerCase()).replace(/[^A-Za-z0-9]+|_+/g, " ").toLowerCase();
282
+ }
283
+ _ModuleTemplateBuilder.toTextCase = toTextCase;
284
+ })(ModuleTemplateBuilder || (ModuleTemplateBuilder = {}));
285
+
286
+ //#endregion
287
+ export { ModuleTemplateBuilder };
288
+ //# sourceMappingURL=ModuleTemplateBuilder.mjs.map
@@ -0,0 +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,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,KAAK,OAAO,MAAM,OAAO,OAAO,IAAI,KAAK,IAAI,QAAQ,MAAM,CAAC,oBAAoB,KAAK,IAAI,MAAM,GAAG,CAAC,CAAC,CAAC;AAClH,SAAO;;CAGX,MAAa,cAAc,SAAqE;AAC5F,OAAK,aAAa,SAAS,cAAc,KA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B,QAAQ;AAE9E,aAAU,KAAK;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"}
@@ -0,0 +1,78 @@
1
+ import { CLI } from "../cli/CLI.mjs";
2
+ import { ConfigReader } from "../cli/ConfigReader.mjs";
3
+ import { PackageJsonBuilder } from "@reciple/utils";
4
+ import { PackageManagerName } from "nypm";
5
+
6
+ //#region src/classes/templates/TemplateBuilder.d.ts
7
+ declare class TemplateBuilder {
8
+ private _directory?;
9
+ cli: CLI;
10
+ typescript?: boolean;
11
+ token?: string;
12
+ defaultAll: boolean;
13
+ config?: ConfigReader;
14
+ packageJson?: PackageJsonBuilder;
15
+ packageManager?: PackageManagerName;
16
+ get directory(): string;
17
+ get relativeDirectory(): string;
18
+ get packageJsonPath(): string;
19
+ get name(): string;
20
+ constructor(options: TemplateBuilder.Options);
21
+ init(): Promise<this>;
22
+ createDirectory(options?: TemplateBuilder.CreateDirectoryOptions): Promise<this>;
23
+ setupLanguage(options?: TemplateBuilder.SetupLanguageOptions): Promise<this>;
24
+ createConfig(options?: TemplateBuilder.CreateConfigOptions): Promise<this>;
25
+ createTemplate(options?: TemplateBuilder.CreateModulesOptions): Promise<this>;
26
+ setPackageManager(options?: TemplateBuilder.SetPackageManagerOptions): Promise<this>;
27
+ createEnvFile(options?: TemplateBuilder.CreateEnvFileOptions): Promise<this>;
28
+ build(options?: TemplateBuilder.BuildOptions): Promise<this>;
29
+ }
30
+ declare namespace TemplateBuilder {
31
+ interface Options {
32
+ cli: CLI;
33
+ directory?: string;
34
+ typescript?: boolean;
35
+ packageManager?: PackageManagerName;
36
+ defaultAll?: boolean;
37
+ token?: string;
38
+ }
39
+ const ignoredDirectoryFiles: string[];
40
+ const dependencies: Record<'ts' | 'js' | 'both', Partial<Record<'dependencies' | 'devDependencies', Record<string, string>>>>;
41
+ function createDependencyRecord(type: 'ts' | 'js'): Partial<Record<'dependencies' | 'devDependencies', Record<string, string>>>;
42
+ interface CreateDirectoryOptions {
43
+ directory?: string;
44
+ ignoredFiles?: string[];
45
+ onNotEmpty?: 'prompt' | 'throw' | 'ignore';
46
+ }
47
+ interface SetupLanguageOptions {
48
+ typescript?: boolean;
49
+ }
50
+ interface CreateConfigOptions extends Partial<ConfigReader.CreateOptions> {}
51
+ interface CreateModulesOptions extends Partial<CopyOptions> {}
52
+ interface SetPackageManagerOptions {
53
+ packageManager?: PackageManagerName;
54
+ }
55
+ interface CreateEnvFileOptions {
56
+ envFile?: string;
57
+ tokenKey?: string;
58
+ env?: Record<string, string>;
59
+ }
60
+ interface BuildOptions {
61
+ skipInstallDependencies?: boolean;
62
+ skipBuild?: boolean;
63
+ }
64
+ interface CopyOptions {
65
+ overwrite?: boolean | ((data: CopyMetadata) => boolean);
66
+ filter?: (data: CopyMetadata) => boolean;
67
+ rename?: (data: CopyMetadata) => string;
68
+ }
69
+ interface CopyMetadata {
70
+ basename: string;
71
+ src: string;
72
+ dest: string;
73
+ }
74
+ function copy(from: string, to: string, options?: CopyOptions): Promise<void>;
75
+ }
76
+ //#endregion
77
+ export { TemplateBuilder };
78
+ //# sourceMappingURL=TemplateBuilder.d.mts.map