commandkit 0.1.6-dev.20231113071041 → 0.1.6-dev.20231124164938

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -32,10 +32,10 @@ var src_exports = {};
32
32
  __export(src_exports, {
33
33
  ButtonKit: () => ButtonKit,
34
34
  CommandKit: () => CommandKit,
35
- CommandType: () => CommandType,
36
- ReloadType: () => ReloadType,
37
35
  createEffect: () => createEffect,
38
- createSignal: () => createSignal
36
+ createSignal: () => createSignal,
37
+ defineConfig: () => defineConfig,
38
+ getConfig: () => getConfig
39
39
  });
40
40
  module.exports = __toCommonJS(src_exports);
41
41
 
@@ -787,6 +787,11 @@ var ValidationHandler = class {
787
787
  // src/CommandKit.ts
788
788
  var CommandKit = class {
789
789
  #data;
790
+ /**
791
+ * Create a new handler with CommandKit.
792
+ * @param options - Options to use (client, commandsPath, eventsPath, etc.)
793
+ * @see {@link https://commandkit.js.org/docs/commandkit-setup}
794
+ */
790
795
  constructor(options) {
791
796
  if (!options.client) {
792
797
  throw new Error(colors_default.red('"client" is required when instantiating CommandKit.'));
@@ -799,6 +804,9 @@ var CommandKit = class {
799
804
  this.#data = options;
800
805
  this.#init();
801
806
  }
807
+ /**
808
+ * (Private) Initialize CommandKit.
809
+ */
802
810
  async #init() {
803
811
  if (this.#data.eventsPath) {
804
812
  const eventHandler = new EventHandler({
@@ -971,6 +979,34 @@ var ButtonKit = class extends import_discord2.ButtonBuilder {
971
979
  }
972
980
  };
973
981
 
982
+ // src/config.ts
983
+ var globalConfig = {
984
+ envExtra: true,
985
+ outDir: "dist",
986
+ watch: true,
987
+ clearRestartLogs: true,
988
+ minify: false,
989
+ sourcemap: false,
990
+ nodeOptions: [],
991
+ antiCrash: true
992
+ };
993
+ function getConfig() {
994
+ return globalConfig;
995
+ }
996
+ var requiredProps = ["src", "main"];
997
+ function defineConfig(config) {
998
+ for (const prop of requiredProps) {
999
+ if (!config[prop]) {
1000
+ throw new Error(`[CommandKit Config] Missing required config property: ${prop}`);
1001
+ }
1002
+ }
1003
+ globalConfig = {
1004
+ ...globalConfig,
1005
+ ...config
1006
+ };
1007
+ return globalConfig;
1008
+ }
1009
+
974
1010
  // src/utils/signal.ts
975
1011
  var context = [];
976
1012
  function createSignal(value) {
@@ -1013,25 +1049,12 @@ function createEffect(callback) {
1013
1049
  function getCurrentObserver() {
1014
1050
  return context[context.length - 1];
1015
1051
  }
1016
-
1017
- // src/types/index.ts
1018
- var CommandType = /* @__PURE__ */ ((CommandType2) => {
1019
- CommandType2[CommandType2["ChatInput"] = 1] = "ChatInput";
1020
- CommandType2[CommandType2["Message"] = 3] = "Message";
1021
- CommandType2[CommandType2["User"] = 2] = "User";
1022
- return CommandType2;
1023
- })(CommandType || {});
1024
- var ReloadType = /* @__PURE__ */ ((ReloadType2) => {
1025
- ReloadType2["Developer"] = "dev";
1026
- ReloadType2["Global"] = "global";
1027
- return ReloadType2;
1028
- })(ReloadType || {});
1029
1052
  // Annotate the CommonJS export names for ESM import in node:
1030
1053
  0 && (module.exports = {
1031
1054
  ButtonKit,
1032
1055
  CommandKit,
1033
- CommandType,
1034
- ReloadType,
1035
1056
  createEffect,
1036
- createSignal
1057
+ createSignal,
1058
+ defineConfig,
1059
+ getConfig
1037
1060
  });
package/dist/index.mjs CHANGED
@@ -754,6 +754,11 @@ var ValidationHandler = class {
754
754
  // src/CommandKit.ts
755
755
  var CommandKit = class {
756
756
  #data;
757
+ /**
758
+ * Create a new handler with CommandKit.
759
+ * @param options - Options to use (client, commandsPath, eventsPath, etc.)
760
+ * @see {@link https://commandkit.js.org/docs/commandkit-setup}
761
+ */
757
762
  constructor(options) {
758
763
  if (!options.client) {
759
764
  throw new Error(colors_default.red('"client" is required when instantiating CommandKit.'));
@@ -766,6 +771,9 @@ var CommandKit = class {
766
771
  this.#data = options;
767
772
  this.#init();
768
773
  }
774
+ /**
775
+ * (Private) Initialize CommandKit.
776
+ */
769
777
  async #init() {
770
778
  if (this.#data.eventsPath) {
771
779
  const eventHandler = new EventHandler({
@@ -942,6 +950,34 @@ var ButtonKit = class extends ButtonBuilder {
942
950
  }
943
951
  };
944
952
 
953
+ // src/config.ts
954
+ var globalConfig = {
955
+ envExtra: true,
956
+ outDir: "dist",
957
+ watch: true,
958
+ clearRestartLogs: true,
959
+ minify: false,
960
+ sourcemap: false,
961
+ nodeOptions: [],
962
+ antiCrash: true
963
+ };
964
+ function getConfig() {
965
+ return globalConfig;
966
+ }
967
+ var requiredProps = ["src", "main"];
968
+ function defineConfig(config) {
969
+ for (const prop of requiredProps) {
970
+ if (!config[prop]) {
971
+ throw new Error(`[CommandKit Config] Missing required config property: ${prop}`);
972
+ }
973
+ }
974
+ globalConfig = {
975
+ ...globalConfig,
976
+ ...config
977
+ };
978
+ return globalConfig;
979
+ }
980
+
945
981
  // src/utils/signal.ts
946
982
  var context = [];
947
983
  function createSignal(value) {
@@ -984,24 +1020,11 @@ function createEffect(callback) {
984
1020
  function getCurrentObserver() {
985
1021
  return context[context.length - 1];
986
1022
  }
987
-
988
- // src/types/index.ts
989
- var CommandType = /* @__PURE__ */ ((CommandType2) => {
990
- CommandType2[CommandType2["ChatInput"] = 1] = "ChatInput";
991
- CommandType2[CommandType2["Message"] = 3] = "Message";
992
- CommandType2[CommandType2["User"] = 2] = "User";
993
- return CommandType2;
994
- })(CommandType || {});
995
- var ReloadType = /* @__PURE__ */ ((ReloadType2) => {
996
- ReloadType2["Developer"] = "dev";
997
- ReloadType2["Global"] = "global";
998
- return ReloadType2;
999
- })(ReloadType || {});
1000
1023
  export {
1001
1024
  ButtonKit,
1002
1025
  CommandKit,
1003
- CommandType,
1004
- ReloadType,
1005
1026
  createEffect,
1006
- createSignal
1027
+ createSignal,
1028
+ defineConfig,
1029
+ getConfig
1007
1030
  };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "commandkit",
3
3
  "description": "Beginner friendly command & event handler for Discord.js",
4
- "version": "0.1.6-dev.20231113071041",
4
+ "version": "0.1.6-dev.20231124164938",
5
5
  "license": "MIT",
6
6
  "main": "./dist/index.js",
7
7
  "module": "./dist/index.mjs",
@@ -24,8 +24,9 @@
24
24
  "build": "tsup",
25
25
  "deploy": "npm publish",
26
26
  "deploy-dev": "npm publish --access public --tag dev",
27
- "test": "tsx tests/index.ts",
28
- "test:watch": "tsx watch tests/index.ts"
27
+ "test": "cd ./tests && node ../bin/index.mjs dev",
28
+ "test:build": "cd ./tests && node ../bin/index.mjs build",
29
+ "test:prod": "cd ./tests && node ../bin/index.mjs start"
29
30
  },
30
31
  "repository": {
31
32
  "url": "git+https://github.com/underctrl-io/commandkit.git"
@@ -1,91 +0,0 @@
1
- // @ts-check
2
- import { config as dotenv } from 'dotenv';
3
- import { build } from 'tsup';
4
- import child_process from 'node:child_process';
5
- import ora from 'ora';
6
- import { join } from 'node:path';
7
- import { Colors, erase, findCommandKitJSON, panic, write } from './common.mjs';
8
-
9
- export async function bootstrapDevelopmentServer(config) {
10
- const { src, main = 'index.mjs', nodeOptions = ['--watch'] } = findCommandKitJSON(config);
11
-
12
- if (!src) {
13
- panic('Could not find src in commandkit.json');
14
- }
15
-
16
- const status = ora(Colors.green('Starting a development server...\n')).start();
17
- const start = performance.now();
18
-
19
- erase('.commandkit');
20
-
21
- try {
22
- await build({
23
- clean: true,
24
- format: ['esm'],
25
- dts: false,
26
- skipNodeModulesBundle: true,
27
- minify: false,
28
- shims: true,
29
- sourcemap: false,
30
- keepNames: true,
31
- outDir: '.commandkit',
32
- silent: true,
33
- entry: [src, '!dist', '!.commandkit'],
34
- watch: nodeOptions.includes('--watch'),
35
- });
36
-
37
- status.succeed(
38
- Colors.green(`Server started in ${(performance.now() - start).toFixed(2)}ms!\n`),
39
- );
40
-
41
- const processEnv = {};
42
-
43
- const env = dotenv({
44
- path: join(process.cwd(), '.env'),
45
- // @ts-expect-error
46
- processEnv,
47
- });
48
-
49
- if (env.error) {
50
- write(Colors.yellow(`[DOTENV] Warning: ${env.error.message}`));
51
- }
52
-
53
- if (env.parsed) {
54
- write(Colors.blue('[DOTENV] Loaded .env file!'));
55
- }
56
-
57
- const ps = child_process.spawn(
58
- 'node',
59
- [...nodeOptions, join(process.cwd(), '.commandkit', main)],
60
- {
61
- env: {
62
- ...process.env,
63
- ...processEnv,
64
- NODE_ENV: 'development',
65
- COMMANDKIT_DEV: 'true',
66
- },
67
- cwd: process.cwd(),
68
- },
69
- );
70
-
71
- ps.stdout.on('data', (data) => {
72
- write(data.toString());
73
- });
74
-
75
- ps.stderr.on('data', (data) => {
76
- write(Colors.red(data.toString()));
77
- });
78
-
79
- ps.on('close', (code) => {
80
- write('\n');
81
- process.exit(code ?? 0);
82
- });
83
-
84
- ps.on('error', (err) => {
85
- panic(err);
86
- });
87
- } catch (e) {
88
- status.fail(`Error occurred after ${(performance.now() - start).toFixed(2)}ms!\n`);
89
- panic(e);
90
- }
91
- }