@dinoxx/dinox-cli 1.0.8 → 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/cli.js CHANGED
@@ -6,6 +6,7 @@ import { registerInfoCommand } from './commands/info/index.js';
6
6
  import { registerNoteCommands } from './commands/notes/index.js';
7
7
  import { registerPromptCommands } from './commands/prompt/index.js';
8
8
  import { registerSyncCommand } from './commands/sync.js';
9
+ import { registerUpdateCommand } from './commands/update.js';
9
10
  import { registerTagsCommand } from './commands/tags/index.js';
10
11
  import { getPackageVersion } from './utils/version.js';
11
12
  export function createCli() {
@@ -25,6 +26,7 @@ export function createCli() {
25
26
  registerConfigCommands(program);
26
27
  registerInfoCommand(program);
27
28
  registerSyncCommand(program);
29
+ registerUpdateCommand(program);
28
30
  registerPromptCommands(program);
29
31
  registerTagsCommand(program);
30
32
  registerNoteCommands(program);
@@ -0,0 +1,2 @@
1
+ import { Command } from 'commander';
2
+ export declare function registerUpdateCommand(program: Command): void;
@@ -0,0 +1,47 @@
1
+ import { spawn } from 'node:child_process';
2
+ import { getPackageVersion } from '../utils/version.js';
3
+ const PACKAGE_NAME = '@dinoxx/dinox-cli';
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];
23
+ return new Promise((resolve, reject) => {
24
+ const child = spawn(bin, args, { stdio: 'inherit' });
25
+ child.on('close', (code) => {
26
+ if (code === 0) {
27
+ resolve();
28
+ }
29
+ else {
30
+ reject(new Error(`${bin} exited with code ${code}`));
31
+ }
32
+ });
33
+ child.on('error', reject);
34
+ });
35
+ }
36
+ export function registerUpdateCommand(program) {
37
+ program
38
+ .command('update')
39
+ .description(`Update ${PACKAGE_NAME} to the latest version`)
40
+ .action(async () => {
41
+ const pm = detectPackageManager();
42
+ console.log(`current version: ${getPackageVersion()}`);
43
+ console.log(`updating ${PACKAGE_NAME} via ${pm}...`);
44
+ await runUpdate(pm);
45
+ console.log('done');
46
+ });
47
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dinoxx/dinox-cli",
3
- "version": "1.0.8",
3
+ "version": "1.0.10",
4
4
  "description": "Dinox CLI",
5
5
  "main": "dist/dinox.js",
6
6
  "scripts": {