create-commandkit 1.1.4-dev.20250615021934 → 1.1.4-dev.20250615131542
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/functions/copyTemplates.d.ts +5 -0
- package/dist/functions/copyTemplates.js +49 -0
- package/dist/functions/installDeps.d.ts +10 -0
- package/dist/functions/installDeps.js +35 -0
- package/dist/functions/setup.d.ts +10 -0
- package/dist/functions/setup.js +23 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +83 -42
- package/dist/types.d.ts +2 -0
- package/dist/types.js +1 -0
- package/dist/utils.d.ts +13 -0
- package/dist/utils.js +13 -0
- package/package.json +4 -5
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import fs from 'fs-extra';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
import url from 'node:url';
|
|
4
|
+
const __dirname = path.dirname(url.fileURLToPath(import.meta.url));
|
|
5
|
+
const templates = {
|
|
6
|
+
js: path.join(__dirname, '..', 'templates', 'JavaScript'),
|
|
7
|
+
ts: path.join(__dirname, '..', 'templates', 'TypeScript'),
|
|
8
|
+
};
|
|
9
|
+
const gitignore = `
|
|
10
|
+
# dependencies
|
|
11
|
+
node_modules
|
|
12
|
+
|
|
13
|
+
# build output
|
|
14
|
+
build
|
|
15
|
+
out
|
|
16
|
+
dist
|
|
17
|
+
|
|
18
|
+
# commandkit
|
|
19
|
+
.commandkit
|
|
20
|
+
dist
|
|
21
|
+
compiled-commandkit.config.mjs
|
|
22
|
+
|
|
23
|
+
# env
|
|
24
|
+
**/*.env*
|
|
25
|
+
!**/*.env.example*
|
|
26
|
+
|
|
27
|
+
# logging
|
|
28
|
+
logs
|
|
29
|
+
*.log
|
|
30
|
+
npm-debug.log*
|
|
31
|
+
yarn-debug.log*
|
|
32
|
+
yarn-error.log*
|
|
33
|
+
lerna-debug.log*
|
|
34
|
+
.pnpm-debug.log*
|
|
35
|
+
|
|
36
|
+
# yarn v2+
|
|
37
|
+
.yarn/cache
|
|
38
|
+
.yarn/unplugged
|
|
39
|
+
.yarn/build-state.yml
|
|
40
|
+
.yarn/install-state.gz
|
|
41
|
+
.pnp.*
|
|
42
|
+
|
|
43
|
+
# other
|
|
44
|
+
**/*.DS_Store
|
|
45
|
+
`;
|
|
46
|
+
export async function copyTemplates({ dir, lang, }) {
|
|
47
|
+
await fs.copy(templates[lang], dir);
|
|
48
|
+
await fs.writeFile(path.join(dir, '.gitignore'), gitignore);
|
|
49
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { type IOType } from 'node:child_process';
|
|
2
|
+
import type { Language, PackageManager } from '../types';
|
|
3
|
+
interface InstallDepsProps {
|
|
4
|
+
manager: PackageManager;
|
|
5
|
+
dir: string;
|
|
6
|
+
lang: Language;
|
|
7
|
+
stdio: IOType;
|
|
8
|
+
}
|
|
9
|
+
export declare function installDeps({ manager, dir, lang, stdio, }: InstallDepsProps): void;
|
|
10
|
+
export {};
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { execSync } from 'node:child_process';
|
|
2
|
+
import ora from 'ora';
|
|
3
|
+
const baseDependencies = [
|
|
4
|
+
// TODO: use latest tag for CommandKit v1
|
|
5
|
+
'commandkit@dev',
|
|
6
|
+
'discord.js',
|
|
7
|
+
];
|
|
8
|
+
const dependencies = {
|
|
9
|
+
js: {
|
|
10
|
+
dependencies: baseDependencies,
|
|
11
|
+
devDependencies: ['@types/node'],
|
|
12
|
+
},
|
|
13
|
+
ts: {
|
|
14
|
+
dependencies: baseDependencies,
|
|
15
|
+
devDependencies: ['@types/node', 'typescript'],
|
|
16
|
+
},
|
|
17
|
+
};
|
|
18
|
+
export function installDeps({ manager, dir, lang, stdio = 'inherit', }) {
|
|
19
|
+
const spinner = ora('Installing dependencies...').start();
|
|
20
|
+
try {
|
|
21
|
+
if (dependencies[lang].dependencies.length) {
|
|
22
|
+
const depsCommand = `${manager} add ${dependencies[lang].dependencies.join(' ')}`;
|
|
23
|
+
execSync(depsCommand, { cwd: dir, stdio });
|
|
24
|
+
}
|
|
25
|
+
if (dependencies[lang].devDependencies.length) {
|
|
26
|
+
const devDepsCommand = `${manager} add -D ${dependencies[lang].devDependencies.join(' ')}`;
|
|
27
|
+
execSync(devDepsCommand, { cwd: dir, stdio });
|
|
28
|
+
}
|
|
29
|
+
spinner.succeed('Dependencies installed successfully!');
|
|
30
|
+
}
|
|
31
|
+
catch (error) {
|
|
32
|
+
spinner.fail('Failed to install dependencies');
|
|
33
|
+
throw error;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { type IOType } from 'child_process';
|
|
2
|
+
import type { PackageManager } from '../types';
|
|
3
|
+
interface SetupProps {
|
|
4
|
+
manager: PackageManager;
|
|
5
|
+
token: string;
|
|
6
|
+
dir: string;
|
|
7
|
+
stdio?: IOType;
|
|
8
|
+
}
|
|
9
|
+
export declare function setup({ manager, token, dir, stdio, }: SetupProps): Promise<void>;
|
|
10
|
+
export {};
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { execSync } from 'child_process';
|
|
2
|
+
import fs from 'fs-extra';
|
|
3
|
+
import path from 'node:path';
|
|
4
|
+
import { commands } from '../utils';
|
|
5
|
+
export async function setup({ manager, token, dir, stdio = 'pipe', }) {
|
|
6
|
+
await fs.emptyDir(dir);
|
|
7
|
+
execSync(commands.init[manager], { cwd: dir, stdio });
|
|
8
|
+
const packageJsonPath = path.join(dir, 'package.json');
|
|
9
|
+
const packageJson = await fs.readJSON(packageJsonPath);
|
|
10
|
+
delete packageJson.main;
|
|
11
|
+
packageJson.name = packageJson.name.toLowerCase();
|
|
12
|
+
packageJson.type = 'module';
|
|
13
|
+
packageJson.version = '0.1.0';
|
|
14
|
+
packageJson.private = true;
|
|
15
|
+
packageJson.description = 'A CommandKit project';
|
|
16
|
+
packageJson.scripts = {
|
|
17
|
+
dev: 'commandkit dev',
|
|
18
|
+
build: 'commandkit build',
|
|
19
|
+
start: 'commandkit start',
|
|
20
|
+
};
|
|
21
|
+
await fs.writeJSON(packageJsonPath, packageJson, { spaces: 2 });
|
|
22
|
+
await fs.writeFile(`${dir}/.env`, `DISCORD_TOKEN="${token}"`);
|
|
23
|
+
}
|
package/dist/index.d.ts
ADDED
package/dist/index.js
CHANGED
|
@@ -1,50 +1,91 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
2
|
+
console.clear();
|
|
3
|
+
import { confirm, intro, outro, password, select, text } from '@clack/prompts';
|
|
4
|
+
import fs from 'fs-extra';
|
|
5
|
+
import gradient from 'gradient-string';
|
|
6
|
+
import { execSync } from 'node:child_process';
|
|
7
|
+
import path from 'node:path';
|
|
8
|
+
import colors from 'picocolors';
|
|
9
|
+
import { copyTemplates } from './functions/copyTemplates';
|
|
10
|
+
import { installDeps } from './functions/installDeps';
|
|
11
|
+
import { setup } from './functions/setup';
|
|
12
|
+
import { textColors } from './utils';
|
|
13
|
+
const commandkitGradient = gradient(textColors.commandkit)('CommandKit');
|
|
14
|
+
intro(`Welcome to ${commandkitGradient}!`);
|
|
15
|
+
const dir = path.resolve(process.cwd(), (await text({
|
|
16
|
+
message: 'Enter a project directory:',
|
|
17
|
+
placeholder: 'Leave blank for current directory',
|
|
18
|
+
defaultValue: '.',
|
|
19
|
+
validate: (value) => {
|
|
20
|
+
value = path.resolve(process.cwd(), value);
|
|
21
|
+
let isEmpty;
|
|
22
|
+
try {
|
|
23
|
+
const contents = fs.readdirSync(value);
|
|
24
|
+
isEmpty = contents.length === 0;
|
|
25
|
+
}
|
|
26
|
+
catch {
|
|
27
|
+
isEmpty = true;
|
|
28
|
+
}
|
|
29
|
+
return isEmpty ? undefined : 'Directory is not empty!';
|
|
30
|
+
},
|
|
31
|
+
})));
|
|
32
|
+
const manager = (await select({
|
|
33
|
+
message: 'Select a package manager:',
|
|
34
|
+
initialValue: 'npm',
|
|
35
|
+
options: [
|
|
36
|
+
{ label: 'npm', value: 'npm' },
|
|
37
|
+
{ label: 'pnpm', value: 'pnpm' },
|
|
38
|
+
{ label: 'yarn', value: 'yarn' },
|
|
39
|
+
{ label: 'bun', value: 'bun' },
|
|
40
|
+
],
|
|
41
|
+
}));
|
|
42
|
+
const lang = (await select({
|
|
43
|
+
message: 'Select the language to use:',
|
|
44
|
+
initialValue: 'ts',
|
|
45
|
+
options: [
|
|
46
|
+
{ label: 'TypeScript', value: 'ts' },
|
|
47
|
+
{ label: 'JavaScript', value: 'js' },
|
|
48
|
+
],
|
|
49
|
+
}));
|
|
50
|
+
const token = (await password({
|
|
51
|
+
message: 'Enter your Discord bot token (stored in .env, optional):',
|
|
52
|
+
mask: colors.gray('*'),
|
|
53
|
+
}));
|
|
54
|
+
const gitInit = await confirm({
|
|
55
|
+
message: 'Initialize a git repository?',
|
|
56
|
+
initialValue: true,
|
|
57
|
+
});
|
|
58
|
+
outro(colors.cyan('Setup complete.'));
|
|
59
|
+
await setup({
|
|
60
|
+
manager,
|
|
61
|
+
dir,
|
|
62
|
+
token,
|
|
63
|
+
});
|
|
64
|
+
await copyTemplates({ dir, lang });
|
|
65
|
+
if (gitInit) {
|
|
66
|
+
try {
|
|
67
|
+
execSync('git init', { cwd: dir, stdio: 'pipe' });
|
|
68
|
+
}
|
|
69
|
+
catch (error) {
|
|
70
|
+
console.log(colors.yellow('Warning: Git initialization failed. Make sure Git is installed on your system.'));
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
installDeps({
|
|
74
|
+
dir,
|
|
75
|
+
manager,
|
|
76
|
+
lang,
|
|
77
|
+
stdio: 'pipe',
|
|
78
|
+
});
|
|
79
|
+
console.log(`${gradient(textColors.commandkit)('Thank you for choosing CommandKit!')}
|
|
39
80
|
|
|
40
81
|
To start your bot, use the following commands:
|
|
41
82
|
${colors.magenta(`${manager} run dev`)} - Run your bot in development mode
|
|
42
83
|
${colors.magenta(`${manager} run build`)} - Build your bot for production
|
|
43
84
|
${colors.magenta(`${manager} run start`)} - Run your bot in production mode
|
|
44
85
|
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
86
|
+
• Documentation: ${colors.blue('https://commandkit.dev')}
|
|
87
|
+
• GitHub: ${colors.blue('https://github.com/underctrl-io/commandkit')}
|
|
88
|
+
• Under Ctrl: ${colors.blue('https://underctrl.io')}
|
|
89
|
+
• Discord community: ${colors.blue('https://ctrl.lol/discord')}
|
|
49
90
|
|
|
50
|
-
Happy coding!
|
|
91
|
+
Happy coding! 🚀`);
|
package/dist/types.d.ts
ADDED
package/dist/types.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/dist/utils.d.ts
ADDED
package/dist/utils.js
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export const textColors = {
|
|
2
|
+
commandkit: ['#fdba74', '#e4a5a2', '#c288de', '#b27bf9'],
|
|
3
|
+
js: ['#f7e01c', '#f7e01c'],
|
|
4
|
+
ts: ['#2480c5', '#2480c5'],
|
|
5
|
+
};
|
|
6
|
+
export const commands = {
|
|
7
|
+
init: {
|
|
8
|
+
npm: 'npm init -y',
|
|
9
|
+
yarn: 'yarn init -y; yarn set version stable; yarn config set nodeLinker node-modules;',
|
|
10
|
+
pnpm: 'pnpm init',
|
|
11
|
+
bun: 'bun init -y -m',
|
|
12
|
+
},
|
|
13
|
+
};
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "create-commandkit",
|
|
3
3
|
"description": "Effortlessly create a CommandKit project",
|
|
4
|
-
"version": "1.1.4-dev.
|
|
4
|
+
"version": "1.1.4-dev.20250615131542",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"module": "./dist/index.js",
|
|
7
7
|
"bin": "./dist/index.js",
|
|
@@ -38,14 +38,13 @@
|
|
|
38
38
|
"@types/fs-extra": "^11.0.4",
|
|
39
39
|
"@types/gradient-string": "^1.1.5",
|
|
40
40
|
"@types/node": "^22.0.0",
|
|
41
|
-
"tsup": "^8.0.1",
|
|
42
41
|
"typescript": "^5.3.3",
|
|
43
|
-
"tsconfig": "0.0.0-dev.
|
|
42
|
+
"tsconfig": "0.0.0-dev.20250615131542"
|
|
44
43
|
},
|
|
45
44
|
"scripts": {
|
|
46
45
|
"lint": "tsc --noEmit",
|
|
47
|
-
"dev": "
|
|
48
|
-
"build": "
|
|
46
|
+
"dev": "tsc --watch",
|
|
47
|
+
"build": "tsc",
|
|
49
48
|
"publish-package": "npm publish"
|
|
50
49
|
}
|
|
51
50
|
}
|