reciple 10.0.1-dev.1 → 10.0.1-dev.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/assets/templates/javascript/jsconfig.json +14 -2
- package/assets/templates/typescript/tsconfig.json +14 -2
- package/dist/_virtual/{_@oxc-project_runtime@0.99.0 → _@oxc-project_runtime@0.103.0}/helpers/decorate.mjs +1 -1
- package/dist/bin/commands/build.mjs +1 -1
- package/dist/bin/commands/build.mjs.map +1 -1
- package/dist/bin/commands/create.mjs +6 -7
- package/dist/bin/commands/create.mjs.map +1 -1
- package/dist/bin/commands/createModule.mjs +1 -1
- package/dist/bin/commands/createModule.mjs.map +1 -1
- package/dist/bin/commands/start.mjs +8 -8
- package/dist/bin/commands/start.mjs.map +1 -1
- package/dist/bin/reciple.mjs +0 -0
- package/dist/classes/cli/CLI.d.mts +1 -1
- package/dist/classes/cli/CLI.mjs +2 -2
- package/dist/classes/cli/CLI.mjs.map +1 -1
- package/dist/classes/cli/ConfigReader.d.mts +21 -29
- package/dist/classes/cli/ConfigReader.mjs +39 -62
- package/dist/classes/cli/ConfigReader.mjs.map +1 -1
- package/dist/classes/client/EventListeners.mjs +1 -1
- package/dist/classes/client/EventListeners.mjs.map +1 -1
- package/dist/classes/client/ModuleLoader.d.mts +1 -1
- package/dist/classes/client/ModuleLoader.mjs.map +1 -1
- package/dist/classes/managers/ModuleManager.mjs +1 -1
- package/dist/classes/modules/PostconditionModule.mjs +1 -1
- package/dist/classes/modules/PreconditionModule.mjs +1 -1
- package/dist/classes/modules/commands/ContextMenuCommandModule.mjs +1 -1
- package/dist/classes/modules/commands/MessageCommandModule.mjs +1 -1
- package/dist/classes/modules/commands/SlashCommandModule.mjs +1 -1
- package/dist/classes/templates/TemplateBuilder.d.mts +7 -2
- package/dist/classes/templates/TemplateBuilder.mjs +108 -77
- package/dist/classes/templates/TemplateBuilder.mjs.map +1 -1
- package/dist/classes/validation/BaseModuleValidator.d.mts +11 -11
- package/dist/classes/validation/CommandModuleValidator.d.mts +18 -18
- package/dist/classes/validation/EventModuleValidator.d.mts +9 -9
- package/dist/classes/validation/PostconditionModule.d.mts +8 -8
- package/dist/classes/validation/PreconditionModule.d.mts +8 -8
- package/dist/helpers/constants.d.mts +1 -2
- package/dist/helpers/constants.mjs +1 -1
- package/dist/helpers/constants.mjs.map +1 -1
- package/dist/index.d.mts +3 -3
- package/dist/index.mjs +3 -3
- package/dist/index.mjs.map +1 -1
- package/dist/package.mjs +12 -15
- package/dist/package.mjs.map +1 -1
- package/package.json +12 -15
- package/LICENSE +0 -155
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
{
|
|
2
|
-
"extends": "@reciple/utils/tsconfig.json",
|
|
3
2
|
"include": [
|
|
4
3
|
"./src/**/*"
|
|
5
4
|
],
|
|
5
|
+
"exclude": [
|
|
6
|
+
"reciple.config.js",
|
|
7
|
+
"./config/**/*"
|
|
8
|
+
],
|
|
6
9
|
"compilerOptions": {
|
|
7
10
|
"baseUrl": "./",
|
|
8
11
|
"rootDir": "./src",
|
|
@@ -12,6 +15,15 @@
|
|
|
12
15
|
"jsxImportSource": "@reciple/jsx",
|
|
13
16
|
"paths": {
|
|
14
17
|
"@/*": ["./src/*"]
|
|
15
|
-
}
|
|
18
|
+
},
|
|
19
|
+
"target": "ESNext",
|
|
20
|
+
"module": "NodeNext",
|
|
21
|
+
"moduleResolution": "NodeNext",
|
|
22
|
+
"forceConsistentCasingInFileNames": true,
|
|
23
|
+
"experimentalDecorators": true,
|
|
24
|
+
"skipLibCheck": true,
|
|
25
|
+
"sourceMap": true,
|
|
26
|
+
"strict": true,
|
|
27
|
+
"verbatimModuleSyntax": true
|
|
16
28
|
}
|
|
17
29
|
}
|
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
{
|
|
2
|
-
"extends": "@reciple/utils/tsconfig.json",
|
|
3
2
|
"include": [
|
|
4
3
|
"./src/**/*"
|
|
5
4
|
],
|
|
5
|
+
"exclude": [
|
|
6
|
+
"reciple.config.ts",
|
|
7
|
+
"./config/**/*"
|
|
8
|
+
],
|
|
6
9
|
"compilerOptions": {
|
|
7
10
|
"baseUrl": "./",
|
|
8
11
|
"rootDir": "./src",
|
|
@@ -12,6 +15,15 @@
|
|
|
12
15
|
"jsxImportSource": "@reciple/jsx",
|
|
13
16
|
"paths": {
|
|
14
17
|
"@/*": ["./src/*"]
|
|
15
|
-
}
|
|
18
|
+
},
|
|
19
|
+
"target": "ESNext",
|
|
20
|
+
"module": "NodeNext",
|
|
21
|
+
"moduleResolution": "NodeNext",
|
|
22
|
+
"forceConsistentCasingInFileNames": true,
|
|
23
|
+
"experimentalDecorators": true,
|
|
24
|
+
"skipLibCheck": true,
|
|
25
|
+
"sourceMap": true,
|
|
26
|
+
"strict": true,
|
|
27
|
+
"verbatimModuleSyntax": true
|
|
16
28
|
}
|
|
17
29
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
//#region \0@oxc-project+runtime@0.
|
|
1
|
+
//#region \0@oxc-project+runtime@0.103.0/helpers/decorate.js
|
|
2
2
|
function __decorate(decorators, target, key, desc) {
|
|
3
3
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
4
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
@@ -8,7 +8,7 @@ import { build } from "tsdown";
|
|
|
8
8
|
var BuildSubcommand = class extends CLISubcommand {
|
|
9
9
|
subcommand = new Command("build").description("Build the reciple modules defined in config file").option("-c, --config <path>", "Path to the configuration file");
|
|
10
10
|
async execute() {
|
|
11
|
-
const { build: buildConfig } = await new ConfigReader(this.subcommand.opts().config ?? await ConfigReader.
|
|
11
|
+
const { build: buildConfig } = await new ConfigReader(this.subcommand.opts().config ?? await ConfigReader.find() ?? ConfigReader.createConfigFilename("js")).read();
|
|
12
12
|
let plugins = buildConfig.plugins ? Array.isArray(buildConfig.plugins) ? buildConfig.plugins : [buildConfig.plugins] : [];
|
|
13
13
|
plugins.push(CLI.createTsdownLogger(this.cli.logger));
|
|
14
14
|
await build({
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"build.mjs","names":[],"sources":["../../../src/bin/commands/build.ts"],"sourcesContent":["import { Command } from 'commander';\nimport { CLISubcommand } from '../../classes/cli/CLISubcommand.js';\nimport { ConfigReader } from '../../classes/cli/ConfigReader.js';\nimport { build } from 'tsdown';\nimport { CLI } from '../../classes/cli/CLI.js';\n\nexport default class BuildSubcommand extends CLISubcommand {\n public subcommand: Command = new Command('build')\n .description('Build the reciple modules defined in config file')\n .option('-c, --config <path>', 'Path to the configuration file');\n\n public async execute(): Promise<void> {\n const flags = this.subcommand.opts<BuildSubcommand.Flags>();\n\n const configReader = new ConfigReader(\n flags.config\n ?? await ConfigReader.
|
|
1
|
+
{"version":3,"file":"build.mjs","names":[],"sources":["../../../src/bin/commands/build.ts"],"sourcesContent":["import { Command } from 'commander';\nimport { CLISubcommand } from '../../classes/cli/CLISubcommand.js';\nimport { ConfigReader } from '../../classes/cli/ConfigReader.js';\nimport { build } from 'tsdown';\nimport { CLI } from '../../classes/cli/CLI.js';\n\nexport default class BuildSubcommand extends CLISubcommand {\n public subcommand: Command = new Command('build')\n .description('Build the reciple modules defined in config file')\n .option('-c, --config <path>', 'Path to the configuration file');\n\n public async execute(): Promise<void> {\n const flags = this.subcommand.opts<BuildSubcommand.Flags>();\n\n const configReader = new ConfigReader(\n flags.config\n ?? await ConfigReader.find()\n ?? ConfigReader.createConfigFilename('js')\n );\n\n const { build: buildConfig } = await configReader.read();\n\n let plugins = buildConfig.plugins\n ? Array.isArray(buildConfig.plugins)\n ? buildConfig.plugins\n : [buildConfig.plugins]\n : [];\n\n plugins.push(CLI.createTsdownLogger(this.cli.logger));\n\n await build({\n ...buildConfig,\n logLevel: 'silent',\n plugins,\n });\n }\n}\n\nexport namespace BuildSubcommand {\n export interface Flags {\n config?: string;\n }\n}\n"],"mappings":";;;;;;;AAMA,IAAqB,kBAArB,cAA6C,cAAc;CACvD,AAAO,aAAsB,IAAI,QAAQ,QAAQ,CAC5C,YAAY,mDAAmD,CAC/D,OAAO,uBAAuB,iCAAiC;CAEpE,MAAa,UAAyB;EASlC,MAAM,EAAE,OAAO,gBAAgB,MANV,IAAI,aAFX,KAAK,WAAW,MAA6B,CAGjD,UACH,MAAM,aAAa,MAAM,IACzB,aAAa,qBAAqB,KAAK,CAC7C,CAEiD,MAAM;EAExD,IAAI,UAAU,YAAY,UACpB,MAAM,QAAQ,YAAY,QAAQ,GAC9B,YAAY,UACZ,CAAC,YAAY,QAAQ,GACzB,EAAE;AAER,UAAQ,KAAK,IAAI,mBAAmB,KAAK,IAAI,OAAO,CAAC;AAErD,QAAM,MAAM;GACR,GAAG;GACH,UAAU;GACV;GACH,CAAC"}
|
|
@@ -14,7 +14,7 @@ var CreateSubcommand = class extends CLISubcommand {
|
|
|
14
14
|
"pnpm",
|
|
15
15
|
"bun",
|
|
16
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);
|
|
17
|
+
])).option("-D, --default", "Use defaults for prompts").option("--install", "Install dependencies during setup", true).option("--no-install", "Do not install dependencies during setup").option("--build", "Build the project after creation", true).option("--no-build", "Do not build the project after creation").allowUnknownOption(true);
|
|
18
18
|
async execute() {
|
|
19
19
|
const flags = this.cli.getFlags("create");
|
|
20
20
|
const template = new TemplateBuilder({
|
|
@@ -30,13 +30,12 @@ var CreateSubcommand = class extends CLISubcommand {
|
|
|
30
30
|
await template.createDirectory();
|
|
31
31
|
await template.setupLanguage();
|
|
32
32
|
await template.createConfig();
|
|
33
|
-
await template.setPackageManager();
|
|
34
|
-
await template.createTemplate();
|
|
35
33
|
await template.createEnvFile({ envFile: this.cli.flags.env[0] });
|
|
36
|
-
await template.
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
34
|
+
await template.createTemplate();
|
|
35
|
+
await template.setPackageManager();
|
|
36
|
+
await template.installDependencies({ value: flags?.install });
|
|
37
|
+
await template.createModules();
|
|
38
|
+
await template.build({ skipBuild: !flags?.build });
|
|
40
39
|
} catch (error) {
|
|
41
40
|
cancel(colors.red(error instanceof NotAnError ? error.message : inspect(error)));
|
|
42
41
|
}
|
|
@@ -1 +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.
|
|
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('--no-install', 'Do not install dependencies during setup')\n .option('--build', 'Build the project after creation', true)\n .option('--no-build', 'Do not build the project after creation')\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.createEnvFile({ envFile: this.cli.flags.env[0] });\n await template.createTemplate();\n await template.setPackageManager();\n await template.installDependencies({ value: flags?.install });\n await template.createModules();\n await template.build({ 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,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
|
14
14
|
async execute() {
|
|
15
15
|
const flags = this.subcommand.opts();
|
|
16
|
-
const configReader = await new ConfigReader(flags.config ?? await ConfigReader.
|
|
16
|
+
const configReader = await new ConfigReader(flags.config ?? await ConfigReader.find() ?? ConfigReader.createConfigFilename("js")).read();
|
|
17
17
|
const template = new ModuleTemplateBuilder({
|
|
18
18
|
cli: this.cli,
|
|
19
19
|
config: configReader,
|
|
@@ -1 +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
|
|
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 new ConfigReader(\n flags.config\n ?? await ConfigReader.find()\n ?? ConfigReader.createConfigFilename('js')\n ).read();\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,MAAM,IAAI,aAC3B,MAAM,UACH,MAAM,aAAa,MAAM,IACzB,aAAa,qBAAqB,KAAK,CAC7C,CAAC,MAAM;EAER,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"}
|
|
@@ -5,7 +5,7 @@ import { RuntimeEnvironment } from "../../classes/cli/RuntimeEnvironment.mjs";
|
|
|
5
5
|
import { EventListeners } from "../../classes/client/EventListeners.mjs";
|
|
6
6
|
import { ModuleLoader } from "../../classes/client/ModuleLoader.mjs";
|
|
7
7
|
import { ModuleManager } from "../../classes/managers/ModuleManager.mjs";
|
|
8
|
-
import { Logger } from "
|
|
8
|
+
import { Logger } from "@prtty/print";
|
|
9
9
|
import { Command } from "commander";
|
|
10
10
|
import { Format, colors, resolveEnvProtocol } from "@reciple/utils";
|
|
11
11
|
import { Client, CommandType } from "@reciple/core";
|
|
@@ -17,7 +17,7 @@ var StartSubcommand = class extends CLISubcommand {
|
|
|
17
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
18
|
async execute() {
|
|
19
19
|
const flags = this.subcommand.opts();
|
|
20
|
-
const { client, config, build: buildConfig } = await new ConfigReader(flags.config ?? await ConfigReader.
|
|
20
|
+
const { client, config, build: buildConfig } = await new ConfigReader(flags.config ?? await ConfigReader.find() ?? ConfigReader.createConfigFilename("js")).read();
|
|
21
21
|
const logger$1 = config.logger instanceof Logger ? this.cli.logger = config.logger : this.cli.logger.clone(config.logger);
|
|
22
22
|
let token = flags.token || config.token || "";
|
|
23
23
|
token = resolveEnvProtocol(token) || token;
|
|
@@ -81,12 +81,12 @@ var StartSubcommand = class extends CLISubcommand {
|
|
|
81
81
|
slash: client.commands.cache.filter((c) => c.type === CommandType.Slash).size
|
|
82
82
|
};
|
|
83
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")}.`);
|
|
84
|
+
logger$1.log(` ├─ Loaded ${colors.green(modules.length.toLocaleString())} ${Format.plural(modules.length, "module")}.`);
|
|
85
|
+
logger$1.log(` ├─ Loaded ${colors.green(commands.contextMenus.toLocaleString())} context menu ${Format.plural(commands.contextMenus, "command")}.`);
|
|
86
|
+
logger$1.log(` ├─ Loaded ${colors.green(commands.message.toLocaleString())} message ${Format.plural(commands.message, "command")}.`);
|
|
87
|
+
logger$1.log(` ├─ Loaded ${colors.green(commands.slash.toLocaleString())} slash ${Format.plural(commands.slash, "command")}.`);
|
|
88
|
+
logger$1.log(` ├─ Loaded ${colors.green(client.preconditions.cache.size.toLocaleString())} global ${Format.plural(client.preconditions.cache.size, "precondition")}.`);
|
|
89
|
+
logger$1.log(` └─ Loaded ${colors.green(client.postconditions.cache.size.toLocaleString())} global ${Format.plural(client.postconditions.cache.size, "postcondition")}.`);
|
|
90
90
|
});
|
|
91
91
|
client.eventListeners.registerProcessExitEvents(async (signal) => RuntimeEnvironment.handleExitSignal(client, signal));
|
|
92
92
|
},
|
|
@@ -1 +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,IAAqB,kBAArB,cAA6C,cAAc;CACvD,AAAO,aAAsB,IAAI,QAAQ,QAAQ,CAC5C,YAAY,2BAA2B,CACvC,OAAO,uBAAuB,iCAAiC,CAC/D,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AO,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"}
|
|
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 '@prtty/print';\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.find()\n ?? ConfigReader.createConfigFilename('js')\n );\n\n const { client, config, build: buildConfig } = await configReader.read();\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.toLocaleString())} ${Format.plural(modules.length, 'module')}.`);\n logger.log(` ├─ Loaded ${colors.green(commands.contextMenus.toLocaleString())} context menu ${Format.plural(commands.contextMenus, 'command')}.`);\n logger.log(` ├─ Loaded ${colors.green(commands.message.toLocaleString())} message ${Format.plural(commands.message, 'command')}.`);\n logger.log(` ├─ Loaded ${colors.green(commands.slash.toLocaleString())} slash ${Format.plural(commands.slash, 'command')}.`);\n logger.log(` ├─ Loaded ${colors.green(client.preconditions.cache.size.toLocaleString())} global ${Format.plural(client.preconditions.cache.size, 'precondition')}.`);\n logger.log(` └─ Loaded ${colors.green(client.postconditions.cache.size.toLocaleString())} 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,IAAqB,kBAArB,cAA6C,cAAc;CACvD,AAAO,aAAsB,IAAI,QAAQ,QAAQ,CAC5C,YAAY,2BAA2B,CACvC,OAAO,uBAAuB,iCAAiC,CAC/D,OAAO,8BAA8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CAAC,GAAG;MACzK;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"}
|
package/dist/bin/reciple.mjs
CHANGED
|
File without changes
|
package/dist/classes/cli/CLI.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { CLISubcommand } from "./CLISubcommand.mjs";
|
|
2
|
-
import { LogLevel, Logger, logger } from "
|
|
2
|
+
import { LogLevel, Logger, logger } from "@prtty/print";
|
|
3
3
|
import { Command } from "commander";
|
|
4
4
|
import { fileURLToPath } from "node:url";
|
|
5
5
|
import path from "node:path";
|
|
@@ -86,7 +86,7 @@ var CLI = class {
|
|
|
86
86
|
(function(_CLI) {
|
|
87
87
|
_CLI.root = path.join(path.dirname(fileURLToPath(import.meta.url)), "../../../");
|
|
88
88
|
_CLI.bin = path.join(CLI.root, "dist/bin/reciple.js");
|
|
89
|
-
_CLI.version = "10.0.1-dev.
|
|
89
|
+
_CLI.version = "10.0.1-dev.11";
|
|
90
90
|
function stringifyFlags(flags, command, ignored = []) {
|
|
91
91
|
let arr = [];
|
|
92
92
|
for (const [key, value] of Object.entries(flags)) {
|
|
@@ -1 +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;;CAG9B,YAAY,AAAgB,SAAsB;EAAtB;AACxB,OAAK,QAAQ,QAAQ;AACrB,OAAK,UAAU,OAAO,OAAO,KAAK,MAAM,IAAI,KAAK,MAAM;AAEvD,OAAK,UAAU,IAAI,SAAQ,CACtB,KAAK,QA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AG,OAAO,OAAO,GAAG,OAAO,CAAC;;GAElF;;;uBAGyB;EAC1B;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACJ"}
|
|
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 '@prtty/print';\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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GACN,kBAAkB;AACd,YAAQ,IAAI,OAAO,MAAM,iCAAiC,CAAC;AAC3D,gBAAY,KAAK,KAAK;;GAE1B,cAAc,MAAM,SAAS;IACzB,MAAM,OAAO,OAAO,MAAM,OAAO,WAAW,MAAM,OAAO,CAAC;AAC1D,YAAQ,IAAI,OAAO,OAAO,KAAK,KAAK,CAAC,IAAI,OAAO,KAAK,KAAK,SAAS,GAAG;AAEtE,WAAO,EAAE,MAAM;;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"}
|
|
@@ -3,7 +3,7 @@ import { BuildConfig } from "../../helpers/types.mjs";
|
|
|
3
3
|
import { ModuleLoader } from "../client/ModuleLoader.mjs";
|
|
4
4
|
import { ModuleManager } from "../managers/ModuleManager.mjs";
|
|
5
5
|
import { EventListeners } from "../client/EventListeners.mjs";
|
|
6
|
-
import { Logger } from "
|
|
6
|
+
import { Logger } from "@prtty/print";
|
|
7
7
|
import { Client, Config } from "@reciple/core";
|
|
8
8
|
import { Options } from "unrun";
|
|
9
9
|
import { UserConfig } from "tsdown";
|
|
@@ -32,49 +32,41 @@ declare class ConfigReader {
|
|
|
32
32
|
get config(): Config;
|
|
33
33
|
get build(): UserConfig;
|
|
34
34
|
constructor(filepath: string);
|
|
35
|
-
read(options?: Omit<
|
|
36
|
-
create(options
|
|
37
|
-
exists(): Promise<boolean>;
|
|
35
|
+
read(options?: Omit<Options, 'path'>): Promise<ConfigReader>;
|
|
36
|
+
create(options: Omit<ConfigReader.CreateOptions, 'path'>): Promise<ConfigReader>;
|
|
37
|
+
static exists(file: string): Promise<boolean>;
|
|
38
38
|
static create(options: ConfigReader.CreateOptions): Promise<ConfigReader>;
|
|
39
|
-
static
|
|
40
|
-
static findConfig(directory: string, type?: 'ts' | 'js'): Promise<string | null>;
|
|
41
|
-
static getDefaultContent(type?: 'ts' | 'js'): Promise<string>;
|
|
39
|
+
static find(options?: ConfigReader.FindOptions): Promise<string | null>;
|
|
42
40
|
}
|
|
43
41
|
declare namespace ConfigReader {
|
|
44
|
-
function getProjectLang(dir: string): Promise<'ts' | 'js'>;
|
|
45
|
-
interface Structure {
|
|
46
|
-
client: Client;
|
|
47
|
-
config: Config;
|
|
48
|
-
}
|
|
49
|
-
interface ReadOptions extends Options {
|
|
50
|
-
createIfNotExists?: boolean;
|
|
51
|
-
createOptions?: Omit<CreateOptions, 'path'>;
|
|
52
|
-
}
|
|
53
42
|
interface CreateOptions {
|
|
54
|
-
|
|
43
|
+
path: string;
|
|
55
44
|
overwrite?: boolean;
|
|
56
|
-
|
|
57
|
-
type
|
|
58
|
-
readOptions?: Omit<
|
|
45
|
+
throwIfExists?: boolean;
|
|
46
|
+
type: LangType;
|
|
47
|
+
readOptions?: Omit<Options, 'path'>;
|
|
59
48
|
}
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
49
|
+
interface FindOptions {
|
|
50
|
+
cwd?: string;
|
|
51
|
+
lang?: LangType;
|
|
52
|
+
directories?: string[];
|
|
53
|
+
}
|
|
54
|
+
function getProjectLang(cwd: string): Promise<LangType>;
|
|
55
|
+
type LangType = 'ts' | 'js';
|
|
56
|
+
const defaultConfigPath: {
|
|
65
57
|
ts: string;
|
|
66
58
|
js: string;
|
|
67
59
|
};
|
|
68
|
-
|
|
60
|
+
function getDefaultContent(type: LangType): Promise<string>;
|
|
61
|
+
const configFilenames: string[];
|
|
62
|
+
function createConfigFilename(type: LangType, esm?: boolean): string;
|
|
69
63
|
function normalizeTsdownConfig({
|
|
70
64
|
type,
|
|
71
65
|
overrides
|
|
72
66
|
}?: {
|
|
73
|
-
type?:
|
|
67
|
+
type?: LangType;
|
|
74
68
|
overrides?: BuildConfig;
|
|
75
69
|
}): UserConfig;
|
|
76
|
-
function createConfigFilename(type: 'ts' | 'js', esm?: boolean): string;
|
|
77
|
-
function getLangTypeFromFilename(filename: string): 'ts' | 'js' | null;
|
|
78
70
|
}
|
|
79
71
|
//#endregion
|
|
80
72
|
export { ConfigReader };
|
|
@@ -3,8 +3,8 @@ import path from "node:path";
|
|
|
3
3
|
import { colors } from "@reciple/utils";
|
|
4
4
|
import { mkdir, readFile, readdir, stat, writeFile } from "node:fs/promises";
|
|
5
5
|
import { Client, RecipleError } from "@reciple/core";
|
|
6
|
-
import { unrun } from "unrun";
|
|
7
6
|
import { resolveTSConfig } from "pkg-types";
|
|
7
|
+
import { unrun } from "unrun";
|
|
8
8
|
|
|
9
9
|
//#region src/classes/cli/ConfigReader.ts
|
|
10
10
|
var ConfigReader = class ConfigReader {
|
|
@@ -25,10 +25,6 @@ var ConfigReader = class ConfigReader {
|
|
|
25
25
|
this.filepath = filepath;
|
|
26
26
|
}
|
|
27
27
|
async read(options) {
|
|
28
|
-
if (!await ConfigReader.hasFile(this.filepath) && options?.createIfNotExists !== false) return ConfigReader.create({
|
|
29
|
-
filepath: this.filepath,
|
|
30
|
-
readOptions: options
|
|
31
|
-
});
|
|
32
28
|
const { module } = await unrun({
|
|
33
29
|
...options,
|
|
34
30
|
path: this.filepath
|
|
@@ -40,70 +36,62 @@ var ConfigReader = class ConfigReader {
|
|
|
40
36
|
return this;
|
|
41
37
|
}
|
|
42
38
|
async create(options) {
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
async exists() {
|
|
49
|
-
return await ConfigReader.hasFile(this.filepath);
|
|
50
|
-
}
|
|
51
|
-
static async create(options) {
|
|
52
|
-
const type = options.type ?? ConfigReader.getLangTypeFromFilename(options.filepath) ?? "js";
|
|
53
|
-
if (await ConfigReader.hasFile(options.filepath) && !options.overwrite) {
|
|
54
|
-
if (options.throwOnConflict !== false) throw new RecipleError(`config file already exists at ${colors.green(options.filepath)}`);
|
|
55
|
-
const reader$1 = new ConfigReader(options.filepath);
|
|
56
|
-
await reader$1.read(options.readOptions);
|
|
57
|
-
return reader$1;
|
|
39
|
+
const exists = await ConfigReader.exists(this.filepath);
|
|
40
|
+
if (exists && options.throwIfExists === true) throw new RecipleError(`Config file already exists at ${colors.green(path.relative(process.cwd(), this.filepath))}.`);
|
|
41
|
+
if (!exists || exists && options.overwrite !== false) {
|
|
42
|
+
await mkdir(path.dirname(this.filepath), { recursive: true });
|
|
43
|
+
await writeFile(this.filepath, await ConfigReader.getDefaultContent(options.type));
|
|
58
44
|
}
|
|
59
|
-
|
|
60
|
-
await writeFile(options.filepath, await this.getDefaultContent(type));
|
|
61
|
-
const reader = new ConfigReader(options.filepath);
|
|
62
|
-
await reader.read(options.readOptions);
|
|
63
|
-
return reader;
|
|
45
|
+
return this.read(options.readOptions);
|
|
64
46
|
}
|
|
65
|
-
static async
|
|
66
|
-
return stat(
|
|
47
|
+
static async exists(file) {
|
|
48
|
+
return await stat(file).then((s) => s.isFile()).catch(() => false);
|
|
67
49
|
}
|
|
68
|
-
static async
|
|
69
|
-
|
|
70
|
-
const files = (await readdir(directory)).find((f) => validFiles.includes(f));
|
|
71
|
-
return files ? path.join(directory, files) : null;
|
|
50
|
+
static async create(options) {
|
|
51
|
+
return new ConfigReader(options.path).create(options);
|
|
72
52
|
}
|
|
73
|
-
static async
|
|
74
|
-
const
|
|
75
|
-
|
|
53
|
+
static async find(options) {
|
|
54
|
+
const filenames = ConfigReader.configFilenames.filter((f) => !options?.lang || f.endsWith(options.lang));
|
|
55
|
+
const cwd = options?.cwd ?? process.cwd();
|
|
56
|
+
const directories = [cwd];
|
|
57
|
+
directories.push(...options?.directories ?? [path.join(cwd, ".config")]);
|
|
58
|
+
for (const directory of directories) {
|
|
59
|
+
if (!(await stat(directory).catch(() => void 0))?.isDirectory()) continue;
|
|
60
|
+
const file = (await readdir(directory)).find((f) => filenames.includes(f));
|
|
61
|
+
if (file) return path.join(directory, file);
|
|
62
|
+
}
|
|
63
|
+
return null;
|
|
76
64
|
}
|
|
77
65
|
};
|
|
78
66
|
(function(_ConfigReader) {
|
|
79
|
-
async function getProjectLang(
|
|
80
|
-
const hasTsConfig = !!await resolveTSConfig(
|
|
81
|
-
const configLangIsTypescript =
|
|
67
|
+
async function getProjectLang(cwd) {
|
|
68
|
+
const hasTsConfig = !!await resolveTSConfig(cwd, { try: true });
|
|
69
|
+
const configLangIsTypescript = !!await ConfigReader.find({
|
|
70
|
+
cwd,
|
|
71
|
+
lang: "ts"
|
|
72
|
+
});
|
|
82
73
|
return hasTsConfig || configLangIsTypescript ? "ts" : "js";
|
|
83
74
|
}
|
|
84
75
|
_ConfigReader.getProjectLang = getProjectLang;
|
|
85
|
-
|
|
86
|
-
ts: [
|
|
87
|
-
"ts",
|
|
88
|
-
"mts",
|
|
89
|
-
"tsx"
|
|
90
|
-
],
|
|
91
|
-
js: [
|
|
92
|
-
"js",
|
|
93
|
-
"mjs",
|
|
94
|
-
"jsx"
|
|
95
|
-
]
|
|
96
|
-
};
|
|
97
|
-
_ConfigReader.defaultConfigFilePaths = {
|
|
76
|
+
_ConfigReader.defaultConfigPath = {
|
|
98
77
|
ts: path.join(CLI.root, "assets/config", `reciple.config.ts`),
|
|
99
78
|
js: path.join(CLI.root, "assets/config", `reciple.config.js`)
|
|
100
79
|
};
|
|
101
|
-
|
|
80
|
+
async function getDefaultContent(type) {
|
|
81
|
+
const filepath = ConfigReader.defaultConfigPath[type];
|
|
82
|
+
return await readFile(filepath, "utf-8");
|
|
83
|
+
}
|
|
84
|
+
_ConfigReader.getDefaultContent = getDefaultContent;
|
|
85
|
+
_ConfigReader.configFilenames = [
|
|
102
86
|
"reciple.config.ts",
|
|
103
87
|
"reciple.config.mts",
|
|
104
88
|
"reciple.config.js",
|
|
105
89
|
"reciple.config.mjs"
|
|
106
90
|
];
|
|
91
|
+
function createConfigFilename(type, esm = false) {
|
|
92
|
+
return `reciple.config.${esm ? "m" : ""}${type}`;
|
|
93
|
+
}
|
|
94
|
+
_ConfigReader.createConfigFilename = createConfigFilename;
|
|
107
95
|
function normalizeTsdownConfig({ type, overrides } = {}) {
|
|
108
96
|
return {
|
|
109
97
|
entry: [`./src/**/*.{ts,tsx,js,jsx}`],
|
|
@@ -123,17 +111,6 @@ var ConfigReader = class ConfigReader {
|
|
|
123
111
|
};
|
|
124
112
|
}
|
|
125
113
|
_ConfigReader.normalizeTsdownConfig = normalizeTsdownConfig;
|
|
126
|
-
function createConfigFilename(type, esm = false) {
|
|
127
|
-
return `reciple.config.${type === "ts" ? esm ? "mts" : "ts" : esm ? "mjs" : "js"}`;
|
|
128
|
-
}
|
|
129
|
-
_ConfigReader.createConfigFilename = createConfigFilename;
|
|
130
|
-
function getLangTypeFromFilename(filename) {
|
|
131
|
-
const extention = path.extname(filename).slice(1);
|
|
132
|
-
if (FileTypes.ts.includes(extention)) return "ts";
|
|
133
|
-
if (FileTypes.js.includes(extention)) return "js";
|
|
134
|
-
return null;
|
|
135
|
-
}
|
|
136
|
-
_ConfigReader.getLangTypeFromFilename = getLangTypeFromFilename;
|
|
137
114
|
})(ConfigReader || (ConfigReader = {}));
|
|
138
115
|
|
|
139
116
|
//#endregion
|