commandkit 0.1.11-dev.20250402101800 → 0.1.11-dev.20250402134128
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 +66 -49
- package/dist/index.js +469 -142
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -2528,7 +2528,7 @@ var init_UseCacheTransformer = __esm({
|
|
|
2528
2528
|
generate = import_generator.default.default || import_generator.default;
|
|
2529
2529
|
IMPORT_PATH = "commandkit";
|
|
2530
2530
|
DIRECTIVE = "use cache";
|
|
2531
|
-
CACHE_IDENTIFIER = "
|
|
2531
|
+
CACHE_IDENTIFIER = "zzz_commandkit_secret_internal_use_cache_wrapper_do_not_use_or_you_will_be_fired";
|
|
2532
2532
|
generateRandomString = /* @__PURE__ */ __name((length = 6) => {
|
|
2533
2533
|
const chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
|
|
2534
2534
|
return Array.from(
|
|
@@ -2550,22 +2550,22 @@ var init_UseCacheTransformer = __esm({
|
|
|
2550
2550
|
};
|
|
2551
2551
|
traverse(ast, {
|
|
2552
2552
|
Program: {
|
|
2553
|
-
enter(
|
|
2554
|
-
const binding =
|
|
2553
|
+
enter(path3) {
|
|
2554
|
+
const binding = path3.scope.getBinding(CACHE_IDENTIFIER);
|
|
2555
2555
|
if (binding) {
|
|
2556
2556
|
state.cacheIdentifierName = `${CACHE_IDENTIFIER}_${generateRandomString()}`;
|
|
2557
2557
|
}
|
|
2558
2558
|
}
|
|
2559
2559
|
},
|
|
2560
|
-
ImportDeclaration(
|
|
2561
|
-
if (
|
|
2560
|
+
ImportDeclaration(path3) {
|
|
2561
|
+
if (path3.node.source.value === IMPORT_PATH && path3.node.specifiers.some(
|
|
2562
2562
|
(spec) => t.isImportSpecifier(spec) && // @ts-ignore
|
|
2563
2563
|
spec.imported.name === CACHE_IDENTIFIER
|
|
2564
2564
|
)) {
|
|
2565
2565
|
state.hasExistingImport = true;
|
|
2566
2566
|
if (state.cacheIdentifierName !== CACHE_IDENTIFIER) {
|
|
2567
2567
|
state.modifications.push(() => {
|
|
2568
|
-
|
|
2568
|
+
path3.node.specifiers.forEach((spec) => {
|
|
2569
2569
|
if (t.isImportSpecifier(spec) && // @ts-ignore
|
|
2570
2570
|
spec.imported.name === CACHE_IDENTIFIER) {
|
|
2571
2571
|
spec.local.name = state.cacheIdentifierName;
|
|
@@ -2575,14 +2575,14 @@ var init_UseCacheTransformer = __esm({
|
|
|
2575
2575
|
}
|
|
2576
2576
|
}
|
|
2577
2577
|
},
|
|
2578
|
-
"FunctionDeclaration|FunctionExpression|ArrowFunctionExpression|ObjectMethod"(
|
|
2578
|
+
"FunctionDeclaration|FunctionExpression|ArrowFunctionExpression|ObjectMethod"(path3) {
|
|
2579
2579
|
var _a2, _b, _c;
|
|
2580
|
-
const body = t.isBlockStatement(
|
|
2580
|
+
const body = t.isBlockStatement(path3.node.body) ? path3.node.body : null;
|
|
2581
2581
|
const hasUseCache = (_a2 = body == null ? void 0 : body.directives) == null ? void 0 : _a2.some(
|
|
2582
2582
|
(d) => d.value.value === DIRECTIVE
|
|
2583
2583
|
);
|
|
2584
|
-
if (!hasUseCache && !t.isBlockStatement(
|
|
2585
|
-
const parentFunction =
|
|
2584
|
+
if (!hasUseCache && !t.isBlockStatement(path3.node.body)) {
|
|
2585
|
+
const parentFunction = path3.findParent(
|
|
2586
2586
|
(p) => (p.isFunction() || p.isProgram()) && "directives" in p.node
|
|
2587
2587
|
);
|
|
2588
2588
|
if (!((_b = parentFunction == null ? void 0 : parentFunction.node.directives) == null ? void 0 : _b.some(
|
|
@@ -2591,35 +2591,35 @@ var init_UseCacheTransformer = __esm({
|
|
|
2591
2591
|
return;
|
|
2592
2592
|
}
|
|
2593
2593
|
}
|
|
2594
|
-
if (hasUseCache || !t.isBlockStatement(
|
|
2595
|
-
if (!
|
|
2594
|
+
if (hasUseCache || !t.isBlockStatement(path3.node.body)) {
|
|
2595
|
+
if (!path3.node.async) {
|
|
2596
2596
|
throw new Error(
|
|
2597
2597
|
`"${DIRECTIVE}" directive may only be used in async functions at ${args.path}
|
|
2598
2598
|
|
|
2599
|
-
${
|
|
2599
|
+
${path3.toString()}
|
|
2600
2600
|
^^^^${"-".repeat(6)} This function must be async`
|
|
2601
2601
|
);
|
|
2602
2602
|
}
|
|
2603
2603
|
state.needsImport = true;
|
|
2604
|
-
const isDeclaration = t.isFunctionDeclaration(
|
|
2605
|
-
const name = isDeclaration ? (_c =
|
|
2606
|
-
const newBody = t.isBlockStatement(
|
|
2607
|
-
|
|
2608
|
-
|
|
2604
|
+
const isDeclaration = t.isFunctionDeclaration(path3.node);
|
|
2605
|
+
const name = isDeclaration ? (_c = path3.node.id) == null ? void 0 : _c.name : void 0;
|
|
2606
|
+
const newBody = t.isBlockStatement(path3.node.body) ? t.blockStatement(
|
|
2607
|
+
path3.node.body.body,
|
|
2608
|
+
path3.node.body.directives.filter(
|
|
2609
2609
|
(d) => d.value.value !== DIRECTIVE
|
|
2610
2610
|
)
|
|
2611
|
-
) :
|
|
2611
|
+
) : path3.node.body;
|
|
2612
2612
|
const wrapped = t.callExpression(
|
|
2613
2613
|
t.identifier(state.cacheIdentifierName),
|
|
2614
|
-
[t.arrowFunctionExpression(
|
|
2614
|
+
[t.arrowFunctionExpression(path3.node.params, newBody, true)]
|
|
2615
2615
|
);
|
|
2616
2616
|
state.modifications.push(() => {
|
|
2617
|
-
if (t.isObjectMethod(
|
|
2618
|
-
|
|
2619
|
-
t.objectProperty(t.identifier(
|
|
2617
|
+
if (t.isObjectMethod(path3.node)) {
|
|
2618
|
+
path3.replaceWith(
|
|
2619
|
+
t.objectProperty(t.identifier(path3.node.key.name), wrapped)
|
|
2620
2620
|
);
|
|
2621
2621
|
} else if (name) {
|
|
2622
|
-
|
|
2622
|
+
path3.replaceWith(
|
|
2623
2623
|
t.variableDeclaration(
|
|
2624
2624
|
"const",
|
|
2625
2625
|
[
|
|
@@ -2627,10 +2627,10 @@ ${path2.toString()}
|
|
|
2627
2627
|
]
|
|
2628
2628
|
)
|
|
2629
2629
|
);
|
|
2630
|
-
} else if (!t.isVariableDeclarator(
|
|
2631
|
-
|
|
2630
|
+
} else if (!t.isVariableDeclarator(path3.parent)) {
|
|
2631
|
+
path3.replaceWith(wrapped);
|
|
2632
2632
|
} else {
|
|
2633
|
-
|
|
2633
|
+
path3.parent.init = wrapped;
|
|
2634
2634
|
}
|
|
2635
2635
|
});
|
|
2636
2636
|
}
|
|
@@ -2814,7 +2814,7 @@ var init_config = __esm({
|
|
|
2814
2814
|
});
|
|
2815
2815
|
|
|
2816
2816
|
// src/utils/constants.ts
|
|
2817
|
-
var COMMANDKIT_CACHE_TAG, COMMANDKIT_IS_DEV, COMMANDKIT_IS_TEST;
|
|
2817
|
+
var COMMANDKIT_CACHE_TAG, COMMANDKIT_IS_DEV, COMMANDKIT_IS_TEST, HMREventType;
|
|
2818
2818
|
var init_constants = __esm({
|
|
2819
2819
|
"src/utils/constants.ts"() {
|
|
2820
2820
|
"use strict";
|
|
@@ -2822,6 +2822,12 @@ var init_constants = __esm({
|
|
|
2822
2822
|
COMMANDKIT_CACHE_TAG = Symbol("kCommandKitCacheTag");
|
|
2823
2823
|
COMMANDKIT_IS_DEV = !!process.env.COMMANDKIT_IS_DEV;
|
|
2824
2824
|
COMMANDKIT_IS_TEST = process.env.COMMANDKIT_IS_TEST === "true";
|
|
2825
|
+
HMREventType = {
|
|
2826
|
+
ReloadCommands: "reload-commands",
|
|
2827
|
+
ReloadEvents: "reload-events",
|
|
2828
|
+
ReloadLocales: "reload-locales",
|
|
2829
|
+
Unknown: "unknown"
|
|
2830
|
+
};
|
|
2825
2831
|
}
|
|
2826
2832
|
});
|
|
2827
2833
|
|
|
@@ -2847,18 +2853,18 @@ var init_DefaultLocalizationStrategy = __esm({
|
|
|
2847
2853
|
const paths = [".js", ".json", ".mjs", ".cjs"].map(
|
|
2848
2854
|
(e) => (0, import_node_path.join)(localesPath, locale, scope) + e
|
|
2849
2855
|
);
|
|
2850
|
-
for (const
|
|
2851
|
-
if (!(0, import_node_fs.existsSync)(
|
|
2856
|
+
for (const path3 of paths) {
|
|
2857
|
+
if (!(0, import_node_fs.existsSync)(path3)) {
|
|
2852
2858
|
continue;
|
|
2853
2859
|
}
|
|
2854
2860
|
try {
|
|
2855
2861
|
let localeData;
|
|
2856
2862
|
try {
|
|
2857
|
-
if (
|
|
2858
|
-
const data = await (0, import_promises2.readFile)(
|
|
2863
|
+
if (path3.endsWith(".json")) {
|
|
2864
|
+
const data = await (0, import_promises2.readFile)(path3, "utf-8");
|
|
2859
2865
|
localeData = JSON.parse(data);
|
|
2860
2866
|
} else {
|
|
2861
|
-
const { default: data } = await import(`file://${
|
|
2867
|
+
const { default: data } = await import(`file://${path3}`);
|
|
2862
2868
|
localeData = data;
|
|
2863
2869
|
}
|
|
2864
2870
|
} catch {
|
|
@@ -2889,8 +2895,8 @@ export {};
|
|
|
2889
2895
|
declare module 'commandkit' {
|
|
2890
2896
|
export interface CommandLocalizationTypeData {
|
|
2891
2897
|
`;
|
|
2892
|
-
const footer = `
|
|
2893
|
-
|
|
2898
|
+
const footer = ` }
|
|
2899
|
+
type TranslatableCommandName = keyof CommandLocalizationTypeData
|
|
2894
2900
|
}`;
|
|
2895
2901
|
const generateType = /* @__PURE__ */ __name((locale) => {
|
|
2896
2902
|
const commandName = locale.command.name;
|
|
@@ -2989,6 +2995,13 @@ function getCurrentDirectory() {
|
|
|
2989
2995
|
currentDir = root;
|
|
2990
2996
|
return root;
|
|
2991
2997
|
}
|
|
2998
|
+
function getSourceDirectories() {
|
|
2999
|
+
const dist = getConfig().distDir;
|
|
3000
|
+
const locations = ["src", ".commandkit", dist].map(
|
|
3001
|
+
(dir) => (0, import_node_path2.join)(process.cwd(), dir)
|
|
3002
|
+
);
|
|
3003
|
+
return locations;
|
|
3004
|
+
}
|
|
2992
3005
|
function findAppDirectory() {
|
|
2993
3006
|
if (appDir) return appDir;
|
|
2994
3007
|
let root = (0, import_node_path2.join)(
|
|
@@ -3038,6 +3051,7 @@ var init_utilities = __esm({
|
|
|
3038
3051
|
appDir = null;
|
|
3039
3052
|
currentDir = null;
|
|
3040
3053
|
__name(getCurrentDirectory, "getCurrentDirectory");
|
|
3054
|
+
__name(getSourceDirectories, "getSourceDirectories");
|
|
3041
3055
|
__name(findAppDirectory, "findAppDirectory");
|
|
3042
3056
|
__name(debounce, "debounce");
|
|
3043
3057
|
}
|
|
@@ -3451,9 +3465,24 @@ var init_environment = __esm({
|
|
|
3451
3465
|
deferredFunctions: /* @__PURE__ */ new Map(),
|
|
3452
3466
|
marker: "",
|
|
3453
3467
|
markStart: 0,
|
|
3454
|
-
markEnd: 0
|
|
3468
|
+
markEnd: 0,
|
|
3469
|
+
context: null
|
|
3455
3470
|
});
|
|
3456
3471
|
}
|
|
3472
|
+
/**
|
|
3473
|
+
* Set the context.
|
|
3474
|
+
* @param context - The context to set.
|
|
3475
|
+
*/
|
|
3476
|
+
setContext(context2) {
|
|
3477
|
+
__privateGet(this, _data).context = context2;
|
|
3478
|
+
}
|
|
3479
|
+
/**
|
|
3480
|
+
* Get the context. `null` if not set.
|
|
3481
|
+
* @internal
|
|
3482
|
+
*/
|
|
3483
|
+
get context() {
|
|
3484
|
+
return __privateGet(this, _data).context;
|
|
3485
|
+
}
|
|
3457
3486
|
/**
|
|
3458
3487
|
* Get the execution error.
|
|
3459
3488
|
* @internal
|
|
@@ -3776,7 +3805,7 @@ async function revalidate(tag, ...args) {
|
|
|
3776
3805
|
function isCachedFunction(fn) {
|
|
3777
3806
|
return Object.prototype.hasOwnProperty.call(fn, CACHED_FN_SYMBOL);
|
|
3778
3807
|
}
|
|
3779
|
-
var import_node_async_hooks2, import_node_crypto2, import_ms, cacheContext, fnStore, DEFAULT_TTL, CACHE_FN_ID, CACHED_FN_SYMBOL;
|
|
3808
|
+
var import_node_async_hooks2, import_node_crypto2, import_ms, cacheContext, fnStore, DEFAULT_TTL, CACHE_FN_ID, CACHED_FN_SYMBOL, zzz_commandkit_secret_internal_use_cache_wrapper_do_not_use_or_you_will_be_fired;
|
|
3780
3809
|
var init_cache = __esm({
|
|
3781
3810
|
"src/cache/cache.ts"() {
|
|
3782
3811
|
"use strict";
|
|
@@ -3799,6 +3828,7 @@ var init_cache = __esm({
|
|
|
3799
3828
|
__name(invalidate, "invalidate");
|
|
3800
3829
|
__name(revalidate, "revalidate");
|
|
3801
3830
|
__name(isCachedFunction, "isCachedFunction");
|
|
3831
|
+
zzz_commandkit_secret_internal_use_cache_wrapper_do_not_use_or_you_will_be_fired = useCache;
|
|
3802
3832
|
}
|
|
3803
3833
|
});
|
|
3804
3834
|
|
|
@@ -3863,6 +3893,9 @@ var init_Context = __esm({
|
|
|
3863
3893
|
this.client = commandkit2.client;
|
|
3864
3894
|
__privateSet(this, _store, config.store ?? /* @__PURE__ */ new Map());
|
|
3865
3895
|
this.command = config.command;
|
|
3896
|
+
if (this.config.environment) {
|
|
3897
|
+
this.config.environment.setContext(this);
|
|
3898
|
+
}
|
|
3866
3899
|
}
|
|
3867
3900
|
/**
|
|
3868
3901
|
* The shared key-value store for this context. This can be used to store data that needs to be shared between middlewares or commands.
|
|
@@ -4883,8 +4916,8 @@ var init_CommandsRouter = __esm({
|
|
|
4883
4916
|
middlewares: Object.fromEntries(this.middlewares.entries())
|
|
4884
4917
|
};
|
|
4885
4918
|
}
|
|
4886
|
-
async traverse(
|
|
4887
|
-
const entries = await (0, import_promises4.readdir)(
|
|
4919
|
+
async traverse(path3, category) {
|
|
4920
|
+
const entries = await (0, import_promises4.readdir)(path3, {
|
|
4888
4921
|
withFileTypes: true
|
|
4889
4922
|
});
|
|
4890
4923
|
for (const entry of entries) {
|
|
@@ -4898,24 +4931,24 @@ var init_CommandsRouter = __esm({
|
|
|
4898
4931
|
}
|
|
4899
4932
|
async handle(entry, category = null) {
|
|
4900
4933
|
const name = entry.name;
|
|
4901
|
-
const
|
|
4934
|
+
const path3 = (0, import_node_path4.join)(entry.parentPath, entry.name);
|
|
4902
4935
|
if (this.isCommand(name)) {
|
|
4903
4936
|
const command = {
|
|
4904
4937
|
id: crypto.randomUUID(),
|
|
4905
|
-
name: (0, import_node_path4.basename)(
|
|
4906
|
-
path:
|
|
4938
|
+
name: (0, import_node_path4.basename)(path3, (0, import_node_path4.extname)(path3)),
|
|
4939
|
+
path: path3,
|
|
4907
4940
|
category,
|
|
4908
4941
|
parentPath: entry.parentPath,
|
|
4909
|
-
relativePath: this.replaceEntrypoint(
|
|
4942
|
+
relativePath: this.replaceEntrypoint(path3),
|
|
4910
4943
|
middlewares: []
|
|
4911
4944
|
};
|
|
4912
4945
|
this.commands.set(command.id, command);
|
|
4913
4946
|
} else if (this.isMiddleware(name)) {
|
|
4914
4947
|
const middleware = {
|
|
4915
4948
|
id: crypto.randomUUID(),
|
|
4916
|
-
name: (0, import_node_path4.basename)(
|
|
4917
|
-
path:
|
|
4918
|
-
relativePath: this.replaceEntrypoint(
|
|
4949
|
+
name: (0, import_node_path4.basename)(path3, (0, import_node_path4.extname)(path3)),
|
|
4950
|
+
path: path3,
|
|
4951
|
+
relativePath: this.replaceEntrypoint(path3),
|
|
4919
4952
|
parentPath: entry.parentPath,
|
|
4920
4953
|
global: GLOBAL_MIDDLEWARE_PATTERN.test(name)
|
|
4921
4954
|
};
|
|
@@ -4933,8 +4966,8 @@ var init_CommandsRouter = __esm({
|
|
|
4933
4966
|
);
|
|
4934
4967
|
});
|
|
4935
4968
|
}
|
|
4936
|
-
replaceEntrypoint(
|
|
4937
|
-
const normalized = (0, import_node_path4.normalize)(
|
|
4969
|
+
replaceEntrypoint(path3) {
|
|
4970
|
+
const normalized = (0, import_node_path4.normalize)(path3);
|
|
4938
4971
|
return normalized.replace(this.options.entrypoint, "");
|
|
4939
4972
|
}
|
|
4940
4973
|
};
|
|
@@ -5024,8 +5057,8 @@ var init_EventsRouter = __esm({
|
|
|
5024
5057
|
const dirs = await (0, import_promises5.readdir)(entrypoint, { withFileTypes: true });
|
|
5025
5058
|
for (const dir of dirs) {
|
|
5026
5059
|
if (dir.isDirectory()) {
|
|
5027
|
-
const
|
|
5028
|
-
await this.scanEvent(dir.name,
|
|
5060
|
+
const path3 = (0, import_node_path5.join)(entrypoint, dir.name);
|
|
5061
|
+
await this.scanEvent(dir.name, path3, null, [], true);
|
|
5029
5062
|
}
|
|
5030
5063
|
}
|
|
5031
5064
|
}
|
|
@@ -5045,14 +5078,14 @@ var init_EventsRouter = __esm({
|
|
|
5045
5078
|
* @param listeners - Array to collect listener file paths
|
|
5046
5079
|
* @returns Promise resolving to the parsed event metadata
|
|
5047
5080
|
*/
|
|
5048
|
-
async scanEvent(event,
|
|
5049
|
-
const files = await (0, import_promises5.readdir)(
|
|
5081
|
+
async scanEvent(event, path3, _namespace = null, listeners = [], isRoot = false) {
|
|
5082
|
+
const files = await (0, import_promises5.readdir)(path3, { withFileTypes: true });
|
|
5050
5083
|
const isNamespace = isRoot && /^\(.+\)$/.test(event);
|
|
5051
5084
|
const namespace = isNamespace ? event.slice(1, -1) : _namespace ?? null;
|
|
5052
5085
|
for (const file of files) {
|
|
5053
5086
|
if (file.name.includes("_")) continue;
|
|
5054
5087
|
if (file.isDirectory()) {
|
|
5055
|
-
const nextPath = (0, import_node_path5.join)(
|
|
5088
|
+
const nextPath = (0, import_node_path5.join)(path3, file.name);
|
|
5056
5089
|
await this.scanEvent(file.name, nextPath, namespace, listeners);
|
|
5057
5090
|
continue;
|
|
5058
5091
|
}
|
|
@@ -5061,7 +5094,7 @@ var init_EventsRouter = __esm({
|
|
|
5061
5094
|
}
|
|
5062
5095
|
}
|
|
5063
5096
|
if (!isNamespace) {
|
|
5064
|
-
this.events.set(event, { event, path:
|
|
5097
|
+
this.events.set(event, { event, path: path3, listeners, namespace });
|
|
5065
5098
|
}
|
|
5066
5099
|
}
|
|
5067
5100
|
};
|
|
@@ -5309,8 +5342,11 @@ var init_common2 = __esm({
|
|
|
5309
5342
|
});
|
|
5310
5343
|
|
|
5311
5344
|
// src/config/loader.ts
|
|
5345
|
+
function getPossibleConfigPaths(root) {
|
|
5346
|
+
return CONFIG_FILE_NAMES.map((name) => (0, import_node_path7.join)(root, name));
|
|
5347
|
+
}
|
|
5312
5348
|
function findConfigFile(cwd) {
|
|
5313
|
-
const locations =
|
|
5349
|
+
const locations = getPossibleConfigPaths(cwd);
|
|
5314
5350
|
for (const location of locations) {
|
|
5315
5351
|
if ((0, import_node_fs7.existsSync)(location)) {
|
|
5316
5352
|
return {
|
|
@@ -5344,6 +5380,7 @@ var init_loader = __esm({
|
|
|
5344
5380
|
"commandkit.config.cjs",
|
|
5345
5381
|
"commandkit.config.ts"
|
|
5346
5382
|
];
|
|
5383
|
+
__name(getPossibleConfigPaths, "getPossibleConfigPaths");
|
|
5347
5384
|
__name(findConfigFile, "findConfigFile");
|
|
5348
5385
|
loadedConfig = null;
|
|
5349
5386
|
__name(loadConfigFile, "loadConfigFile");
|
|
@@ -5355,38 +5392,53 @@ function registerDevHooks(commandkit2) {
|
|
|
5355
5392
|
if (!COMMANDKIT_IS_DEV) return;
|
|
5356
5393
|
process.on("message", async (message) => {
|
|
5357
5394
|
if (typeof message !== "object" || message === null) return;
|
|
5358
|
-
const { event, path:
|
|
5395
|
+
const { event, path: path3, id } = message;
|
|
5359
5396
|
if (!event) return;
|
|
5360
5397
|
if (process.env.COMMANDKIT_DEBUG_HMR === "true") {
|
|
5361
|
-
Logger.info(`Received HMR event: ${event}${
|
|
5398
|
+
Logger.info(`Received HMR event: ${event}${path3 ? ` for ${path3}` : ""}`);
|
|
5362
5399
|
}
|
|
5363
|
-
let accepted = false, prevented = false;
|
|
5400
|
+
let accepted = false, prevented = false, handled = false;
|
|
5364
5401
|
const hmrEvent = {
|
|
5365
5402
|
accept() {
|
|
5366
5403
|
accepted = true;
|
|
5367
5404
|
},
|
|
5368
5405
|
preventDefault() {
|
|
5369
|
-
prevented =
|
|
5406
|
+
prevented = true;
|
|
5370
5407
|
},
|
|
5371
|
-
path:
|
|
5408
|
+
path: path3,
|
|
5372
5409
|
event
|
|
5373
5410
|
};
|
|
5374
|
-
|
|
5375
|
-
|
|
5376
|
-
|
|
5377
|
-
|
|
5378
|
-
|
|
5379
|
-
|
|
5380
|
-
|
|
5381
|
-
|
|
5382
|
-
|
|
5383
|
-
|
|
5384
|
-
|
|
5385
|
-
|
|
5386
|
-
|
|
5387
|
-
|
|
5388
|
-
|
|
5389
|
-
|
|
5411
|
+
try {
|
|
5412
|
+
await commandkit2.plugins.execute(async (ctx, plugin) => {
|
|
5413
|
+
var _a;
|
|
5414
|
+
if (accepted) return;
|
|
5415
|
+
await ((_a = plugin.performHMR) == null ? void 0 : _a.call(plugin, ctx, hmrEvent));
|
|
5416
|
+
});
|
|
5417
|
+
if (prevented) return;
|
|
5418
|
+
switch (event) {
|
|
5419
|
+
case HMREventType.ReloadCommands:
|
|
5420
|
+
commandkit2.commandHandler.reloadCommands();
|
|
5421
|
+
handled = true;
|
|
5422
|
+
break;
|
|
5423
|
+
case HMREventType.ReloadEvents:
|
|
5424
|
+
case HMREventType.ReloadLocales:
|
|
5425
|
+
commandkit2.eventHandler.reloadEvents();
|
|
5426
|
+
handled = true;
|
|
5427
|
+
break;
|
|
5428
|
+
case HMREventType.Unknown:
|
|
5429
|
+
handled = false;
|
|
5430
|
+
break;
|
|
5431
|
+
default:
|
|
5432
|
+
break;
|
|
5433
|
+
}
|
|
5434
|
+
} finally {
|
|
5435
|
+
if (id && process.send) {
|
|
5436
|
+
process.send({
|
|
5437
|
+
type: "commandkit-hmr-ack",
|
|
5438
|
+
id,
|
|
5439
|
+
handled: handled || accepted
|
|
5440
|
+
});
|
|
5441
|
+
}
|
|
5390
5442
|
}
|
|
5391
5443
|
});
|
|
5392
5444
|
}
|
|
@@ -5514,7 +5566,6 @@ var init_CommandKit = __esm({
|
|
|
5514
5566
|
if (options.cacheProvider !== null && (!options.cacheProvider || !(options.cacheProvider instanceof CacheProvider))) {
|
|
5515
5567
|
options.cacheProvider = new MemoryCache();
|
|
5516
5568
|
}
|
|
5517
|
-
this.eventInterceptor = new EventInterceptor(options.client);
|
|
5518
5569
|
this.plugins = new CommandKitPluginRuntime(this);
|
|
5519
5570
|
if (!_CommandKit.instance) {
|
|
5520
5571
|
_CommandKit.instance = this;
|
|
@@ -5527,6 +5578,12 @@ var init_CommandKit = __esm({
|
|
|
5527
5578
|
*/
|
|
5528
5579
|
async start(token) {
|
|
5529
5580
|
if (__privateGet(this, _started)) return;
|
|
5581
|
+
if (!this.options.client) {
|
|
5582
|
+
throw new Error(
|
|
5583
|
+
colors_default.red('"client" is required when starting CommandKit.')
|
|
5584
|
+
);
|
|
5585
|
+
}
|
|
5586
|
+
this.eventInterceptor = new EventInterceptor(this.client);
|
|
5530
5587
|
if (COMMANDKIT_IS_DEV) {
|
|
5531
5588
|
try {
|
|
5532
5589
|
registerDevHooks(this);
|
|
@@ -5740,7 +5797,7 @@ var init_version = __esm({
|
|
|
5740
5797
|
"use strict";
|
|
5741
5798
|
init_cjs_shims();
|
|
5742
5799
|
version = /* @__MACRO__ $version */
|
|
5743
|
-
"0.1.11-dev.
|
|
5800
|
+
"0.1.11-dev.20250402134128";
|
|
5744
5801
|
}
|
|
5745
5802
|
});
|
|
5746
5803
|
|
|
@@ -5890,7 +5947,7 @@ ${wrapInAsyncIIFE([envScript(isDev), antiCrashScript, requireScript])}
|
|
|
5890
5947
|
import { CommandKit } from 'commandkit';
|
|
5891
5948
|
import app from './app.js';
|
|
5892
5949
|
|
|
5893
|
-
async function
|
|
5950
|
+
async function bootstrap() {
|
|
5894
5951
|
const commandkit = new CommandKit({
|
|
5895
5952
|
client: app,
|
|
5896
5953
|
});
|
|
@@ -5898,7 +5955,9 @@ async function main() {
|
|
|
5898
5955
|
await commandkit.start();
|
|
5899
5956
|
}
|
|
5900
5957
|
|
|
5901
|
-
await
|
|
5958
|
+
await bootstrap().catch((e) => {
|
|
5959
|
+
console.error('Failed to bootstrap CommandKit application:\\n', e.stack);
|
|
5960
|
+
})
|
|
5902
5961
|
`;
|
|
5903
5962
|
const dist = isDev ? ".commandkit" : distDir || "dist";
|
|
5904
5963
|
await (0, import_promises6.writeFile)((0, import_node_path10.join)(configPath, dist, "index.js"), code);
|
|
@@ -5980,52 +6039,116 @@ async function buildAndStart(configPath, skipStart = false) {
|
|
|
5980
6039
|
});
|
|
5981
6040
|
if (skipStart) return null;
|
|
5982
6041
|
const ps = createAppProcess(mainFile, configPath, true);
|
|
5983
|
-
ps.on("message", (message) => {
|
|
5984
|
-
console.log(`Received message from child process: ${message}`);
|
|
5985
|
-
});
|
|
5986
6042
|
return ps;
|
|
5987
6043
|
}
|
|
5988
6044
|
async function bootstrapDevelopmentServer(configPath) {
|
|
5989
6045
|
const start = performance.now();
|
|
5990
6046
|
const cwd = configPath || process.cwd();
|
|
5991
|
-
const
|
|
6047
|
+
const configPaths = getPossibleConfigPaths(cwd);
|
|
6048
|
+
const watcher = (0, import_chokidar.watch)([(0, import_path2.join)(cwd, "src"), ...configPaths], {
|
|
5992
6049
|
ignoreInitial: true
|
|
5993
6050
|
});
|
|
5994
6051
|
let ps = null;
|
|
5995
|
-
const
|
|
5996
|
-
|
|
5997
|
-
|
|
5998
|
-
|
|
5999
|
-
|
|
6000
|
-
|
|
6052
|
+
const waitForAcknowledgment = /* @__PURE__ */ __name((messageId) => {
|
|
6053
|
+
return new Promise((resolve) => {
|
|
6054
|
+
if (!ps) return resolve(false);
|
|
6055
|
+
let _handled = false;
|
|
6056
|
+
const onMessage = /* @__PURE__ */ __name((message) => {
|
|
6057
|
+
_handled = true;
|
|
6058
|
+
if (typeof message !== "object" || message === null) return;
|
|
6059
|
+
const { type, id, handled } = message;
|
|
6060
|
+
if (type === "commandkit-hmr-ack" && id === messageId) {
|
|
6061
|
+
ps == null ? void 0 : ps.off("message", onMessage);
|
|
6062
|
+
resolve(!!handled);
|
|
6063
|
+
}
|
|
6064
|
+
}, "onMessage");
|
|
6065
|
+
ps.once("message", onMessage);
|
|
6066
|
+
if (!_handled) {
|
|
6067
|
+
(0, import_promises7.setTimeout)(3e3).then(() => {
|
|
6068
|
+
ps == null ? void 0 : ps.off("message", onMessage);
|
|
6069
|
+
resolve(false);
|
|
6070
|
+
});
|
|
6071
|
+
}
|
|
6072
|
+
});
|
|
6073
|
+
}, "waitForAcknowledgment");
|
|
6074
|
+
const sendHmrEvent = /* @__PURE__ */ __name(async (event, path3) => {
|
|
6075
|
+
if (!ps || !ps.send) return false;
|
|
6076
|
+
const messageId = (0, import_node_crypto3.randomUUID)();
|
|
6077
|
+
const messagePromise = waitForAcknowledgment(messageId);
|
|
6078
|
+
ps.send({ event, path: path3, id: messageId });
|
|
6079
|
+
try {
|
|
6080
|
+
let triggered = false;
|
|
6081
|
+
const res = !!await Promise.race(
|
|
6082
|
+
[
|
|
6083
|
+
messagePromise,
|
|
6084
|
+
(0, import_promises7.setTimeout)(3e3).then(() => {
|
|
6085
|
+
if (!triggered) {
|
|
6086
|
+
console.warn(
|
|
6087
|
+
colors_default.yellow(
|
|
6088
|
+
`HMR acknowledgment timed out for event ${event} on path ${path3}`
|
|
6089
|
+
)
|
|
6090
|
+
);
|
|
6091
|
+
}
|
|
6092
|
+
return false;
|
|
6093
|
+
})
|
|
6094
|
+
]
|
|
6001
6095
|
);
|
|
6002
|
-
|
|
6003
|
-
|
|
6004
|
-
|
|
6005
|
-
|
|
6006
|
-
|
|
6007
|
-
console.log(
|
|
6008
|
-
`${colors_default.cyanBright("Reloading event(s) at ")} ${colors_default.yellowBright(path2)}`
|
|
6096
|
+
triggered = true;
|
|
6097
|
+
return res;
|
|
6098
|
+
} catch (error) {
|
|
6099
|
+
console.error(
|
|
6100
|
+
colors_default.red(`Error waiting for HMR acknowledgment: ${error}`)
|
|
6009
6101
|
);
|
|
6010
|
-
|
|
6011
|
-
ps.send({ event: "reload-events", path: path2 });
|
|
6012
|
-
return true;
|
|
6102
|
+
return false;
|
|
6013
6103
|
}
|
|
6014
|
-
|
|
6104
|
+
}, "sendHmrEvent");
|
|
6105
|
+
const performHMR = debounce(async (path3) => {
|
|
6106
|
+
if (!path3 || !ps) return false;
|
|
6107
|
+
let eventType = null;
|
|
6108
|
+
let eventDescription = "";
|
|
6109
|
+
if (isCommandSource(path3)) {
|
|
6110
|
+
eventType = HMREventType.ReloadCommands;
|
|
6111
|
+
eventDescription = "command(s)";
|
|
6112
|
+
} else if (isEventSource(path3)) {
|
|
6113
|
+
eventType = HMREventType.ReloadEvents;
|
|
6114
|
+
eventDescription = "event(s)";
|
|
6115
|
+
} else if (isLocaleSource(path3)) {
|
|
6116
|
+
eventType = HMREventType.ReloadLocales;
|
|
6117
|
+
eventDescription = "locale(s)";
|
|
6118
|
+
} else {
|
|
6119
|
+
eventType = HMREventType.Unknown;
|
|
6120
|
+
eventDescription = "unknown source";
|
|
6121
|
+
}
|
|
6122
|
+
if (eventType) {
|
|
6015
6123
|
console.log(
|
|
6016
|
-
`${colors_default.cyanBright(
|
|
6124
|
+
`${colors_default.cyanBright(`Attempting to reload ${eventDescription} at`)} ${colors_default.yellowBright(path3)}`
|
|
6017
6125
|
);
|
|
6018
6126
|
await buildAndStart(cwd, true);
|
|
6019
|
-
|
|
6020
|
-
|
|
6127
|
+
const hmrHandled = await sendHmrEvent(eventType, path3);
|
|
6128
|
+
if (hmrHandled) {
|
|
6129
|
+
console.log(
|
|
6130
|
+
`${colors_default.greenBright(`Successfully hot reloaded ${eventDescription} at`)} ${colors_default.yellowBright(path3)}`
|
|
6131
|
+
);
|
|
6132
|
+
return true;
|
|
6133
|
+
}
|
|
6021
6134
|
}
|
|
6022
6135
|
return false;
|
|
6023
6136
|
}, 300);
|
|
6024
|
-
const
|
|
6025
|
-
const
|
|
6137
|
+
const isConfigUpdate = /* @__PURE__ */ __name((path3) => {
|
|
6138
|
+
const isConfig = configPaths.some((configPath2) => path3 === configPath2);
|
|
6139
|
+
console.log(
|
|
6140
|
+
colors_default.yellowBright(
|
|
6141
|
+
"It seems like commandkit config file was updated, please restart the server manually to apply changes."
|
|
6142
|
+
)
|
|
6143
|
+
);
|
|
6144
|
+
return isConfig;
|
|
6145
|
+
}, "isConfigUpdate");
|
|
6146
|
+
const hmrHandler = /* @__PURE__ */ __name(async (path3) => {
|
|
6147
|
+
if (isConfigUpdate(path3)) return;
|
|
6148
|
+
const hmr = await performHMR(path3);
|
|
6026
6149
|
if (hmr) return;
|
|
6027
6150
|
console.log(
|
|
6028
|
-
`${colors_default.yellowBright("\u26A1\uFE0F Performing full restart due to the changes in")} ${colors_default.cyanBright(
|
|
6151
|
+
`${colors_default.yellowBright("\u26A1\uFE0F Performing full restart due to the changes in")} ${colors_default.cyanBright(path3)}`
|
|
6029
6152
|
);
|
|
6030
6153
|
ps == null ? void 0 : ps.kill();
|
|
6031
6154
|
ps = await buildAndStart(cwd);
|
|
@@ -6037,19 +6160,19 @@ async function bootstrapDevelopmentServer(configPath) {
|
|
|
6037
6160
|
console.log(`Received restart command, restarting...`);
|
|
6038
6161
|
ps == null ? void 0 : ps.kill();
|
|
6039
6162
|
ps = null;
|
|
6040
|
-
await buildAndStart(cwd);
|
|
6163
|
+
ps = await buildAndStart(cwd);
|
|
6041
6164
|
break;
|
|
6042
6165
|
case "rc":
|
|
6043
6166
|
console.log(`Received reload commands command, reloading...`);
|
|
6044
|
-
|
|
6167
|
+
await sendHmrEvent(HMREventType.ReloadCommands);
|
|
6045
6168
|
break;
|
|
6046
6169
|
case "re":
|
|
6047
6170
|
console.log(`Received reload events command, reloading...`);
|
|
6048
|
-
|
|
6171
|
+
await sendHmrEvent(HMREventType.ReloadEvents);
|
|
6049
6172
|
break;
|
|
6050
6173
|
case "rl":
|
|
6051
6174
|
console.log(`Received reload locales command, reloading...`);
|
|
6052
|
-
|
|
6175
|
+
await sendHmrEvent(HMREventType.ReloadLocales);
|
|
6053
6176
|
break;
|
|
6054
6177
|
}
|
|
6055
6178
|
});
|
|
@@ -6073,7 +6196,7 @@ ${colors_default.yellowBright("re")} - Reload all events
|
|
|
6073
6196
|
${colors_default.yellowBright("rl")} - Reload all locales`
|
|
6074
6197
|
);
|
|
6075
6198
|
}
|
|
6076
|
-
var import_path2, import_chokidar, isCommandSource, isEventSource, isLocaleSource;
|
|
6199
|
+
var import_path2, import_chokidar, import_promises7, import_node_crypto3, isCommandSource, isEventSource, isLocaleSource;
|
|
6077
6200
|
var init_development = __esm({
|
|
6078
6201
|
"src/cli/development.ts"() {
|
|
6079
6202
|
"use strict";
|
|
@@ -6086,6 +6209,9 @@ var init_development = __esm({
|
|
|
6086
6209
|
import_chokidar = require("chokidar");
|
|
6087
6210
|
init_utilities();
|
|
6088
6211
|
init_colors();
|
|
6212
|
+
import_promises7 = require("timers/promises");
|
|
6213
|
+
import_node_crypto3 = require("crypto");
|
|
6214
|
+
init_constants();
|
|
6089
6215
|
__name(buildAndStart, "buildAndStart");
|
|
6090
6216
|
isCommandSource = /* @__PURE__ */ __name((p) => p.replaceAll("\\", "/").includes("src/app/commands"), "isCommandSource");
|
|
6091
6217
|
isEventSource = /* @__PURE__ */ __name((p) => p.replaceAll("\\", "/").includes("src/app/events"), "isEventSource");
|
|
@@ -6171,15 +6297,8 @@ __export(generators_exports, {
|
|
|
6171
6297
|
function determineExtension() {
|
|
6172
6298
|
return (0, import_fs2.existsSync)((0, import_path4.join)(BASE_PATH, "tsconfig.json")) ? "ts" : "js";
|
|
6173
6299
|
}
|
|
6174
|
-
|
|
6175
|
-
|
|
6176
|
-
if (!(0, import_fs2.existsSync)(cmdPath)) await (0, import_promises7.mkdir)(cmdPath, { recursive: true });
|
|
6177
|
-
const fileName = `${name}.${determineExtension()}`;
|
|
6178
|
-
if ((0, import_fs2.existsSync)((0, import_path4.join)(cmdPath, fileName))) {
|
|
6179
|
-
panic(`Command ${name} already exists.`);
|
|
6180
|
-
}
|
|
6181
|
-
const commandFile = `
|
|
6182
|
-
import type { CommandData, SlashCommand, MessageCommand } from 'commandkit';
|
|
6300
|
+
function TS_COMMAND_SOURCE(name) {
|
|
6301
|
+
return `import type { CommandData, SlashCommand, MessageCommand } from 'commandkit';
|
|
6183
6302
|
|
|
6184
6303
|
export const command: CommandData = {
|
|
6185
6304
|
name: '${name}',
|
|
@@ -6193,8 +6312,43 @@ export const chatInput: SlashCommand = async (ctx) => {
|
|
|
6193
6312
|
export const message: MessageCommand = async (ctx) => {
|
|
6194
6313
|
await ctx.message.reply('Hello from ${name}!');
|
|
6195
6314
|
};
|
|
6196
|
-
|
|
6197
|
-
|
|
6315
|
+
`;
|
|
6316
|
+
}
|
|
6317
|
+
function JS_COMMAND_SOURCE(name) {
|
|
6318
|
+
return `/**
|
|
6319
|
+
* @type {import('commandkit').CommandData}
|
|
6320
|
+
*/
|
|
6321
|
+
export const command = {
|
|
6322
|
+
name: '${name}',
|
|
6323
|
+
description: '${name} command',
|
|
6324
|
+
};
|
|
6325
|
+
|
|
6326
|
+
/**
|
|
6327
|
+
* @type {import('commandkit').SlashCommand}
|
|
6328
|
+
*/
|
|
6329
|
+
export const chatInput = async (ctx) => {
|
|
6330
|
+
await ctx.interaction.reply('Hello from ${name}!');
|
|
6331
|
+
};
|
|
6332
|
+
|
|
6333
|
+
/**
|
|
6334
|
+
* @type {import('commandkit').MessageCommand}
|
|
6335
|
+
*/
|
|
6336
|
+
export const message = async (ctx) => {
|
|
6337
|
+
await ctx.message.reply('Hello from ${name}!');
|
|
6338
|
+
};
|
|
6339
|
+
`;
|
|
6340
|
+
}
|
|
6341
|
+
async function generateCommand(name, customPath) {
|
|
6342
|
+
const cmdPath = (0, import_path4.join)(customPath || COMMANDS_DIR);
|
|
6343
|
+
if (!(0, import_fs2.existsSync)(cmdPath)) await (0, import_promises8.mkdir)(cmdPath, { recursive: true });
|
|
6344
|
+
const ext = determineExtension();
|
|
6345
|
+
const isTypeScript = ext === "ts";
|
|
6346
|
+
const fileName = `${name}.${ext}`;
|
|
6347
|
+
if ((0, import_fs2.existsSync)((0, import_path4.join)(cmdPath, fileName))) {
|
|
6348
|
+
panic(`Command ${name} already exists.`);
|
|
6349
|
+
}
|
|
6350
|
+
const commandFile = isTypeScript ? TS_COMMAND_SOURCE(name) : JS_COMMAND_SOURCE(name);
|
|
6351
|
+
await (0, import_promises8.writeFile)((0, import_path4.join)(cmdPath, fileName), commandFile);
|
|
6198
6352
|
console.log(
|
|
6199
6353
|
colors_default.green(
|
|
6200
6354
|
`Command ${colors_default.magenta(name)} created at ${colors_default.blue(formatPath(`${cmdPath}/${fileName}`))}`
|
|
@@ -6203,10 +6357,11 @@ export const message: MessageCommand = async (ctx) => {
|
|
|
6203
6357
|
}
|
|
6204
6358
|
async function generateEvent(name, customPath) {
|
|
6205
6359
|
const eventPath = (0, import_path4.join)(customPath || EVENTS_DIR, name);
|
|
6206
|
-
if (!(0, import_fs2.existsSync)(eventPath)) await (0,
|
|
6207
|
-
|
|
6360
|
+
if (!(0, import_fs2.existsSync)(eventPath)) await (0, import_promises8.mkdir)(eventPath, { recursive: true });
|
|
6361
|
+
const ext = determineExtension();
|
|
6362
|
+
let filename = `event.${ext}`;
|
|
6208
6363
|
if ((0, import_fs2.existsSync)((0, import_path4.join)(eventPath, filename))) {
|
|
6209
|
-
const count = (await (0,
|
|
6364
|
+
const count = (await (0, import_promises8.readdir)(eventPath)).length;
|
|
6210
6365
|
filename = `${String(count).padStart(2, "0")}_${filename}`;
|
|
6211
6366
|
}
|
|
6212
6367
|
const eventFile = `
|
|
@@ -6214,7 +6369,7 @@ export default async function on${name[0].toUpperCase() + name.slice(1)}() {
|
|
|
6214
6369
|
console.log('${name} event fired!');
|
|
6215
6370
|
};
|
|
6216
6371
|
`.trim();
|
|
6217
|
-
await (0,
|
|
6372
|
+
await (0, import_promises8.writeFile)((0, import_path4.join)(eventPath, filename), eventFile);
|
|
6218
6373
|
console.log(
|
|
6219
6374
|
colors_default.green(
|
|
6220
6375
|
`Event ${colors_default.magenta(name)} created at ${colors_default.blue(formatPath(eventPath))}/${colors_default.magenta(filename)}`
|
|
@@ -6232,7 +6387,7 @@ async function generateLocale(locale, commandName, customPath) {
|
|
|
6232
6387
|
panic("Command name is required.");
|
|
6233
6388
|
}
|
|
6234
6389
|
const localePath = (0, import_path4.join)(customPath || LOCALES_DIR, locale);
|
|
6235
|
-
if (!(0, import_fs2.existsSync)(localePath)) await (0,
|
|
6390
|
+
if (!(0, import_fs2.existsSync)(localePath)) await (0, import_promises8.mkdir)(localePath, { recursive: true });
|
|
6236
6391
|
if ((0, import_fs2.existsSync)((0, import_path4.join)(localePath, `${commandName}.json`))) {
|
|
6237
6392
|
panic(`Locale file for ${commandName} already exists.`);
|
|
6238
6393
|
}
|
|
@@ -6243,7 +6398,7 @@ async function generateLocale(locale, commandName, customPath) {
|
|
|
6243
6398
|
},
|
|
6244
6399
|
translations: {}
|
|
6245
6400
|
};
|
|
6246
|
-
await (0,
|
|
6401
|
+
await (0, import_promises8.writeFile)(
|
|
6247
6402
|
(0, import_path4.join)(localePath, `${commandName}.json`),
|
|
6248
6403
|
JSON.stringify(localeFile, null, 2)
|
|
6249
6404
|
);
|
|
@@ -6255,12 +6410,12 @@ async function generateLocale(locale, commandName, customPath) {
|
|
|
6255
6410
|
)
|
|
6256
6411
|
);
|
|
6257
6412
|
}
|
|
6258
|
-
var
|
|
6413
|
+
var import_promises8, import_path4, import_discord21, import_fs2, BASE_PATH, COMMANDS_DIR, EVENTS_DIR, LOCALES_DIR, formatPath;
|
|
6259
6414
|
var init_generators = __esm({
|
|
6260
6415
|
"src/cli/generators.ts"() {
|
|
6261
6416
|
"use strict";
|
|
6262
6417
|
init_cjs_shims();
|
|
6263
|
-
|
|
6418
|
+
import_promises8 = require("fs/promises");
|
|
6264
6419
|
import_path4 = require("path");
|
|
6265
6420
|
import_discord21 = require("discord.js");
|
|
6266
6421
|
init_common2();
|
|
@@ -6270,14 +6425,169 @@ var init_generators = __esm({
|
|
|
6270
6425
|
COMMANDS_DIR = (0, import_path4.join)(BASE_PATH, "src/app/commands");
|
|
6271
6426
|
EVENTS_DIR = (0, import_path4.join)(BASE_PATH, "src/app/events");
|
|
6272
6427
|
LOCALES_DIR = (0, import_path4.join)(BASE_PATH, "src/app/locales");
|
|
6273
|
-
formatPath = /* @__PURE__ */ __name((
|
|
6428
|
+
formatPath = /* @__PURE__ */ __name((path3) => path3.replace(process.cwd(), ".").replace(/\\/g, "/"), "formatPath");
|
|
6274
6429
|
__name(determineExtension, "determineExtension");
|
|
6430
|
+
__name(TS_COMMAND_SOURCE, "TS_COMMAND_SOURCE");
|
|
6431
|
+
__name(JS_COMMAND_SOURCE, "JS_COMMAND_SOURCE");
|
|
6275
6432
|
__name(generateCommand, "generateCommand");
|
|
6276
6433
|
__name(generateEvent, "generateEvent");
|
|
6277
6434
|
__name(generateLocale, "generateLocale");
|
|
6278
6435
|
}
|
|
6279
6436
|
});
|
|
6280
6437
|
|
|
6438
|
+
// src/cli/information.ts
|
|
6439
|
+
var information_exports = {};
|
|
6440
|
+
__export(information_exports, {
|
|
6441
|
+
showInformation: () => showInformation
|
|
6442
|
+
});
|
|
6443
|
+
function findPackageVersion(packageName) {
|
|
6444
|
+
try {
|
|
6445
|
+
const packageJsonPath = require.resolve(`${packageName}/package.json`);
|
|
6446
|
+
const packageJson = require(packageJsonPath);
|
|
6447
|
+
return packageJson.version;
|
|
6448
|
+
} catch (e) {
|
|
6449
|
+
try {
|
|
6450
|
+
const basePaths = [
|
|
6451
|
+
import_node_path11.default.join(process.cwd(), "node_modules", packageName),
|
|
6452
|
+
import_node_path11.default.join(process.cwd(), "..", "..", "node_modules", packageName),
|
|
6453
|
+
import_node_path11.default.join(process.cwd(), "..", "..", ".pnpm", packageName),
|
|
6454
|
+
import_node_path11.default.join(
|
|
6455
|
+
process.cwd(),
|
|
6456
|
+
"..",
|
|
6457
|
+
"..",
|
|
6458
|
+
"node_modules",
|
|
6459
|
+
".pnpm",
|
|
6460
|
+
packageName
|
|
6461
|
+
)
|
|
6462
|
+
];
|
|
6463
|
+
for (const basePath of basePaths) {
|
|
6464
|
+
const packageJsonPath = import_node_path11.default.join(basePath, "package.json");
|
|
6465
|
+
if (import_node_fs10.default.existsSync(packageJsonPath)) {
|
|
6466
|
+
const packageJson = JSON.parse(
|
|
6467
|
+
import_node_fs10.default.readFileSync(packageJsonPath, "utf8")
|
|
6468
|
+
);
|
|
6469
|
+
return packageJson.version;
|
|
6470
|
+
}
|
|
6471
|
+
}
|
|
6472
|
+
const nodeModulesPath = import_node_path11.default.join(
|
|
6473
|
+
process.cwd(),
|
|
6474
|
+
"..",
|
|
6475
|
+
"..",
|
|
6476
|
+
"node_modules",
|
|
6477
|
+
".pnpm"
|
|
6478
|
+
);
|
|
6479
|
+
if (import_node_fs10.default.existsSync(nodeModulesPath)) {
|
|
6480
|
+
const folders = import_node_fs10.default.readdirSync(nodeModulesPath);
|
|
6481
|
+
const packageFolder = folders.find(
|
|
6482
|
+
(folder) => folder.startsWith(`${packageName.replace("/", "+")}@`)
|
|
6483
|
+
);
|
|
6484
|
+
if (packageFolder) {
|
|
6485
|
+
const packageJsonPath = import_node_path11.default.join(
|
|
6486
|
+
nodeModulesPath,
|
|
6487
|
+
packageFolder,
|
|
6488
|
+
"node_modules",
|
|
6489
|
+
packageName,
|
|
6490
|
+
"package.json"
|
|
6491
|
+
);
|
|
6492
|
+
if (import_node_fs10.default.existsSync(packageJsonPath)) {
|
|
6493
|
+
const packageJson = JSON.parse(
|
|
6494
|
+
import_node_fs10.default.readFileSync(packageJsonPath, "utf8")
|
|
6495
|
+
);
|
|
6496
|
+
return packageJson.version;
|
|
6497
|
+
}
|
|
6498
|
+
}
|
|
6499
|
+
}
|
|
6500
|
+
return null;
|
|
6501
|
+
} catch {
|
|
6502
|
+
return null;
|
|
6503
|
+
}
|
|
6504
|
+
}
|
|
6505
|
+
}
|
|
6506
|
+
function getBinaryVersion(binary) {
|
|
6507
|
+
try {
|
|
6508
|
+
const version2 = (0, import_node_child_process2.execSync)(`${binary} --version`).toString().trim();
|
|
6509
|
+
return version2;
|
|
6510
|
+
} catch {
|
|
6511
|
+
return null;
|
|
6512
|
+
}
|
|
6513
|
+
}
|
|
6514
|
+
async function showInformation() {
|
|
6515
|
+
const knownPlugins = [
|
|
6516
|
+
"@commandkit/redis",
|
|
6517
|
+
"@commandkit/legacy",
|
|
6518
|
+
"@commandkit/devtools"
|
|
6519
|
+
];
|
|
6520
|
+
const runtimeName = (() => {
|
|
6521
|
+
if ("Deno" in globalThis && typeof Deno !== "undefined") return "Deno";
|
|
6522
|
+
if ("Bun" in globalThis && typeof Bun !== "undefined") return "Bun";
|
|
6523
|
+
return "Node.js";
|
|
6524
|
+
})();
|
|
6525
|
+
const info = {
|
|
6526
|
+
"Operating System": {
|
|
6527
|
+
Platform: process.platform,
|
|
6528
|
+
Arch: process.arch,
|
|
6529
|
+
Version: import_node_os.default.version(),
|
|
6530
|
+
"Available Memory (MB)": Math.round(import_node_os.default.totalmem() / 1024 / 1024),
|
|
6531
|
+
"Available CPU cores": import_node_os.default.cpus().length
|
|
6532
|
+
},
|
|
6533
|
+
Runtime: runtimeName,
|
|
6534
|
+
Binaries: {
|
|
6535
|
+
Node: process.version,
|
|
6536
|
+
npm: getBinaryVersion("npm") || "N/A",
|
|
6537
|
+
Yarn: getBinaryVersion("yarn") || "N/A",
|
|
6538
|
+
pnpm: getBinaryVersion("pnpm") || "N/A",
|
|
6539
|
+
Bun: getBinaryVersion("bun") || "N/A",
|
|
6540
|
+
Deno: getBinaryVersion("deno") || "N/A"
|
|
6541
|
+
},
|
|
6542
|
+
"Relevant Packages": {
|
|
6543
|
+
commandkit: version,
|
|
6544
|
+
"discord.js": findPackageVersion("discord.js") || "N/A",
|
|
6545
|
+
typescript: findPackageVersion("typescript") || "N/A",
|
|
6546
|
+
esbuild: findPackageVersion("esbuild") || "N/A",
|
|
6547
|
+
tsup: findPackageVersion("tsup") || "N/A",
|
|
6548
|
+
...knownPlugins.reduce(
|
|
6549
|
+
(acc, plugin) => {
|
|
6550
|
+
acc[plugin] = findPackageVersion(plugin) || "N/A";
|
|
6551
|
+
return acc;
|
|
6552
|
+
},
|
|
6553
|
+
{}
|
|
6554
|
+
)
|
|
6555
|
+
}
|
|
6556
|
+
};
|
|
6557
|
+
let output = "";
|
|
6558
|
+
for (const [section, data] of Object.entries(info)) {
|
|
6559
|
+
output += `${section}:
|
|
6560
|
+
`;
|
|
6561
|
+
if (typeof data === "string") {
|
|
6562
|
+
output += ` ${data}
|
|
6563
|
+
|
|
6564
|
+
`;
|
|
6565
|
+
continue;
|
|
6566
|
+
}
|
|
6567
|
+
for (const [key, value] of Object.entries(data)) {
|
|
6568
|
+
output += ` ${key}: ${value}
|
|
6569
|
+
`;
|
|
6570
|
+
}
|
|
6571
|
+
output += "\n";
|
|
6572
|
+
}
|
|
6573
|
+
console.log(output.trim());
|
|
6574
|
+
}
|
|
6575
|
+
var import_node_os, import_node_child_process2, import_node_fs10, import_node_path11;
|
|
6576
|
+
var init_information = __esm({
|
|
6577
|
+
"src/cli/information.ts"() {
|
|
6578
|
+
"use strict";
|
|
6579
|
+
init_cjs_shims();
|
|
6580
|
+
import_node_os = __toESM(require("os"));
|
|
6581
|
+
import_node_child_process2 = require("child_process");
|
|
6582
|
+
init_version();
|
|
6583
|
+
import_node_fs10 = __toESM(require("fs"));
|
|
6584
|
+
import_node_path11 = __toESM(require("path"));
|
|
6585
|
+
__name(findPackageVersion, "findPackageVersion");
|
|
6586
|
+
__name(getBinaryVersion, "getBinaryVersion");
|
|
6587
|
+
__name(showInformation, "showInformation");
|
|
6588
|
+
}
|
|
6589
|
+
});
|
|
6590
|
+
|
|
6281
6591
|
// src/index.ts
|
|
6282
6592
|
var index_exports = {};
|
|
6283
6593
|
__export(index_exports, {
|
|
@@ -6285,6 +6595,9 @@ __export(index_exports, {
|
|
|
6285
6595
|
AppCommandHandler: () => AppCommandHandler,
|
|
6286
6596
|
Button: () => Button,
|
|
6287
6597
|
ButtonKit: () => ButtonKit,
|
|
6598
|
+
COMMANDKIT_CACHE_TAG: () => COMMANDKIT_CACHE_TAG,
|
|
6599
|
+
COMMANDKIT_IS_DEV: () => COMMANDKIT_IS_DEV,
|
|
6600
|
+
COMMANDKIT_IS_TEST: () => COMMANDKIT_IS_TEST,
|
|
6288
6601
|
CacheProvider: () => CacheProvider,
|
|
6289
6602
|
ChannelSelectMenu: () => ChannelSelectMenu,
|
|
6290
6603
|
ChannelSelectMenuKit: () => ChannelSelectMenuKit,
|
|
@@ -6303,6 +6616,7 @@ __export(index_exports, {
|
|
|
6303
6616
|
EventInterceptor: () => EventInterceptor,
|
|
6304
6617
|
EventsRouter: () => EventsRouter,
|
|
6305
6618
|
Fragment: () => Fragment,
|
|
6619
|
+
HMREventType: () => HMREventType,
|
|
6306
6620
|
Localization: () => Localization,
|
|
6307
6621
|
Logger: () => Logger,
|
|
6308
6622
|
MemoryCache: () => MemoryCache,
|
|
@@ -6343,6 +6657,7 @@ __export(index_exports, {
|
|
|
6343
6657
|
getContext: () => getContext,
|
|
6344
6658
|
getCurrentDirectory: () => getCurrentDirectory,
|
|
6345
6659
|
getElement: () => getElement,
|
|
6660
|
+
getSourceDirectories: () => getSourceDirectories,
|
|
6346
6661
|
invalidate: () => invalidate,
|
|
6347
6662
|
isCachedFunction: () => isCachedFunction,
|
|
6348
6663
|
isCommandKitElement: () => isCommandKitElement,
|
|
@@ -6355,9 +6670,9 @@ __export(index_exports, {
|
|
|
6355
6670
|
redirect: () => redirect,
|
|
6356
6671
|
rethrow: () => rethrow,
|
|
6357
6672
|
revalidate: () => revalidate,
|
|
6358
|
-
super_duper_secret_internal_for_use_cache_directive_of_commandkit_cli_do_not_use_it_directly_or_you_will_be_fired_from_your_job_kthxbai: () => useCache,
|
|
6359
6673
|
useEnvironment: () => useEnvironment,
|
|
6360
|
-
version: () => version
|
|
6674
|
+
version: () => version,
|
|
6675
|
+
zzz_commandkit_secret_internal_use_cache_wrapper_do_not_use_or_you_will_be_fired: () => zzz_commandkit_secret_internal_use_cache_wrapper_do_not_use_or_you_will_be_fired
|
|
6361
6676
|
});
|
|
6362
6677
|
module.exports = __toCommonJS(index_exports);
|
|
6363
6678
|
init_cjs_shims();
|
|
@@ -6410,12 +6725,13 @@ init_router();
|
|
|
6410
6725
|
init_version();
|
|
6411
6726
|
init_plugins();
|
|
6412
6727
|
init_utilities();
|
|
6728
|
+
init_constants();
|
|
6413
6729
|
|
|
6414
6730
|
// src/cli/init.ts
|
|
6415
6731
|
init_cjs_shims();
|
|
6416
|
-
var
|
|
6417
|
-
var
|
|
6418
|
-
var
|
|
6732
|
+
var import_node_fs11 = require("fs");
|
|
6733
|
+
var import_promises9 = require("fs/promises");
|
|
6734
|
+
var import_node_path12 = require("path");
|
|
6419
6735
|
async function bootstrapCommandkitCLI(argv, options) {
|
|
6420
6736
|
process.title = "CommandKit CLI";
|
|
6421
6737
|
const { Command } = await import("commander");
|
|
@@ -6423,6 +6739,7 @@ async function bootstrapCommandkitCLI(argv, options) {
|
|
|
6423
6739
|
const { bootstrapProductionServer: bootstrapProductionServer2, createProductionBuild: createProductionBuild2 } = await Promise.resolve().then(() => (init_production(), production_exports));
|
|
6424
6740
|
const { generateCommand: generateCommand2, generateEvent: generateEvent2, generateLocale: generateLocale2 } = await Promise.resolve().then(() => (init_generators(), generators_exports));
|
|
6425
6741
|
const { version: version2 } = await Promise.resolve().then(() => (init_version(), version_exports));
|
|
6742
|
+
const { showInformation: showInformation2 } = await Promise.resolve().then(() => (init_information(), information_exports));
|
|
6426
6743
|
const program = new Command("commandkit");
|
|
6427
6744
|
program.command("dev").version(version2).description("Start your bot in development mode.").option(
|
|
6428
6745
|
"-c, --config [path]",
|
|
@@ -6432,6 +6749,11 @@ async function bootstrapCommandkitCLI(argv, options) {
|
|
|
6432
6749
|
const options2 = program.opts();
|
|
6433
6750
|
bootstrapDevelopmentServer2(options2.config);
|
|
6434
6751
|
});
|
|
6752
|
+
program.command("info").description(
|
|
6753
|
+
"Show information about the system which can be used to report bugs."
|
|
6754
|
+
).action(async () => {
|
|
6755
|
+
await showInformation2();
|
|
6756
|
+
});
|
|
6435
6757
|
program.command("start").description(
|
|
6436
6758
|
"Start your bot in production mode after running the build command."
|
|
6437
6759
|
).option("-c, --config [path]", "Path to your commandkit.json file.").action(() => {
|
|
@@ -6463,9 +6785,9 @@ async function bootstrapCommandkitCLI(argv, options) {
|
|
|
6463
6785
|
}
|
|
6464
6786
|
});
|
|
6465
6787
|
await program.parseAsync(argv, options);
|
|
6466
|
-
const types = (0,
|
|
6467
|
-
if (!(0,
|
|
6468
|
-
await (0,
|
|
6788
|
+
const types = (0, import_node_path12.join)(process.cwd(), "node_modules", "commandkit-types");
|
|
6789
|
+
if (!(0, import_node_fs11.existsSync)(types)) {
|
|
6790
|
+
await (0, import_promises9.mkdir)(types, { recursive: true }).catch(() => {
|
|
6469
6791
|
});
|
|
6470
6792
|
}
|
|
6471
6793
|
}
|
|
@@ -6479,6 +6801,9 @@ var index_default = CommandKit;
|
|
|
6479
6801
|
AppCommandHandler,
|
|
6480
6802
|
Button,
|
|
6481
6803
|
ButtonKit,
|
|
6804
|
+
COMMANDKIT_CACHE_TAG,
|
|
6805
|
+
COMMANDKIT_IS_DEV,
|
|
6806
|
+
COMMANDKIT_IS_TEST,
|
|
6482
6807
|
CacheProvider,
|
|
6483
6808
|
ChannelSelectMenu,
|
|
6484
6809
|
ChannelSelectMenuKit,
|
|
@@ -6497,6 +6822,7 @@ var index_default = CommandKit;
|
|
|
6497
6822
|
EventInterceptor,
|
|
6498
6823
|
EventsRouter,
|
|
6499
6824
|
Fragment,
|
|
6825
|
+
HMREventType,
|
|
6500
6826
|
Localization,
|
|
6501
6827
|
Logger,
|
|
6502
6828
|
MemoryCache,
|
|
@@ -6536,6 +6862,7 @@ var index_default = CommandKit;
|
|
|
6536
6862
|
getContext,
|
|
6537
6863
|
getCurrentDirectory,
|
|
6538
6864
|
getElement,
|
|
6865
|
+
getSourceDirectories,
|
|
6539
6866
|
invalidate,
|
|
6540
6867
|
isCachedFunction,
|
|
6541
6868
|
isCommandKitElement,
|
|
@@ -6548,8 +6875,8 @@ var index_default = CommandKit;
|
|
|
6548
6875
|
redirect,
|
|
6549
6876
|
rethrow,
|
|
6550
6877
|
revalidate,
|
|
6551
|
-
super_duper_secret_internal_for_use_cache_directive_of_commandkit_cli_do_not_use_it_directly_or_you_will_be_fired_from_your_job_kthxbai,
|
|
6552
6878
|
useEnvironment,
|
|
6553
|
-
version
|
|
6879
|
+
version,
|
|
6880
|
+
zzz_commandkit_secret_internal_use_cache_wrapper_do_not_use_or_you_will_be_fired
|
|
6554
6881
|
});
|
|
6555
6882
|
//# sourceMappingURL=index.js.map
|