reciple 9.9.0 → 10.0.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/assets/config/reciple.config.js +87 -0
  2. package/assets/config/reciple.config.ts +80 -0
  3. package/assets/global/README.md +1 -0
  4. package/assets/global/gitignore +121 -0
  5. package/assets/global/nodemon.json +13 -0
  6. package/assets/modules/javascript/Base.js +21 -0
  7. package/assets/modules/javascript/ClientEvent.js +14 -0
  8. package/assets/modules/javascript/ContextMenuCommand.js +17 -0
  9. package/assets/modules/javascript/Event.js +17 -0
  10. package/assets/modules/javascript/MessageCommand.js +16 -0
  11. package/assets/modules/javascript/RESTEvent.js +14 -0
  12. package/assets/modules/javascript/SlashCommand.js +16 -0
  13. package/assets/modules/typescript/Base.ts +17 -0
  14. package/assets/modules/typescript/ClientEvent.ts +15 -0
  15. package/assets/modules/typescript/ContextMenuCommand.ts +15 -0
  16. package/assets/modules/typescript/Event.ts +16 -0
  17. package/assets/modules/typescript/MessageCommand.ts +14 -0
  18. package/assets/modules/typescript/RESTEvent.ts +15 -0
  19. package/assets/modules/typescript/SlashCommand.ts +14 -0
  20. package/assets/templates/javascript/jsconfig.json +17 -0
  21. package/assets/templates/typescript/tsconfig.json +17 -0
  22. package/dist/_virtual/_@oxc-project_runtime@0.99.0/helpers/decorate.mjs +10 -0
  23. package/dist/bin/commands/build.d.mts +16 -0
  24. package/dist/bin/commands/build.mjs +24 -0
  25. package/dist/bin/commands/build.mjs.map +1 -0
  26. package/dist/bin/commands/create.d.mts +23 -0
  27. package/dist/bin/commands/create.mjs +48 -0
  28. package/dist/bin/commands/create.mjs.map +1 -0
  29. package/dist/bin/commands/createModule.d.mts +21 -0
  30. package/dist/bin/commands/createModule.mjs +40 -0
  31. package/dist/bin/commands/createModule.mjs.map +1 -0
  32. package/dist/bin/commands/start.d.mts +18 -0
  33. package/dist/bin/commands/start.mjs +104 -0
  34. package/dist/bin/commands/start.mjs.map +1 -0
  35. package/dist/bin/reciple.d.mts +1 -0
  36. package/dist/bin/reciple.mjs +9 -0
  37. package/dist/bin/reciple.mjs.map +1 -0
  38. package/dist/classes/NotAnError.d.mts +7 -0
  39. package/dist/classes/NotAnError.mjs +11 -0
  40. package/dist/classes/NotAnError.mjs.map +1 -0
  41. package/dist/classes/cli/CLI.d.mts +54 -0
  42. package/dist/classes/cli/CLI.mjs +156 -0
  43. package/dist/classes/cli/CLI.mjs.map +1 -0
  44. package/dist/classes/cli/CLISubcommand.d.mts +27 -0
  45. package/dist/classes/cli/CLISubcommand.mjs +23 -0
  46. package/dist/classes/cli/CLISubcommand.mjs.map +1 -0
  47. package/dist/classes/cli/ConfigReader.d.mts +81 -0
  48. package/dist/classes/cli/ConfigReader.mjs +141 -0
  49. package/dist/classes/cli/ConfigReader.mjs.map +1 -0
  50. package/dist/classes/cli/RuntimeEnvironment.d.mts +14 -0
  51. package/dist/classes/cli/RuntimeEnvironment.mjs +36 -0
  52. package/dist/classes/cli/RuntimeEnvironment.mjs.map +1 -0
  53. package/dist/classes/client/EventListeners.d.mts +26 -0
  54. package/dist/classes/client/EventListeners.mjs +103 -0
  55. package/dist/classes/client/EventListeners.mjs.map +1 -0
  56. package/dist/classes/client/ModuleLoader.d.mts +55 -0
  57. package/dist/classes/client/ModuleLoader.mjs +152 -0
  58. package/dist/classes/client/ModuleLoader.mjs.map +1 -0
  59. package/dist/classes/managers/ModuleManager.d.mts +55 -0
  60. package/dist/classes/managers/ModuleManager.mjs +107 -0
  61. package/dist/classes/managers/ModuleManager.mjs.map +1 -0
  62. package/dist/classes/modules/BaseModule.d.mts +34 -0
  63. package/dist/classes/modules/BaseModule.mjs +33 -0
  64. package/dist/classes/modules/BaseModule.mjs.map +1 -0
  65. package/dist/classes/modules/PostconditionModule.d.mts +20 -0
  66. package/dist/classes/modules/PostconditionModule.mjs +24 -0
  67. package/dist/classes/modules/PostconditionModule.mjs.map +1 -0
  68. package/dist/classes/modules/PreconditionModule.d.mts +20 -0
  69. package/dist/classes/modules/PreconditionModule.mjs +24 -0
  70. package/dist/classes/modules/PreconditionModule.mjs.map +1 -0
  71. package/dist/classes/modules/commands/ContextMenuCommandModule.d.mts +24 -0
  72. package/dist/classes/modules/commands/ContextMenuCommandModule.mjs +27 -0
  73. package/dist/classes/modules/commands/ContextMenuCommandModule.mjs.map +1 -0
  74. package/dist/classes/modules/commands/MessageCommandModule.d.mts +24 -0
  75. package/dist/classes/modules/commands/MessageCommandModule.mjs +27 -0
  76. package/dist/classes/modules/commands/MessageCommandModule.mjs.map +1 -0
  77. package/dist/classes/modules/commands/SlashCommandModule.d.mts +24 -0
  78. package/dist/classes/modules/commands/SlashCommandModule.mjs +27 -0
  79. package/dist/classes/modules/commands/SlashCommandModule.mjs.map +1 -0
  80. package/dist/classes/modules/events/ClientEventModule.d.mts +11 -0
  81. package/dist/classes/modules/events/ClientEventModule.mjs +10 -0
  82. package/dist/classes/modules/events/ClientEventModule.mjs.map +1 -0
  83. package/dist/classes/modules/events/EventModule.d.mts +29 -0
  84. package/dist/classes/modules/events/EventModule.mjs +26 -0
  85. package/dist/classes/modules/events/EventModule.mjs.map +1 -0
  86. package/dist/classes/modules/events/RESTEventModule.d.mts +11 -0
  87. package/dist/classes/modules/events/RESTEventModule.mjs +10 -0
  88. package/dist/classes/modules/events/RESTEventModule.mjs.map +1 -0
  89. package/dist/classes/templates/ModuleTemplateBuilder.d.mts +84 -0
  90. package/dist/classes/templates/ModuleTemplateBuilder.mjs +288 -0
  91. package/dist/classes/templates/ModuleTemplateBuilder.mjs.map +1 -0
  92. package/dist/classes/templates/TemplateBuilder.d.mts +78 -0
  93. package/dist/classes/templates/TemplateBuilder.mjs +351 -0
  94. package/dist/classes/templates/TemplateBuilder.mjs.map +1 -0
  95. package/dist/classes/validation/BaseModuleValidator.d.mts +23 -0
  96. package/dist/classes/validation/BaseModuleValidator.mjs +46 -0
  97. package/dist/classes/validation/BaseModuleValidator.mjs.map +1 -0
  98. package/dist/classes/validation/CommandModuleValidator.d.mts +12 -0
  99. package/dist/classes/validation/CommandModuleValidator.mjs +16 -0
  100. package/dist/classes/validation/CommandModuleValidator.mjs.map +1 -0
  101. package/dist/classes/validation/EventModuleValidator.d.mts +21 -0
  102. package/dist/classes/validation/EventModuleValidator.mjs +42 -0
  103. package/dist/classes/validation/EventModuleValidator.mjs.map +1 -0
  104. package/dist/classes/validation/PostconditionModule.d.mts +18 -0
  105. package/dist/classes/validation/PostconditionModule.mjs +34 -0
  106. package/dist/classes/validation/PostconditionModule.mjs.map +1 -0
  107. package/dist/classes/validation/PreconditionModule.d.mts +16 -0
  108. package/dist/classes/validation/PreconditionModule.mjs +29 -0
  109. package/dist/classes/validation/PreconditionModule.mjs.map +1 -0
  110. package/dist/helpers/constants.d.mts +19 -0
  111. package/dist/helpers/constants.mjs +28 -0
  112. package/dist/helpers/constants.mjs.map +1 -0
  113. package/dist/helpers/types.d.mts +20 -0
  114. package/dist/helpers/types.mjs +1 -0
  115. package/dist/index.d.mts +39 -0
  116. package/dist/index.mjs +39 -0
  117. package/dist/index.mjs.map +1 -0
  118. package/dist/package.mjs +79 -0
  119. package/dist/package.mjs.map +1 -0
  120. package/package.json +80 -66
  121. package/LICENSE +0 -674
  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,48 @@
1
+ import { NotAnError } from "../../classes/NotAnError.mjs";
2
+ import { CLISubcommand } from "../../classes/cli/CLISubcommand.mjs";
3
+ import { TemplateBuilder } from "../../classes/templates/TemplateBuilder.mjs";
4
+ import { Command, Option } from "commander";
5
+ import { colors } from "@reciple/utils";
6
+ import { cancel } from "@clack/prompts";
7
+ import { inspect } from "node:util";
8
+
9
+ //#region src/bin/commands/create.ts
10
+ var CreateSubcommand = class extends CLISubcommand {
11
+ subcommand = new Command("create").description("Create a new reciple project").argument("[output]", "The directory to create the project in").option("-c, --config <path>", "Path to the configuration file").option("-t, --token <DiscordToken>", "Set your Discord Bot token").option("-T, --typescript", "Use TypeScript").addOption(new Option("-p, --package-manager <name>", "The name of the package manager to use").choices([
12
+ "npm",
13
+ "yarn",
14
+ "pnpm",
15
+ "bun",
16
+ "deno"
17
+ ])).option("-D, --default", "Use defaults for prompts").option("--install", "Install dependencies during setup", true).option("--build", "Build the project after creation", true).allowUnknownOption(true);
18
+ async execute() {
19
+ const flags = this.cli.getFlags("create");
20
+ const template = new TemplateBuilder({
21
+ cli: this.cli,
22
+ directory: this.subcommand.args[0],
23
+ typescript: flags?.typescript,
24
+ packageManager: flags?.packageManager,
25
+ defaultAll: flags?.default,
26
+ token: flags?.token
27
+ });
28
+ try {
29
+ await template.init();
30
+ await template.createDirectory();
31
+ await template.setupLanguage();
32
+ await template.createConfig();
33
+ await template.setPackageManager();
34
+ await template.createTemplate();
35
+ await template.createEnvFile({ envFile: this.cli.flags.env[0] });
36
+ await template.build({
37
+ skipInstallDependencies: !flags?.install,
38
+ skipBuild: !flags?.build
39
+ });
40
+ } catch (error) {
41
+ cancel(colors.red(error instanceof NotAnError ? error.message : inspect(error)));
42
+ }
43
+ }
44
+ };
45
+
46
+ //#endregion
47
+ export { CreateSubcommand as default };
48
+ //# sourceMappingURL=create.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"create.mjs","names":[],"sources":["../../../src/bin/commands/create.ts"],"sourcesContent":["import { Command, Option } from 'commander';\nimport { CLISubcommand } from '../../classes/cli/CLISubcommand.js';\nimport { colors } from '@reciple/utils';\nimport { TemplateBuilder } from '../../classes/templates/TemplateBuilder.js';\nimport { cancel } from '@clack/prompts';\nimport { inspect } from 'node:util';\nimport { NotAnError } from '../../classes/NotAnError.js';\nimport type { PackageManagerName } from 'nypm';\n\nexport default class CreateSubcommand extends CLISubcommand {\n public subcommand: Command = new Command('create')\n .description('Create a new reciple project')\n .argument('[output]', 'The directory to create the project in')\n .option('-c, --config <path>', 'Path to the configuration file')\n .option('-t, --token <DiscordToken>', 'Set your Discord Bot token')\n .option('-T, --typescript', 'Use TypeScript')\n .addOption(new Option('-p, --package-manager <name>', 'The name of the package manager to use')\n .choices(['npm', 'yarn', 'pnpm', 'bun', 'deno'])\n )\n .option('-D, --default', 'Use defaults for prompts')\n .option('--install', 'Install dependencies during setup', true)\n .option('--build', 'Build the project after creation', true)\n .allowUnknownOption(true);\n\n public async execute(): Promise<void> {\n const flags = this.cli.getFlags<CreateSubcommand.Flags>('create');\n const template = new TemplateBuilder({\n cli: this.cli,\n directory: this.subcommand.args[0],\n typescript: flags?.typescript,\n packageManager: flags?.packageManager,\n defaultAll: flags?.default,\n token: flags?.token,\n });\n\n try {\n await template.init();\n await template.createDirectory();\n await template.setupLanguage();\n await template.createConfig();\n await template.setPackageManager();\n await template.createTemplate();\n await template.createEnvFile({ envFile: this.cli.flags.env[0] });\n await template.build({ skipInstallDependencies: !flags?.install, skipBuild: !flags?.build });\n } catch (error) {\n cancel(colors.red(error instanceof NotAnError ? error.message : inspect(error)));\n }\n }\n}\n\nexport namespace CreateSubcommand {\n export interface Flags {\n config?: string;\n token?: string;\n default?: boolean;\n typescript?: boolean;\n packageManager?: PackageManagerName;\n install: boolean;\n build: boolean;\n }\n}\n"],"mappings":";;;;;;;;;AASA,IAAqB,mBAArB,cAA8C,cAAc;CACxD,AAAO,aAAsB,IAAI,QAAQ,SAAS,CAC7C,YAAY,+BAA+B,CAC3C,SAAS,YAAY,yCAAyC,CAC9D,OAAO,uBAAuB,iCAAiC,CAC/D,OAAO,8BAA8B,6BAA6B,CAClE,OAAO,oBAAoB,iBAAiB,CAC5C,UAAU,IAAI,OAAO,gCAAgC,yCAAyC,CAC1F,QAAQ;EAAC;EAAO;EAAQ;EAAQ;EAAO;EAAO,CAAC,CACnD,CACA,OAAO,iBAAiB,2BAA2B,CACnD,OAAO,aAAa,qCAAqC,KAAK,CAC9D,OAAO,WAAW,oCAAoC,KAAK,CAC3D,mBAAmB,KAAK;CAE7B,MAAa,UAAyB;EAClC,MAAM,QAAQ,KAAK,IAAI,SAAiC,SAAS;EACjE,MAAM,WAAW,IAAI,gBAAgB;GACjC,KAAK,KAAK;GACV,WAAW,KAAK,WAAW,KAAK;GAChC,YAAY,OAAO;GACnB,gBAAgB,OAAO;GACvB,YAAY,OAAO;GACnB,OAAO,OAAO;GACjB,CAAC;AAEF,MAAI;AACA,SAAM,SAAS,MAAM;AACrB,SAAM,SAAS,iBAAiB;AAChC,SAAM,SAAS,eAAe;AAC9B,SAAM,SAAS,cAAc;AAC7B,SAAM,SAAS,mBAAmB;AAClC,SAAM,SAAS,gBAAgB;AAC/B,SAAM,SAAS,cAAc,EAAE,SAAS,KAAK,IAAI,MAAM,IAAI,IAAI,CAAC;AAChE,SAAM,SAAS,MAAM;IAAE,yBAAyB,CAAC,OAAO;IAAS,WAAW,CAAC,OAAO;IAAO,CAAC;WACvF,OAAO;AACZ,UAAO,OAAO,IAAI,iBAAiB,aAAa,MAAM,UAAU,QAAQ,MAAM,CAAC,CAAC"}
@@ -0,0 +1,21 @@
1
+ import { CLISubcommand } from "../../classes/cli/CLISubcommand.mjs";
2
+ import { Command } from "commander";
3
+
4
+ //#region src/bin/commands/createModule.d.ts
5
+ declare class CreateModuleSubcommand extends CLISubcommand {
6
+ subcommand: Command;
7
+ parent: string;
8
+ execute(): Promise<void>;
9
+ }
10
+ declare namespace CreateModuleSubcommand {
11
+ interface Flags {
12
+ template?: string;
13
+ filename?: string;
14
+ config?: string;
15
+ typescript?: boolean;
16
+ default?: boolean;
17
+ }
18
+ }
19
+ //#endregion
20
+ export { CreateModuleSubcommand, CreateModuleSubcommand as default };
21
+ //# sourceMappingURL=createModule.d.mts.map
@@ -0,0 +1,40 @@
1
+ import { NotAnError } from "../../classes/NotAnError.mjs";
2
+ import { CLISubcommand } from "../../classes/cli/CLISubcommand.mjs";
3
+ import { ConfigReader } from "../../classes/cli/ConfigReader.mjs";
4
+ import { ModuleTemplateBuilder } from "../../classes/templates/ModuleTemplateBuilder.mjs";
5
+ import { Command } from "commander";
6
+ import { colors } from "@reciple/utils";
7
+ import { cancel } from "@clack/prompts";
8
+ import { inspect } from "node:util";
9
+
10
+ //#region src/bin/commands/createModule.ts
11
+ var CreateModuleSubcommand = class extends CLISubcommand {
12
+ subcommand = new Command("module").description("Creates new module").argument("[output]", "The directory to create the module in").option("--template, -t <template>", "Template source name").option("--filename", "The filename of the module").option("-c, --config <path>", "Path to the configuration file").option("-T, --typescript", "Use TypeScript").option("-D, --default", "Use defaults for prompts").enablePositionalOptions(true);
13
+ parent = "create";
14
+ async execute() {
15
+ const flags = this.subcommand.opts();
16
+ const configReader = await new ConfigReader(flags.config ?? await ConfigReader.findConfig(process.cwd()) ?? ConfigReader.createConfigFilename("js")).read({ createIfNotExists: false });
17
+ const template = new ModuleTemplateBuilder({
18
+ cli: this.cli,
19
+ config: configReader,
20
+ typescript: flags.typescript,
21
+ filename: flags.filename,
22
+ defaultAll: flags?.default
23
+ });
24
+ try {
25
+ await template.init();
26
+ await template.setupLanguage();
27
+ await template.setupTemplate();
28
+ await template.setupPlaceholders();
29
+ await template.setupDirectory();
30
+ await template.setupFilename();
31
+ await template.build();
32
+ } catch (error) {
33
+ cancel(colors.red(error instanceof NotAnError ? error.message : inspect(error)));
34
+ }
35
+ }
36
+ };
37
+
38
+ //#endregion
39
+ export { CreateModuleSubcommand as default };
40
+ //# sourceMappingURL=createModule.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"createModule.mjs","names":[],"sources":["../../../src/bin/commands/createModule.ts"],"sourcesContent":["import { Command } from 'commander';\nimport { CLISubcommand } from '../../classes/cli/CLISubcommand.js';\nimport { ConfigReader } from '../../classes/cli/ConfigReader.js';\nimport { ModuleTemplateBuilder } from '../../classes/templates/ModuleTemplateBuilder.js';\nimport { cancel } from '@clack/prompts';\nimport { colors } from '@reciple/utils';\nimport { NotAnError } from '../../classes/NotAnError.js';\nimport { inspect } from 'node:util';\n\nexport default class CreateModuleSubcommand extends CLISubcommand {\n public subcommand: Command = new Command('module')\n .description('Creates new module')\n .argument('[output]', 'The directory to create the module in')\n .option('--template, -t <template>', 'Template source name')\n .option('--filename', 'The filename of the module')\n .option('-c, --config <path>', 'Path to the configuration file')\n .option('-T, --typescript', 'Use TypeScript')\n .option('-D, --default', 'Use defaults for prompts')\n .enablePositionalOptions(true);\n\n public parent: string = 'create';\n\n public async execute(): Promise<void> {\n const flags = this.subcommand.opts<CreateModuleSubcommand.Flags>();\n\n const configReader = await (\n new ConfigReader(\n flags.config\n ?? await ConfigReader.findConfig(process.cwd())\n ?? ConfigReader.createConfigFilename('js')\n ).read({\n createIfNotExists: false\n })\n );\n\n const template = new ModuleTemplateBuilder({\n cli: this.cli,\n config: configReader,\n typescript: flags.typescript,\n filename: flags.filename,\n defaultAll: flags?.default\n });\n\n try {\n await template.init();\n await template.setupLanguage();\n await template.setupTemplate();\n await template.setupPlaceholders();\n await template.setupDirectory();\n await template.setupFilename();\n await template.build();\n } catch (error) {\n cancel(colors.red(error instanceof NotAnError ? error.message : inspect(error)));\n }\n }\n}\n\nexport namespace CreateModuleSubcommand {\n export interface Flags {\n template?: string;\n filename?: string;\n config?: string;\n typescript?: boolean;\n default?: boolean;\n }\n}\n"],"mappings":";;;;;;;;;;AASA,IAAqB,yBAArB,cAAoD,cAAc;CAC9D,AAAO,aAAsB,IAAI,QAAQ,SAAS,CAC7C,YAAY,qBAAqB,CACjC,SAAS,YAAY,wCAAwC,CAC7D,OAAO,6BAA6B,uBAAuB,CAC3D,OAAO,cAAc,6BAA6B,CAClD,OAAO,uBAAuB,iCAAiC,CAC/D,OAAO,oBAAoB,iBAAiB,CAC5C,OAAO,iBAAiB,2BAA2B,CACnD,wBAAwB,KAAK;CAElC,AAAO,SAAiB;CAExB,MAAa,UAAyB;EAClC,MAAM,QAAQ,KAAK,WAAW,MAAoC;EAElE,MAAM,eAAe,MACjB,IAAI,aACA,MAAM,UACH,MAAM,aAAa,WAAW,QAAQ,KAAK,CAAC,IAC5C,aAAa,qBAAqB,KAAK,CAC7C,CAAC,KAAK,EACH,mBAAmB,OACtB,CAAC;EAGN,MAAM,WAAW,IAAI,sBAAsB;GACvC,KAAK,KAAK;GACV,QAAQ;GACR,YAAY,MAAM;GAClB,UAAU,MAAM;GAChB,YAAY,OAAO;GACtB,CAAC;AAEF,MAAI;AACA,SAAM,SAAS,MAAM;AACrB,SAAM,SAAS,eAAe;AAC9B,SAAM,SAAS,eAAe;AAC9B,SAAM,SAAS,mBAAmB;AAClC,SAAM,SAAS,gBAAgB;AAC/B,SAAM,SAAS,eAAe;AAC9B,SAAM,SAAS,OAAO;WACjB,OAAO;AACZ,UAAO,OAAO,IAAI,iBAAiB,aAAa,MAAM,UAAU,QAAQ,MAAM,CAAC,CAAC"}
@@ -0,0 +1,18 @@
1
+ import { CLISubcommand } from "../../classes/cli/CLISubcommand.mjs";
2
+ import { Command } from "commander";
3
+
4
+ //#region src/bin/commands/start.d.ts
5
+ declare class StartSubcommand extends CLISubcommand {
6
+ subcommand: Command;
7
+ execute(): Promise<void>;
8
+ }
9
+ declare namespace StartSubcommand {
10
+ interface Flags {
11
+ config?: string;
12
+ token?: string;
13
+ build?: boolean;
14
+ }
15
+ }
16
+ //#endregion
17
+ export { StartSubcommand, StartSubcommand as default };
18
+ //# sourceMappingURL=start.d.mts.map
@@ -0,0 +1,104 @@
1
+ import { CLISubcommand } from "../../classes/cli/CLISubcommand.mjs";
2
+ import { CLI } from "../../classes/cli/CLI.mjs";
3
+ import { ConfigReader } from "../../classes/cli/ConfigReader.mjs";
4
+ import { RuntimeEnvironment } from "../../classes/cli/RuntimeEnvironment.mjs";
5
+ import { EventListeners } from "../../classes/client/EventListeners.mjs";
6
+ import { ModuleLoader } from "../../classes/client/ModuleLoader.mjs";
7
+ import { ModuleManager } from "../../classes/managers/ModuleManager.mjs";
8
+ import { Logger } from "prtyprnt";
9
+ import { Command } from "commander";
10
+ import { Format, colors, resolveEnvProtocol } from "@reciple/utils";
11
+ import { Client, CommandType } from "@reciple/core";
12
+ import { version } from "discord.js";
13
+ import { build } from "tsdown";
14
+
15
+ //#region src/bin/commands/start.ts
16
+ var StartSubcommand = class extends CLISubcommand {
17
+ subcommand = new Command("start").description("Start the reciple client").option("-c, --config <path>", "Path to the configuration file").option("-t, --token <DiscordToken>", "Set your Discord Bot token").option("-b, --build", "Build the modules before starting the client").allowUnknownOption(true);
18
+ async execute() {
19
+ const flags = this.subcommand.opts();
20
+ const { client, config, build: buildConfig } = await new ConfigReader(flags.config ?? await ConfigReader.findConfig(process.cwd()) ?? ConfigReader.createConfigFilename("js")).read({ createIfNotExists: false });
21
+ const logger$1 = config.logger instanceof Logger ? this.cli.logger = config.logger : this.cli.logger.clone(config.logger);
22
+ let token = flags.token || config.token || "";
23
+ token = resolveEnvProtocol(token) || token;
24
+ function handleProcessError(err) {
25
+ logger$1.error(err);
26
+ process.exit(1);
27
+ }
28
+ process.once("uncaughtException", handleProcessError);
29
+ process.once("unhandledRejection", handleProcessError);
30
+ process.on("warning", (warn) => logger$1.warn(warn));
31
+ logger$1.log(colors.magenta(`⚡ Initializing reciple!`));
32
+ if (flags.build) {
33
+ let plugins = buildConfig.plugins ? Array.isArray(buildConfig.plugins) ? buildConfig.plugins : [buildConfig.plugins] : [];
34
+ plugins.push(CLI.createTsdownLogger());
35
+ await build({
36
+ ...buildConfig,
37
+ logLevel: "silent",
38
+ plugins
39
+ });
40
+ }
41
+ Object.assign(client, {
42
+ logger: logger$1,
43
+ cli: this.cli,
44
+ config
45
+ });
46
+ Object.assign(client, {
47
+ modules: new ModuleManager(client),
48
+ moduleLoader: new ModuleLoader(client),
49
+ eventListeners: new EventListeners()
50
+ });
51
+ Reflect.set(global, "useClient", () => client);
52
+ Reflect.set(global, "useLogger", () => logger$1);
53
+ EventListeners.registerLoggerEventListeners(client);
54
+ logger$1.log(colors.green(`📦 Version Info:`));
55
+ logger$1.log(` ├─ ${colors.cyan(`reciple`)}\t\t${colors.yellow(`${this.cli.version}`)}`);
56
+ logger$1.log(` ├─ ${colors.cyan(`@reciple/client`)}\t${colors.yellow(`${Client.version}`)}`);
57
+ logger$1.log(` └─ ${colors.cyan(`discord.js`)}\t${colors.yellow(`${version}`)}`);
58
+ const modules = await client.moduleLoader.findModules();
59
+ Object.assign(client, {
60
+ _onBeforeLogin: async () => {
61
+ const enabledModules = await client.modules.enableModules({ modules });
62
+ client.once("clientReady", async () => {
63
+ if (!client.isReady()) return;
64
+ EventListeners.registerCommandsEventListeners(client);
65
+ logger$1.debug(`Client is ready!`);
66
+ process.removeListener("uncaughtException", handleProcessError);
67
+ process.removeListener("unhandledRejection", handleProcessError);
68
+ const notEnabledModules = modules.length - enabledModules.length;
69
+ logger$1.log(colors.green(`✅ ${enabledModules.length} ${Format.plural(enabledModules.length, "module")} ${Format.plural(enabledModules.length, "is", "are")} enabled.${notEnabledModules > 0 ? colors.red(` (${notEnabledModules} not enabled)`) : ""}`));
70
+ const readyModules = await client.modules.readyModules();
71
+ const notReadyModules = readyModules.length - enabledModules.length;
72
+ logger$1.log(colors.green(`✅ ${readyModules.length} ${Format.plural(readyModules.length, "module")} ${Format.plural(readyModules.length, "is", "are")} ready.${notReadyModules > 0 ? colors.red(` (${notReadyModules} not ready)`) : ""}`));
73
+ await client.commands.registerApplicationCommands({
74
+ ...config.applicationCommandsRegister,
75
+ commands: client.commands.applicationCommands
76
+ });
77
+ process.stdin.resume();
78
+ const commands = {
79
+ contextMenus: client.commands.cache.filter((c) => c.type === CommandType.ContextMenu).size,
80
+ message: client.commands.cache.filter((c) => c.type === CommandType.Message).size,
81
+ slash: client.commands.cache.filter((c) => c.type === CommandType.Slash).size
82
+ };
83
+ logger$1.log(`🔑 Logged in as ${colors.bold(colors.cyan(client.user.displayName))} ${colors.magenta(`(${client.user.id})`)}`);
84
+ logger$1.log(` ├─ Loaded ${colors.green(modules.length)} ${Format.plural(modules.length, "module")}.`);
85
+ logger$1.log(` ├─ Loaded ${colors.green(commands.contextMenus)} context menu ${Format.plural(commands.contextMenus, "command")}.`);
86
+ logger$1.log(` ├─ Loaded ${colors.green(commands.message)} message ${Format.plural(commands.message, "command")}.`);
87
+ logger$1.log(` ├─ Loaded ${colors.green(commands.slash)} slash ${Format.plural(commands.slash, "command")}.`);
88
+ logger$1.log(` ├─ Loaded ${colors.green(client.preconditions.cache.size)} global ${Format.plural(client.preconditions.cache.size, "precondition")}.`);
89
+ logger$1.log(` └─ Loaded ${colors.green(client.postconditions.cache.size)} global ${Format.plural(client.postconditions.cache.size, "postcondition")}.`);
90
+ });
91
+ client.eventListeners.registerProcessExitEvents(async (signal) => RuntimeEnvironment.handleExitSignal(client, signal));
92
+ },
93
+ _onBeforeDestroy: async (client$1) => {
94
+ await client$1.modules.disableModules();
95
+ }
96
+ });
97
+ logger$1.debug(`Logging in...`);
98
+ await client.login(token);
99
+ }
100
+ };
101
+
102
+ //#endregion
103
+ export { StartSubcommand as default };
104
+ //# sourceMappingURL=start.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"start.mjs","names":["logger","DiscordJsVersion","client"],"sources":["../../../src/bin/commands/start.ts"],"sourcesContent":["import { Command } from 'commander';\nimport { CLISubcommand } from '../../classes/cli/CLISubcommand.js';\nimport { ConfigReader } from '../../classes/cli/ConfigReader.js';\nimport { Logger } from 'prtyprnt';\nimport { colors, Format, resolveEnvProtocol } from '@reciple/utils';\nimport { Client, CommandType } from '@reciple/core';\nimport { ModuleLoader } from '../../classes/client/ModuleLoader.js';\nimport { ModuleManager } from '../../classes/managers/ModuleManager.js';\nimport { version as DiscordJsVersion } from 'discord.js';\nimport { EventListeners } from '../../classes/client/EventListeners.js';\nimport { RuntimeEnvironment } from '../../classes/cli/RuntimeEnvironment.js';\nimport { build } from 'tsdown';\nimport { CLI } from '../../classes/cli/CLI.js';\n\nexport default class StartSubcommand extends CLISubcommand {\n public subcommand: Command = new Command('start')\n .description('Start the reciple client')\n .option('-c, --config <path>', 'Path to the configuration file')\n .option('-t, --token <DiscordToken>', 'Set your Discord Bot token')\n .option('-b, --build', 'Build the modules before starting the client')\n .allowUnknownOption(true);\n\n public async execute(): Promise<void> {\n const flags = this.subcommand.opts<StartSubcommand.Flags>();\n const configReader = new ConfigReader(\n flags.config\n ?? await ConfigReader.findConfig(process.cwd())\n ?? ConfigReader.createConfigFilename('js')\n );\n\n const { client, config, build: buildConfig } = await configReader.read({\n createIfNotExists: false\n });\n\n const logger = config.logger instanceof Logger ? this.cli.logger = config.logger : this.cli.logger.clone(config.logger);\n\n let token = flags.token || config.token || '';\n token = resolveEnvProtocol(token) || token;\n\n function handleProcessError(err: unknown) {\n logger.error(err);\n process.exit(1);\n }\n\n process.once('uncaughtException', handleProcessError);\n process.once('unhandledRejection', handleProcessError);\n process.on('warning', warn => logger.warn(warn));\n\n logger.log(colors.magenta(`⚡ Initializing reciple!`));\n\n if (flags.build) {\n let plugins = buildConfig.plugins\n ? Array.isArray(buildConfig.plugins)\n ? buildConfig.plugins\n : [buildConfig.plugins]\n : [];\n\n plugins.push(CLI.createTsdownLogger());\n\n await build({\n ...buildConfig,\n logLevel: 'silent',\n plugins,\n });\n }\n\n Object.assign(client, {\n logger,\n cli: this.cli,\n config\n });\n\n Object.assign(client, {\n modules: new ModuleManager(client),\n moduleLoader: new ModuleLoader(client),\n eventListeners: new EventListeners()\n });\n\n Reflect.set(global, 'useClient', () => client);\n Reflect.set(global, 'useLogger', () => logger);\n\n EventListeners.registerLoggerEventListeners(client);\n\n logger.log(colors.green(`📦 Version Info:`));\n logger.log(` ├─ ${colors.cyan(`reciple`)}\\t\\t${colors.yellow(`${this.cli.version}`)}`);\n logger.log(` ├─ ${colors.cyan(`@reciple/client`)}\\t${colors.yellow(`${Client.version}`)}`);\n logger.log(` └─ ${colors.cyan(`discord.js`)}\\t${colors.yellow(`${DiscordJsVersion}`)}`);\n\n const modules = await client.moduleLoader.findModules();\n\n Object.assign(client, {\n _onBeforeLogin: async() => {\n const enabledModules = await client.modules.enableModules({ modules });\n\n client.once('clientReady', async() => {\n if (!client.isReady()) return;\n\n EventListeners.registerCommandsEventListeners(client);\n\n logger.debug(`Client is ready!`);\n process.removeListener('uncaughtException', handleProcessError);\n process.removeListener('unhandledRejection', handleProcessError);\n\n const notEnabledModules = modules.length - enabledModules.length;\n logger.log(colors.green(`✅ ${enabledModules.length} ${Format.plural(enabledModules.length, 'module')} ${Format.plural(enabledModules.length, 'is', 'are')} enabled.${notEnabledModules > 0 ? colors.red(` (${notEnabledModules} not enabled)`) : ''}`));\n\n const readyModules = await client.modules.readyModules();\n const notReadyModules = readyModules.length - enabledModules.length;\n\n logger.log(colors.green(`✅ ${readyModules.length} ${Format.plural(readyModules.length, 'module')} ${Format.plural(readyModules.length, 'is', 'are')} ready.${notReadyModules > 0 ? colors.red(` (${notReadyModules} not ready)`) : ''}`));\n\n await client.commands.registerApplicationCommands({\n ...config.applicationCommandsRegister,\n commands: client.commands.applicationCommands,\n });\n\n process.stdin.resume();\n\n const commands = {\n contextMenus: client.commands.cache.filter(c => c.type === CommandType.ContextMenu).size,\n message: client.commands.cache.filter(c => c.type === CommandType.Message).size,\n slash: client.commands.cache.filter(c => c.type === CommandType.Slash).size\n };\n\n logger.log(`🔑 Logged in as ${colors.bold(colors.cyan(client.user.displayName))} ${colors.magenta(`(${client.user.id})`)}`);\n logger.log(` ├─ Loaded ${colors.green(modules.length)} ${Format.plural(modules.length, 'module')}.`);\n logger.log(` ├─ Loaded ${colors.green(commands.contextMenus)} context menu ${Format.plural(commands.contextMenus, 'command')}.`);\n logger.log(` ├─ Loaded ${colors.green(commands.message)} message ${Format.plural(commands.message, 'command')}.`);\n logger.log(` ├─ Loaded ${colors.green(commands.slash)} slash ${Format.plural(commands.slash, 'command')}.`);\n logger.log(` ├─ Loaded ${colors.green(client.preconditions.cache.size)} global ${Format.plural(client.preconditions.cache.size, 'precondition')}.`);\n logger.log(` └─ Loaded ${colors.green(client.postconditions.cache.size)} global ${Format.plural(client.postconditions.cache.size, 'postcondition')}.`);\n });\n\n client.eventListeners.registerProcessExitEvents(async signal => RuntimeEnvironment.handleExitSignal(client, signal));\n },\n _onBeforeDestroy: async (client: Client) => {\n await client.modules.disableModules();\n }\n })\n\n logger.debug(`Logging in...`);\n await client.login(token);\n }\n}\n\nexport namespace StartSubcommand {\n export interface Flags {\n config?: string;\n token?: string;\n build?: boolean;\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;AAcA,IAAq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OAAO,MAAM,OAAO,eAAe,MAAM,KAAK,CAAC,UAAU,OAAO,OAAO,OAAO,eAAe,MAAM,MAAM,gBAAgB,CAAC,GAAG;MACxJ;AAEF,WAAO,eAAe,0BAA0B,OAAM,WAAU,mBAAmB,iBAAiB,QAAQ,OAAO,CAAC;;GAExH,kBAAkB,OAAO,aAAmB;AACxC,UAAMC,SAAO,QAAQ,gBAAgB;;GAE5C,CAAC;AAEF,WAAO,MAAM,gBAAgB;AAC7B,QAAM,OAAO,MAAM,MAAM"}
@@ -0,0 +1 @@
1
+ export { };
@@ -0,0 +1,9 @@
1
+ #!/usr/bin/env node
2
+ import { cli } from "../helpers/constants.mjs";
3
+
4
+ //#region src/bin/reciple.ts
5
+ await cli.parse();
6
+
7
+ //#endregion
8
+ export { };
9
+ //# sourceMappingURL=reciple.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"reciple.mjs","names":[],"sources":["../../src/bin/reciple.ts"],"sourcesContent":["#!/usr/bin/env node\nimport { cli } from '../helpers/constants.js';\n\nawait cli.parse();\n"],"mappings":";;;;AAGA,MAAM,IAAI,OAAO"}
@@ -0,0 +1,7 @@
1
+ //#region src/classes/NotAnError.d.ts
2
+ declare class NotAnError extends Error {
3
+ constructor(message: string);
4
+ }
5
+ //#endregion
6
+ export { NotAnError };
7
+ //# sourceMappingURL=NotAnError.d.mts.map
@@ -0,0 +1,11 @@
1
+ //#region src/classes/NotAnError.ts
2
+ var NotAnError = class extends Error {
3
+ constructor(message) {
4
+ super(message);
5
+ this.name = "NotAnError";
6
+ }
7
+ };
8
+
9
+ //#endregion
10
+ export { NotAnError };
11
+ //# sourceMappingURL=NotAnError.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"NotAnError.mjs","names":[],"sources":["../../src/classes/NotAnError.ts"],"sourcesContent":["export class NotAnError extends Error {\n constructor(message: string) {\n super(message);\n this.name = 'NotAnError';\n }\n}\n"],"mappings":";AAAA,IAAa,aAAb,cAAgC,MAAM;CAClC,YAAY,SAAiB;AACzB,QAAM,QAAQ;AACd,OAAK,OAAO"}
@@ -0,0 +1,54 @@
1
+ import { Logger } from "prtyprnt";
2
+ import { Command } from "commander";
3
+ import { SpinnerOptions, spinner } from "@clack/prompts";
4
+ import { RolldownPlugin } from "rolldown";
5
+
6
+ //#region src/classes/cli/CLI.d.ts
7
+ declare class CLI {
8
+ readonly options: CLI.Options;
9
+ build: string;
10
+ version: string;
11
+ command: Command;
12
+ logger: Logger;
13
+ get isDebugging(): boolean;
14
+ get flags(): CLI.Flags;
15
+ constructor(options: CLI.Options);
16
+ parse(argv?: string[]): Promise<this>;
17
+ loadCommands(): Promise<void>;
18
+ handlePreAction(cmd: Command, action: Command): Promise<void>;
19
+ getFlags<Flags extends Record<string, any> = Record<string, any>>(command: Command | string, mergeDefault?: false): Flags | undefined;
20
+ getFlags<Flags extends Record<string, any> = Record<string, any>>(command: Command | string, mergeDefault: true): Flags & CLI.Flags | undefined;
21
+ getFlags(command?: undefined): CLI.Flags;
22
+ getCommand(name: string): Command | undefined;
23
+ getCommand(name?: undefined): Command;
24
+ }
25
+ declare namespace CLI {
26
+ interface Options {
27
+ name: string;
28
+ description: string;
29
+ build: string;
30
+ subcommandsDir: string;
31
+ logger?: Logger | Logger.Options;
32
+ }
33
+ interface Flags {
34
+ debug: boolean;
35
+ env: string[];
36
+ }
37
+ const root: string;
38
+ const bin: string;
39
+ const version: string | undefined;
40
+ function stringifyFlags(flags: Record<string, any>, command: Command, ignored?: string[]): string[];
41
+ interface SpinnerPromiseOptions<T> {
42
+ indicator?: SpinnerOptions['indicator'];
43
+ promise: Promise<T>;
44
+ message?: string;
45
+ successMessage?: string;
46
+ errorMessage?: string;
47
+ }
48
+ function createSpinnerPromise<T>(options: SpinnerPromiseOptions<T>): [Promise<T>, ReturnType<typeof spinner>];
49
+ function createTsdownLogger(_logger?: Logger): RolldownPlugin;
50
+ const ignoredDefault: string[];
51
+ }
52
+ //#endregion
53
+ export { CLI };
54
+ //# sourceMappingURL=CLI.d.mts.map
@@ -0,0 +1,156 @@
1
+ import { CLISubcommand } from "./CLISubcommand.mjs";
2
+ import { LogLevel, Logger, logger } from "prtyprnt";
3
+ import { Command } from "commander";
4
+ import { fileURLToPath } from "node:url";
5
+ import path from "node:path";
6
+ import { coerce } from "semver";
7
+ import { Format, colors, isDebugging, recursiveDefaults } from "@reciple/utils";
8
+ import { config } from "@dotenvx/dotenvx";
9
+ import { readdir, stat } from "node:fs/promises";
10
+ import { spinner } from "@clack/prompts";
11
+
12
+ //#region src/classes/cli/CLI.ts
13
+ var CLI = class {
14
+ build;
15
+ version;
16
+ command;
17
+ logger;
18
+ get isDebugging() {
19
+ return this.flags.debug;
20
+ }
21
+ get flags() {
22
+ return this.command.opts();
23
+ }
24
+ constructor(options) {
25
+ this.options = options;
26
+ this.build = options.build;
27
+ this.version = String(coerce(this.build) ?? this.build);
28
+ this.command = new Command().name(options.name).description(options.description).version(options.build, "-v, --version", "Output the CLI version number").option("-D, --debug", "Enable debug mode", isDebugging()).option("--env <file>", "Load environment variables from .env file", (v, p) => p.concat(v), []).enablePositionalOptions(true).hook("preAction", this.handlePreAction.bind(this)).showHelpAfterError();
29
+ this.logger = options.logger instanceof Logger ? options.logger : new Logger(options.logger);
30
+ if (this.flags.debug) {
31
+ this.logger.logLevel = LogLevel.Debug;
32
+ this.logger.writeLevel = LogLevel.Debug;
33
+ }
34
+ }
35
+ async parse(argv) {
36
+ await this.loadCommands();
37
+ await this.command.parseAsync(argv);
38
+ return this;
39
+ }
40
+ async loadCommands() {
41
+ this.logger.debug(`Loading cli commands from ${this.options.subcommandsDir}`);
42
+ if (!(await stat(this.options.subcommandsDir).catch(() => void 0))?.isDirectory()) return;
43
+ const files = (await readdir(this.options.subcommandsDir)).map((f) => path.join(this.options.subcommandsDir, f)).filter((f) => f.endsWith(".mjs"));
44
+ const hasParent = [];
45
+ for (const file of files) {
46
+ const Subommand = recursiveDefaults(await (path.isAbsolute(file) ? import(`file://${file}`) : import(file)));
47
+ if (!Subommand || typeof Subommand !== "function") continue;
48
+ const instance = new Subommand({
49
+ cli: this,
50
+ command: this.command
51
+ });
52
+ if (instance.parent) {
53
+ hasParent.push(instance);
54
+ continue;
55
+ }
56
+ CLISubcommand.registerSubcommand(instance);
57
+ }
58
+ for (const instance of hasParent) CLISubcommand.registerSubcommand(instance);
59
+ }
60
+ async handlePreAction(cmd, action) {
61
+ this.logger.debug(`Executing ${action.name()}`);
62
+ this.logger.debug(`Debug mode is ${this.flags.debug ? "enabled" : "disabled"}`);
63
+ process.env.NODE_ENV = this.flags.debug ? "development" : process.env.NODE_ENV;
64
+ config({
65
+ path: this.flags.env.length ? this.flags.env : [path.join(process.cwd(), ".env")],
66
+ debug: this.flags.debug,
67
+ quiet: !this.flags.debug,
68
+ ignore: ["MISSING_ENV_FILE"]
69
+ });
70
+ this.logger.debug(`Loaded environment variables from ${this.flags.env.join(", ")}`);
71
+ }
72
+ getFlags(command, mergeDefault = false) {
73
+ if (!command) return this.flags;
74
+ command = typeof command === "string" ? this.command.commands.find((c) => c.name() === command) : command;
75
+ const flags = command?.opts();
76
+ return mergeDefault ? {
77
+ ...this.flags,
78
+ ...flags
79
+ } : flags;
80
+ }
81
+ getCommand(name) {
82
+ if (!name) return this.command;
83
+ return this.command.commands.find((c) => c.name() === name);
84
+ }
85
+ };
86
+ (function(_CLI) {
87
+ _CLI.root = path.join(path.dirname(fileURLToPath(import.meta.url)), "../../../");
88
+ _CLI.bin = path.join(CLI.root, "dist/bin/reciple.js");
89
+ _CLI.version = "10.0.0";
90
+ function stringifyFlags(flags, command, ignored = []) {
91
+ let arr = [];
92
+ for (const [key, value] of Object.entries(flags)) {
93
+ const option = command.options.find((o) => o.name() === key || o.attributeName() === key);
94
+ if (!option || ignored.includes(key)) continue;
95
+ const flag = option.long ?? option.short ?? `--${option.name()}`;
96
+ if (!option.flags.endsWith(">") && !option.flags.endsWith("]") && typeof value === "boolean") {
97
+ if (value) arr.push(flag);
98
+ continue;
99
+ }
100
+ arr.push(flag, String(value));
101
+ }
102
+ return arr;
103
+ }
104
+ _CLI.stringifyFlags = stringifyFlags;
105
+ function createSpinnerPromise(options) {
106
+ const loader = spinner({ indicator: options.indicator });
107
+ return [new Promise((resolve, reject) => {
108
+ loader.start(options.message);
109
+ options.promise.then((value) => {
110
+ loader.stop(options.successMessage);
111
+ resolve(value);
112
+ }).catch((error) => {
113
+ loader.stop(options.errorMessage);
114
+ reject(error);
115
+ });
116
+ }), loader];
117
+ }
118
+ _CLI.createSpinnerPromise = createSpinnerPromise;
119
+ function createTsdownLogger(_logger = logger) {
120
+ let startedAt;
121
+ return {
122
+ name: "reciple:log-build-completion",
123
+ buildStart: () => {
124
+ _logger.log(colors.green("🚀 Building reciple modules..."));
125
+ startedAt = Date.now();
126
+ },
127
+ renderChunk: (code, info) => {
128
+ const size = Format.bytes(Buffer.byteLength(code, "utf8"));
129
+ _logger.log(` ├─ ${colors.cyan(size)}\t${colors.bold(info.fileName)}`);
130
+ return { code };
131
+ },
132
+ buildEnd: (error) => {
133
+ if (error) _logger.error(error);
134
+ },
135
+ closeBundle: () => {
136
+ const time = Format.duration(Date.now() - startedAt);
137
+ _logger.log(colors.green(`✅ Build success in `) + colors.yellow(`${time}`));
138
+ }
139
+ };
140
+ }
141
+ _CLI.createTsdownLogger = createTsdownLogger;
142
+ _CLI.ignoredDefault = [
143
+ ".git",
144
+ ".log",
145
+ ".nyc_output",
146
+ ".sass-cache",
147
+ ".yarn",
148
+ "bower_components",
149
+ "coverage",
150
+ "node_modules"
151
+ ];
152
+ })(CLI || (CLI = {}));
153
+
154
+ //#endregion
155
+ export { CLI };
156
+ //# sourceMappingURL=CLI.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"CLI.mjs","names":[],"sources":["../../../src/classes/cli/CLI.ts"],"sourcesContent":["import { Command } from 'commander';\nimport { fileURLToPath } from 'node:url';\nimport path from 'node:path';\nimport { coerce } from 'semver';\nimport { colors, Format, isDebugging, recursiveDefaults } from '@reciple/utils';\nimport { logger, Logger, LogLevel } from 'prtyprnt';\nimport { config as loadEnv } from '@dotenvx/dotenvx';\nimport { readdir, stat } from 'node:fs/promises';\nimport { CLISubcommand } from './CLISubcommand.js';\nimport { spinner, type SpinnerOptions } from '@clack/prompts';\nimport type { RolldownPlugin } from 'rolldown';\n\nexport class CLI {\n public build: string;\n public version: string;\n public command: Command;\n public logger: Logger;\n\n get isDebugging(): boolean {\n return this.flags.debug;\n }\n\n get flags(): CLI.Flags {\n return this.command.opts();\n }\n\n constructor(public readonly options: CLI.Options) {\n this.build = options.build;\n this.version = String(coerce(this.build) ?? this.build);\n\n this.command = new Command()\n .name(options.name)\n .description(options.description)\n .version(options.build, '-v, --version', 'Output the CLI version number')\n .option('-D, --debug', 'Enable debug mode', isDebugging())\n .option('--env <file>', 'Load environment variables from .env file', (v, p) => p.concat(v), [] as string[])\n .enablePositionalOptions(true)\n .hook('preAction', this.handlePreAction.bind(this))\n .showHelpAfterError();\n\n this.logger = options.logger instanceof Logger ? options.logger : new Logger(options.logger);\n\n if (this.flags.debug) {\n this.logger.logLevel = LogLevel.Debug;\n this.logger.writeLevel = LogLevel.Debug;\n }\n }\n\n public async parse(argv?: string[]): Promise<this> {\n await this.loadCommands();\n await this.command.parseAsync(argv);\n return this;\n }\n\n public async loadCommands(): Promise<void> {\n this.logger.debug(`Loading cli commands from ${this.options.subcommandsDir}`);\n\n const dirStat = await stat(this.options.subcommandsDir).catch(() => undefined);\n if (!dirStat?.isDirectory()) return;\n\n const files = (await readdir(this.options.subcommandsDir))\n .map(f => path.join(this.options.subcommandsDir, f))\n .filter(f => f.endsWith('.mjs'));\n\n const hasParent: CLISubcommand[] = [];\n\n for (const file of files) {\n const Subommand = recursiveDefaults<CLISubcommand.Constructor>(await import(path.isAbsolute(file) ? `file://${file}` : file));\n if (!Subommand || typeof Subommand !== 'function') continue;\n\n const instance = new Subommand({ cli: this, command: this.command });\n\n if (instance.parent) {\n hasParent.push(instance);\n continue;\n }\n\n CLISubcommand.registerSubcommand(instance);\n }\n\n for (const instance of hasParent) {\n CLISubcommand.registerSubcommand(instance);\n }\n }\n\n public async handlePreAction(cmd: Command, action: Command): Promise<void> {\n this.logger.debug(`Executing ${action.name()}`);\n this.logger.debug(`Debug mode is ${this.flags.debug ? 'enabled' : 'disabled'}`);\n process.env.NODE_ENV = this.flags.debug ? 'development' : process.env.NODE_ENV;\n\n loadEnv({\n path: this.flags.env.length ? this.flags.env : [path.join(process.cwd(), '.env')],\n debug: this.flags.debug,\n quiet: !this.flags.debug,\n ignore: ['MISSING_ENV_FILE']\n });\n\n this.logger.debug(`Loaded environment variables from ${this.flags.env.join(', ')}`);\n }\n\n public getFlags<Flags extends Record<string, any> = Record<string, any>>(command: Command|string, mergeDefault?: false): Flags|undefined;\n public getFlags<Flags extends Record<string, any> = Record<string, any>>(command: Command|string, mergeDefault: true): Flags & CLI.Flags|undefined;\n public getFlags(command?: undefined): CLI.Flags;\n public getFlags(command?: Command|string, mergeDefault: boolean = false): Record<string, any>|undefined {\n if (!command) return this.flags;\n\n command = typeof command === 'string' ? this.command.commands.find(c => c.name() === command) : command;\n const flags = command?.opts();\n\n return mergeDefault ? { ...this.flags, ...flags } : flags;\n }\n\n public getCommand(name: string): Command|undefined;\n public getCommand(name?: undefined): Command;\n public getCommand(name?: string): Command|undefined {\n if (!name) return this.command;\n\n return this.command.commands.find(c => c.name() === name);\n }\n}\n\nexport namespace CLI {\n export interface Options {\n name: string;\n description: string;\n build: string;\n subcommandsDir: string;\n logger?: Logger|Logger.Options;\n }\n\n export interface Flags {\n debug: boolean;\n env: string[];\n }\n\n export const root: string = path.join(path.dirname(fileURLToPath(import.meta.url)), '../../../');\n export const bin: string = path.join(CLI.root, 'dist/bin/reciple.js');\n export const version = process.env.__VERSION__;\n\n export function stringifyFlags(flags: Record<string, any>, command: Command, ignored: string[] = []): string[] {\n let arr: string[] = [];\n\n for (const [key, value] of Object.entries(flags)) {\n const option = command.options.find(o => o.name() === key || o.attributeName() === key);\n if (!option || ignored.includes(key)) continue;\n\n const flag = option.long ?? option.short ?? `--${option.name()}`;\n\n if (!option.flags.endsWith('>') && !option.flags.endsWith(']') && typeof value === 'boolean') {\n if (value) arr.push(flag);\n continue;\n }\n\n arr.push(flag, String(value));\n }\n\n return arr;\n }\n\n export interface SpinnerPromiseOptions<T> {\n indicator?: SpinnerOptions['indicator'];\n promise: Promise<T>;\n message?: string;\n successMessage?: string;\n errorMessage?: string;\n }\n\n export function createSpinnerPromise<T>(options: SpinnerPromiseOptions<T>): [Promise<T>, ReturnType<typeof spinner>] {\n const loader = spinner({ indicator: options.indicator });\n\n return [\n new Promise<T>((resolve, reject) => {\n loader.start(options.message);\n\n options.promise\n .then((value) => {\n loader.stop(options.successMessage);\n resolve(value);\n })\n .catch((error) => {\n loader.stop(options.errorMessage);\n reject(error);\n });\n }),\n loader\n ];\n }\n\n export function createTsdownLogger(_logger: Logger = logger): RolldownPlugin {\n let startedAt: number;\n\n return {\n name: 'reciple:log-build-completion',\n buildStart: () => {\n _logger.log(colors.green('🚀 Building reciple modules...'));\n startedAt = Date.now();\n },\n renderChunk: (code, info) => {\n const size = Format.bytes(Buffer.byteLength(code, 'utf8'));\n _logger.log(` ├─ ${colors.cyan(size)}\\t${colors.bold(info.fileName)}`);\n\n return { code };\n },\n buildEnd: error => {\n if (error) _logger.error(error)\n },\n closeBundle: () => {\n const time = Format.duration(Date.now() - startedAt);\n _logger.log(colors.green(`✅ Build success in `) + colors.yellow(`${time}`));\n }\n };\n }\n\n export const ignoredDefault = [\n '.git',\n '.log',\n '.nyc_output',\n '.sass-cache',\n '.yarn',\n 'bower_components',\n 'coverage',\n 'node_modules'\n ]\n}\n"],"mappings":";;;;;;;;;;;;AAYA,IAAa,MAAb,MAAiB;CACb,AAAO;CACP,AAAO;CACP,AAAO;CACP,AAAO;CAEP,IAAI,cAAuB;AACvB,SAAO,KAAK,MAAM;;CAGtB,IAAI,QAAmB;AACnB,SAAO,KAAK,QAAQ,MAAM;;CA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GAEnB,WAAU,UAAS;AACf,QAAI,MAAO,SAAQ,MAAM,MAAK;;GAElC,mBAAmB;IACf,MAAM,OAAO,OAAO,SAAS,KAAK,KAAK,GAAG,UAAU;AACpD,YAAQ,IAAI,OAAO,MAAM,sBAAsB,GAAG,OAAO,OAAO,GAAG,OAAO,CAAC;;GAElF;;;uBAGyB;EAC1B;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACJ"}
@@ -0,0 +1,27 @@
1
+ import { CLI } from "./CLI.mjs";
2
+ import { Command } from "commander";
3
+
4
+ //#region src/classes/cli/CLISubcommand.d.ts
5
+ declare abstract class CLISubcommand<Flags extends Record<string, any> = Record<string, any>> {
6
+ cli: CLI;
7
+ command: Command;
8
+ parent?: string;
9
+ abstract subcommand: Command;
10
+ get flags(): Flags;
11
+ constructor({
12
+ cli,
13
+ command
14
+ }: CLISubcommand.Options);
15
+ execute(): Promise<void>;
16
+ static registerSubcommand(instance: CLISubcommand): void;
17
+ }
18
+ declare namespace CLISubcommand {
19
+ type Constructor = new (options: Options) => CLISubcommand;
20
+ interface Options {
21
+ cli: CLI;
22
+ command: Command;
23
+ }
24
+ }
25
+ //#endregion
26
+ export { CLISubcommand };
27
+ //# sourceMappingURL=CLISubcommand.d.mts.map
@@ -0,0 +1,23 @@
1
+ //#region src/classes/cli/CLISubcommand.ts
2
+ var CLISubcommand = class {
3
+ cli;
4
+ command;
5
+ parent;
6
+ get flags() {
7
+ return this.cli.getFlags(this.subcommand) ?? {};
8
+ }
9
+ constructor({ cli, command }) {
10
+ this.cli = cli;
11
+ this.command = command;
12
+ }
13
+ async execute() {}
14
+ static registerSubcommand(instance) {
15
+ instance.subcommand.action(instance.execute.bind(instance));
16
+ if (instance.parent) instance.command.commands.find((c) => c.name() === instance.parent)?.addCommand(instance.subcommand);
17
+ else instance.command.addCommand(instance.subcommand);
18
+ }
19
+ };
20
+
21
+ //#endregion
22
+ export { CLISubcommand };
23
+ //# sourceMappingURL=CLISubcommand.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"CLISubcommand.mjs","names":[],"sources":["../../../src/classes/cli/CLISubcommand.ts"],"sourcesContent":["import type { Command } from 'commander';\nimport type { CLI } from './CLI.js';\n\nexport abstract class CLISubcommand<Flags extends Record<string, any> = Record<string, any>> {\n public cli: CLI;\n public command: Command;\n public parent?: string;\n public abstract subcommand: Command;\n\n get flags(): Flags {\n return this.cli.getFlags(this.subcommand) ?? {} as Flags;\n }\n\n constructor({ cli, command }: CLISubcommand.Options) {\n this.cli = cli;\n this.command = command;\n }\n\n public async execute(): Promise<void> {}\n\n public static registerSubcommand(instance: CLISubcommand): void {\n instance.subcommand.action(instance.execute.bind(instance));\n\n if (instance.parent) {\n instance.command.commands.find(c => c.name() === instance.parent)?.addCommand(instance.subcommand);\n } else {\n instance.command.addCommand(instance.subcommand);\n }\n }\n}\n\nexport namespace CLISubcommand {\n export type Constructor = new (options: Options) => CLISubcommand;\n export interface Options {\n cli: CLI;\n command: Command;\n }\n}\n"],"mappings":";AAGA,IAAsB,gBAAtB,MAA6F;CACzF,AAAO;CACP,AAAO;CACP,AAAO;CAGP,IAAI,QAAe;AACf,SAAO,KAAK,IAAI,SAAS,KAAK,WAAW,IAAI,EAAE;;CAGnD,YAAY,EAAE,KAAK,WAAkC;AACjD,OAAK,MAAM;AACX,OAAK,UAAU;;CAGnB,MAAa,UAAyB;CAEtC,OAAc,mBAAmB,UAA+B;AAC5D,WAAS,WAAW,OAAO,SAAS,QAAQ,KAAK,SAAS,CAAC;AAE3D,MAAI,SAAS,OACT,UAAS,QAAQ,SAAS,MAAK,MAAK,EAAE,MAAM,KAAK,SAAS,OAAO,EAAE,WAAW,SAAS,WAAW;MAElG,UAAS,QAAQ,WAAW,SAAS,WAAW"}