Skip to content

Commit 57bd27a

Browse files
committed
feat: dynamic version selection
1 parent 7cf12da commit 57bd27a

File tree

1 file changed

+22
-2
lines changed

1 file changed

+22
-2
lines changed

packages/create-commandkit/src/index.ts

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { confirm, intro, outro, password, text } from '@clack/prompts';
55
import fs from 'fs-extra';
66
import gradient from 'gradient-string';
77
import { execSync } from 'node:child_process';
8-
import path from 'node:path';
8+
import path, { join } from 'node:path';
99
import colors from 'picocolors';
1010

1111
import { parseCLI } from './cli.js';
@@ -22,6 +22,7 @@ import {
2222
resolvePackageManager,
2323
textColors,
2424
} from './utils.js';
25+
import { readFile } from 'node:fs/promises';
2526

2627
async function main() {
2728
const cliOptions = parseCLI();
@@ -181,9 +182,28 @@ Examples:
181182
);
182183

183184
try {
185+
const tagMap = [
186+
['-dev.', 'dev'],
187+
['-rc.', 'next'],
188+
];
189+
190+
const tag = await readFile(
191+
join(import.meta.dirname, '..', 'package.json'),
192+
'utf-8',
193+
)
194+
.then((data) => {
195+
const version = JSON.parse(data).version;
196+
197+
return (
198+
tagMap.find(([suffix]) => version.includes(suffix))?.[1] ||
199+
'latest'
200+
);
201+
})
202+
.catch(() => 'latest');
203+
184204
// Install dependencies
185205
const depsCommand = getInstallCommand(manager, [
186-
'commandkit@rc',
206+
`commandkit@${tag}`,
187207
'discord.js',
188208
]);
189209
execSync(depsCommand, { cwd: projectDir, stdio: 'pipe' });

0 commit comments

Comments
 (0)