Skip to content

Commit 0157307

Browse files
committed
feat: improvements
1 parent 00c839a commit 0157307

File tree

6 files changed

+78
-25
lines changed

6 files changed

+78
-25
lines changed

packages/create-commandkit/package.json

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,16 +35,16 @@
3535
},
3636
"dependencies": {
3737
"@clack/prompts": "^0.7.0",
38-
"colors": "^1.4.0",
3938
"fs-extra": "^11.1.1",
40-
"gradient-string": "^2.0.2"
39+
"gradient-string": "^2.0.2",
40+
"picocolors": "^1.1.1"
4141
},
4242
"devDependencies": {
43-
"@types/node": "^20.11.6",
44-
"@types/gradient-string": "^1.1.5",
4543
"@types/fs-extra": "^11.0.4",
46-
"typescript": "^5.3.3",
44+
"@types/gradient-string": "^1.1.5",
45+
"@types/node": "^20.11.6",
4746
"tsconfig": "workspace:*",
48-
"tsup": "^8.0.1"
47+
"tsup": "^8.0.1",
48+
"typescript": "^5.3.3"
4949
}
5050
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import { execSync } from 'node:child_process';
2+
3+
export async function initializeGit(dir: string) {
4+
try {
5+
execSync('git init', { cwd: dir, stdio: 'pipe' });
6+
} catch {}
7+
}

packages/create-commandkit/src/index.ts

Lines changed: 44 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
11
#!/usr/bin/env node
22
console.clear();
33

4-
import type { Language, ModuleType, PackageManager } from './types';
4+
import type {
5+
HandlerType,
6+
Language,
7+
ModuleType,
8+
PackageManager,
9+
} from './types';
510

611
import { intro, text, select, password, confirm, outro } from '@clack/prompts';
712
import { commandkit, hints, outroMsg } from './utils';
@@ -10,8 +15,9 @@ import { installDeps } from './functions/installDeps';
1015
import { copyTemplates } from './functions/copyTemplates';
1116

1217
import path from 'node:path';
13-
import colors from 'colors';
18+
import colors from 'picocolors';
1419
import fs from 'fs-extra';
20+
import { initializeGit } from './functions/initializeGit';
1521

1622
await intro(`Welcome to ${commandkit}!`);
1723

@@ -39,23 +45,43 @@ const dir = path.resolve(
3945

4046
const manager = (await select({
4147
message: 'Select a package manager:',
48+
initialValue: 'npm' as PackageManager,
4249
options: [
4350
{ label: 'npm', value: 'npm' },
4451
{ label: 'pnpm', value: 'pnpm' },
4552
{ label: 'yarn', value: 'yarn' },
53+
{ label: 'bun', value: 'bun' },
4654
],
4755
})) as PackageManager;
4856

4957
const lang = (await select({
5058
message: 'Select the language to use:',
59+
initialValue: 'ts' as Language,
5160
options: [
5261
{ label: 'JavaScript', value: 'js' },
5362
{ label: 'TypeScript', value: 'ts' },
5463
],
5564
})) as Language;
5665

66+
const handler = (await select({
67+
message: 'Select a command handler:',
68+
initialValue: 'app' as HandlerType,
69+
options: [
70+
{
71+
label: 'App',
72+
value: 'app',
73+
hint: 'recommended',
74+
},
75+
{
76+
label: 'Legacy',
77+
value: 'legacy',
78+
},
79+
],
80+
})) as HandlerType;
81+
5782
const type = (await select({
5883
message: 'Select a module type:',
84+
initialValue: 'esm' as ModuleType,
5985
options: [
6086
{
6187
label: 'CommonJS',
@@ -71,7 +97,7 @@ const type = (await select({
7197
})) as ModuleType;
7298

7399
const token = (await password({
74-
message: 'Enter your bot token:',
100+
message: 'Enter your bot token (stored in .env):',
75101
mask: colors.gray('*'),
76102
})) as string;
77103

@@ -80,13 +106,26 @@ const installNow = await confirm({
80106
initialValue: true,
81107
});
82108

109+
const gitInit = await confirm({
110+
message: 'Initialize a git repository?',
111+
initialValue: true,
112+
});
113+
83114
outro(colors.cyan('Setup complete.'));
84115

85116
await setup({ manager, dir, token, type });
86-
await copyTemplates({ type, dir, lang });
117+
await copyTemplates({ type, dir, lang, handler });
118+
119+
if (gitInit) {
120+
await initializeGit(dir);
121+
}
87122

88123
if (installNow) {
89124
await installDeps({ manager, dir, lang: 'js', stdio: 'inherit' });
90125
}
91126

92-
console.log(outroMsg);
127+
console.log(
128+
outroMsg({
129+
manager,
130+
}),
131+
);
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
export type Language = 'js' | 'ts';
2-
export type PackageManager = 'npm' | 'pnpm' | 'yarn';
2+
export type PackageManager = 'npm' | 'pnpm' | 'yarn' | 'bun';
33
export type ModuleType = 'esm' | 'cjs';
44
export type HandlerType = 'app' | 'legacy';

packages/create-commandkit/src/utils.ts

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
import colors from 'colors';
1+
import colors from 'picocolors';
22
import gradient from 'gradient-string';
33
import path from 'node:path';
44
import url from 'node:url';
5+
import { PackageManager } from './types';
56

67
const __dirname = path.dirname(url.fileURLToPath(import.meta.url));
78

@@ -85,6 +86,7 @@ export const commands = {
8586
npm: 'npm init -y',
8687
yarn: 'yarn init -y; yarn config set nodeLinker node-modules; yarn set version stable',
8788
pnpm: 'pnpm init',
89+
bun: 'bun init -y',
8890
},
8991
};
9092

@@ -95,15 +97,26 @@ export const hints = {
9597
module: gradient(textColors.module)('exports'),
9698
javascript: gradient(textColors.js)('JavaScript'),
9799
typescript: gradient(textColors.ts)('TypeScript'),
98-
app: gradient(textColors.app)('app'),
99-
legacy: gradient(textColors.legacy)('legacy'),
100100
};
101101

102102
export const commandkit = gradient(textColors.commandkit)('CommandKit');
103-
export const outroMsg = `
103+
104+
interface OutroMessageProps {
105+
manager: PackageManager;
106+
}
107+
108+
export const outroMsg = ({ manager }: OutroMessageProps) => `
104109
${gradient(textColors.commandkit)('Thank you for choosing CommandKit!')}
105110
111+
To start your bot, use the following commands:
112+
${colors.magenta(`${manager} run dev`)} - Run your bot in development mode
113+
${colors.magenta(`${manager} run build`)} - Build your bot for production
114+
${colors.magenta(`${manager} run start`)} - Run your bot in production mode
115+
106116
• Documentation: ${colors.blue('https://commandkit.dev')}
107117
• GitHub: ${colors.blue('https://github.com/underctrl-io/commandkit')}
118+
• UnderCtrl: ${colors.blue('https://underctrl.io')}
108119
• Join us on Discord: ${colors.blue('https://ctrl.lol/discord')}
120+
121+
Happy coding! 🚀
109122
`;

pnpm-lock.yaml

Lines changed: 3 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)