commandkit 0.1.11-dev.20250307192025 → 0.1.11-dev.20250308073818
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/dist/index.d.ts +10 -0
- package/dist/index.js +113 -48
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -1086,6 +1086,10 @@ interface ParsedSubCommand {
|
|
|
1086
1086
|
* The group name of the subcommand. This is used to group subcommands together in the Discord UI.
|
|
1087
1087
|
*/
|
|
1088
1088
|
group: string | null;
|
|
1089
|
+
/**
|
|
1090
|
+
* The category of this subcommand. This will be the parent directory segment that matches /(category)/ in the path.
|
|
1091
|
+
*/
|
|
1092
|
+
category: string | null;
|
|
1089
1093
|
/**
|
|
1090
1094
|
* The absolute path to the subcommand file.
|
|
1091
1095
|
*/
|
|
@@ -1136,9 +1140,15 @@ declare class CommandsRouter {
|
|
|
1136
1140
|
toJSON(): CommandTree;
|
|
1137
1141
|
scan(): Promise<CommandTree>;
|
|
1138
1142
|
private scanDeep;
|
|
1143
|
+
/**
|
|
1144
|
+
* Gets path segments between two paths, excluding the start and end paths
|
|
1145
|
+
* Used to check if all directories between a path and the entrypoint are category directories
|
|
1146
|
+
*/
|
|
1147
|
+
private getPathSegmentsBetween;
|
|
1139
1148
|
private processMiddleware;
|
|
1140
1149
|
private processSubcommand;
|
|
1141
1150
|
private processCommand;
|
|
1151
|
+
private extractDirOmitCategory;
|
|
1142
1152
|
/**
|
|
1143
1153
|
* Gets the appropriate file name, handling index files specially
|
|
1144
1154
|
* For index files, it returns the parent directory name (excluding category markers)
|
package/dist/index.js
CHANGED
|
@@ -3772,7 +3772,7 @@ var init_AppCommandHandler = __esm({
|
|
|
3772
3772
|
});
|
|
3773
3773
|
|
|
3774
3774
|
// src/app/router/CommandsRouter.ts
|
|
3775
|
-
var import_discord11, import_node_fs3, import_promises3,
|
|
3775
|
+
var import_discord11, import_node_fs3, import_promises3, path2, _CommandsRouter, CommandsRouter;
|
|
3776
3776
|
var init_CommandsRouter = __esm({
|
|
3777
3777
|
"src/app/router/CommandsRouter.ts"() {
|
|
3778
3778
|
"use strict";
|
|
@@ -3780,7 +3780,7 @@ var init_CommandsRouter = __esm({
|
|
|
3780
3780
|
import_discord11 = require("discord.js");
|
|
3781
3781
|
import_node_fs3 = require("fs");
|
|
3782
3782
|
import_promises3 = require("fs/promises");
|
|
3783
|
-
|
|
3783
|
+
path2 = __toESM(require("path"));
|
|
3784
3784
|
_CommandsRouter = class _CommandsRouter {
|
|
3785
3785
|
constructor(options) {
|
|
3786
3786
|
this.options = options;
|
|
@@ -3879,32 +3879,38 @@ var init_CommandsRouter = __esm({
|
|
|
3879
3879
|
await this.scanDeep(root);
|
|
3880
3880
|
return this.toJSON();
|
|
3881
3881
|
}
|
|
3882
|
-
async scanDeep(entry, currentDepth =
|
|
3883
|
-
const normalizedPath =
|
|
3882
|
+
async scanDeep(entry, currentDepth = 3) {
|
|
3883
|
+
const normalizedPath = path2.normalize(entry);
|
|
3884
3884
|
const content = await (0, import_promises3.readdir)(normalizedPath, { withFileTypes: true });
|
|
3885
|
+
const isRootOrDirectSubdir = normalizedPath === this.entrypoint || path2.dirname(normalizedPath) === this.entrypoint || // Check if parent directories between this and entrypoint are all category directories
|
|
3886
|
+
this.getPathSegmentsBetween(normalizedPath, this.entrypoint).every(
|
|
3887
|
+
(segment) => this.isCategoryDirectory(segment)
|
|
3888
|
+
);
|
|
3889
|
+
const effectiveDepth = isRootOrDirectSubdir ? 3 : currentDepth;
|
|
3885
3890
|
for (const item of content) {
|
|
3886
|
-
const itemPath =
|
|
3891
|
+
const itemPath = path2.join(normalizedPath, item.name);
|
|
3887
3892
|
if (this.shouldIgnore(itemPath, item.isDirectory())) continue;
|
|
3888
3893
|
if (item.isDirectory()) {
|
|
3889
3894
|
const isCategoryDir = this.isCategoryDirectory(item.name);
|
|
3890
|
-
if (
|
|
3891
|
-
const nextDepth = isCategoryDir ?
|
|
3895
|
+
if (isCategoryDir || effectiveDepth >= 0) {
|
|
3896
|
+
const nextDepth = isCategoryDir ? effectiveDepth : effectiveDepth - 1;
|
|
3892
3897
|
await this.scanDeep(itemPath, nextDepth);
|
|
3893
3898
|
}
|
|
3894
3899
|
} else {
|
|
3895
|
-
const isInnerSubCommand = currentDepth === 0;
|
|
3896
|
-
const isSubCommandGroup = currentDepth === 1;
|
|
3897
3900
|
const category = this.extractCategory(itemPath);
|
|
3898
3901
|
const fileName = this.extractName(itemPath);
|
|
3899
|
-
const isIndexFile = fileName === "index"
|
|
3902
|
+
const isIndexFile = fileName === "index";
|
|
3900
3903
|
if (this.isMiddleware(itemPath)) {
|
|
3901
3904
|
this.processMiddleware(itemPath, category);
|
|
3902
|
-
} else if (
|
|
3905
|
+
} else if (effectiveDepth <= 1) {
|
|
3903
3906
|
this.processSubcommand(
|
|
3904
3907
|
itemPath,
|
|
3905
|
-
|
|
3906
|
-
|
|
3907
|
-
|
|
3908
|
+
path2.basename(normalizedPath),
|
|
3909
|
+
effectiveDepth === 0,
|
|
3910
|
+
// isSubCommandGroup when depth is 0
|
|
3911
|
+
isIndexFile,
|
|
3912
|
+
effectiveDepth,
|
|
3913
|
+
category
|
|
3908
3914
|
);
|
|
3909
3915
|
} else {
|
|
3910
3916
|
this.processCommand(
|
|
@@ -3916,6 +3922,17 @@ var init_CommandsRouter = __esm({
|
|
|
3916
3922
|
}
|
|
3917
3923
|
}
|
|
3918
3924
|
}
|
|
3925
|
+
/**
|
|
3926
|
+
* Gets path segments between two paths, excluding the start and end paths
|
|
3927
|
+
* Used to check if all directories between a path and the entrypoint are category directories
|
|
3928
|
+
*/
|
|
3929
|
+
getPathSegmentsBetween(path1, path22) {
|
|
3930
|
+
const normalizedPath1 = path2.normalize(path1);
|
|
3931
|
+
const normalizedPath2 = path2.normalize(path22);
|
|
3932
|
+
if (normalizedPath1 === normalizedPath2) return [];
|
|
3933
|
+
const relativePath = path2.relative(normalizedPath2, normalizedPath1);
|
|
3934
|
+
return relativePath.split(path2.sep).filter((segment) => segment !== "." && segment !== "..");
|
|
3935
|
+
}
|
|
3919
3936
|
processMiddleware(filePath, category) {
|
|
3920
3937
|
const middleware = {
|
|
3921
3938
|
id: crypto.randomUUID(),
|
|
@@ -3927,19 +3944,41 @@ var init_CommandsRouter = __esm({
|
|
|
3927
3944
|
this.middlewares.set(middleware.id, middleware);
|
|
3928
3945
|
this.applyMiddlewareToCommands(middleware);
|
|
3929
3946
|
}
|
|
3930
|
-
processSubcommand(filePath, parentDirName, isGrouped, isIndexFile = false) {
|
|
3931
|
-
|
|
3932
|
-
|
|
3933
|
-
|
|
3934
|
-
|
|
3935
|
-
|
|
3936
|
-
|
|
3937
|
-
|
|
3938
|
-
|
|
3939
|
-
|
|
3940
|
-
|
|
3947
|
+
processSubcommand(filePath, parentDirName, isGrouped, isIndexFile = false, depth, category) {
|
|
3948
|
+
if (isIndexFile) {
|
|
3949
|
+
const cleanParentDirName = this.extractDirOmitCategory(parentDirName);
|
|
3950
|
+
const parentCommand = this.commands.find((cmd) => {
|
|
3951
|
+
return cmd.name === cleanParentDirName;
|
|
3952
|
+
});
|
|
3953
|
+
if (!parentCommand) {
|
|
3954
|
+
const command = {
|
|
3955
|
+
id: crypto.randomUUID(),
|
|
3956
|
+
name: cleanParentDirName,
|
|
3957
|
+
category,
|
|
3958
|
+
middlewares: [],
|
|
3959
|
+
path: filePath,
|
|
3960
|
+
relativePath: this.getRelativePath(filePath),
|
|
3961
|
+
subcommands: []
|
|
3962
|
+
};
|
|
3963
|
+
this.commands.set(command.id, command);
|
|
3964
|
+
}
|
|
3965
|
+
} else {
|
|
3966
|
+
const subcommand = {
|
|
3967
|
+
id: crypto.randomUUID(),
|
|
3968
|
+
name: this.extractName(filePath),
|
|
3969
|
+
// For subcommands, the group is the directory name (excluding category markers)
|
|
3970
|
+
group: isGrouped ? this.extractDirOmitCategory(parentDirName) : null,
|
|
3971
|
+
middlewares: [],
|
|
3972
|
+
path: filePath,
|
|
3973
|
+
category,
|
|
3974
|
+
relativePath: this.getRelativePath(filePath)
|
|
3975
|
+
};
|
|
3976
|
+
this.subcommands.set(subcommand.id, subcommand);
|
|
3977
|
+
this.applySubcommandToCommands(subcommand);
|
|
3978
|
+
}
|
|
3941
3979
|
}
|
|
3942
3980
|
processCommand(filePath, category, parentPath = null) {
|
|
3981
|
+
console.log({ filePath, category, parentPath });
|
|
3943
3982
|
const command = {
|
|
3944
3983
|
id: crypto.randomUUID(),
|
|
3945
3984
|
name: parentPath ? this.getDirectoryName(parentPath) : this.extractName(filePath),
|
|
@@ -3951,13 +3990,24 @@ var init_CommandsRouter = __esm({
|
|
|
3951
3990
|
};
|
|
3952
3991
|
this.commands.set(command.id, command);
|
|
3953
3992
|
}
|
|
3993
|
+
extractDirOmitCategory(dirPath) {
|
|
3994
|
+
const segments = path2.normalize(dirPath).split(path2.sep).reverse();
|
|
3995
|
+
let name = "";
|
|
3996
|
+
while (segments.length > 0) {
|
|
3997
|
+
const segment = segments.pop();
|
|
3998
|
+
if (this.isCategoryDirectory(segment)) continue;
|
|
3999
|
+
name = segment;
|
|
4000
|
+
break;
|
|
4001
|
+
}
|
|
4002
|
+
return name;
|
|
4003
|
+
}
|
|
3954
4004
|
/**
|
|
3955
4005
|
* Gets the appropriate file name, handling index files specially
|
|
3956
4006
|
* For index files, it returns the parent directory name (excluding category markers)
|
|
3957
4007
|
*/
|
|
3958
4008
|
getAppropriateFileName(filePath) {
|
|
3959
4009
|
const fileName = this.extractName(filePath);
|
|
3960
|
-
if (fileName === "index" &&
|
|
4010
|
+
if (fileName === "index" && path2.dirname(filePath) !== this.entrypoint) {
|
|
3961
4011
|
return this.getDirectoryName(filePath);
|
|
3962
4012
|
}
|
|
3963
4013
|
return fileName;
|
|
@@ -3966,7 +4016,7 @@ var init_CommandsRouter = __esm({
|
|
|
3966
4016
|
* Extract the clean directory name, removing any category markers
|
|
3967
4017
|
*/
|
|
3968
4018
|
getDirectoryName(filePath) {
|
|
3969
|
-
const dirName =
|
|
4019
|
+
const dirName = path2.basename(path2.dirname(filePath));
|
|
3970
4020
|
return dirName.replace(/^\((\w+)\)$/, "$1");
|
|
3971
4021
|
}
|
|
3972
4022
|
// Helper method to identify category directories
|
|
@@ -3975,7 +4025,7 @@ var init_CommandsRouter = __esm({
|
|
|
3975
4025
|
}
|
|
3976
4026
|
applyMiddlewareToCommands(middleware) {
|
|
3977
4027
|
for (const command of this.commands.values()) {
|
|
3978
|
-
const middlewareFileName =
|
|
4028
|
+
const middlewareFileName = path2.basename(middleware.path);
|
|
3979
4029
|
const match = middlewareFileName.startsWith(command.name) || middlewareFileName === "middleware";
|
|
3980
4030
|
if (!match) continue;
|
|
3981
4031
|
if (command.middlewares.includes(middleware.id)) continue;
|
|
@@ -3984,31 +4034,41 @@ var init_CommandsRouter = __esm({
|
|
|
3984
4034
|
}
|
|
3985
4035
|
applySubcommandToCommands(subcommand) {
|
|
3986
4036
|
for (const command of this.commands.values()) {
|
|
3987
|
-
|
|
3988
|
-
|
|
3989
|
-
|
|
4037
|
+
const subcommandPathParts = path2.normalize(subcommand.path).split(path2.sep);
|
|
4038
|
+
const commandName = command.name;
|
|
4039
|
+
const relevantDirectories = subcommandPathParts.map((part) => path2.basename(part)).filter((part) => !this.isCategoryDirectory(part));
|
|
4040
|
+
if (relevantDirectories.includes(commandName)) {
|
|
4041
|
+
if (!command.subcommands.includes(subcommand.id)) {
|
|
4042
|
+
command.subcommands.push(subcommand.id);
|
|
4043
|
+
}
|
|
4044
|
+
}
|
|
3990
4045
|
}
|
|
3991
4046
|
}
|
|
3992
4047
|
extractCategory(entry) {
|
|
3993
|
-
return entry.split(
|
|
4048
|
+
return path2.normalize(entry).split(path2.sep).map((segment) => {
|
|
3994
4049
|
const match = segment.match(/^\((\w+)\)$/);
|
|
3995
4050
|
return match ? match[1] : null;
|
|
3996
|
-
}).filter(Boolean).join(":");
|
|
4051
|
+
}).filter(Boolean).join(":") || null;
|
|
3997
4052
|
}
|
|
3998
4053
|
getRelativePath(entry) {
|
|
3999
|
-
return
|
|
4054
|
+
return path2.relative(this.entrypoint, entry);
|
|
4000
4055
|
}
|
|
4001
4056
|
isMiddleware(entry) {
|
|
4002
|
-
|
|
4057
|
+
const fileName = path2.basename(entry);
|
|
4058
|
+
return fileName === "middleware.js" || fileName === "middleware.ts" || fileName === "middleware.mjs" || fileName === "middleware.cjs" || fileName === "middleware.jsx" || fileName === "middleware.tsx" || /\.middleware\.(c|m)?(j|t)sx?$/.test(fileName);
|
|
4003
4059
|
}
|
|
4004
4060
|
shouldIgnore(entry, dir = false) {
|
|
4005
|
-
const fileName =
|
|
4061
|
+
const fileName = path2.basename(entry);
|
|
4006
4062
|
if (fileName.startsWith("_")) return true;
|
|
4007
|
-
if (!dir)
|
|
4063
|
+
if (!dir) {
|
|
4064
|
+
const ext = path2.extname(fileName).toLowerCase();
|
|
4065
|
+
return ![".js", ".ts", ".jsx", ".tsx", ".mjs", ".cjs"].includes(ext);
|
|
4066
|
+
}
|
|
4008
4067
|
return false;
|
|
4009
4068
|
}
|
|
4010
4069
|
extractName(entry) {
|
|
4011
|
-
|
|
4070
|
+
const fileName = path2.basename(entry);
|
|
4071
|
+
return path2.parse(fileName).name;
|
|
4012
4072
|
}
|
|
4013
4073
|
};
|
|
4014
4074
|
__name(_CommandsRouter, "CommandsRouter");
|
|
@@ -4529,7 +4589,7 @@ var init_CommandKitEventsChannel = __esm({
|
|
|
4529
4589
|
});
|
|
4530
4590
|
|
|
4531
4591
|
// src/CommandKit.ts
|
|
4532
|
-
var import_node_events2, import_discord12, import_node_path7, _started, _CommandKit_instances, init_fn, initCommands_fn, initEvents_fn, _CommandKit, CommandKit;
|
|
4592
|
+
var import_node_events2, import_discord12, import_node_path7, import_node_fs8, _started, _CommandKit_instances, init_fn, initCommands_fn, initEvents_fn, _CommandKit, CommandKit;
|
|
4533
4593
|
var init_CommandKit = __esm({
|
|
4534
4594
|
"src/CommandKit.ts"() {
|
|
4535
4595
|
"use strict";
|
|
@@ -4551,6 +4611,7 @@ var init_CommandKit = __esm({
|
|
|
4551
4611
|
init_loader();
|
|
4552
4612
|
init_constants();
|
|
4553
4613
|
init_dev_hooks();
|
|
4614
|
+
import_node_fs8 = require("fs");
|
|
4554
4615
|
init_CommandKitEventsChannel();
|
|
4555
4616
|
init_plugins();
|
|
4556
4617
|
init_types_package();
|
|
@@ -4800,10 +4861,14 @@ var init_CommandKit = __esm({
|
|
|
4800
4861
|
}, "#init");
|
|
4801
4862
|
initCommands_fn = /* @__PURE__ */ __name(async function() {
|
|
4802
4863
|
if (this.commandsRouter.isValidPath()) {
|
|
4803
|
-
await this.commandsRouter.scan();
|
|
4864
|
+
const result = await this.commandsRouter.scan();
|
|
4804
4865
|
if (COMMANDKIT_IS_DEV) {
|
|
4805
4866
|
const visual = this.commandsRouter.visualize();
|
|
4806
|
-
|
|
4867
|
+
Logger.info(visual);
|
|
4868
|
+
(0, import_node_fs8.writeFileSync)(
|
|
4869
|
+
"./.commandkit/commands.json",
|
|
4870
|
+
JSON.stringify(result, null, 2)
|
|
4871
|
+
);
|
|
4807
4872
|
}
|
|
4808
4873
|
}
|
|
4809
4874
|
await this.commandHandler.loadCommands();
|
|
@@ -4833,7 +4898,7 @@ var init_version = __esm({
|
|
|
4833
4898
|
"use strict";
|
|
4834
4899
|
init_cjs_shims();
|
|
4835
4900
|
version = /* @__MACRO__ $version */
|
|
4836
|
-
"0.1.11-dev.
|
|
4901
|
+
"0.1.11-dev.20250308073818";
|
|
4837
4902
|
}
|
|
4838
4903
|
});
|
|
4839
4904
|
|
|
@@ -4875,7 +4940,7 @@ function getStdio(supportsCommands) {
|
|
|
4875
4940
|
}
|
|
4876
4941
|
function createAppProcess(fileName, cwd, isDev) {
|
|
4877
4942
|
var _a, _b;
|
|
4878
|
-
if (!(0,
|
|
4943
|
+
if (!(0, import_node_fs9.existsSync)((0, import_node_path8.join)(cwd, fileName))) {
|
|
4879
4944
|
panic(`Could not locate the entrypoint file: ${fileName}`);
|
|
4880
4945
|
}
|
|
4881
4946
|
const stdio = getStdio(isDev);
|
|
@@ -4897,7 +4962,7 @@ function createAppProcess(fileName, cwd, isDev) {
|
|
|
4897
4962
|
(_b = ps.stderr) == null ? void 0 : _b.pipe(process.stderr);
|
|
4898
4963
|
return ps;
|
|
4899
4964
|
}
|
|
4900
|
-
var import_node_child_process, import_node_path8,
|
|
4965
|
+
var import_node_child_process, import_node_path8, import_node_fs9;
|
|
4901
4966
|
var init_app_process = __esm({
|
|
4902
4967
|
"src/cli/app-process.ts"() {
|
|
4903
4968
|
"use strict";
|
|
@@ -4905,7 +4970,7 @@ var init_app_process = __esm({
|
|
|
4905
4970
|
import_node_child_process = require("child_process");
|
|
4906
4971
|
init_env();
|
|
4907
4972
|
import_node_path8 = require("path");
|
|
4908
|
-
|
|
4973
|
+
import_node_fs9 = require("fs");
|
|
4909
4974
|
init_common();
|
|
4910
4975
|
__name(getStdio, "getStdio");
|
|
4911
4976
|
__name(createAppProcess, "createAppProcess");
|
|
@@ -5147,7 +5212,7 @@ async function bootstrapDevelopmentServer(configPath) {
|
|
|
5147
5212
|
watcher.on("add", hmrHandler);
|
|
5148
5213
|
watcher.on("unlink", hmrHandler);
|
|
5149
5214
|
watcher.on("unlinkDir", (path3) => {
|
|
5150
|
-
const hasChild = (0,
|
|
5215
|
+
const hasChild = (0, import_node_fs10.readdirSync)(path3).length > 0;
|
|
5151
5216
|
if (hasChild) return hmrHandler(path3);
|
|
5152
5217
|
});
|
|
5153
5218
|
watcher.on("error", (e) => {
|
|
@@ -5166,7 +5231,7 @@ ${colors_default.yellowBright("re")} - Reload all events
|
|
|
5166
5231
|
${colors_default.yellowBright("rl")} - Reload all locales`
|
|
5167
5232
|
);
|
|
5168
5233
|
}
|
|
5169
|
-
var import_path2, import_chokidar,
|
|
5234
|
+
var import_path2, import_chokidar, import_node_fs10, isCommandSource, isEventSource, isLocaleSource;
|
|
5170
5235
|
var init_development = __esm({
|
|
5171
5236
|
"src/cli/development.ts"() {
|
|
5172
5237
|
"use strict";
|
|
@@ -5177,7 +5242,7 @@ var init_development = __esm({
|
|
|
5177
5242
|
init_app_process();
|
|
5178
5243
|
init_build();
|
|
5179
5244
|
import_chokidar = require("chokidar");
|
|
5180
|
-
|
|
5245
|
+
import_node_fs10 = require("fs");
|
|
5181
5246
|
init_utilities();
|
|
5182
5247
|
init_colors();
|
|
5183
5248
|
__name(buildAndStart, "buildAndStart");
|