@dinoxx/dinox-cli 1.0.9 → 1.0.10
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/commands/update.js +24 -6
- package/package.json +1 -1
package/dist/commands/update.js
CHANGED
|
@@ -1,16 +1,33 @@
|
|
|
1
1
|
import { spawn } from 'node:child_process';
|
|
2
2
|
import { getPackageVersion } from '../utils/version.js';
|
|
3
3
|
const PACKAGE_NAME = '@dinoxx/dinox-cli';
|
|
4
|
-
function
|
|
4
|
+
function detectPackageManager() {
|
|
5
|
+
const scriptPath = process.argv[1] ?? '';
|
|
6
|
+
if (scriptPath.includes('/.bun/'))
|
|
7
|
+
return 'bun';
|
|
8
|
+
if (scriptPath.includes('/pnpm/'))
|
|
9
|
+
return 'pnpm';
|
|
10
|
+
if (scriptPath.includes('/.yarn/') || scriptPath.includes('/yarn/global'))
|
|
11
|
+
return 'yarn';
|
|
12
|
+
return 'npm';
|
|
13
|
+
}
|
|
14
|
+
const WIN = process.platform === 'win32';
|
|
15
|
+
const PM_COMMANDS = {
|
|
16
|
+
npm: { bin: WIN ? 'npm.cmd' : 'npm', args: ['update', '-g', PACKAGE_NAME] },
|
|
17
|
+
pnpm: { bin: WIN ? 'pnpm.cmd' : 'pnpm', args: ['update', '--global', PACKAGE_NAME] },
|
|
18
|
+
yarn: { bin: WIN ? 'yarn.cmd' : 'yarn', args: ['global', 'upgrade', PACKAGE_NAME] },
|
|
19
|
+
bun: { bin: 'bun', args: ['add', '--global', PACKAGE_NAME] },
|
|
20
|
+
};
|
|
21
|
+
function runUpdate(pm) {
|
|
22
|
+
const { bin, args } = PM_COMMANDS[pm];
|
|
5
23
|
return new Promise((resolve, reject) => {
|
|
6
|
-
const
|
|
7
|
-
const child = spawn(npm, ['update', '-g', PACKAGE_NAME], { stdio: 'inherit' });
|
|
24
|
+
const child = spawn(bin, args, { stdio: 'inherit' });
|
|
8
25
|
child.on('close', (code) => {
|
|
9
26
|
if (code === 0) {
|
|
10
27
|
resolve();
|
|
11
28
|
}
|
|
12
29
|
else {
|
|
13
|
-
reject(new Error(
|
|
30
|
+
reject(new Error(`${bin} exited with code ${code}`));
|
|
14
31
|
}
|
|
15
32
|
});
|
|
16
33
|
child.on('error', reject);
|
|
@@ -21,9 +38,10 @@ export function registerUpdateCommand(program) {
|
|
|
21
38
|
.command('update')
|
|
22
39
|
.description(`Update ${PACKAGE_NAME} to the latest version`)
|
|
23
40
|
.action(async () => {
|
|
41
|
+
const pm = detectPackageManager();
|
|
24
42
|
console.log(`current version: ${getPackageVersion()}`);
|
|
25
|
-
console.log(`updating ${PACKAGE_NAME}...`);
|
|
26
|
-
await
|
|
43
|
+
console.log(`updating ${PACKAGE_NAME} via ${pm}...`);
|
|
44
|
+
await runUpdate(pm);
|
|
27
45
|
console.log('done');
|
|
28
46
|
});
|
|
29
47
|
}
|