commandkit 0.1.11-dev.20250128160021 → 0.1.11-dev.20250128162551
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/bin/index.mjs +2 -50
- package/dist/CommandKit.js +6 -6
- package/dist/CommandKit.js.map +1 -1
- package/dist/CommandKit.mjs +1 -1
- package/dist/cache/CacheProvider.js +1 -1
- package/dist/cache/CacheProvider.js.map +1 -1
- package/dist/cache/CacheProvider.mjs +1 -1
- package/dist/cache/MemoryCache.js +1 -1
- package/dist/cache/MemoryCache.js.map +1 -1
- package/dist/cache/MemoryCache.mjs +1 -1
- package/dist/cache/cache.js +6 -6
- package/dist/cache/cache.js.map +1 -1
- package/dist/cache/cache.mjs +1 -1
- package/dist/cache/index.js +6 -6
- package/dist/cache/index.js.map +1 -1
- package/dist/cache/index.mjs +1 -1
- package/dist/chunk-35OSBS47.mjs +2 -0
- package/dist/chunk-6ZU6MOKA.mjs +2 -0
- package/dist/chunk-73NFQRKA.mjs +7 -0
- package/dist/{chunk-XJCWZEWC.mjs.map → chunk-73NFQRKA.mjs.map} +1 -1
- package/dist/chunk-B5T552SB.mjs +2 -0
- package/dist/{chunk-4OV4GE7B.mjs.map → chunk-B5T552SB.mjs.map} +1 -1
- package/dist/{chunk-6AX5YJEO.mjs → chunk-BNTMQC76.mjs} +2 -2
- package/dist/{chunk-DW5KRS5H.mjs → chunk-DTKEXOZL.mjs} +3 -3
- package/dist/{chunk-DW5KRS5H.mjs.map → chunk-DTKEXOZL.mjs.map} +1 -1
- package/dist/chunk-FC5WQLBI.mjs +3 -0
- package/dist/chunk-FC5WQLBI.mjs.map +1 -0
- package/dist/{chunk-4CG7S6RY.mjs → chunk-ICJ4BBWI.mjs} +2 -2
- package/dist/chunk-IRBJOQ7G.mjs +2 -0
- package/dist/{chunk-CO2EZ53K.mjs.map → chunk-IRBJOQ7G.mjs.map} +1 -1
- package/dist/chunk-JYUG7HAX.mjs +2 -0
- package/dist/{chunk-Z4FBPRS6.mjs.map → chunk-JYUG7HAX.mjs.map} +1 -1
- package/dist/chunk-KAJRRZVI.mjs +2 -0
- package/dist/{chunk-5KRNT4BG.mjs.map → chunk-KAJRRZVI.mjs.map} +1 -1
- package/dist/chunk-LQPVE73I.mjs +2 -0
- package/dist/{chunk-RGQOLRR6.mjs.map → chunk-LQPVE73I.mjs.map} +1 -1
- package/dist/{chunk-6W2KY7FK.mjs → chunk-PTP2L33V.mjs} +2 -2
- package/dist/{chunk-C6WU57FQ.mjs → chunk-QXMWKQIO.mjs} +2 -2
- package/dist/{chunk-CKNUFVNV.mjs → chunk-R4SWJR4N.mjs} +2 -2
- package/dist/chunk-RQ3ABUE3.mjs +2 -0
- package/dist/chunk-RQ3ABUE3.mjs.map +1 -0
- package/dist/{chunk-6BSP7AD3.mjs → chunk-RVGLG66X.mjs} +2 -2
- package/dist/chunk-SI3L34FF.mjs +2 -0
- package/dist/{chunk-UPJYI5Q6.mjs.map → chunk-SI3L34FF.mjs.map} +1 -1
- package/dist/chunk-TEL2J6LT.mjs +2 -0
- package/dist/{chunk-WNEBLBID.mjs.map → chunk-TEL2J6LT.mjs.map} +1 -1
- package/dist/chunk-ULPF2QCW.mjs +2 -0
- package/dist/chunk-ULPF2QCW.mjs.map +1 -0
- package/dist/{chunk-J7CCGFUZ.mjs → chunk-UP6ACDGE.mjs} +2 -2
- package/dist/{chunk-J7CCGFUZ.mjs.map → chunk-UP6ACDGE.mjs.map} +1 -1
- package/dist/chunk-UYDZJJZT.mjs +4 -0
- package/dist/{chunk-K43A7OIY.mjs.map → chunk-UYDZJJZT.mjs.map} +1 -1
- package/dist/chunk-WZU7OSUV.mjs +13 -0
- package/dist/chunk-WZU7OSUV.mjs.map +1 -0
- package/dist/chunk-Y522NY4J.mjs +2 -0
- package/dist/chunk-Y522NY4J.mjs.map +1 -0
- package/dist/chunk-ZCUZ5ENB.mjs +2 -0
- package/dist/chunk-ZCUZ5ENB.mjs.map +1 -0
- package/dist/cli/build.d.mts +4 -0
- package/dist/cli/build.d.ts +4 -0
- package/dist/cli/build.js +14 -0
- package/dist/cli/build.js.map +1 -0
- package/dist/cli/build.mjs +2 -0
- package/dist/cli/build.mjs.map +1 -0
- package/dist/cli/common.d.mts +35 -0
- package/dist/cli/common.d.ts +35 -0
- package/dist/cli/common.js +3 -0
- package/dist/cli/common.js.map +1 -0
- package/dist/cli/common.mjs +2 -0
- package/dist/cli/common.mjs.map +1 -0
- package/dist/cli/development.d.mts +3 -0
- package/dist/cli/development.d.ts +3 -0
- package/dist/cli/development.js +17 -0
- package/dist/cli/development.js.map +1 -0
- package/dist/cli/development.mjs +7 -0
- package/dist/cli/development.mjs.map +1 -0
- package/dist/cli/esbuild-plugins/plugin.d.mts +10 -0
- package/dist/cli/esbuild-plugins/plugin.d.ts +10 -0
- package/dist/cli/esbuild-plugins/plugin.js +2 -0
- package/dist/cli/esbuild-plugins/plugin.js.map +1 -0
- package/dist/cli/esbuild-plugins/plugin.mjs +2 -0
- package/dist/cli/esbuild-plugins/plugin.mjs.map +1 -0
- package/dist/cli/esbuild-plugins/use-cache.d.mts +6 -0
- package/dist/cli/esbuild-plugins/use-cache.d.ts +6 -0
- package/dist/cli/esbuild-plugins/use-cache.js +2 -0
- package/dist/cli/esbuild-plugins/use-cache.js.map +1 -0
- package/dist/cli/esbuild-plugins/use-cache.mjs +2 -0
- package/dist/cli/esbuild-plugins/use-cache.mjs.map +1 -0
- package/dist/cli/init.d.mts +10 -0
- package/dist/cli/init.d.ts +10 -0
- package/dist/cli/init.js +20 -0
- package/dist/cli/init.js.map +1 -0
- package/dist/cli/init.mjs +2 -0
- package/dist/cli/init.mjs.map +1 -0
- package/dist/cli/parse-env.d.mts +3 -0
- package/dist/cli/parse-env.d.ts +3 -0
- package/dist/cli/parse-env.js +2 -0
- package/dist/cli/parse-env.js.map +1 -0
- package/dist/cli/parse-env.mjs +2 -0
- package/dist/cli/parse-env.mjs.map +1 -0
- package/dist/cli/production.d.mts +3 -0
- package/dist/cli/production.d.ts +3 -0
- package/dist/cli/production.js +4 -0
- package/dist/cli/production.js.map +1 -0
- package/dist/cli/production.mjs +3 -0
- package/dist/cli/production.mjs.map +1 -0
- package/dist/components/ButtonKit.js +1 -1
- package/dist/components/ButtonKit.js.map +1 -1
- package/dist/components/ButtonKit.mjs +1 -1
- package/dist/components/index.js +1 -1
- package/dist/components/index.js.map +1 -1
- package/dist/components/index.mjs +1 -1
- package/dist/config.mjs +1 -1
- package/dist/context/async-context.js +6 -6
- package/dist/context/async-context.js.map +1 -1
- package/dist/context/async-context.mjs +1 -1
- package/dist/context/environment.js +1 -1
- package/dist/context/environment.js.map +1 -1
- package/dist/context/environment.mjs +1 -1
- package/dist/handlers/command-handler/CommandHandler.js +6 -6
- package/dist/handlers/command-handler/CommandHandler.js.map +1 -1
- package/dist/handlers/command-handler/CommandHandler.mjs +1 -1
- package/dist/handlers/command-handler/functions/loadCommandsWithRest.js +2 -2
- package/dist/handlers/command-handler/functions/loadCommandsWithRest.js.map +1 -1
- package/dist/handlers/command-handler/functions/loadCommandsWithRest.mjs +1 -1
- package/dist/handlers/command-handler/functions/registerCommands.js +2 -2
- package/dist/handlers/command-handler/functions/registerCommands.js.map +1 -1
- package/dist/handlers/command-handler/functions/registerCommands.mjs +1 -1
- package/dist/handlers/command-handler/utils/areSlashCommandsDifferent.mjs +1 -1
- package/dist/handlers/command-handler/validations/devOnly.js +1 -1
- package/dist/handlers/command-handler/validations/devOnly.js.map +1 -1
- package/dist/handlers/command-handler/validations/devOnly.mjs +1 -1
- package/dist/handlers/command-handler/validations/index.js +1 -1
- package/dist/handlers/command-handler/validations/index.js.map +1 -1
- package/dist/handlers/command-handler/validations/index.mjs +1 -1
- package/dist/handlers/command-handler/validations/permissions.js +1 -1
- package/dist/handlers/command-handler/validations/permissions.js.map +1 -1
- package/dist/handlers/command-handler/validations/permissions.mjs +1 -1
- package/dist/handlers/event-handler/EventHandler.js +1 -1
- package/dist/handlers/event-handler/EventHandler.js.map +1 -1
- package/dist/handlers/event-handler/EventHandler.mjs +1 -1
- package/dist/handlers/index.js +6 -6
- package/dist/handlers/index.js.map +1 -1
- package/dist/handlers/index.mjs +1 -1
- package/dist/handlers/validation-handler/ValidationHandler.js +1 -1
- package/dist/handlers/validation-handler/ValidationHandler.js.map +1 -1
- package/dist/handlers/validation-handler/ValidationHandler.mjs +1 -1
- package/dist/index.d.mts +2 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +24 -6
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +1 -1
- package/dist/index.mjs.map +1 -1
- package/dist/types.mjs +1 -1
- package/dist/utils/clone.mjs +1 -1
- package/dist/utils/colors.mjs +1 -1
- package/dist/utils/constants.mjs +1 -1
- package/dist/utils/error-codes.mjs +1 -1
- package/dist/utils/get-paths.mjs +1 -1
- package/dist/utils/resolve-file-url.mjs +1 -1
- package/dist/utils/warn-unstable.mjs +1 -1
- package/package.json +3 -13
- package/bin/build.mjs +0 -129
- package/bin/common.mjs +0 -125
- package/bin/development.mjs +0 -187
- package/bin/esbuild-plugins/plugin.mjs +0 -74
- package/bin/esbuild-plugins/use-cache.mjs +0 -160
- package/bin/parse-env.mjs +0 -65
- package/bin/production.mjs +0 -86
- package/dist/chunk-4OV4GE7B.mjs +0 -2
- package/dist/chunk-5KRNT4BG.mjs +0 -2
- package/dist/chunk-6TIBWNPX.mjs +0 -2
- package/dist/chunk-6TIGKCSX.mjs +0 -2
- package/dist/chunk-CO2EZ53K.mjs +0 -2
- package/dist/chunk-K43A7OIY.mjs +0 -4
- package/dist/chunk-RGQOLRR6.mjs +0 -2
- package/dist/chunk-UPJYI5Q6.mjs +0 -2
- package/dist/chunk-WNEBLBID.mjs +0 -2
- package/dist/chunk-XJCWZEWC.mjs +0 -7
- package/dist/chunk-Z4FBPRS6.mjs +0 -2
- /package/dist/{chunk-6TIBWNPX.mjs.map → chunk-35OSBS47.mjs.map} +0 -0
- /package/dist/{chunk-6TIGKCSX.mjs.map → chunk-6ZU6MOKA.mjs.map} +0 -0
- /package/dist/{chunk-6AX5YJEO.mjs.map → chunk-BNTMQC76.mjs.map} +0 -0
- /package/dist/{chunk-4CG7S6RY.mjs.map → chunk-ICJ4BBWI.mjs.map} +0 -0
- /package/dist/{chunk-6W2KY7FK.mjs.map → chunk-PTP2L33V.mjs.map} +0 -0
- /package/dist/{chunk-C6WU57FQ.mjs.map → chunk-QXMWKQIO.mjs.map} +0 -0
- /package/dist/{chunk-CKNUFVNV.mjs.map → chunk-R4SWJR4N.mjs.map} +0 -0
- /package/dist/{chunk-6BSP7AD3.mjs.map → chunk-RVGLG66X.mjs.map} +0 -0
package/dist/utils/colors.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{colors_default}from"../chunk-
|
|
1
|
+
import{colors_default}from"../chunk-QXMWKQIO.mjs";import"../chunk-35OSBS47.mjs";export{colors_default as default};
|
|
2
2
|
//# sourceMappingURL=colors.mjs.map
|
package/dist/utils/constants.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import"../chunk-
|
|
1
|
+
import"../chunk-35OSBS47.mjs";var COMMANDKIT_CACHE_TAG=Symbol("kCommandKitCacheTag");export{COMMANDKIT_CACHE_TAG};
|
|
2
2
|
//# sourceMappingURL=constants.mjs.map
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{CommandKitErrorCodes,isCommandKitError}from"../chunk-
|
|
1
|
+
import{CommandKitErrorCodes,isCommandKitError}from"../chunk-R4SWJR4N.mjs";import"../chunk-35OSBS47.mjs";export{CommandKitErrorCodes,isCommandKitError};
|
|
2
2
|
//# sourceMappingURL=error-codes.mjs.map
|
package/dist/utils/get-paths.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{getFilePaths,getFolderPaths}from"../chunk-
|
|
1
|
+
import{getFilePaths,getFolderPaths}from"../chunk-RVGLG66X.mjs";import"../chunk-35OSBS47.mjs";export{getFilePaths,getFolderPaths};
|
|
2
2
|
//# sourceMappingURL=get-paths.mjs.map
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{toFileURL}from"../chunk-
|
|
1
|
+
import{toFileURL}from"../chunk-ICJ4BBWI.mjs";import"../chunk-35OSBS47.mjs";export{toFileURL};
|
|
2
2
|
//# sourceMappingURL=resolve-file-url.mjs.map
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{__name}from"../chunk-
|
|
1
|
+
import{__name}from"../chunk-35OSBS47.mjs";var WARNED_KEYS=new Set;function emitWarning(message,code="CommandKitWarning"){process.emitWarning(message,{code})}__name(emitWarning,"emitWarning");function warnUnstable(name){WARNED_KEYS.has(name)||(WARNED_KEYS.add(name),emitWarning(`${name} is unstable and may change in future versions.`,"CommandKitUnstableWarning"))}__name(warnUnstable,"warnUnstable");export{emitWarning,warnUnstable};
|
|
2
2
|
//# sourceMappingURL=warn-unstable.mjs.map
|
package/package.json
CHANGED
|
@@ -1,24 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "commandkit",
|
|
3
3
|
"description": "Beginner friendly command & event handler for Discord.js",
|
|
4
|
-
"version": "0.1.11-dev.
|
|
4
|
+
"version": "0.1.11-dev.20250128162551",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"main": "./dist/index.js",
|
|
7
7
|
"module": "./dist/index.mjs",
|
|
8
8
|
"types": "./dist/index.d.ts",
|
|
9
9
|
"bin": "./bin/index.mjs",
|
|
10
|
-
"exports": {
|
|
11
|
-
".": {
|
|
12
|
-
"require": "./dist/index.js",
|
|
13
|
-
"import": "./dist/index.mjs",
|
|
14
|
-
"types": "./dist/index.d.ts"
|
|
15
|
-
},
|
|
16
|
-
"./cli": {
|
|
17
|
-
"require": "./dist/environment/cli.js",
|
|
18
|
-
"import": "./dist/environment/cli.mjs",
|
|
19
|
-
"types": "./dist/environment/cli.d.ts"
|
|
20
|
-
}
|
|
21
|
-
},
|
|
22
10
|
"files": [
|
|
23
11
|
"dist",
|
|
24
12
|
"bin"
|
|
@@ -55,6 +43,8 @@
|
|
|
55
43
|
"tsup": "^8.3.5"
|
|
56
44
|
},
|
|
57
45
|
"devDependencies": {
|
|
46
|
+
"@types/babel__generator": "^7.6.8",
|
|
47
|
+
"@types/babel__traverse": "^7.20.6",
|
|
58
48
|
"@types/ms": "^0.7.34",
|
|
59
49
|
"@types/node": "^22.10.2",
|
|
60
50
|
"@types/yargs": "^17.0.32",
|
package/bin/build.mjs
DELETED
|
@@ -1,129 +0,0 @@
|
|
|
1
|
-
// @ts-check
|
|
2
|
-
|
|
3
|
-
import { readFile, writeFile } from 'node:fs/promises';
|
|
4
|
-
import { join } from 'node:path';
|
|
5
|
-
import { build } from 'tsup';
|
|
6
|
-
import {
|
|
7
|
-
Colors,
|
|
8
|
-
erase,
|
|
9
|
-
findCommandKitConfig,
|
|
10
|
-
panic,
|
|
11
|
-
write,
|
|
12
|
-
} from './common.mjs';
|
|
13
|
-
import ora from 'ora';
|
|
14
|
-
import { commandkitPlugin } from './esbuild-plugins/plugin.mjs';
|
|
15
|
-
|
|
16
|
-
export async function bootstrapProductionBuild(config) {
|
|
17
|
-
const {
|
|
18
|
-
sourcemap = false,
|
|
19
|
-
minify = false,
|
|
20
|
-
outDir = 'dist',
|
|
21
|
-
antiCrash = true,
|
|
22
|
-
src,
|
|
23
|
-
main,
|
|
24
|
-
requirePolyfill: polyfillRequire,
|
|
25
|
-
} = await findCommandKitConfig(config);
|
|
26
|
-
|
|
27
|
-
const status = ora('Creating optimized production build...\n').start();
|
|
28
|
-
const start = performance.now();
|
|
29
|
-
|
|
30
|
-
erase(outDir);
|
|
31
|
-
|
|
32
|
-
try {
|
|
33
|
-
await build({
|
|
34
|
-
clean: true,
|
|
35
|
-
format: ['esm'],
|
|
36
|
-
dts: false,
|
|
37
|
-
skipNodeModulesBundle: true,
|
|
38
|
-
minify,
|
|
39
|
-
shims: true,
|
|
40
|
-
banner: {
|
|
41
|
-
js: '/* Optimized production build generated by CommandKit */',
|
|
42
|
-
},
|
|
43
|
-
sourcemap,
|
|
44
|
-
keepNames: true,
|
|
45
|
-
outDir,
|
|
46
|
-
silent: true,
|
|
47
|
-
watch: false,
|
|
48
|
-
cjsInterop: true,
|
|
49
|
-
entry: [src, '!dist', '!.commandkit', `!${outDir}`],
|
|
50
|
-
esbuildPlugins: [commandkitPlugin()],
|
|
51
|
-
});
|
|
52
|
-
|
|
53
|
-
await injectShims(outDir, main, antiCrash, polyfillRequire);
|
|
54
|
-
|
|
55
|
-
status.succeed(
|
|
56
|
-
Colors.green(
|
|
57
|
-
`Build completed in ${(performance.now() - start).toFixed(2)}ms!`,
|
|
58
|
-
),
|
|
59
|
-
);
|
|
60
|
-
write(
|
|
61
|
-
Colors.green(
|
|
62
|
-
`\nRun ${Colors.magenta(`commandkit start`)} ${Colors.green(
|
|
63
|
-
'to start your bot.',
|
|
64
|
-
)}`,
|
|
65
|
-
),
|
|
66
|
-
);
|
|
67
|
-
} catch (e) {
|
|
68
|
-
status.fail(
|
|
69
|
-
`Build failed after ${(performance.now() - start).toFixed(2)}ms!`,
|
|
70
|
-
);
|
|
71
|
-
panic(e);
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
export async function injectShims(outDir, main, antiCrash, polyfillRequire) {
|
|
76
|
-
const path = join(process.cwd(), outDir, main);
|
|
77
|
-
|
|
78
|
-
const head = ['\n\n;await (async()=>{', " 'use strict';"].join('\n');
|
|
79
|
-
const tail = '\n})();';
|
|
80
|
-
const requireScript = polyfillRequire
|
|
81
|
-
? [
|
|
82
|
-
'// --- CommandKit require() polyfill ---',
|
|
83
|
-
' if (typeof require === "undefined") {',
|
|
84
|
-
' const { createRequire } = await import("node:module");',
|
|
85
|
-
' const __require = createRequire(import.meta.url);',
|
|
86
|
-
' Object.defineProperty(globalThis, "require", {',
|
|
87
|
-
' value: (id) => {',
|
|
88
|
-
' return __require(id);',
|
|
89
|
-
' },',
|
|
90
|
-
' configurable: true,',
|
|
91
|
-
' enumerable: false,',
|
|
92
|
-
' writable: true,',
|
|
93
|
-
' });',
|
|
94
|
-
' }',
|
|
95
|
-
'// --- CommandKit require() polyfill ---',
|
|
96
|
-
].join('\n')
|
|
97
|
-
: '';
|
|
98
|
-
|
|
99
|
-
const antiCrashScript = antiCrash
|
|
100
|
-
? [
|
|
101
|
-
'// --- CommandKit Anti-Crash Monitor ---',
|
|
102
|
-
" // 'uncaughtException' event is supposed to be used to perform synchronous cleanup before shutting down the process",
|
|
103
|
-
' // instead of using it as a means to resume operation.',
|
|
104
|
-
' // But it exists here due to compatibility reasons with discord bot ecosystem.',
|
|
105
|
-
" const p = (t) => `\\x1b[33m${t}\\x1b[0m`, b = '[CommandKit Anti-Crash Monitor]', l = console.log, e1 = 'uncaughtException', e2 = 'unhandledRejection';",
|
|
106
|
-
' if (!process.eventNames().includes(e1)) // skip if it is already handled',
|
|
107
|
-
' process.on(e1, (e) => {',
|
|
108
|
-
' l(p(`${b} Uncaught Exception`)); l(p(b), p(e.stack || e));',
|
|
109
|
-
' })',
|
|
110
|
-
' if (!process.eventNames().includes(e2)) // skip if it is already handled',
|
|
111
|
-
' process.on(e2, (r) => {',
|
|
112
|
-
' l(p(`${b} Unhandled promise rejection`)); l(p(`${b} ${r.stack || r}`));',
|
|
113
|
-
' });',
|
|
114
|
-
'// --- CommandKit Anti-Crash Monitor ---',
|
|
115
|
-
].join('\n')
|
|
116
|
-
: '';
|
|
117
|
-
|
|
118
|
-
const contents = await readFile(path, 'utf-8');
|
|
119
|
-
const finalScript = [
|
|
120
|
-
head,
|
|
121
|
-
requireScript,
|
|
122
|
-
antiCrashScript,
|
|
123
|
-
tail,
|
|
124
|
-
'\n\n',
|
|
125
|
-
contents,
|
|
126
|
-
].join('\n');
|
|
127
|
-
|
|
128
|
-
return writeFile(path, finalScript);
|
|
129
|
-
}
|
package/bin/common.mjs
DELETED
|
@@ -1,125 +0,0 @@
|
|
|
1
|
-
// @ts-check
|
|
2
|
-
|
|
3
|
-
import { rimrafSync } from 'rimraf';
|
|
4
|
-
import { join } from 'node:path';
|
|
5
|
-
import fs from 'node:fs';
|
|
6
|
-
|
|
7
|
-
const resetColor = '\x1b[0m';
|
|
8
|
-
|
|
9
|
-
export const Colors = {
|
|
10
|
-
reset: (text) => `${text}${resetColor}`,
|
|
11
|
-
bright: (text) => `\x1b[1m${text}${resetColor}`,
|
|
12
|
-
dim: (text) => `\x1b[2m${text}${resetColor}`,
|
|
13
|
-
underscore: (text) => `\x1b[4m${text}${resetColor}`,
|
|
14
|
-
blink: (text) => `\x1b[5m${text}${resetColor}`,
|
|
15
|
-
reverse: (text) => `\x1b[7m${text}${resetColor}`,
|
|
16
|
-
hidden: (text) => `\x1b[8m${text}${resetColor}`,
|
|
17
|
-
|
|
18
|
-
black: (text) => `\x1b[30m${text}${resetColor}`,
|
|
19
|
-
red: (text) => `\x1b[31m${text}${resetColor}`,
|
|
20
|
-
green: (text) => `\x1b[32m${text}${resetColor}`,
|
|
21
|
-
yellow: (text) => `\x1b[33m${text}${resetColor}`,
|
|
22
|
-
blue: (text) => `\x1b[34m${text}${resetColor}`,
|
|
23
|
-
magenta: (text) => `\x1b[35m${text}${resetColor}`,
|
|
24
|
-
cyan: (text) => `\x1b[36m${text}${resetColor}`,
|
|
25
|
-
white: (text) => `\x1b[37m${text}${resetColor}`,
|
|
26
|
-
|
|
27
|
-
bgBlack: (text) => `\x1b[40m${text}${resetColor}`,
|
|
28
|
-
bgRed: (text) => `\x1b[41m${text}${resetColor}`,
|
|
29
|
-
bgGreen: (text) => `\x1b[42m${text}${resetColor}`,
|
|
30
|
-
bgYellow: (text) => `\x1b[43m${text}${resetColor}`,
|
|
31
|
-
bgBlue: (text) => `\x1b[44m${text}${resetColor}`,
|
|
32
|
-
bgMagenta: (text) => `\x1b[45m${text}${resetColor}`,
|
|
33
|
-
bgCyan: (text) => `\x1b[46m${text}${resetColor}`,
|
|
34
|
-
bgWhite: (text) => `\x1b[47m${text}${resetColor}`,
|
|
35
|
-
};
|
|
36
|
-
|
|
37
|
-
export function write(message) {
|
|
38
|
-
process.stdout.write(message);
|
|
39
|
-
process.stdout.write('\n');
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
/**
|
|
43
|
-
* @returns {never}
|
|
44
|
-
*/
|
|
45
|
-
export function panic(message) {
|
|
46
|
-
write(Colors.red(`Error: ${message}`));
|
|
47
|
-
process.exit(1);
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
export function findPackageJSON() {
|
|
51
|
-
const cwd = process.cwd();
|
|
52
|
-
const target = join(cwd, 'package.json');
|
|
53
|
-
|
|
54
|
-
if (!fs.existsSync(target)) {
|
|
55
|
-
panic('Could not find package.json in current directory.');
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
return JSON.parse(fs.readFileSync(target, 'utf8'));
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
const possibleFileNames = [
|
|
62
|
-
'commandkit.json',
|
|
63
|
-
'commandkit.config.json',
|
|
64
|
-
'commandkit.js',
|
|
65
|
-
'commandkit.config.js',
|
|
66
|
-
'commandkit.mjs',
|
|
67
|
-
'commandkit.config.mjs',
|
|
68
|
-
'commandkit.cjs',
|
|
69
|
-
'commandkit.config.cjs',
|
|
70
|
-
'commandkit.ts',
|
|
71
|
-
'commandkit.mts',
|
|
72
|
-
'commandkit.cts',
|
|
73
|
-
];
|
|
74
|
-
|
|
75
|
-
export async function findCommandKitConfig(src) {
|
|
76
|
-
const cwd = process.cwd();
|
|
77
|
-
const locations = src
|
|
78
|
-
? [join(cwd, src)]
|
|
79
|
-
: possibleFileNames.map((name) => join(cwd, name));
|
|
80
|
-
|
|
81
|
-
for (const location of locations) {
|
|
82
|
-
try {
|
|
83
|
-
return await loadConfigInner(location);
|
|
84
|
-
} catch (e) {
|
|
85
|
-
continue;
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
panic(`Could not locate commandkit config from ${cwd}`);
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
function ensureTypeScript(target) {
|
|
93
|
-
const isTypeScript = /\.(c|m)tsx?$/.test(target);
|
|
94
|
-
|
|
95
|
-
if (isTypeScript && !process.features.typescript) {
|
|
96
|
-
panic(
|
|
97
|
-
'You are trying to load commandkit config file that is written in typescript. The current Node.js version does not have TypeScript feature enabled.',
|
|
98
|
-
);
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
async function loadConfigInner(target) {
|
|
103
|
-
const isJSON = target.endsWith('.json');
|
|
104
|
-
|
|
105
|
-
await ensureExists(target);
|
|
106
|
-
|
|
107
|
-
ensureTypeScript(target);
|
|
108
|
-
|
|
109
|
-
/**
|
|
110
|
-
* @type {import('..').CommandKitConfig}
|
|
111
|
-
*/
|
|
112
|
-
const config = await import(`file://${target}`, {
|
|
113
|
-
assert: isJSON ? { type: 'json' } : undefined,
|
|
114
|
-
}).then((conf) => conf.default || conf);
|
|
115
|
-
|
|
116
|
-
return config;
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
async function ensureExists(loc) {
|
|
120
|
-
await fs.promises.access(loc, fs.constants.F_OK);
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
export function erase(dir) {
|
|
124
|
-
rimrafSync(dir);
|
|
125
|
-
}
|
package/bin/development.mjs
DELETED
|
@@ -1,187 +0,0 @@
|
|
|
1
|
-
// @ts-check
|
|
2
|
-
import { config as dotenv } from 'dotenv';
|
|
3
|
-
import { join } from 'node:path';
|
|
4
|
-
import { build } from 'tsup';
|
|
5
|
-
import {
|
|
6
|
-
Colors,
|
|
7
|
-
erase,
|
|
8
|
-
findCommandKitConfig,
|
|
9
|
-
panic,
|
|
10
|
-
write,
|
|
11
|
-
} from './common.mjs';
|
|
12
|
-
import { parseEnv } from './parse-env.mjs';
|
|
13
|
-
import child_process from 'node:child_process';
|
|
14
|
-
import ora from 'ora';
|
|
15
|
-
import { injectShims } from './build.mjs';
|
|
16
|
-
import { commandkitPlugin } from './esbuild-plugins/plugin.mjs';
|
|
17
|
-
|
|
18
|
-
const RESTARTING_MSG_PATTERN = /^Restarting '|".+'|"\n?$/;
|
|
19
|
-
const FAILED_RUNNING_PATTERN = /^Failed running '.+'|"\n?$/;
|
|
20
|
-
|
|
21
|
-
export async function bootstrapDevelopmentServer(opts) {
|
|
22
|
-
const {
|
|
23
|
-
src,
|
|
24
|
-
main,
|
|
25
|
-
watch = Boolean(opts.noWatch),
|
|
26
|
-
nodeOptions = [],
|
|
27
|
-
envExtra = true,
|
|
28
|
-
clearRestartLogs = true,
|
|
29
|
-
outDir,
|
|
30
|
-
requirePolyfill,
|
|
31
|
-
} = await findCommandKitConfig(opts.config);
|
|
32
|
-
|
|
33
|
-
if (!src) {
|
|
34
|
-
panic('Could not find src in commandkit.json');
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
if (!main) {
|
|
38
|
-
panic('Could not find main in commandkit.json');
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
const watchMode = watch;
|
|
42
|
-
const status = ora(
|
|
43
|
-
Colors.green('Starting a development server...\n'),
|
|
44
|
-
).start();
|
|
45
|
-
const start = performance.now();
|
|
46
|
-
|
|
47
|
-
if (watchMode && !nodeOptions.includes('--watch')) {
|
|
48
|
-
nodeOptions.push('--watch');
|
|
49
|
-
} else if (!watchMode && nodeOptions.includes('--watch')) {
|
|
50
|
-
nodeOptions.splice(nodeOptions.indexOf('--watch'), 1);
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
if (!nodeOptions.includes('--enable-source-maps')) {
|
|
54
|
-
nodeOptions.push('--enable-source-maps');
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
erase('.commandkit');
|
|
58
|
-
|
|
59
|
-
try {
|
|
60
|
-
await build({
|
|
61
|
-
clean: true,
|
|
62
|
-
format: ['esm'],
|
|
63
|
-
dts: false,
|
|
64
|
-
skipNodeModulesBundle: true,
|
|
65
|
-
minify: false,
|
|
66
|
-
shims: true,
|
|
67
|
-
sourcemap: 'inline',
|
|
68
|
-
keepNames: true,
|
|
69
|
-
outDir: '.commandkit',
|
|
70
|
-
silent: true,
|
|
71
|
-
entry: [src, '!dist', '!.commandkit', `!${outDir}`].filter(Boolean),
|
|
72
|
-
watch: watchMode,
|
|
73
|
-
cjsInterop: true,
|
|
74
|
-
async onSuccess() {
|
|
75
|
-
return await injectShims('.commandkit', main, false, requirePolyfill);
|
|
76
|
-
},
|
|
77
|
-
esbuildPlugins: [
|
|
78
|
-
commandkitPlugin({
|
|
79
|
-
'use-macro': false,
|
|
80
|
-
}),
|
|
81
|
-
],
|
|
82
|
-
});
|
|
83
|
-
|
|
84
|
-
status.succeed(
|
|
85
|
-
Colors.green(
|
|
86
|
-
`Dev server started in ${(performance.now() - start).toFixed(2)}ms!\n`,
|
|
87
|
-
),
|
|
88
|
-
);
|
|
89
|
-
|
|
90
|
-
if (watchMode) write(Colors.cyan('Watching for file changes...\n'));
|
|
91
|
-
|
|
92
|
-
const processEnv = {};
|
|
93
|
-
|
|
94
|
-
const env = dotenv({
|
|
95
|
-
path: join(process.cwd(), '.env'),
|
|
96
|
-
// @ts-expect-error
|
|
97
|
-
processEnv,
|
|
98
|
-
});
|
|
99
|
-
|
|
100
|
-
if (envExtra) {
|
|
101
|
-
parseEnv(processEnv);
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
if (env.error) {
|
|
105
|
-
write(Colors.yellow(`[DOTENV] Warning: ${env.error.message}`));
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
if (env.parsed) {
|
|
109
|
-
write(Colors.blue('[DOTENV] Loaded .env file!'));
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
/**
|
|
113
|
-
* @type {child_process.ChildProcessWithoutNullStreams}
|
|
114
|
-
*/
|
|
115
|
-
const ps = child_process.spawn(
|
|
116
|
-
'node',
|
|
117
|
-
[...nodeOptions, join(process.cwd(), '.commandkit', main)],
|
|
118
|
-
{
|
|
119
|
-
env: {
|
|
120
|
-
...process.env,
|
|
121
|
-
...processEnv,
|
|
122
|
-
NODE_ENV: 'development',
|
|
123
|
-
// @ts-expect-error
|
|
124
|
-
COMMANDKIT_DEV: true,
|
|
125
|
-
// @ts-expect-error
|
|
126
|
-
COMMANDKIT_PRODUCTION: false,
|
|
127
|
-
},
|
|
128
|
-
cwd: process.cwd(),
|
|
129
|
-
},
|
|
130
|
-
);
|
|
131
|
-
|
|
132
|
-
let isLastLogRestarting = false,
|
|
133
|
-
hasStarted = false;
|
|
134
|
-
|
|
135
|
-
ps.stdout.on('data', (data) => {
|
|
136
|
-
const message = data.toString();
|
|
137
|
-
|
|
138
|
-
if (FAILED_RUNNING_PATTERN.test(message)) {
|
|
139
|
-
write(Colors.cyan('Failed running the bot, waiting for changes...'));
|
|
140
|
-
isLastLogRestarting = false;
|
|
141
|
-
if (!hasStarted) hasStarted = true;
|
|
142
|
-
return;
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
if (clearRestartLogs && !RESTARTING_MSG_PATTERN.test(message)) {
|
|
146
|
-
write(message);
|
|
147
|
-
isLastLogRestarting = false;
|
|
148
|
-
} else {
|
|
149
|
-
if (isLastLogRestarting || !hasStarted) {
|
|
150
|
-
if (!hasStarted) hasStarted = true;
|
|
151
|
-
return;
|
|
152
|
-
}
|
|
153
|
-
write(Colors.cyan('⌀ Restarting the bot...'));
|
|
154
|
-
isLastLogRestarting = true;
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
if (!hasStarted) hasStarted = true;
|
|
158
|
-
});
|
|
159
|
-
|
|
160
|
-
ps.stderr.on('data', (data) => {
|
|
161
|
-
const message = data.toString();
|
|
162
|
-
|
|
163
|
-
if (
|
|
164
|
-
message.includes(
|
|
165
|
-
'ExperimentalWarning: Watch mode is an experimental feature and might change at any time',
|
|
166
|
-
)
|
|
167
|
-
)
|
|
168
|
-
return;
|
|
169
|
-
|
|
170
|
-
write(Colors.red(message));
|
|
171
|
-
});
|
|
172
|
-
|
|
173
|
-
ps.on('close', (code) => {
|
|
174
|
-
write('\n');
|
|
175
|
-
process.exit(code ?? 0);
|
|
176
|
-
});
|
|
177
|
-
|
|
178
|
-
ps.on('error', (err) => {
|
|
179
|
-
panic(err);
|
|
180
|
-
});
|
|
181
|
-
} catch (e) {
|
|
182
|
-
status.fail(
|
|
183
|
-
`Error occurred after ${(performance.now() - start).toFixed(2)}ms!\n`,
|
|
184
|
-
);
|
|
185
|
-
panic(e.stack ?? e);
|
|
186
|
-
}
|
|
187
|
-
}
|
|
@@ -1,74 +0,0 @@
|
|
|
1
|
-
import { MacroTransformer } from 'use-macro';
|
|
2
|
-
import { cacheDirectivePlugin } from './use-cache.mjs';
|
|
3
|
-
import { readFile } from 'node:fs/promises';
|
|
4
|
-
|
|
5
|
-
const defaultConfig = {
|
|
6
|
-
'use-macro': true,
|
|
7
|
-
'use-cache': true,
|
|
8
|
-
};
|
|
9
|
-
|
|
10
|
-
/**
|
|
11
|
-
* @typedef {Object} CommandKitEsbuildPluginConfig
|
|
12
|
-
* @property {boolean} [use-macro]
|
|
13
|
-
* @property {boolean} [use-cache]
|
|
14
|
-
*/
|
|
15
|
-
|
|
16
|
-
/**
|
|
17
|
-
* @param {CommandKitEsbuildPluginConfig} [config]
|
|
18
|
-
*/
|
|
19
|
-
export const commandkitPlugin = (config) => {
|
|
20
|
-
config = Object.assign({}, defaultConfig, config);
|
|
21
|
-
|
|
22
|
-
const plugins = [
|
|
23
|
-
{
|
|
24
|
-
name: 'use-macro',
|
|
25
|
-
plugin: async (content, args) => {
|
|
26
|
-
const transformer = new MacroTransformer();
|
|
27
|
-
const { contents } = await transformer.transform(content, args.path);
|
|
28
|
-
return contents;
|
|
29
|
-
},
|
|
30
|
-
},
|
|
31
|
-
{
|
|
32
|
-
name: 'use-cache',
|
|
33
|
-
plugin: async (content, args) => {
|
|
34
|
-
const { contents } = await cacheDirectivePlugin(content, args);
|
|
35
|
-
return contents;
|
|
36
|
-
},
|
|
37
|
-
},
|
|
38
|
-
].filter((p) => {
|
|
39
|
-
return !!config[p.name];
|
|
40
|
-
});
|
|
41
|
-
|
|
42
|
-
return {
|
|
43
|
-
name: 'commandkit-transformer-plugin',
|
|
44
|
-
setup(build) {
|
|
45
|
-
if (!plugins.length) return;
|
|
46
|
-
|
|
47
|
-
const fileFilter = /\.(c|m)?(t|j)sx?$/;
|
|
48
|
-
|
|
49
|
-
build.onLoad({ filter: fileFilter }, async (args) => {
|
|
50
|
-
const source = await readFile(args.path, 'utf8');
|
|
51
|
-
const loader = args.path.split('.').pop();
|
|
52
|
-
|
|
53
|
-
let contents = source;
|
|
54
|
-
|
|
55
|
-
for (const _plugin of plugins) {
|
|
56
|
-
const { plugin, name } = _plugin;
|
|
57
|
-
try {
|
|
58
|
-
contents = await plugin(contents, args);
|
|
59
|
-
} catch (e) {
|
|
60
|
-
const err = new Error(`Plugin ${name} failed with ${e}`);
|
|
61
|
-
err.stack = e.stack;
|
|
62
|
-
|
|
63
|
-
throw err;
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
return {
|
|
68
|
-
contents,
|
|
69
|
-
loader,
|
|
70
|
-
};
|
|
71
|
-
});
|
|
72
|
-
},
|
|
73
|
-
};
|
|
74
|
-
};
|