commandkit 0.1.6-dev.20231026074421 → 0.1.6-dev.20231112142249

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/build.mjs ADDED
@@ -0,0 +1,44 @@
1
+ // @ts-check
2
+
3
+ import { build } from 'tsup';
4
+ import ora from 'ora';
5
+ import { Colors, erase, findCommandKitJSON, panic, write } from './common.mjs';
6
+
7
+ export async function bootstrapProductionBuild(config) {
8
+ const {
9
+ minify = false,
10
+ outDir = 'dist',
11
+ main,
12
+ src,
13
+ } = findCommandKitJSON(config);
14
+
15
+ const status = ora('Creating optimized production build...\n').start();
16
+ const start = performance.now();
17
+
18
+ erase(outDir);
19
+
20
+ try {
21
+ await build({
22
+ clean: true,
23
+ format: ['esm'],
24
+ dts: false,
25
+ skipNodeModulesBundle: true,
26
+ minify,
27
+ shims: true,
28
+ banner: {
29
+ js: '/* Optimized production build of your project, generated by CommandKit */'
30
+ },
31
+ sourcemap: false,
32
+ keepNames: true,
33
+ outDir,
34
+ silent: true,
35
+ entry: [src, '!dist', '!.commandkit'],
36
+ });
37
+
38
+ status.succeed(Colors.green(`Build completed in ${(performance.now() - start).toFixed(2)}ms!`));
39
+ write(Colors.green(`\nRun ${Colors.magenta(`node ${outDir}/${main}`)} ${Colors.green('to start your bot.')}`))
40
+ } catch (e) {
41
+ status.fail(`Build failed after ${(performance.now() - start).toFixed(2)}ms!`)
42
+ panic(e);
43
+ }
44
+ }
package/bin/common.mjs ADDED
@@ -0,0 +1,74 @@
1
+ // @ts-check
2
+
3
+ import { join } from 'node:path'
4
+ import fs from 'node:fs';
5
+ import { rimrafSync } from 'rimraf'
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
+ export function findCommandKitJSON(src) {
62
+ const cwd = process.cwd();
63
+ const target = src || join(cwd, 'commandkit.json');
64
+
65
+ if (!fs.existsSync(target)) {
66
+ panic('Could not find commandkit.json in current directory.');
67
+ }
68
+
69
+ return JSON.parse(fs.readFileSync(target, 'utf8'));
70
+ }
71
+
72
+ export function erase(dir) {
73
+ rimrafSync(dir);
74
+ }
@@ -0,0 +1,89 @@
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 {
11
+ src,
12
+ main = 'index.mjs',
13
+ nodeOptions = ['--watch']
14
+ } = findCommandKitJSON(config);
15
+
16
+ if (!src) {
17
+ panic('Could not find src in commandkit.json');
18
+ }
19
+
20
+ const status = ora(Colors.green('Starting a development server...\n')).start();
21
+ const start = performance.now();
22
+
23
+ erase('.commandkit');
24
+
25
+ try {
26
+ await build({
27
+ clean: true,
28
+ format: ['esm'],
29
+ dts: false,
30
+ skipNodeModulesBundle: true,
31
+ minify: false,
32
+ shims: true,
33
+ sourcemap: false,
34
+ keepNames: true,
35
+ outDir: '.commandkit',
36
+ silent: true,
37
+ entry: [src, '!dist', '!.commandkit'],
38
+ watch: nodeOptions.includes('--watch'),
39
+ });
40
+
41
+ status.succeed(Colors.green(`Server started in ${(performance.now() - start).toFixed(2)}ms!\n`));
42
+
43
+ const processEnv = {};
44
+
45
+ const env = dotenv({
46
+ path: join(process.cwd(), '.env'),
47
+ // @ts-expect-error
48
+ processEnv
49
+ });
50
+
51
+ if (env.error) {
52
+ write(Colors.yellow(`[DOTENV] Warning: ${env.error.message}`));
53
+ }
54
+
55
+ if (env.parsed) {
56
+ write(Colors.blue('[DOTENV] Loaded .env file!'));
57
+ }
58
+
59
+ const ps = child_process.spawn('node', [...nodeOptions, join(process.cwd(), '.commandkit', main)], {
60
+ env: {
61
+ ...process.env,
62
+ ...processEnv,
63
+ NODE_ENV: 'development',
64
+ COMMANDKIT_DEV: 'true'
65
+ },
66
+ cwd: process.cwd(),
67
+ });
68
+
69
+ ps.stdout.on('data', (data) => {
70
+ write(data.toString());
71
+ });
72
+
73
+ ps.stderr.on('data', (data) => {
74
+ write(Colors.red(data.toString()));
75
+ });
76
+
77
+ ps.on('close', (code) => {
78
+ write('\n');
79
+ process.exit(code ?? 0);
80
+ });
81
+
82
+ ps.on('error', (err) => {
83
+ panic(err);
84
+ });
85
+ } catch (e) {
86
+ status.fail(`Error occurred after ${(performance.now() - start).toFixed(2)}ms!\n`)
87
+ panic(e);
88
+ }
89
+ }
package/bin/index.mjs ADDED
@@ -0,0 +1,27 @@
1
+ #!/usr/bin/env node
2
+
3
+ // @ts-check
4
+
5
+ import { Command } from 'commander';
6
+ import { bootstrapDevelopmentServer } from './dev-server.mjs';
7
+ import { bootstrapProductionBuild } from './build.mjs';
8
+
9
+ const program = new Command('commandkit');
10
+
11
+ program.command('dev')
12
+ .description('Start your bot in development mode.')
13
+ .option('-c, --config <path>', 'Path to your commandkit.json file.', './commandkit.json')
14
+ .action(() => {
15
+ const options = program.opts();
16
+ bootstrapDevelopmentServer(options.config)
17
+ });
18
+
19
+ program.command('build')
20
+ .description('Build your project for production usage.')
21
+ .option('-c, --config <path>', 'Path to your commandkit.json file.', './commandkit.json')
22
+ .action(() => {
23
+ const options = program.opts();
24
+ bootstrapProductionBuild(options.config)
25
+ });
26
+
27
+ program.parse();
package/package.json CHANGED
@@ -1,11 +1,12 @@
1
1
  {
2
2
  "name": "commandkit",
3
3
  "description": "Beginner friendly command & event handler for Discord.js",
4
- "version": "0.1.6-dev.20231026074421",
4
+ "version": "0.1.6-dev.20231112142249",
5
5
  "license": "MIT",
6
6
  "main": "./dist/index.js",
7
7
  "module": "./dist/index.mjs",
8
8
  "types": "./dist/index.d.ts",
9
+ "bin": "./bin/index.mjs",
9
10
  "exports": {
10
11
  ".": {
11
12
  "require": "./dist/index.js",
@@ -13,6 +14,10 @@
13
14
  "types": "./dist/index.d.ts"
14
15
  }
15
16
  },
17
+ "files": [
18
+ "dist",
19
+ "bin"
20
+ ],
16
21
  "scripts": {
17
22
  "lint": "tsc",
18
23
  "dev": "tsup --watch",
@@ -32,14 +37,17 @@
32
37
  "event handler"
33
38
  ],
34
39
  "dependencies": {
35
- "rfdc": "^1.3.0"
40
+ "commander": "^11.1.0",
41
+ "ora": "^7.0.1",
42
+ "rfdc": "^1.3.0",
43
+ "rimraf": "^5.0.5",
44
+ "tsup": "^7.2.0"
36
45
  },
37
46
  "devDependencies": {
38
47
  "@types/node": "^20.5.9",
39
48
  "discord.js": "^14.13.0",
40
49
  "dotenv": "^16.3.1",
41
50
  "tsconfig": "workspace:*",
42
- "tsup": "^7.2.0",
43
51
  "tsx": "^3.12.8",
44
52
  "typescript": "^5.1.6"
45
53
  },