commandkit 0.1.11-dev.20250402134128 → 0.1.11-dev.20250403165006
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/LICENSE +5 -0
- package/dist/index.d.ts +9 -116
- package/dist/index.js +326 -581
- package/dist/index.js.map +1 -1
- package/package.json +10 -10
package/dist/index.js
CHANGED
|
@@ -1871,6 +1871,23 @@ var init_components = __esm({
|
|
|
1871
1871
|
}
|
|
1872
1872
|
});
|
|
1873
1873
|
|
|
1874
|
+
// src/utils/constants.ts
|
|
1875
|
+
var COMMANDKIT_CACHE_TAG, COMMANDKIT_IS_DEV, COMMANDKIT_IS_TEST, HMREventType;
|
|
1876
|
+
var init_constants = __esm({
|
|
1877
|
+
"src/utils/constants.ts"() {
|
|
1878
|
+
"use strict";
|
|
1879
|
+
init_cjs_shims();
|
|
1880
|
+
COMMANDKIT_CACHE_TAG = Symbol("kCommandKitCacheTag");
|
|
1881
|
+
COMMANDKIT_IS_DEV = !!process.env.COMMANDKIT_IS_DEV;
|
|
1882
|
+
COMMANDKIT_IS_TEST = process.env.COMMANDKIT_IS_TEST === "true";
|
|
1883
|
+
HMREventType = {
|
|
1884
|
+
ReloadCommands: "reload-commands",
|
|
1885
|
+
ReloadEvents: "reload-events",
|
|
1886
|
+
Unknown: "unknown"
|
|
1887
|
+
};
|
|
1888
|
+
}
|
|
1889
|
+
});
|
|
1890
|
+
|
|
1874
1891
|
// src/plugins/PluginCommon.ts
|
|
1875
1892
|
var _PluginCommon, PluginCommon;
|
|
1876
1893
|
var init_PluginCommon = __esm({
|
|
@@ -2028,6 +2045,14 @@ var init_RuntimePlugin = __esm({
|
|
|
2028
2045
|
*/
|
|
2029
2046
|
async performHMR(ctx, event) {
|
|
2030
2047
|
}
|
|
2048
|
+
/**
|
|
2049
|
+
* Called before command is loaded for registration. This method can be used to modify the command data before it is loaded.
|
|
2050
|
+
* @param ctx The context
|
|
2051
|
+
* @param commands The command that is being loaded. This is a CommandBuilderLike object which represents Discord's command
|
|
2052
|
+
*/
|
|
2053
|
+
async prepareCommand(ctx, commands) {
|
|
2054
|
+
return null;
|
|
2055
|
+
}
|
|
2031
2056
|
};
|
|
2032
2057
|
__name(_RuntimePlugin, "RuntimePlugin");
|
|
2033
2058
|
RuntimePlugin = _RuntimePlugin;
|
|
@@ -2754,8 +2779,7 @@ var init_default = __esm({
|
|
|
2754
2779
|
development: true,
|
|
2755
2780
|
production: true
|
|
2756
2781
|
},
|
|
2757
|
-
typedCommands: true
|
|
2758
|
-
typedLocales: true
|
|
2782
|
+
typedCommands: true
|
|
2759
2783
|
};
|
|
2760
2784
|
}
|
|
2761
2785
|
});
|
|
@@ -2793,7 +2817,6 @@ function defineConfig(config = {}) {
|
|
|
2793
2817
|
},
|
|
2794
2818
|
static: config.static ?? defaultConfig.static,
|
|
2795
2819
|
typedCommands: config.typedCommands ?? defaultConfig.typedCommands,
|
|
2796
|
-
typedLocales: config.typedLocales ?? defaultConfig.typedLocales,
|
|
2797
2820
|
typescript: {
|
|
2798
2821
|
...defaultConfig.typescript,
|
|
2799
2822
|
...config.typescript
|
|
@@ -2813,205 +2836,34 @@ var init_config = __esm({
|
|
|
2813
2836
|
}
|
|
2814
2837
|
});
|
|
2815
2838
|
|
|
2816
|
-
// src/utils/constants.ts
|
|
2817
|
-
var COMMANDKIT_CACHE_TAG, COMMANDKIT_IS_DEV, COMMANDKIT_IS_TEST, HMREventType;
|
|
2818
|
-
var init_constants = __esm({
|
|
2819
|
-
"src/utils/constants.ts"() {
|
|
2820
|
-
"use strict";
|
|
2821
|
-
init_cjs_shims();
|
|
2822
|
-
COMMANDKIT_CACHE_TAG = Symbol("kCommandKitCacheTag");
|
|
2823
|
-
COMMANDKIT_IS_DEV = !!process.env.COMMANDKIT_IS_DEV;
|
|
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
|
-
};
|
|
2831
|
-
}
|
|
2832
|
-
});
|
|
2833
|
-
|
|
2834
|
-
// src/app/i18n/DefaultLocalizationStrategy.ts
|
|
2835
|
-
var import_promises2, import_node_path, import_node_fs, _DefaultLocalizationStrategy, DefaultLocalizationStrategy;
|
|
2836
|
-
var init_DefaultLocalizationStrategy = __esm({
|
|
2837
|
-
"src/app/i18n/DefaultLocalizationStrategy.ts"() {
|
|
2838
|
-
"use strict";
|
|
2839
|
-
init_cjs_shims();
|
|
2840
|
-
import_promises2 = require("fs/promises");
|
|
2841
|
-
import_node_path = require("path");
|
|
2842
|
-
init_config();
|
|
2843
|
-
import_node_fs = require("fs");
|
|
2844
|
-
init_constants();
|
|
2845
|
-
_DefaultLocalizationStrategy = class _DefaultLocalizationStrategy {
|
|
2846
|
-
constructor(commandkit2) {
|
|
2847
|
-
this.commandkit = commandkit2;
|
|
2848
|
-
}
|
|
2849
|
-
translations = /* @__PURE__ */ new Map();
|
|
2850
|
-
async locateTranslation(scope, locale) {
|
|
2851
|
-
const localesPath = this.commandkit.getPath("locales");
|
|
2852
|
-
if (!localesPath) return null;
|
|
2853
|
-
const paths = [".js", ".json", ".mjs", ".cjs"].map(
|
|
2854
|
-
(e) => (0, import_node_path.join)(localesPath, locale, scope) + e
|
|
2855
|
-
);
|
|
2856
|
-
for (const path3 of paths) {
|
|
2857
|
-
if (!(0, import_node_fs.existsSync)(path3)) {
|
|
2858
|
-
continue;
|
|
2859
|
-
}
|
|
2860
|
-
try {
|
|
2861
|
-
let localeData;
|
|
2862
|
-
try {
|
|
2863
|
-
if (path3.endsWith(".json")) {
|
|
2864
|
-
const data = await (0, import_promises2.readFile)(path3, "utf-8");
|
|
2865
|
-
localeData = JSON.parse(data);
|
|
2866
|
-
} else {
|
|
2867
|
-
const { default: data } = await import(`file://${path3}`);
|
|
2868
|
-
localeData = data;
|
|
2869
|
-
}
|
|
2870
|
-
} catch {
|
|
2871
|
-
continue;
|
|
2872
|
-
}
|
|
2873
|
-
if (!localeData) continue;
|
|
2874
|
-
await this.generateLocaleTypes(localeData).catch(() => {
|
|
2875
|
-
});
|
|
2876
|
-
return localeData;
|
|
2877
|
-
} catch {
|
|
2878
|
-
return null;
|
|
2879
|
-
}
|
|
2880
|
-
}
|
|
2881
|
-
return null;
|
|
2882
|
-
}
|
|
2883
|
-
async generateLocaleTypes(localeData) {
|
|
2884
|
-
if (!COMMANDKIT_IS_DEV) return;
|
|
2885
|
-
const { typedLocales } = getConfig();
|
|
2886
|
-
if (!typedLocales) return;
|
|
2887
|
-
const file = (0, import_node_path.join)(
|
|
2888
|
-
process.cwd(),
|
|
2889
|
-
"node_modules",
|
|
2890
|
-
"commandkit-types",
|
|
2891
|
-
"locale_types.d.ts"
|
|
2892
|
-
);
|
|
2893
|
-
const header = `// auto generated file do not edit
|
|
2894
|
-
export {};
|
|
2895
|
-
declare module 'commandkit' {
|
|
2896
|
-
export interface CommandLocalizationTypeData {
|
|
2897
|
-
`;
|
|
2898
|
-
const footer = ` }
|
|
2899
|
-
type TranslatableCommandName = keyof CommandLocalizationTypeData
|
|
2900
|
-
}`;
|
|
2901
|
-
const generateType = /* @__PURE__ */ __name((locale) => {
|
|
2902
|
-
const commandName = locale.command.name;
|
|
2903
|
-
const translationTypes = Object.entries(locale.translations).map(([key, value]) => {
|
|
2904
|
-
const args = value.match(/{([^}]+)}/g);
|
|
2905
|
-
if (!args) {
|
|
2906
|
-
return ` "${key}": null`;
|
|
2907
|
-
}
|
|
2908
|
-
const argUnion = args.map((arg) => `"${arg.slice(1, -1)}"`).join(" | ");
|
|
2909
|
-
return ` "${key}": ${argUnion}`;
|
|
2910
|
-
}).join(",\n");
|
|
2911
|
-
return ` "${commandName}": {
|
|
2912
|
-
${translationTypes}
|
|
2913
|
-
}`;
|
|
2914
|
-
}, "generateType");
|
|
2915
|
-
try {
|
|
2916
|
-
let commandDefinitions = /* @__PURE__ */ new Map();
|
|
2917
|
-
if ((0, import_node_fs.existsSync)(file)) {
|
|
2918
|
-
try {
|
|
2919
|
-
const data = await (0, import_promises2.readFile)(file, "utf-8");
|
|
2920
|
-
const content = data.toString();
|
|
2921
|
-
const regex = /"([^"]+)":\s*\{([^}]*)\}/gs;
|
|
2922
|
-
let match;
|
|
2923
|
-
while ((match = regex.exec(content)) !== null) {
|
|
2924
|
-
const [fullMatch, commandName] = match;
|
|
2925
|
-
if (commandName !== localeData.command.name) {
|
|
2926
|
-
commandDefinitions.set(commandName, fullMatch);
|
|
2927
|
-
}
|
|
2928
|
-
}
|
|
2929
|
-
} catch (err) {
|
|
2930
|
-
console.warn("Could not parse existing type file, creating new one");
|
|
2931
|
-
}
|
|
2932
|
-
}
|
|
2933
|
-
const newCommandType = generateType(localeData);
|
|
2934
|
-
commandDefinitions.set(localeData.command.name, newCommandType);
|
|
2935
|
-
let fileContent = header;
|
|
2936
|
-
const entries = Array.from(commandDefinitions.values());
|
|
2937
|
-
fileContent += entries.join(",\n");
|
|
2938
|
-
fileContent += "\n" + footer;
|
|
2939
|
-
const dir = (0, import_node_path.join)(process.cwd(), "node_modules", "commandkit-types");
|
|
2940
|
-
if (!(0, import_node_fs.existsSync)(dir)) {
|
|
2941
|
-
await (0, import_promises2.mkdir)(dir, { recursive: true });
|
|
2942
|
-
}
|
|
2943
|
-
await (0, import_promises2.writeFile)(file, fileContent);
|
|
2944
|
-
} catch (error) {
|
|
2945
|
-
console.error("Failed to generate locale types:", error);
|
|
2946
|
-
}
|
|
2947
|
-
}
|
|
2948
|
-
async getTranslationStrict(scope, locale) {
|
|
2949
|
-
const key = `${scope}:${locale}`;
|
|
2950
|
-
if (!this.translations.has(key)) {
|
|
2951
|
-
const translation = await this.locateTranslation(scope, locale);
|
|
2952
|
-
if (!translation) {
|
|
2953
|
-
throw new Error(`Translation not found for ${key}`);
|
|
2954
|
-
}
|
|
2955
|
-
this.translations.set(key, translation);
|
|
2956
|
-
return translation;
|
|
2957
|
-
}
|
|
2958
|
-
return this.translations.get(key);
|
|
2959
|
-
}
|
|
2960
|
-
async getTranslation(scope, locale) {
|
|
2961
|
-
try {
|
|
2962
|
-
return this.getTranslationStrict(scope, locale);
|
|
2963
|
-
} catch (e) {
|
|
2964
|
-
return null;
|
|
2965
|
-
}
|
|
2966
|
-
}
|
|
2967
|
-
async translate(request) {
|
|
2968
|
-
const { scope, key, args, locale } = request;
|
|
2969
|
-
const translation = await this.getTranslation(scope, locale);
|
|
2970
|
-
if (!translation) return `${scope}.${key}`;
|
|
2971
|
-
const value = translation.translations[key];
|
|
2972
|
-
const translated = this.applyTranslation(value, args);
|
|
2973
|
-
return translated || `${scope}.${key}`;
|
|
2974
|
-
}
|
|
2975
|
-
applyTranslation(translation, args) {
|
|
2976
|
-
if (!translation || !args) return translation;
|
|
2977
|
-
return translation.replace(/{([^}]+)}/g, (_, key) => {
|
|
2978
|
-
return String(args[key] ?? `{${key}}`);
|
|
2979
|
-
});
|
|
2980
|
-
}
|
|
2981
|
-
};
|
|
2982
|
-
__name(_DefaultLocalizationStrategy, "DefaultLocalizationStrategy");
|
|
2983
|
-
DefaultLocalizationStrategy = _DefaultLocalizationStrategy;
|
|
2984
|
-
}
|
|
2985
|
-
});
|
|
2986
|
-
|
|
2987
2839
|
// src/utils/utilities.ts
|
|
2988
2840
|
function getCurrentDirectory() {
|
|
2989
2841
|
if (currentDir) return currentDir;
|
|
2990
|
-
let root = (0,
|
|
2842
|
+
let root = (0, import_node_path.join)(
|
|
2991
2843
|
process.cwd(),
|
|
2992
2844
|
COMMANDKIT_IS_DEV ? ".commandkit" : getConfig().distDir
|
|
2993
2845
|
);
|
|
2994
|
-
if (!(0,
|
|
2846
|
+
if (!(0, import_node_fs.existsSync)(root)) root = process.cwd();
|
|
2995
2847
|
currentDir = root;
|
|
2996
2848
|
return root;
|
|
2997
2849
|
}
|
|
2998
2850
|
function getSourceDirectories() {
|
|
2999
2851
|
const dist = getConfig().distDir;
|
|
3000
2852
|
const locations = ["src", ".commandkit", dist].map(
|
|
3001
|
-
(dir) => (0,
|
|
2853
|
+
(dir) => (0, import_node_path.join)(process.cwd(), dir)
|
|
3002
2854
|
);
|
|
3003
2855
|
return locations;
|
|
3004
2856
|
}
|
|
3005
2857
|
function findAppDirectory() {
|
|
3006
2858
|
if (appDir) return appDir;
|
|
3007
|
-
let root = (0,
|
|
2859
|
+
let root = (0, import_node_path.join)(
|
|
3008
2860
|
process.cwd(),
|
|
3009
2861
|
COMMANDKIT_IS_DEV ? ".commandkit" : getConfig().distDir
|
|
3010
2862
|
);
|
|
3011
|
-
if (!(0,
|
|
3012
|
-
const dirs = ["app"].map((dir) => (0,
|
|
2863
|
+
if (!(0, import_node_fs.existsSync)(root)) root = process.cwd();
|
|
2864
|
+
const dirs = ["app"].map((dir) => (0, import_node_path.join)(root, dir));
|
|
3013
2865
|
for (const dir of dirs) {
|
|
3014
|
-
if ((0,
|
|
2866
|
+
if ((0, import_node_fs.existsSync)(dir)) {
|
|
3015
2867
|
appDir = dir;
|
|
3016
2868
|
return dir;
|
|
3017
2869
|
}
|
|
@@ -3039,13 +2891,13 @@ function debounce(fn, ms2) {
|
|
|
3039
2891
|
});
|
|
3040
2892
|
};
|
|
3041
2893
|
}
|
|
3042
|
-
var
|
|
2894
|
+
var import_node_fs, import_node_path, appDir, currentDir;
|
|
3043
2895
|
var init_utilities = __esm({
|
|
3044
2896
|
"src/utils/utilities.ts"() {
|
|
3045
2897
|
"use strict";
|
|
3046
2898
|
init_cjs_shims();
|
|
3047
|
-
|
|
3048
|
-
|
|
2899
|
+
import_node_fs = require("fs");
|
|
2900
|
+
import_node_path = require("path");
|
|
3049
2901
|
init_constants();
|
|
3050
2902
|
init_config();
|
|
3051
2903
|
appDir = null;
|
|
@@ -3611,67 +3463,6 @@ var init_environment = __esm({
|
|
|
3611
3463
|
}
|
|
3612
3464
|
});
|
|
3613
3465
|
|
|
3614
|
-
// src/app/i18n/Localization.ts
|
|
3615
|
-
var _Localization, Localization;
|
|
3616
|
-
var init_Localization = __esm({
|
|
3617
|
-
"src/app/i18n/Localization.ts"() {
|
|
3618
|
-
"use strict";
|
|
3619
|
-
init_cjs_shims();
|
|
3620
|
-
_Localization = class _Localization {
|
|
3621
|
-
/**
|
|
3622
|
-
* Creates a new localization instance.
|
|
3623
|
-
* @param commandkit The command kit instance.
|
|
3624
|
-
* @param config The localization configuration.
|
|
3625
|
-
*/
|
|
3626
|
-
constructor(commandkit2, config) {
|
|
3627
|
-
this.commandkit = commandkit2;
|
|
3628
|
-
this.config = config;
|
|
3629
|
-
const strategy = this.commandkit.config.localizationStrategy;
|
|
3630
|
-
const { locale, target } = this.config;
|
|
3631
|
-
this.t = (translatable, args) => {
|
|
3632
|
-
return strategy.translate({
|
|
3633
|
-
args,
|
|
3634
|
-
key: translatable,
|
|
3635
|
-
locale,
|
|
3636
|
-
scope: target
|
|
3637
|
-
});
|
|
3638
|
-
};
|
|
3639
|
-
}
|
|
3640
|
-
/**
|
|
3641
|
-
* Translates the given translatable object.
|
|
3642
|
-
* @param translatable The translatable object to translate.
|
|
3643
|
-
*/
|
|
3644
|
-
t;
|
|
3645
|
-
/**
|
|
3646
|
-
* Get the localization strategy.
|
|
3647
|
-
*/
|
|
3648
|
-
getStrategy() {
|
|
3649
|
-
return this.commandkit.config.localizationStrategy;
|
|
3650
|
-
}
|
|
3651
|
-
/**
|
|
3652
|
-
* Get the default locale
|
|
3653
|
-
*/
|
|
3654
|
-
getDefaultLocale() {
|
|
3655
|
-
return this.commandkit.config.defaultLocale;
|
|
3656
|
-
}
|
|
3657
|
-
/**
|
|
3658
|
-
* Get the current locale
|
|
3659
|
-
*/
|
|
3660
|
-
getLocale() {
|
|
3661
|
-
return this.config.locale;
|
|
3662
|
-
}
|
|
3663
|
-
/**
|
|
3664
|
-
* Get the localization target
|
|
3665
|
-
*/
|
|
3666
|
-
getTarget() {
|
|
3667
|
-
return this.config.target;
|
|
3668
|
-
}
|
|
3669
|
-
};
|
|
3670
|
-
__name(_Localization, "Localization");
|
|
3671
|
-
Localization = _Localization;
|
|
3672
|
-
}
|
|
3673
|
-
});
|
|
3674
|
-
|
|
3675
3466
|
// src/app/middleware/signals.ts
|
|
3676
3467
|
function exitMiddleware() {
|
|
3677
3468
|
throw createCommandKitError(CommandKitErrorCodes.ExitMiddleware);
|
|
@@ -3693,10 +3484,59 @@ var init_signals = __esm({
|
|
|
3693
3484
|
}
|
|
3694
3485
|
});
|
|
3695
3486
|
|
|
3696
|
-
// src/cache/
|
|
3697
|
-
function
|
|
3698
|
-
return
|
|
3487
|
+
// src/cache/utils.ts
|
|
3488
|
+
function isSerializablePrimitive(value) {
|
|
3489
|
+
return value === null || PRIMITIVE_TYPES.has(typeof value);
|
|
3490
|
+
}
|
|
3491
|
+
function createKey(val) {
|
|
3492
|
+
return `commandkit:cache:object:${val}`;
|
|
3699
3493
|
}
|
|
3494
|
+
function getObjectId(obj) {
|
|
3495
|
+
const primitive = isSerializablePrimitive(obj);
|
|
3496
|
+
if (primitive) return createKey(obj);
|
|
3497
|
+
if (obj instanceof Date) return createKey(obj.getTime());
|
|
3498
|
+
if (obj instanceof RegExp) return createKey(obj);
|
|
3499
|
+
const ref = references.get(obj);
|
|
3500
|
+
if (ref) return createKey(ref);
|
|
3501
|
+
const id = tracker++;
|
|
3502
|
+
references.set(obj, id);
|
|
3503
|
+
return createKey(id);
|
|
3504
|
+
}
|
|
3505
|
+
async function createObjectHash(...args) {
|
|
3506
|
+
const serializedKey = args.map(getObjectId).join(":");
|
|
3507
|
+
try {
|
|
3508
|
+
const hash = (0, import_node_crypto2.createHash)("sha256");
|
|
3509
|
+
hash.update(serializedKey);
|
|
3510
|
+
return hash.digest("hex");
|
|
3511
|
+
} catch {
|
|
3512
|
+
return serializedKey;
|
|
3513
|
+
}
|
|
3514
|
+
}
|
|
3515
|
+
var import_node_crypto2, tracker, references, PRIMITIVE_TYPES;
|
|
3516
|
+
var init_utils = __esm({
|
|
3517
|
+
"src/cache/utils.ts"() {
|
|
3518
|
+
"use strict";
|
|
3519
|
+
init_cjs_shims();
|
|
3520
|
+
import_node_crypto2 = require("crypto");
|
|
3521
|
+
tracker = 0n;
|
|
3522
|
+
references = /* @__PURE__ */ new WeakMap();
|
|
3523
|
+
PRIMITIVE_TYPES = /* @__PURE__ */ new Set(
|
|
3524
|
+
[
|
|
3525
|
+
"string",
|
|
3526
|
+
"number",
|
|
3527
|
+
"boolean",
|
|
3528
|
+
"bigint",
|
|
3529
|
+
"undefined"
|
|
3530
|
+
]
|
|
3531
|
+
);
|
|
3532
|
+
__name(isSerializablePrimitive, "isSerializablePrimitive");
|
|
3533
|
+
__name(createKey, "createKey");
|
|
3534
|
+
__name(getObjectId, "getObjectId");
|
|
3535
|
+
__name(createObjectHash, "createObjectHash");
|
|
3536
|
+
}
|
|
3537
|
+
});
|
|
3538
|
+
|
|
3539
|
+
// src/cache/use-cache.ts
|
|
3700
3540
|
function getCacheProvider() {
|
|
3701
3541
|
const commandkit2 = getCommandKit(true);
|
|
3702
3542
|
const provider = commandkit2.getCacheProvider();
|
|
@@ -3712,10 +3552,10 @@ function useCache(fn, id, params) {
|
|
|
3712
3552
|
if (id && !isLocal) {
|
|
3713
3553
|
throw new Error("Illegal use of cache function.");
|
|
3714
3554
|
}
|
|
3715
|
-
const fnId = (0,
|
|
3716
|
-
const memo = /* @__PURE__ */ __name((...args) => {
|
|
3555
|
+
const fnId = (0, import_node_crypto3.randomUUID)();
|
|
3556
|
+
const memo = /* @__PURE__ */ __name(async (...args) => {
|
|
3717
3557
|
const forcedName = isLocal ? params == null ? void 0 : params.name : null;
|
|
3718
|
-
const keyHash = forcedName ??
|
|
3558
|
+
const keyHash = forcedName ?? await createObjectHash(fnId, ...args);
|
|
3719
3559
|
const resolvedTTL = isLocal && (params == null ? void 0 : params.ttl) != null ? typeof params.ttl === "string" ? (0, import_ms.default)(params.ttl) : params.ttl : null;
|
|
3720
3560
|
return cacheContext.run(
|
|
3721
3561
|
{
|
|
@@ -3805,21 +3645,21 @@ async function revalidate(tag, ...args) {
|
|
|
3805
3645
|
function isCachedFunction(fn) {
|
|
3806
3646
|
return Object.prototype.hasOwnProperty.call(fn, CACHED_FN_SYMBOL);
|
|
3807
3647
|
}
|
|
3808
|
-
var import_node_async_hooks2,
|
|
3809
|
-
var
|
|
3810
|
-
"src/cache/cache.ts"() {
|
|
3648
|
+
var import_node_async_hooks2, import_node_crypto3, 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;
|
|
3649
|
+
var init_use_cache = __esm({
|
|
3650
|
+
"src/cache/use-cache.ts"() {
|
|
3811
3651
|
"use strict";
|
|
3812
3652
|
init_cjs_shims();
|
|
3813
3653
|
import_node_async_hooks2 = require("async_hooks");
|
|
3814
3654
|
init_async_context();
|
|
3815
|
-
|
|
3655
|
+
import_node_crypto3 = require("crypto");
|
|
3816
3656
|
import_ms = __toESM(require("ms"));
|
|
3657
|
+
init_utils();
|
|
3817
3658
|
cacheContext = new import_node_async_hooks2.AsyncLocalStorage();
|
|
3818
3659
|
fnStore = /* @__PURE__ */ new Map();
|
|
3819
3660
|
DEFAULT_TTL = (0, import_ms.default)("15m");
|
|
3820
3661
|
CACHE_FN_ID = `__cache_fn_id_${Date.now()}__${Math.random()}__`;
|
|
3821
3662
|
CACHED_FN_SYMBOL = Symbol("commandkit.cache.sentinel");
|
|
3822
|
-
__name(md5, "md5");
|
|
3823
3663
|
__name(getCacheProvider, "getCacheProvider");
|
|
3824
3664
|
__name(useCache, "useCache");
|
|
3825
3665
|
__name(cache, "cache");
|
|
@@ -3833,13 +3673,13 @@ var init_cache = __esm({
|
|
|
3833
3673
|
});
|
|
3834
3674
|
|
|
3835
3675
|
// src/cache/index.ts
|
|
3836
|
-
var
|
|
3676
|
+
var init_cache = __esm({
|
|
3837
3677
|
"src/cache/index.ts"() {
|
|
3838
3678
|
"use strict";
|
|
3839
3679
|
init_cjs_shims();
|
|
3840
3680
|
init_CacheProvider();
|
|
3841
3681
|
init_MemoryCache();
|
|
3842
|
-
|
|
3682
|
+
init_use_cache();
|
|
3843
3683
|
}
|
|
3844
3684
|
});
|
|
3845
3685
|
|
|
@@ -3849,11 +3689,10 @@ var init_Context = __esm({
|
|
|
3849
3689
|
"src/app/commands/Context.ts"() {
|
|
3850
3690
|
"use strict";
|
|
3851
3691
|
init_cjs_shims();
|
|
3852
|
-
init_Localization();
|
|
3853
3692
|
init_environment();
|
|
3854
3693
|
init_async_context();
|
|
3855
3694
|
init_signals();
|
|
3856
|
-
|
|
3695
|
+
init_cache();
|
|
3857
3696
|
CommandExecutionMode = {
|
|
3858
3697
|
SlashCommand: "chatInput",
|
|
3859
3698
|
MessageContextMenu: "messageContextMenu",
|
|
@@ -4057,21 +3896,6 @@ var init_Context = __esm({
|
|
|
4057
3896
|
setLocale(locale) {
|
|
4058
3897
|
this._locale = locale;
|
|
4059
3898
|
}
|
|
4060
|
-
/**
|
|
4061
|
-
* Returns the i18n api for this command.
|
|
4062
|
-
* @param locale The locale to use for the i18n api.
|
|
4063
|
-
* @template T The command name for type-safe translations. Will provide autocomplete from available translations.
|
|
4064
|
-
*/
|
|
4065
|
-
locale(locale) {
|
|
4066
|
-
const selectedLocale = locale ?? this.getLocale();
|
|
4067
|
-
return new Localization(
|
|
4068
|
-
this.commandkit,
|
|
4069
|
-
{
|
|
4070
|
-
locale: selectedLocale,
|
|
4071
|
-
target: this.getCommandIdentifier()
|
|
4072
|
-
}
|
|
4073
|
-
);
|
|
4074
|
-
}
|
|
4075
3899
|
/**
|
|
4076
3900
|
* Creates a clone of this context
|
|
4077
3901
|
*/
|
|
@@ -4331,13 +4155,12 @@ var init_AppCommandRunner = __esm({
|
|
|
4331
4155
|
|
|
4332
4156
|
// src/utils/types-package.ts
|
|
4333
4157
|
async function generateTypesPackage() {
|
|
4334
|
-
const location = (0,
|
|
4158
|
+
const location = (0, import_node_path2.join)(process.cwd(), "node_modules", "commandkit-types");
|
|
4335
4159
|
if (!COMMANDKIT_IS_DEV) return location;
|
|
4336
|
-
const packageJSON = (0,
|
|
4337
|
-
const index = (0,
|
|
4338
|
-
const types = (0,
|
|
4339
|
-
const
|
|
4340
|
-
const command = (0, import_node_path3.join)(location, "command.d.ts");
|
|
4160
|
+
const packageJSON = (0, import_node_path2.join)(location, "package.json");
|
|
4161
|
+
const index = (0, import_node_path2.join)(location, "index.js");
|
|
4162
|
+
const types = (0, import_node_path2.join)(location, "index.d.ts");
|
|
4163
|
+
const command = (0, import_node_path2.join)(location, "command.d.ts");
|
|
4341
4164
|
const packageJSONContent = {
|
|
4342
4165
|
name: "commandkit-types",
|
|
4343
4166
|
version: "1.0.0",
|
|
@@ -4348,31 +4171,20 @@ async function generateTypesPackage() {
|
|
|
4348
4171
|
};
|
|
4349
4172
|
const indexContent = `module.exports = {};`;
|
|
4350
4173
|
const typesContent = `// Main types index file - imports all type declarations
|
|
4351
|
-
import './locale_types';
|
|
4352
4174
|
import './command';
|
|
4353
4175
|
export {};
|
|
4354
4176
|
`;
|
|
4355
|
-
const localeTypesContent = `// Auto-generated localization types
|
|
4356
|
-
export {};
|
|
4357
|
-
declare module 'commandkit' {
|
|
4358
|
-
interface CommandLocalizationTypeData {
|
|
4359
|
-
// This interface will be populated with localizations
|
|
4360
|
-
}
|
|
4361
|
-
|
|
4362
|
-
type TranslatableCommandName = keyof CommandLocalizationTypeData
|
|
4363
|
-
}`;
|
|
4364
4177
|
const commandTypesContent = `// Auto-generated command types
|
|
4365
4178
|
export {};
|
|
4366
4179
|
declare module 'commandkit' {
|
|
4367
4180
|
type CommandTypeData = string
|
|
4368
4181
|
}`;
|
|
4369
|
-
await (0,
|
|
4182
|
+
await (0, import_promises2.mkdir)(location, { recursive: true }).catch(() => {
|
|
4370
4183
|
});
|
|
4371
|
-
await (0,
|
|
4372
|
-
await (0,
|
|
4373
|
-
await (0,
|
|
4374
|
-
await (0,
|
|
4375
|
-
await (0, import_promises3.writeFile)(command, commandTypesContent);
|
|
4184
|
+
await (0, import_promises2.writeFile)(packageJSON, JSON.stringify(packageJSONContent, null, 2));
|
|
4185
|
+
await (0, import_promises2.writeFile)(index, indexContent);
|
|
4186
|
+
await (0, import_promises2.writeFile)(types, typesContent);
|
|
4187
|
+
await (0, import_promises2.writeFile)(command, commandTypesContent);
|
|
4376
4188
|
return location;
|
|
4377
4189
|
}
|
|
4378
4190
|
async function rewriteCommandDeclaration(data) {
|
|
@@ -4382,20 +4194,20 @@ async function rewriteCommandDeclaration(data) {
|
|
|
4382
4194
|
}
|
|
4383
4195
|
export {};
|
|
4384
4196
|
`;
|
|
4385
|
-
const location = (0,
|
|
4386
|
-
if (!(0,
|
|
4387
|
-
const type = (0,
|
|
4388
|
-
await (0,
|
|
4197
|
+
const location = (0, import_node_path2.join)(process.cwd(), "node_modules", "commandkit-types");
|
|
4198
|
+
if (!(0, import_node_fs2.existsSync)(location)) return;
|
|
4199
|
+
const type = (0, import_node_path2.join)(location, "command.d.ts");
|
|
4200
|
+
await (0, import_promises2.writeFile)(type, commandTypesContent, { encoding: "utf-8" });
|
|
4389
4201
|
}
|
|
4390
|
-
var
|
|
4202
|
+
var import_promises2, import_node_path2, import_node_fs2;
|
|
4391
4203
|
var init_types_package = __esm({
|
|
4392
4204
|
"src/utils/types-package.ts"() {
|
|
4393
4205
|
"use strict";
|
|
4394
4206
|
init_cjs_shims();
|
|
4395
|
-
|
|
4396
|
-
|
|
4207
|
+
import_promises2 = require("fs/promises");
|
|
4208
|
+
import_node_path2 = require("path");
|
|
4397
4209
|
init_constants();
|
|
4398
|
-
|
|
4210
|
+
import_node_fs2 = require("fs");
|
|
4399
4211
|
__name(generateTypesPackage, "generateTypesPackage");
|
|
4400
4212
|
__name(rewriteCommandDeclaration, "rewriteCommandDeclaration");
|
|
4401
4213
|
}
|
|
@@ -4714,15 +4526,19 @@ var init_AppCommandHandler = __esm({
|
|
|
4714
4526
|
`Invalid export for command ${command.name}: at least one handler function must be provided`
|
|
4715
4527
|
);
|
|
4716
4528
|
}
|
|
4717
|
-
|
|
4718
|
-
|
|
4529
|
+
let lastUpdated = data.command;
|
|
4530
|
+
await this.commandkit.plugins.execute(async (ctx, plugin) => {
|
|
4531
|
+
const res = await plugin.prepareCommand(ctx, lastUpdated);
|
|
4532
|
+
if (res) {
|
|
4533
|
+
lastUpdated = res;
|
|
4534
|
+
}
|
|
4719
4535
|
});
|
|
4720
4536
|
this.loadedCommands.set(id, {
|
|
4721
4537
|
command,
|
|
4722
4538
|
guilds: data.guilds,
|
|
4723
4539
|
data: {
|
|
4724
4540
|
...data,
|
|
4725
|
-
command:
|
|
4541
|
+
command: "toJSON" in lastUpdated ? lastUpdated.toJSON() : lastUpdated
|
|
4726
4542
|
}
|
|
4727
4543
|
});
|
|
4728
4544
|
this.commandNameToId.set(command.name, id);
|
|
@@ -4730,113 +4546,6 @@ var init_AppCommandHandler = __esm({
|
|
|
4730
4546
|
Logger.error(`Failed to load command ${command.name} (${id})`, error);
|
|
4731
4547
|
}
|
|
4732
4548
|
}
|
|
4733
|
-
async applyLocalizations(command) {
|
|
4734
|
-
var _a, _b, _c, _d, _e;
|
|
4735
|
-
const localization = this.commandkit.config.localizationStrategy;
|
|
4736
|
-
const validLocales = Object.values(import_discord16.Locale).filter(
|
|
4737
|
-
(v) => typeof v === "string"
|
|
4738
|
-
);
|
|
4739
|
-
const localizationKey = command.name;
|
|
4740
|
-
for (const locale of validLocales) {
|
|
4741
|
-
const translation = await localization.locateTranslation(
|
|
4742
|
-
localizationKey,
|
|
4743
|
-
locale
|
|
4744
|
-
);
|
|
4745
|
-
if (!(translation == null ? void 0 : translation.command)) continue;
|
|
4746
|
-
if (command instanceof import_discord16.SlashCommandBuilder) {
|
|
4747
|
-
if (translation.command.name) {
|
|
4748
|
-
command.setNameLocalization(locale, translation.command.name);
|
|
4749
|
-
}
|
|
4750
|
-
if (translation.command.description) {
|
|
4751
|
-
command.setDescriptionLocalization(
|
|
4752
|
-
locale,
|
|
4753
|
-
translation.command.description
|
|
4754
|
-
);
|
|
4755
|
-
}
|
|
4756
|
-
const raw = command.toJSON();
|
|
4757
|
-
if (((_a = raw.options) == null ? void 0 : _a.length) && ((_b = translation.command.options) == null ? void 0 : _b.length)) {
|
|
4758
|
-
const opt = translation.command.options.slice();
|
|
4759
|
-
let o;
|
|
4760
|
-
while (o = opt.shift()) {
|
|
4761
|
-
(_c = raw.options) == null ? void 0 : _c.forEach((option) => {
|
|
4762
|
-
var _a2;
|
|
4763
|
-
if (option.name === o.ref) {
|
|
4764
|
-
if (option.name) {
|
|
4765
|
-
option.name_localizations ??= {};
|
|
4766
|
-
option.name_localizations[locale] = o.name;
|
|
4767
|
-
}
|
|
4768
|
-
if (option.description) {
|
|
4769
|
-
option.description_localizations ??= {};
|
|
4770
|
-
option.description_localizations[locale] = o.description;
|
|
4771
|
-
}
|
|
4772
|
-
const opts = option.options;
|
|
4773
|
-
if ((opts == null ? void 0 : opts.length) && ((_a2 = o.options) == null ? void 0 : _a2.length)) {
|
|
4774
|
-
o.options.forEach((subOpt) => {
|
|
4775
|
-
const targetOption = opts == null ? void 0 : opts.find(
|
|
4776
|
-
(opt2) => opt2.name === subOpt.name
|
|
4777
|
-
);
|
|
4778
|
-
if (targetOption) {
|
|
4779
|
-
targetOption.name_localizations ??= {};
|
|
4780
|
-
targetOption.name_localizations[locale] = subOpt.name;
|
|
4781
|
-
if ("description" in targetOption) {
|
|
4782
|
-
targetOption.description_localizations ??= {};
|
|
4783
|
-
targetOption.description_localizations[locale] = subOpt.description;
|
|
4784
|
-
}
|
|
4785
|
-
}
|
|
4786
|
-
});
|
|
4787
|
-
}
|
|
4788
|
-
}
|
|
4789
|
-
});
|
|
4790
|
-
}
|
|
4791
|
-
}
|
|
4792
|
-
} else if (command instanceof import_discord16.ContextMenuCommandBuilder) {
|
|
4793
|
-
if (translation.command.name) {
|
|
4794
|
-
command.setNameLocalization(locale, translation.command.name);
|
|
4795
|
-
}
|
|
4796
|
-
} else {
|
|
4797
|
-
command.name_localizations ??= {};
|
|
4798
|
-
command.name_localizations[locale] = translation.command.name;
|
|
4799
|
-
if (command.description) {
|
|
4800
|
-
command.description_localizations ??= {};
|
|
4801
|
-
command.description_localizations[locale] = translation.command.description;
|
|
4802
|
-
}
|
|
4803
|
-
if (((_d = command.options) == null ? void 0 : _d.length) && ((_e = translation.command.options) == null ? void 0 : _e.length)) {
|
|
4804
|
-
const opt = translation.command.options.slice();
|
|
4805
|
-
let o;
|
|
4806
|
-
while (o = opt.shift()) {
|
|
4807
|
-
command.options.forEach((option) => {
|
|
4808
|
-
var _a2;
|
|
4809
|
-
if (option.name === o.ref) {
|
|
4810
|
-
option.name_localizations ??= {};
|
|
4811
|
-
option.name_localizations[locale] = o.name;
|
|
4812
|
-
if ("description" in option) {
|
|
4813
|
-
option.description_localizations ??= {};
|
|
4814
|
-
option.description_localizations[locale] = o.description;
|
|
4815
|
-
}
|
|
4816
|
-
const opts = option.options;
|
|
4817
|
-
if ((opts == null ? void 0 : opts.length) && ((_a2 = o.options) == null ? void 0 : _a2.length)) {
|
|
4818
|
-
o.options.forEach((subOpt) => {
|
|
4819
|
-
const targetOption = opts == null ? void 0 : opts.find(
|
|
4820
|
-
(opt2) => opt2.name === subOpt.name
|
|
4821
|
-
);
|
|
4822
|
-
if (targetOption) {
|
|
4823
|
-
targetOption.name_localizations ??= {};
|
|
4824
|
-
targetOption.name_localizations[locale] = subOpt.name;
|
|
4825
|
-
if ("description" in targetOption) {
|
|
4826
|
-
targetOption.description_localizations ??= {};
|
|
4827
|
-
targetOption.description_localizations[locale] = subOpt.description;
|
|
4828
|
-
}
|
|
4829
|
-
}
|
|
4830
|
-
});
|
|
4831
|
-
}
|
|
4832
|
-
}
|
|
4833
|
-
});
|
|
4834
|
-
}
|
|
4835
|
-
}
|
|
4836
|
-
}
|
|
4837
|
-
}
|
|
4838
|
-
return command;
|
|
4839
|
-
}
|
|
4840
4549
|
};
|
|
4841
4550
|
__name(_AppCommandHandler, "AppCommandHandler");
|
|
4842
4551
|
AppCommandHandler = _AppCommandHandler;
|
|
@@ -4844,15 +4553,15 @@ var init_AppCommandHandler = __esm({
|
|
|
4844
4553
|
});
|
|
4845
4554
|
|
|
4846
4555
|
// src/app/router/CommandsRouter.ts
|
|
4847
|
-
var import_discord17,
|
|
4556
|
+
var import_discord17, import_node_fs3, import_promises3, import_node_path3, MIDDLEWARE_PATTERN, GLOBAL_MIDDLEWARE_PATTERN, COMMAND_PATTERN, CATEGORY_PATTERN, _CommandsRouter, CommandsRouter;
|
|
4848
4557
|
var init_CommandsRouter = __esm({
|
|
4849
4558
|
"src/app/router/CommandsRouter.ts"() {
|
|
4850
4559
|
"use strict";
|
|
4851
4560
|
init_cjs_shims();
|
|
4852
4561
|
import_discord17 = require("discord.js");
|
|
4853
|
-
|
|
4854
|
-
|
|
4855
|
-
|
|
4562
|
+
import_node_fs3 = require("fs");
|
|
4563
|
+
import_promises3 = require("fs/promises");
|
|
4564
|
+
import_node_path3 = require("path");
|
|
4856
4565
|
MIDDLEWARE_PATTERN = /^\+middleware\.(m|c)?(j|t)sx?$/;
|
|
4857
4566
|
GLOBAL_MIDDLEWARE_PATTERN = /^\+global-middleware\.(m|c)?(j|t)sx?$/;
|
|
4858
4567
|
COMMAND_PATTERN = /^([^+().][^().]*)\.(m|c)?(j|t)sx?$/;
|
|
@@ -4872,7 +4581,7 @@ var init_CommandsRouter = __esm({
|
|
|
4872
4581
|
}
|
|
4873
4582
|
}
|
|
4874
4583
|
isValidPath() {
|
|
4875
|
-
return (0,
|
|
4584
|
+
return (0, import_node_fs3.existsSync)(this.options.entrypoint);
|
|
4876
4585
|
}
|
|
4877
4586
|
isCommand(name) {
|
|
4878
4587
|
return COMMAND_PATTERN.test(name);
|
|
@@ -4888,12 +4597,12 @@ var init_CommandsRouter = __esm({
|
|
|
4888
4597
|
this.middlewares.clear();
|
|
4889
4598
|
}
|
|
4890
4599
|
async scan() {
|
|
4891
|
-
const entries = await (0,
|
|
4600
|
+
const entries = await (0, import_promises3.readdir)(this.options.entrypoint, {
|
|
4892
4601
|
withFileTypes: true
|
|
4893
4602
|
});
|
|
4894
4603
|
for (const entry of entries) {
|
|
4895
4604
|
if (entry.name.startsWith("_")) continue;
|
|
4896
|
-
const fullPath = (0,
|
|
4605
|
+
const fullPath = (0, import_node_path3.join)(this.options.entrypoint, entry.name);
|
|
4897
4606
|
if (entry.isDirectory()) {
|
|
4898
4607
|
const category = this.isCategory(entry.name) ? entry.name.slice(1, -1) : null;
|
|
4899
4608
|
await this.traverse(fullPath, category);
|
|
@@ -4917,7 +4626,7 @@ var init_CommandsRouter = __esm({
|
|
|
4917
4626
|
};
|
|
4918
4627
|
}
|
|
4919
4628
|
async traverse(path3, category) {
|
|
4920
|
-
const entries = await (0,
|
|
4629
|
+
const entries = await (0, import_promises3.readdir)(path3, {
|
|
4921
4630
|
withFileTypes: true
|
|
4922
4631
|
});
|
|
4923
4632
|
for (const entry of entries) {
|
|
@@ -4931,11 +4640,11 @@ var init_CommandsRouter = __esm({
|
|
|
4931
4640
|
}
|
|
4932
4641
|
async handle(entry, category = null) {
|
|
4933
4642
|
const name = entry.name;
|
|
4934
|
-
const path3 = (0,
|
|
4643
|
+
const path3 = (0, import_node_path3.join)(entry.parentPath, entry.name);
|
|
4935
4644
|
if (this.isCommand(name)) {
|
|
4936
4645
|
const command = {
|
|
4937
4646
|
id: crypto.randomUUID(),
|
|
4938
|
-
name: (0,
|
|
4647
|
+
name: (0, import_node_path3.basename)(path3, (0, import_node_path3.extname)(path3)),
|
|
4939
4648
|
path: path3,
|
|
4940
4649
|
category,
|
|
4941
4650
|
parentPath: entry.parentPath,
|
|
@@ -4946,7 +4655,7 @@ var init_CommandsRouter = __esm({
|
|
|
4946
4655
|
} else if (this.isMiddleware(name)) {
|
|
4947
4656
|
const middleware = {
|
|
4948
4657
|
id: crypto.randomUUID(),
|
|
4949
|
-
name: (0,
|
|
4658
|
+
name: (0, import_node_path3.basename)(path3, (0, import_node_path3.extname)(path3)),
|
|
4950
4659
|
path: path3,
|
|
4951
4660
|
relativePath: this.replaceEntrypoint(path3),
|
|
4952
4661
|
parentPath: entry.parentPath,
|
|
@@ -4967,7 +4676,7 @@ var init_CommandsRouter = __esm({
|
|
|
4967
4676
|
});
|
|
4968
4677
|
}
|
|
4969
4678
|
replaceEntrypoint(path3) {
|
|
4970
|
-
const normalized = (0,
|
|
4679
|
+
const normalized = (0, import_node_path3.normalize)(path3);
|
|
4971
4680
|
return normalized.replace(this.options.entrypoint, "");
|
|
4972
4681
|
}
|
|
4973
4682
|
};
|
|
@@ -4977,15 +4686,15 @@ var init_CommandsRouter = __esm({
|
|
|
4977
4686
|
});
|
|
4978
4687
|
|
|
4979
4688
|
// src/app/router/EventsRouter.ts
|
|
4980
|
-
var import_discord18,
|
|
4689
|
+
var import_discord18, import_node_fs4, import_promises4, import_node_path4, _EventsRouter, EventsRouter;
|
|
4981
4690
|
var init_EventsRouter = __esm({
|
|
4982
4691
|
"src/app/router/EventsRouter.ts"() {
|
|
4983
4692
|
"use strict";
|
|
4984
4693
|
init_cjs_shims();
|
|
4985
4694
|
import_discord18 = require("discord.js");
|
|
4986
|
-
|
|
4987
|
-
|
|
4988
|
-
|
|
4695
|
+
import_node_fs4 = require("fs");
|
|
4696
|
+
import_promises4 = require("fs/promises");
|
|
4697
|
+
import_node_path4 = require("path");
|
|
4989
4698
|
_EventsRouter = class _EventsRouter {
|
|
4990
4699
|
/**
|
|
4991
4700
|
* Creates a new EventsRouter instance
|
|
@@ -5032,7 +4741,7 @@ var init_EventsRouter = __esm({
|
|
|
5032
4741
|
* Checks if the entrypoint path is valid
|
|
5033
4742
|
*/
|
|
5034
4743
|
isValidPath() {
|
|
5035
|
-
return this.entrypoints.every((entrypoint) => (0,
|
|
4744
|
+
return this.entrypoints.every((entrypoint) => (0, import_node_fs4.existsSync)(entrypoint));
|
|
5036
4745
|
}
|
|
5037
4746
|
/**
|
|
5038
4747
|
* Clear all parsed events
|
|
@@ -5054,10 +4763,10 @@ var init_EventsRouter = __esm({
|
|
|
5054
4763
|
*/
|
|
5055
4764
|
async scan() {
|
|
5056
4765
|
for (const entrypoint of this.entrypoints) {
|
|
5057
|
-
const dirs = await (0,
|
|
4766
|
+
const dirs = await (0, import_promises4.readdir)(entrypoint, { withFileTypes: true });
|
|
5058
4767
|
for (const dir of dirs) {
|
|
5059
4768
|
if (dir.isDirectory()) {
|
|
5060
|
-
const path3 = (0,
|
|
4769
|
+
const path3 = (0, import_node_path4.join)(entrypoint, dir.name);
|
|
5061
4770
|
await this.scanEvent(dir.name, path3, null, [], true);
|
|
5062
4771
|
}
|
|
5063
4772
|
}
|
|
@@ -5079,18 +4788,18 @@ var init_EventsRouter = __esm({
|
|
|
5079
4788
|
* @returns Promise resolving to the parsed event metadata
|
|
5080
4789
|
*/
|
|
5081
4790
|
async scanEvent(event, path3, _namespace = null, listeners = [], isRoot = false) {
|
|
5082
|
-
const files = await (0,
|
|
4791
|
+
const files = await (0, import_promises4.readdir)(path3, { withFileTypes: true });
|
|
5083
4792
|
const isNamespace = isRoot && /^\(.+\)$/.test(event);
|
|
5084
4793
|
const namespace = isNamespace ? event.slice(1, -1) : _namespace ?? null;
|
|
5085
4794
|
for (const file of files) {
|
|
5086
4795
|
if (file.name.includes("_")) continue;
|
|
5087
4796
|
if (file.isDirectory()) {
|
|
5088
|
-
const nextPath = (0,
|
|
4797
|
+
const nextPath = (0, import_node_path4.join)(path3, file.name);
|
|
5089
4798
|
await this.scanEvent(file.name, nextPath, namespace, listeners);
|
|
5090
4799
|
continue;
|
|
5091
4800
|
}
|
|
5092
4801
|
if (file.isFile() && /\.(m|c)?(j|t)sx?$/.test(file.name)) {
|
|
5093
|
-
listeners.push((0,
|
|
4802
|
+
listeners.push((0, import_node_path4.join)(file.parentPath, file.name));
|
|
5094
4803
|
}
|
|
5095
4804
|
}
|
|
5096
4805
|
if (!isNamespace) {
|
|
@@ -5284,21 +4993,24 @@ async function ensureTypeScript(target) {
|
|
|
5284
4993
|
const isTypeScript = /\.(c|m)?tsx?$/.test(target);
|
|
5285
4994
|
if (!isTypeScript) return false;
|
|
5286
4995
|
if (process.features.typescript) return true;
|
|
5287
|
-
|
|
5288
|
-
try {
|
|
5289
|
-
ts = await import("typescript");
|
|
5290
|
-
} catch {
|
|
5291
|
-
panic("TypeScript must be installed to use TypeScript config files.");
|
|
5292
|
-
}
|
|
5293
|
-
}
|
|
4996
|
+
await loadTypeScript();
|
|
5294
4997
|
return true;
|
|
5295
4998
|
}
|
|
4999
|
+
async function loadTypeScript(e) {
|
|
5000
|
+
if (ts) return ts;
|
|
5001
|
+
try {
|
|
5002
|
+
ts = await import("typescript");
|
|
5003
|
+
} catch {
|
|
5004
|
+
panic(e || "TypeScript must be installed to use TypeScript config files.");
|
|
5005
|
+
}
|
|
5006
|
+
return ts;
|
|
5007
|
+
}
|
|
5296
5008
|
async function loadConfigFileFromPath(target) {
|
|
5297
5009
|
await ensureExists(target);
|
|
5298
5010
|
const isTs = await ensureTypeScript(target);
|
|
5299
5011
|
if (isTs && ts) {
|
|
5300
5012
|
const { transpileModule } = ts;
|
|
5301
|
-
const src =
|
|
5013
|
+
const src = import_node_fs5.default.readFileSync(target, "utf8");
|
|
5302
5014
|
const { outputText } = transpileModule(src, {
|
|
5303
5015
|
compilerOptions: {
|
|
5304
5016
|
module: ts.ModuleKind.ESNext,
|
|
@@ -5308,8 +5020,8 @@ async function loadConfigFileFromPath(target) {
|
|
|
5308
5020
|
fileName: target
|
|
5309
5021
|
});
|
|
5310
5022
|
const nodeModulesPath = await generateTypesPackage();
|
|
5311
|
-
const tmpFile = (0,
|
|
5312
|
-
|
|
5023
|
+
const tmpFile = (0, import_node_path5.join)(nodeModulesPath, "compiled-commandkit.config.mjs");
|
|
5024
|
+
import_node_fs5.default.writeFileSync(tmpFile, outputText);
|
|
5313
5025
|
target = tmpFile;
|
|
5314
5026
|
}
|
|
5315
5027
|
const config = await import(`file://${target}`).then(
|
|
@@ -5318,24 +5030,25 @@ async function loadConfigFileFromPath(target) {
|
|
|
5318
5030
|
return config;
|
|
5319
5031
|
}
|
|
5320
5032
|
async function ensureExists(loc) {
|
|
5321
|
-
const exists =
|
|
5033
|
+
const exists = import_node_fs5.default.existsSync(loc);
|
|
5322
5034
|
if (!exists) {
|
|
5323
5035
|
throw new Error(`File not found: ${loc}`);
|
|
5324
5036
|
}
|
|
5325
5037
|
}
|
|
5326
|
-
var import_rimraf,
|
|
5038
|
+
var import_rimraf, import_node_path5, import_node_fs5, ts;
|
|
5327
5039
|
var init_common2 = __esm({
|
|
5328
5040
|
"src/cli/common.ts"() {
|
|
5329
5041
|
"use strict";
|
|
5330
5042
|
init_cjs_shims();
|
|
5331
5043
|
import_rimraf = require("rimraf");
|
|
5332
|
-
|
|
5333
|
-
|
|
5044
|
+
import_node_path5 = require("path");
|
|
5045
|
+
import_node_fs5 = __toESM(require("fs"));
|
|
5334
5046
|
init_colors();
|
|
5335
5047
|
init_types_package();
|
|
5336
5048
|
__name(write, "write");
|
|
5337
5049
|
__name(panic, "panic");
|
|
5338
5050
|
__name(ensureTypeScript, "ensureTypeScript");
|
|
5051
|
+
__name(loadTypeScript, "loadTypeScript");
|
|
5339
5052
|
__name(loadConfigFileFromPath, "loadConfigFileFromPath");
|
|
5340
5053
|
__name(ensureExists, "ensureExists");
|
|
5341
5054
|
}
|
|
@@ -5343,12 +5056,12 @@ var init_common2 = __esm({
|
|
|
5343
5056
|
|
|
5344
5057
|
// src/config/loader.ts
|
|
5345
5058
|
function getPossibleConfigPaths(root) {
|
|
5346
|
-
return CONFIG_FILE_NAMES.map((name) => (0,
|
|
5059
|
+
return CONFIG_FILE_NAMES.map((name) => (0, import_node_path6.join)(root, name));
|
|
5347
5060
|
}
|
|
5348
5061
|
function findConfigFile(cwd) {
|
|
5349
5062
|
const locations = getPossibleConfigPaths(cwd);
|
|
5350
5063
|
for (const location of locations) {
|
|
5351
|
-
if ((0,
|
|
5064
|
+
if ((0, import_node_fs6.existsSync)(location)) {
|
|
5352
5065
|
return {
|
|
5353
5066
|
path: location,
|
|
5354
5067
|
isTypeScript: /\.ts$/.test(location)
|
|
@@ -5365,13 +5078,13 @@ async function loadConfigFile(entrypoint = process.cwd()) {
|
|
|
5365
5078
|
loadedConfig = config;
|
|
5366
5079
|
return config;
|
|
5367
5080
|
}
|
|
5368
|
-
var
|
|
5081
|
+
var import_node_fs6, import_node_path6, CONFIG_FILE_NAMES, loadedConfig;
|
|
5369
5082
|
var init_loader = __esm({
|
|
5370
5083
|
"src/config/loader.ts"() {
|
|
5371
5084
|
"use strict";
|
|
5372
5085
|
init_cjs_shims();
|
|
5373
|
-
|
|
5374
|
-
|
|
5086
|
+
import_node_fs6 = require("fs");
|
|
5087
|
+
import_node_path6 = require("path");
|
|
5375
5088
|
init_common2();
|
|
5376
5089
|
init_config();
|
|
5377
5090
|
CONFIG_FILE_NAMES = [
|
|
@@ -5421,7 +5134,6 @@ function registerDevHooks(commandkit2) {
|
|
|
5421
5134
|
handled = true;
|
|
5422
5135
|
break;
|
|
5423
5136
|
case HMREventType.ReloadEvents:
|
|
5424
|
-
case HMREventType.ReloadLocales:
|
|
5425
5137
|
commandkit2.eventHandler.reloadEvents();
|
|
5426
5138
|
handled = true;
|
|
5427
5139
|
break;
|
|
@@ -5499,7 +5211,7 @@ var init_CommandKitEventsChannel = __esm({
|
|
|
5499
5211
|
});
|
|
5500
5212
|
|
|
5501
5213
|
// src/CommandKit.ts
|
|
5502
|
-
var import_node_events2, import_discord19,
|
|
5214
|
+
var import_node_events2, import_discord19, import_node_path7, import_node_fs7, commandkit, _started, _CommandKit_instances, init_fn, initCommands_fn, initEvents_fn, _CommandKit, CommandKit;
|
|
5503
5215
|
var init_CommandKit = __esm({
|
|
5504
5216
|
"src/CommandKit.ts"() {
|
|
5505
5217
|
"use strict";
|
|
@@ -5511,9 +5223,8 @@ var init_CommandKit = __esm({
|
|
|
5511
5223
|
init_components();
|
|
5512
5224
|
init_EventInterceptor();
|
|
5513
5225
|
import_discord19 = require("discord.js");
|
|
5514
|
-
init_DefaultLocalizationStrategy();
|
|
5515
5226
|
init_utilities();
|
|
5516
|
-
|
|
5227
|
+
import_node_path7 = require("path");
|
|
5517
5228
|
init_AppCommandHandler();
|
|
5518
5229
|
init_router();
|
|
5519
5230
|
init_AppEventsHandler();
|
|
@@ -5521,7 +5232,7 @@ var init_CommandKit = __esm({
|
|
|
5521
5232
|
init_loader();
|
|
5522
5233
|
init_constants();
|
|
5523
5234
|
init_dev_hooks();
|
|
5524
|
-
|
|
5235
|
+
import_node_fs7 = require("fs");
|
|
5525
5236
|
init_CommandKitEventsChannel();
|
|
5526
5237
|
init_plugins();
|
|
5527
5238
|
init_types_package();
|
|
@@ -5554,7 +5265,6 @@ var init_CommandKit = __esm({
|
|
|
5554
5265
|
__publicField(this, "eventInterceptor");
|
|
5555
5266
|
__publicField(this, "config", {
|
|
5556
5267
|
defaultLocale: import_discord19.Locale.EnglishUS,
|
|
5557
|
-
localizationStrategy: new DefaultLocalizationStrategy(this),
|
|
5558
5268
|
getMessageCommandPrefix: /* @__PURE__ */ __name(() => "!", "getMessageCommandPrefix")
|
|
5559
5269
|
});
|
|
5560
5270
|
__publicField(this, "commandsRouter");
|
|
@@ -5664,14 +5374,6 @@ var init_CommandKit = __esm({
|
|
|
5664
5374
|
this.options.cacheProvider = provider;
|
|
5665
5375
|
return this;
|
|
5666
5376
|
}
|
|
5667
|
-
/**
|
|
5668
|
-
* Sets the localization strategy for the command handler.
|
|
5669
|
-
* @param strategy The localization strategy.
|
|
5670
|
-
*/
|
|
5671
|
-
setLocalizationStrategy(strategy) {
|
|
5672
|
-
this.config.localizationStrategy = strategy;
|
|
5673
|
-
return this;
|
|
5674
|
-
}
|
|
5675
5377
|
/**
|
|
5676
5378
|
* Resolves the current cache provider.
|
|
5677
5379
|
*/
|
|
@@ -5726,12 +5428,10 @@ var init_CommandKit = __esm({
|
|
|
5726
5428
|
const appDir2 = this.getAppDirectory();
|
|
5727
5429
|
if (!appDir2) return null;
|
|
5728
5430
|
switch (to) {
|
|
5729
|
-
case "locales":
|
|
5730
|
-
return (0, import_node_path8.join)(appDir2, "locales");
|
|
5731
5431
|
case "commands":
|
|
5732
|
-
return (0,
|
|
5432
|
+
return (0, import_node_path7.join)(appDir2, "commands");
|
|
5733
5433
|
case "events":
|
|
5734
|
-
return (0,
|
|
5434
|
+
return (0, import_node_path7.join)(appDir2, "events");
|
|
5735
5435
|
default:
|
|
5736
5436
|
return to;
|
|
5737
5437
|
}
|
|
@@ -5763,7 +5463,7 @@ var init_CommandKit = __esm({
|
|
|
5763
5463
|
if (this.commandsRouter.isValidPath()) {
|
|
5764
5464
|
const result = await this.commandsRouter.scan();
|
|
5765
5465
|
if (COMMANDKIT_IS_DEV) {
|
|
5766
|
-
(0,
|
|
5466
|
+
(0, import_node_fs7.writeFileSync)(
|
|
5767
5467
|
"./.commandkit/commands.json",
|
|
5768
5468
|
JSON.stringify(result, null, 2)
|
|
5769
5469
|
);
|
|
@@ -5797,7 +5497,7 @@ var init_version = __esm({
|
|
|
5797
5497
|
"use strict";
|
|
5798
5498
|
init_cjs_shims();
|
|
5799
5499
|
version = /* @__MACRO__ $version */
|
|
5800
|
-
"0.1.11-dev.
|
|
5500
|
+
"0.1.11-dev.20250403165006";
|
|
5801
5501
|
}
|
|
5802
5502
|
});
|
|
5803
5503
|
|
|
@@ -5839,7 +5539,7 @@ function getStdio(supportsCommands) {
|
|
|
5839
5539
|
}
|
|
5840
5540
|
function createAppProcess(fileName, cwd, isDev) {
|
|
5841
5541
|
var _a, _b;
|
|
5842
|
-
if (!(0,
|
|
5542
|
+
if (!(0, import_node_fs8.existsSync)((0, import_node_path8.join)(cwd, fileName))) {
|
|
5843
5543
|
panic(`Could not locate the entrypoint file: ${fileName}`);
|
|
5844
5544
|
}
|
|
5845
5545
|
const stdio = getStdio(isDev);
|
|
@@ -5861,21 +5561,130 @@ function createAppProcess(fileName, cwd, isDev) {
|
|
|
5861
5561
|
(_b = ps.stderr) == null ? void 0 : _b.pipe(process.stderr);
|
|
5862
5562
|
return ps;
|
|
5863
5563
|
}
|
|
5864
|
-
var import_node_child_process,
|
|
5564
|
+
var import_node_child_process, import_node_path8, import_node_fs8;
|
|
5865
5565
|
var init_app_process = __esm({
|
|
5866
5566
|
"src/cli/app-process.ts"() {
|
|
5867
5567
|
"use strict";
|
|
5868
5568
|
init_cjs_shims();
|
|
5869
5569
|
import_node_child_process = require("child_process");
|
|
5870
5570
|
init_env();
|
|
5871
|
-
|
|
5872
|
-
|
|
5571
|
+
import_node_path8 = require("path");
|
|
5572
|
+
import_node_fs8 = require("fs");
|
|
5873
5573
|
init_common2();
|
|
5874
5574
|
__name(getStdio, "getStdio");
|
|
5875
5575
|
__name(createAppProcess, "createAppProcess");
|
|
5876
5576
|
}
|
|
5877
5577
|
});
|
|
5878
5578
|
|
|
5579
|
+
// src/cli/type-checker.ts
|
|
5580
|
+
function formatDiagnostic(ts2, diagnostic, cwd) {
|
|
5581
|
+
const messageText = ts2.flattenDiagnosticMessageText(
|
|
5582
|
+
diagnostic.messageText,
|
|
5583
|
+
"\n"
|
|
5584
|
+
);
|
|
5585
|
+
if (!diagnostic.file) {
|
|
5586
|
+
return `${colors_default.red("error")}: ${messageText}`;
|
|
5587
|
+
}
|
|
5588
|
+
const { line, character } = ts2.getLineAndCharacterOfPosition(
|
|
5589
|
+
diagnostic.file,
|
|
5590
|
+
diagnostic.start
|
|
5591
|
+
);
|
|
5592
|
+
const fileName = (0, import_node_path9.relative)(cwd, diagnostic.file.fileName);
|
|
5593
|
+
const position = `${line + 1}:${character + 1}`;
|
|
5594
|
+
const errorCode = diagnostic.code ? `TS${diagnostic.code}` : "";
|
|
5595
|
+
return [
|
|
5596
|
+
`${colors_default.bold(colors_default.cyan(fileName))}:${colors_default.bold(colors_default.yellow(position))} - ${colors_default.red("error")} ${colors_default.gray(errorCode)}`,
|
|
5597
|
+
`${messageText}`
|
|
5598
|
+
].join("\n");
|
|
5599
|
+
}
|
|
5600
|
+
async function performTypeCheck(path3) {
|
|
5601
|
+
const tsconfigPath = (0, import_node_path9.join)(path3, "tsconfig.json");
|
|
5602
|
+
if (!(0, import_node_fs9.existsSync)(tsconfigPath)) return;
|
|
5603
|
+
const ts2 = await loadTypeScript(TS_NOT_FOUND_ERR);
|
|
5604
|
+
const formatHost = {
|
|
5605
|
+
getCanonicalFileName: /* @__PURE__ */ __name((path4) => path4, "getCanonicalFileName"),
|
|
5606
|
+
getCurrentDirectory: ts2.sys.getCurrentDirectory,
|
|
5607
|
+
getNewLine: /* @__PURE__ */ __name(() => ts2.sys.newLine, "getNewLine")
|
|
5608
|
+
};
|
|
5609
|
+
const configFile = ts2.readConfigFile(tsconfigPath, ts2.sys.readFile);
|
|
5610
|
+
if (configFile.error) {
|
|
5611
|
+
console.error(
|
|
5612
|
+
colors_default.red(
|
|
5613
|
+
`Error reading tsconfig.json: ${ts2.formatDiagnostic(configFile.error, formatHost)}`
|
|
5614
|
+
)
|
|
5615
|
+
);
|
|
5616
|
+
process.exit(1);
|
|
5617
|
+
}
|
|
5618
|
+
const parsedConfig = ts2.parseJsonConfigFileContent(
|
|
5619
|
+
configFile.config,
|
|
5620
|
+
ts2.sys,
|
|
5621
|
+
path3
|
|
5622
|
+
);
|
|
5623
|
+
parsedConfig.options.noEmit = true;
|
|
5624
|
+
const program = ts2.createProgram({
|
|
5625
|
+
rootNames: parsedConfig.fileNames,
|
|
5626
|
+
options: parsedConfig.options,
|
|
5627
|
+
projectReferences: parsedConfig.projectReferences
|
|
5628
|
+
});
|
|
5629
|
+
const diagnostics = [
|
|
5630
|
+
...program.getOptionsDiagnostics(),
|
|
5631
|
+
...program.getGlobalDiagnostics(),
|
|
5632
|
+
...program.getSyntacticDiagnostics(),
|
|
5633
|
+
...program.getSemanticDiagnostics()
|
|
5634
|
+
];
|
|
5635
|
+
if (diagnostics.length > 0) {
|
|
5636
|
+
console.log("");
|
|
5637
|
+
console.error(
|
|
5638
|
+
colors_default.bold(
|
|
5639
|
+
colors_default.red("Type checking failed with the following errors:")
|
|
5640
|
+
)
|
|
5641
|
+
);
|
|
5642
|
+
console.log("");
|
|
5643
|
+
const byFile = /* @__PURE__ */ new Map();
|
|
5644
|
+
for (const diagnostic of diagnostics) {
|
|
5645
|
+
const fileName = diagnostic.file ? diagnostic.file.fileName : "Global";
|
|
5646
|
+
if (!byFile.has(fileName)) {
|
|
5647
|
+
byFile.set(fileName, []);
|
|
5648
|
+
}
|
|
5649
|
+
byFile.get(fileName).push(diagnostic);
|
|
5650
|
+
}
|
|
5651
|
+
const totalErrors = diagnostics.length;
|
|
5652
|
+
let counter = 0;
|
|
5653
|
+
for (const [_, fileDiags] of byFile) {
|
|
5654
|
+
for (const diagnostic of fileDiags) {
|
|
5655
|
+
counter++;
|
|
5656
|
+
console.log(formatDiagnostic(ts2, diagnostic, path3));
|
|
5657
|
+
if (counter < totalErrors) {
|
|
5658
|
+
console.log("");
|
|
5659
|
+
}
|
|
5660
|
+
}
|
|
5661
|
+
}
|
|
5662
|
+
console.log("");
|
|
5663
|
+
console.error(
|
|
5664
|
+
colors_default.bold(
|
|
5665
|
+
colors_default.red(`Found ${totalErrors} error${totalErrors > 1 ? "s" : ""}`)
|
|
5666
|
+
)
|
|
5667
|
+
);
|
|
5668
|
+
console.log("");
|
|
5669
|
+
process.exit(1);
|
|
5670
|
+
}
|
|
5671
|
+
console.log(colors_default.green("\u2713 Type checking completed successfully."));
|
|
5672
|
+
}
|
|
5673
|
+
var import_node_fs9, import_node_path9, TS_NOT_FOUND_ERR;
|
|
5674
|
+
var init_type_checker = __esm({
|
|
5675
|
+
"src/cli/type-checker.ts"() {
|
|
5676
|
+
"use strict";
|
|
5677
|
+
init_cjs_shims();
|
|
5678
|
+
import_node_fs9 = require("fs");
|
|
5679
|
+
init_common2();
|
|
5680
|
+
import_node_path9 = require("path");
|
|
5681
|
+
init_colors();
|
|
5682
|
+
TS_NOT_FOUND_ERR = `TypeScript must be installed in order to use the type checker. Please install it using \`npm install typescript\` or \`yarn add typescript\``;
|
|
5683
|
+
__name(formatDiagnostic, "formatDiagnostic");
|
|
5684
|
+
__name(performTypeCheck, "performTypeCheck");
|
|
5685
|
+
}
|
|
5686
|
+
});
|
|
5687
|
+
|
|
5879
5688
|
// src/cli/build.ts
|
|
5880
5689
|
async function buildApplication({
|
|
5881
5690
|
plugins,
|
|
@@ -5883,7 +5692,11 @@ async function buildApplication({
|
|
|
5883
5692
|
isDev,
|
|
5884
5693
|
configPath
|
|
5885
5694
|
}) {
|
|
5695
|
+
var _a;
|
|
5886
5696
|
const config = await loadConfigFile(configPath);
|
|
5697
|
+
if (!isDev && !((_a = config == null ? void 0 : config.typescript) == null ? void 0 : _a.ignoreDuringBuilds)) {
|
|
5698
|
+
await performTypeCheck(configPath || process.cwd());
|
|
5699
|
+
}
|
|
5887
5700
|
const pluginRuntime = new CompilerPluginRuntime(plugins || []);
|
|
5888
5701
|
const esbuildPluginList = pluginRuntime.isEmpty() ? [] : [pluginRuntime.toEsbuildPlugin()];
|
|
5889
5702
|
if (esbuildPlugins == null ? void 0 : esbuildPlugins.length) {
|
|
@@ -5960,9 +5773,9 @@ await bootstrap().catch((e) => {
|
|
|
5960
5773
|
})
|
|
5961
5774
|
`;
|
|
5962
5775
|
const dist = isDev ? ".commandkit" : distDir || "dist";
|
|
5963
|
-
await (0,
|
|
5776
|
+
await (0, import_promises5.writeFile)((0, import_node_path10.join)(configPath, dist, "index.js"), code);
|
|
5964
5777
|
}
|
|
5965
|
-
var import_tsup,
|
|
5778
|
+
var import_tsup, import_promises5, import_node_path10, import_rimraf2, envScript, requireScript, antiCrashScript, wrapInAsyncIIFE;
|
|
5966
5779
|
var init_build = __esm({
|
|
5967
5780
|
"src/cli/build.ts"() {
|
|
5968
5781
|
"use strict";
|
|
@@ -5970,10 +5783,11 @@ var init_build = __esm({
|
|
|
5970
5783
|
import_tsup = require("tsup");
|
|
5971
5784
|
init_plugins();
|
|
5972
5785
|
init_loader();
|
|
5973
|
-
|
|
5786
|
+
import_promises5 = require("fs/promises");
|
|
5974
5787
|
import_node_path10 = require("path");
|
|
5975
5788
|
init_env();
|
|
5976
5789
|
import_rimraf2 = require("rimraf");
|
|
5790
|
+
init_type_checker();
|
|
5977
5791
|
__name(buildApplication, "buildApplication");
|
|
5978
5792
|
envScript = /* @__PURE__ */ __name((dev) => `// --- Environment Variables Loader ---
|
|
5979
5793
|
const $env = [${(dev ? devEnvFileArgs : prodEnvFileArgs).map((p) => `"${p}"`).join(", ")}];
|
|
@@ -6064,7 +5878,7 @@ async function bootstrapDevelopmentServer(configPath) {
|
|
|
6064
5878
|
}, "onMessage");
|
|
6065
5879
|
ps.once("message", onMessage);
|
|
6066
5880
|
if (!_handled) {
|
|
6067
|
-
(0,
|
|
5881
|
+
(0, import_promises6.setTimeout)(3e3).then(() => {
|
|
6068
5882
|
ps == null ? void 0 : ps.off("message", onMessage);
|
|
6069
5883
|
resolve(false);
|
|
6070
5884
|
});
|
|
@@ -6073,7 +5887,7 @@ async function bootstrapDevelopmentServer(configPath) {
|
|
|
6073
5887
|
}, "waitForAcknowledgment");
|
|
6074
5888
|
const sendHmrEvent = /* @__PURE__ */ __name(async (event, path3) => {
|
|
6075
5889
|
if (!ps || !ps.send) return false;
|
|
6076
|
-
const messageId = (0,
|
|
5890
|
+
const messageId = (0, import_node_crypto4.randomUUID)();
|
|
6077
5891
|
const messagePromise = waitForAcknowledgment(messageId);
|
|
6078
5892
|
ps.send({ event, path: path3, id: messageId });
|
|
6079
5893
|
try {
|
|
@@ -6081,7 +5895,7 @@ async function bootstrapDevelopmentServer(configPath) {
|
|
|
6081
5895
|
const res = !!await Promise.race(
|
|
6082
5896
|
[
|
|
6083
5897
|
messagePromise,
|
|
6084
|
-
(0,
|
|
5898
|
+
(0, import_promises6.setTimeout)(3e3).then(() => {
|
|
6085
5899
|
if (!triggered) {
|
|
6086
5900
|
console.warn(
|
|
6087
5901
|
colors_default.yellow(
|
|
@@ -6112,9 +5926,6 @@ async function bootstrapDevelopmentServer(configPath) {
|
|
|
6112
5926
|
} else if (isEventSource(path3)) {
|
|
6113
5927
|
eventType = HMREventType.ReloadEvents;
|
|
6114
5928
|
eventDescription = "event(s)";
|
|
6115
|
-
} else if (isLocaleSource(path3)) {
|
|
6116
|
-
eventType = HMREventType.ReloadLocales;
|
|
6117
|
-
eventDescription = "locale(s)";
|
|
6118
5929
|
} else {
|
|
6119
5930
|
eventType = HMREventType.Unknown;
|
|
6120
5931
|
eventDescription = "unknown source";
|
|
@@ -6170,9 +5981,6 @@ async function bootstrapDevelopmentServer(configPath) {
|
|
|
6170
5981
|
console.log(`Received reload events command, reloading...`);
|
|
6171
5982
|
await sendHmrEvent(HMREventType.ReloadEvents);
|
|
6172
5983
|
break;
|
|
6173
|
-
case "rl":
|
|
6174
|
-
console.log(`Received reload locales command, reloading...`);
|
|
6175
|
-
await sendHmrEvent(HMREventType.ReloadLocales);
|
|
6176
5984
|
break;
|
|
6177
5985
|
}
|
|
6178
5986
|
});
|
|
@@ -6192,11 +6000,10 @@ ${colors_default.greenBright("Watching for changes in")} ${colors_default.yellow
|
|
|
6192
6000
|
${colors_default.greenBright("Commands:")}
|
|
6193
6001
|
${colors_default.yellowBright("r")} - Restart the server
|
|
6194
6002
|
${colors_default.yellowBright("rc")} - Reload all commands
|
|
6195
|
-
${colors_default.yellowBright("re")} - Reload all events
|
|
6196
|
-
${colors_default.yellowBright("rl")} - Reload all locales`
|
|
6003
|
+
${colors_default.yellowBright("re")} - Reload all events`
|
|
6197
6004
|
);
|
|
6198
6005
|
}
|
|
6199
|
-
var import_path2, import_chokidar,
|
|
6006
|
+
var import_path2, import_chokidar, import_promises6, import_node_crypto4, isCommandSource, isEventSource;
|
|
6200
6007
|
var init_development = __esm({
|
|
6201
6008
|
"src/cli/development.ts"() {
|
|
6202
6009
|
"use strict";
|
|
@@ -6209,13 +6016,12 @@ var init_development = __esm({
|
|
|
6209
6016
|
import_chokidar = require("chokidar");
|
|
6210
6017
|
init_utilities();
|
|
6211
6018
|
init_colors();
|
|
6212
|
-
|
|
6213
|
-
|
|
6019
|
+
import_promises6 = require("timers/promises");
|
|
6020
|
+
import_node_crypto4 = require("crypto");
|
|
6214
6021
|
init_constants();
|
|
6215
6022
|
__name(buildAndStart, "buildAndStart");
|
|
6216
6023
|
isCommandSource = /* @__PURE__ */ __name((p) => p.replaceAll("\\", "/").includes("src/app/commands"), "isCommandSource");
|
|
6217
6024
|
isEventSource = /* @__PURE__ */ __name((p) => p.replaceAll("\\", "/").includes("src/app/events"), "isEventSource");
|
|
6218
|
-
isLocaleSource = /* @__PURE__ */ __name((p) => p.replaceAll("\\", "/").includes("src/app/locales"), "isLocaleSource");
|
|
6219
6025
|
__name(bootstrapDevelopmentServer, "bootstrapDevelopmentServer");
|
|
6220
6026
|
}
|
|
6221
6027
|
});
|
|
@@ -6231,7 +6037,7 @@ async function createSpinner(text) {
|
|
|
6231
6037
|
});
|
|
6232
6038
|
}
|
|
6233
6039
|
var ora;
|
|
6234
|
-
var
|
|
6040
|
+
var init_utils2 = __esm({
|
|
6235
6041
|
"src/cli/utils.ts"() {
|
|
6236
6042
|
"use strict";
|
|
6237
6043
|
init_cjs_shims();
|
|
@@ -6259,7 +6065,9 @@ async function bootstrapProductionServer(configPath) {
|
|
|
6259
6065
|
async function createProductionBuild(configPath) {
|
|
6260
6066
|
const cwd = configPath || process.cwd();
|
|
6261
6067
|
const config = await loadConfigFile(cwd);
|
|
6262
|
-
const spinner = await createSpinner(
|
|
6068
|
+
const spinner = await createSpinner(
|
|
6069
|
+
"Creating an optimized production build\n"
|
|
6070
|
+
);
|
|
6263
6071
|
spinner.start();
|
|
6264
6072
|
await buildApplication({
|
|
6265
6073
|
configPath: cwd,
|
|
@@ -6281,7 +6089,7 @@ var init_production = __esm({
|
|
|
6281
6089
|
init_common2();
|
|
6282
6090
|
init_build();
|
|
6283
6091
|
init_plugins();
|
|
6284
|
-
|
|
6092
|
+
init_utils2();
|
|
6285
6093
|
__name(bootstrapProductionServer, "bootstrapProductionServer");
|
|
6286
6094
|
__name(createProductionBuild, "createProductionBuild");
|
|
6287
6095
|
}
|
|
@@ -6291,8 +6099,7 @@ var init_production = __esm({
|
|
|
6291
6099
|
var generators_exports = {};
|
|
6292
6100
|
__export(generators_exports, {
|
|
6293
6101
|
generateCommand: () => generateCommand,
|
|
6294
|
-
generateEvent: () => generateEvent
|
|
6295
|
-
generateLocale: () => generateLocale
|
|
6102
|
+
generateEvent: () => generateEvent
|
|
6296
6103
|
});
|
|
6297
6104
|
function determineExtension() {
|
|
6298
6105
|
return (0, import_fs2.existsSync)((0, import_path4.join)(BASE_PATH, "tsconfig.json")) ? "ts" : "js";
|
|
@@ -6340,7 +6147,7 @@ export const message = async (ctx) => {
|
|
|
6340
6147
|
}
|
|
6341
6148
|
async function generateCommand(name, customPath) {
|
|
6342
6149
|
const cmdPath = (0, import_path4.join)(customPath || COMMANDS_DIR);
|
|
6343
|
-
if (!(0, import_fs2.existsSync)(cmdPath)) await (0,
|
|
6150
|
+
if (!(0, import_fs2.existsSync)(cmdPath)) await (0, import_promises7.mkdir)(cmdPath, { recursive: true });
|
|
6344
6151
|
const ext = determineExtension();
|
|
6345
6152
|
const isTypeScript = ext === "ts";
|
|
6346
6153
|
const fileName = `${name}.${ext}`;
|
|
@@ -6348,7 +6155,7 @@ async function generateCommand(name, customPath) {
|
|
|
6348
6155
|
panic(`Command ${name} already exists.`);
|
|
6349
6156
|
}
|
|
6350
6157
|
const commandFile = isTypeScript ? TS_COMMAND_SOURCE(name) : JS_COMMAND_SOURCE(name);
|
|
6351
|
-
await (0,
|
|
6158
|
+
await (0, import_promises7.writeFile)((0, import_path4.join)(cmdPath, fileName), commandFile);
|
|
6352
6159
|
console.log(
|
|
6353
6160
|
colors_default.green(
|
|
6354
6161
|
`Command ${colors_default.magenta(name)} created at ${colors_default.blue(formatPath(`${cmdPath}/${fileName}`))}`
|
|
@@ -6357,11 +6164,11 @@ async function generateCommand(name, customPath) {
|
|
|
6357
6164
|
}
|
|
6358
6165
|
async function generateEvent(name, customPath) {
|
|
6359
6166
|
const eventPath = (0, import_path4.join)(customPath || EVENTS_DIR, name);
|
|
6360
|
-
if (!(0, import_fs2.existsSync)(eventPath)) await (0,
|
|
6167
|
+
if (!(0, import_fs2.existsSync)(eventPath)) await (0, import_promises7.mkdir)(eventPath, { recursive: true });
|
|
6361
6168
|
const ext = determineExtension();
|
|
6362
6169
|
let filename = `event.${ext}`;
|
|
6363
6170
|
if ((0, import_fs2.existsSync)((0, import_path4.join)(eventPath, filename))) {
|
|
6364
|
-
const count = (await (0,
|
|
6171
|
+
const count = (await (0, import_promises7.readdir)(eventPath)).length;
|
|
6365
6172
|
filename = `${String(count).padStart(2, "0")}_${filename}`;
|
|
6366
6173
|
}
|
|
6367
6174
|
const eventFile = `
|
|
@@ -6369,69 +6176,32 @@ export default async function on${name[0].toUpperCase() + name.slice(1)}() {
|
|
|
6369
6176
|
console.log('${name} event fired!');
|
|
6370
6177
|
};
|
|
6371
6178
|
`.trim();
|
|
6372
|
-
await (0,
|
|
6179
|
+
await (0, import_promises7.writeFile)((0, import_path4.join)(eventPath, filename), eventFile);
|
|
6373
6180
|
console.log(
|
|
6374
6181
|
colors_default.green(
|
|
6375
6182
|
`Event ${colors_default.magenta(name)} created at ${colors_default.blue(formatPath(eventPath))}/${colors_default.magenta(filename)}`
|
|
6376
6183
|
)
|
|
6377
6184
|
);
|
|
6378
6185
|
}
|
|
6379
|
-
|
|
6380
|
-
const localeNames = Object.fromEntries(
|
|
6381
|
-
Object.entries(import_discord21.Locale).map(([k, v]) => [v, k])
|
|
6382
|
-
);
|
|
6383
|
-
if (!localeNames[locale]) {
|
|
6384
|
-
panic(`Invalid locale: ${locale}`);
|
|
6385
|
-
}
|
|
6386
|
-
if (!commandName) {
|
|
6387
|
-
panic("Command name is required.");
|
|
6388
|
-
}
|
|
6389
|
-
const localePath = (0, import_path4.join)(customPath || LOCALES_DIR, locale);
|
|
6390
|
-
if (!(0, import_fs2.existsSync)(localePath)) await (0, import_promises8.mkdir)(localePath, { recursive: true });
|
|
6391
|
-
if ((0, import_fs2.existsSync)((0, import_path4.join)(localePath, `${commandName}.json`))) {
|
|
6392
|
-
panic(`Locale file for ${commandName} already exists.`);
|
|
6393
|
-
}
|
|
6394
|
-
const localeFile = {
|
|
6395
|
-
command: {
|
|
6396
|
-
name: `${commandName}`,
|
|
6397
|
-
description: `${commandName} command`
|
|
6398
|
-
},
|
|
6399
|
-
translations: {}
|
|
6400
|
-
};
|
|
6401
|
-
await (0, import_promises8.writeFile)(
|
|
6402
|
-
(0, import_path4.join)(localePath, `${commandName}.json`),
|
|
6403
|
-
JSON.stringify(localeFile, null, 2)
|
|
6404
|
-
);
|
|
6405
|
-
console.log(
|
|
6406
|
-
colors_default.green(
|
|
6407
|
-
`Locale file for ${colors_default.magenta(commandName)} created at ${colors_default.blue(
|
|
6408
|
-
formatPath(localePath)
|
|
6409
|
-
)}/${colors_default.magenta(`${commandName}.json`)}`
|
|
6410
|
-
)
|
|
6411
|
-
);
|
|
6412
|
-
}
|
|
6413
|
-
var import_promises8, import_path4, import_discord21, import_fs2, BASE_PATH, COMMANDS_DIR, EVENTS_DIR, LOCALES_DIR, formatPath;
|
|
6186
|
+
var import_promises7, import_path4, import_fs2, BASE_PATH, COMMANDS_DIR, EVENTS_DIR, formatPath;
|
|
6414
6187
|
var init_generators = __esm({
|
|
6415
6188
|
"src/cli/generators.ts"() {
|
|
6416
6189
|
"use strict";
|
|
6417
6190
|
init_cjs_shims();
|
|
6418
|
-
|
|
6191
|
+
import_promises7 = require("fs/promises");
|
|
6419
6192
|
import_path4 = require("path");
|
|
6420
|
-
import_discord21 = require("discord.js");
|
|
6421
6193
|
init_common2();
|
|
6422
6194
|
import_fs2 = require("fs");
|
|
6423
6195
|
init_colors();
|
|
6424
6196
|
BASE_PATH = process.cwd();
|
|
6425
6197
|
COMMANDS_DIR = (0, import_path4.join)(BASE_PATH, "src/app/commands");
|
|
6426
6198
|
EVENTS_DIR = (0, import_path4.join)(BASE_PATH, "src/app/events");
|
|
6427
|
-
LOCALES_DIR = (0, import_path4.join)(BASE_PATH, "src/app/locales");
|
|
6428
6199
|
formatPath = /* @__PURE__ */ __name((path3) => path3.replace(process.cwd(), ".").replace(/\\/g, "/"), "formatPath");
|
|
6429
6200
|
__name(determineExtension, "determineExtension");
|
|
6430
6201
|
__name(TS_COMMAND_SOURCE, "TS_COMMAND_SOURCE");
|
|
6431
6202
|
__name(JS_COMMAND_SOURCE, "JS_COMMAND_SOURCE");
|
|
6432
6203
|
__name(generateCommand, "generateCommand");
|
|
6433
6204
|
__name(generateEvent, "generateEvent");
|
|
6434
|
-
__name(generateLocale, "generateLocale");
|
|
6435
6205
|
}
|
|
6436
6206
|
});
|
|
6437
6207
|
|
|
@@ -6537,7 +6307,7 @@ async function showInformation() {
|
|
|
6537
6307
|
Yarn: getBinaryVersion("yarn") || "N/A",
|
|
6538
6308
|
pnpm: getBinaryVersion("pnpm") || "N/A",
|
|
6539
6309
|
Bun: getBinaryVersion("bun") || "N/A",
|
|
6540
|
-
Deno: getBinaryVersion("deno") || "N/A"
|
|
6310
|
+
Deno: (getBinaryVersion("deno") || "N/A").replace(/\n|\r/g, " ")
|
|
6541
6311
|
},
|
|
6542
6312
|
"Relevant Packages": {
|
|
6543
6313
|
commandkit: version,
|
|
@@ -6610,14 +6380,12 @@ __export(index_exports, {
|
|
|
6610
6380
|
CompilerPlugin: () => CompilerPlugin,
|
|
6611
6381
|
CompilerPluginRuntime: () => CompilerPluginRuntime,
|
|
6612
6382
|
Context: () => Context,
|
|
6613
|
-
DefaultLocalizationStrategy: () => DefaultLocalizationStrategy,
|
|
6614
6383
|
DefaultLogger: () => DefaultLogger,
|
|
6615
6384
|
ElementType: () => ElementType,
|
|
6616
6385
|
EventInterceptor: () => EventInterceptor,
|
|
6617
6386
|
EventsRouter: () => EventsRouter,
|
|
6618
6387
|
Fragment: () => Fragment,
|
|
6619
6388
|
HMREventType: () => HMREventType,
|
|
6620
|
-
Localization: () => Localization,
|
|
6621
6389
|
Logger: () => Logger,
|
|
6622
6390
|
MemoryCache: () => MemoryCache,
|
|
6623
6391
|
MentionableSelectMenu: () => MentionableSelectMenu,
|
|
@@ -6682,23 +6450,13 @@ init_components();
|
|
|
6682
6450
|
init_config();
|
|
6683
6451
|
init_async_context();
|
|
6684
6452
|
init_environment();
|
|
6685
|
-
|
|
6453
|
+
init_cache();
|
|
6686
6454
|
|
|
6687
6455
|
// src/app/index.ts
|
|
6688
6456
|
init_cjs_shims();
|
|
6689
6457
|
init_AppCommandHandler();
|
|
6690
6458
|
init_Context();
|
|
6691
6459
|
init_MessageCommandParser();
|
|
6692
|
-
init_DefaultLocalizationStrategy();
|
|
6693
|
-
init_Localization();
|
|
6694
|
-
|
|
6695
|
-
// src/app/i18n/LocalizationStrategy.ts
|
|
6696
|
-
init_cjs_shims();
|
|
6697
|
-
|
|
6698
|
-
// src/app/i18n/Translation.ts
|
|
6699
|
-
init_cjs_shims();
|
|
6700
|
-
|
|
6701
|
-
// src/app/index.ts
|
|
6702
6460
|
init_signals();
|
|
6703
6461
|
|
|
6704
6462
|
// src/app/commands/helpers.ts
|
|
@@ -6730,14 +6488,14 @@ init_constants();
|
|
|
6730
6488
|
// src/cli/init.ts
|
|
6731
6489
|
init_cjs_shims();
|
|
6732
6490
|
var import_node_fs11 = require("fs");
|
|
6733
|
-
var
|
|
6491
|
+
var import_promises8 = require("fs/promises");
|
|
6734
6492
|
var import_node_path12 = require("path");
|
|
6735
6493
|
async function bootstrapCommandkitCLI(argv, options) {
|
|
6736
6494
|
process.title = "CommandKit CLI";
|
|
6737
6495
|
const { Command } = await import("commander");
|
|
6738
6496
|
const { bootstrapDevelopmentServer: bootstrapDevelopmentServer2 } = await Promise.resolve().then(() => (init_development(), development_exports));
|
|
6739
6497
|
const { bootstrapProductionServer: bootstrapProductionServer2, createProductionBuild: createProductionBuild2 } = await Promise.resolve().then(() => (init_production(), production_exports));
|
|
6740
|
-
const { generateCommand: generateCommand2, generateEvent: generateEvent2
|
|
6498
|
+
const { generateCommand: generateCommand2, generateEvent: generateEvent2 } = await Promise.resolve().then(() => (init_generators(), generators_exports));
|
|
6741
6499
|
const { version: version2 } = await Promise.resolve().then(() => (init_version(), version_exports));
|
|
6742
6500
|
const { showInformation: showInformation2 } = await Promise.resolve().then(() => (init_information(), information_exports));
|
|
6743
6501
|
const program = new Command("commandkit");
|
|
@@ -6756,38 +6514,27 @@ async function bootstrapCommandkitCLI(argv, options) {
|
|
|
6756
6514
|
});
|
|
6757
6515
|
program.command("start").description(
|
|
6758
6516
|
"Start your bot in production mode after running the build command."
|
|
6759
|
-
).option("-c, --config [path]", "Path to your commandkit
|
|
6517
|
+
).option("-c, --config [path]", "Path to your commandkit config file.").action(() => {
|
|
6760
6518
|
const options2 = program.opts();
|
|
6761
6519
|
bootstrapProductionServer2(options2.config);
|
|
6762
6520
|
});
|
|
6763
|
-
program.command("build").description("Build your project for production usage.").option("-c, --config [path]", "Path to your commandkit
|
|
6521
|
+
program.command("build").description("Build your project for production usage.").option("-c, --config [path]", "Path to your commandkit config file.").action(() => {
|
|
6764
6522
|
const options2 = program.opts();
|
|
6765
6523
|
return createProductionBuild2(options2.config);
|
|
6766
6524
|
});
|
|
6767
|
-
program.command("create").description("Create new commands
|
|
6768
|
-
"-l, --locale <locale>",
|
|
6769
|
-
"Specify the locale code (e.g. nl, es, fr)"
|
|
6770
|
-
).argument("<name>", "The name of the command or event").action(async (name, options2) => {
|
|
6525
|
+
program.command("create").description("Create new commands or events files").option("-c, --command", "Create a new command").option("-e, --event", "Create a new event").argument("<name>", "The name of the command or event").action(async (name, options2) => {
|
|
6771
6526
|
if (options2.command) {
|
|
6772
6527
|
await generateCommand2(name);
|
|
6773
6528
|
} else if (options2.event) {
|
|
6774
6529
|
await generateEvent2(name);
|
|
6775
|
-
} else if (options2.locale) {
|
|
6776
|
-
if (!name) {
|
|
6777
|
-
console.error("Please specify a command name for the locale file");
|
|
6778
|
-
return;
|
|
6779
|
-
}
|
|
6780
|
-
await generateLocale2(options2.locale, name);
|
|
6781
6530
|
} else {
|
|
6782
|
-
console.error(
|
|
6783
|
-
"Please specify what to create: --command, --event, or --locale"
|
|
6784
|
-
);
|
|
6531
|
+
console.error("Please specify what to create: --command or --event");
|
|
6785
6532
|
}
|
|
6786
6533
|
});
|
|
6787
6534
|
await program.parseAsync(argv, options);
|
|
6788
6535
|
const types = (0, import_node_path12.join)(process.cwd(), "node_modules", "commandkit-types");
|
|
6789
6536
|
if (!(0, import_node_fs11.existsSync)(types)) {
|
|
6790
|
-
await (0,
|
|
6537
|
+
await (0, import_promises8.mkdir)(types, { recursive: true }).catch(() => {
|
|
6791
6538
|
});
|
|
6792
6539
|
}
|
|
6793
6540
|
}
|
|
@@ -6816,14 +6563,12 @@ var index_default = CommandKit;
|
|
|
6816
6563
|
CompilerPlugin,
|
|
6817
6564
|
CompilerPluginRuntime,
|
|
6818
6565
|
Context,
|
|
6819
|
-
DefaultLocalizationStrategy,
|
|
6820
6566
|
DefaultLogger,
|
|
6821
6567
|
ElementType,
|
|
6822
6568
|
EventInterceptor,
|
|
6823
6569
|
EventsRouter,
|
|
6824
6570
|
Fragment,
|
|
6825
6571
|
HMREventType,
|
|
6826
|
-
Localization,
|
|
6827
6572
|
Logger,
|
|
6828
6573
|
MemoryCache,
|
|
6829
6574
|
MentionableSelectMenu,
|