|
| 1 | +import { execFileSync } from 'node:child_process'; |
1 | 2 | import { readFile } from 'node:fs/promises'; |
2 | 3 | import { dirname, join } from 'node:path'; |
3 | 4 | import { fileURLToPath } from 'node:url'; |
@@ -38,9 +39,38 @@ export async function updateCommand(options: UpdateOptions): Promise<void> { |
38 | 39 |
|
39 | 40 | if (currentVersion !== latestVersion) { |
40 | 41 | console.log(); |
41 | | - logger.warn(`Installed CLI package is ${chalk.cyan(currentVersion)}, but latest release is ${chalk.cyan(release.tag_name)}.`); |
42 | | - logger.info(`Update the CLI package first: ${chalk.cyan(`npm install -g uipro-cli@${latestVersion}`)}`); |
43 | | - logger.info('Then rerun: uipro init --ai <platform>'); |
| 42 | + |
| 43 | + // Only auto-run with a well-formed semver, so nothing unexpected can |
| 44 | + // reach the shell that npm.cmd requires on Windows. |
| 45 | + if (!/^\d+\.\d+\.\d+([.-][0-9A-Za-z.-]+)?$/.test(latestVersion)) { |
| 46 | + logger.warn(`Installed CLI is ${chalk.cyan(currentVersion)}; latest release is ${chalk.cyan(release.tag_name)}.`); |
| 47 | + logger.info(`Update the CLI package: ${chalk.cyan(`npm install -g uipro-cli@${latestVersion}`)}`); |
| 48 | + logger.info('Then rerun: uipro init --ai <platform> --force'); |
| 49 | + return; |
| 50 | + } |
| 51 | + |
| 52 | + logger.info(`Updating CLI from ${chalk.cyan(currentVersion)} to ${chalk.cyan(latestVersion)}...`); |
| 53 | + console.log(); |
| 54 | + |
| 55 | + const isWindows = process.platform === 'win32'; |
| 56 | + try { |
| 57 | + // execFileSync with an explicit args array — no shell string to expand. |
| 58 | + // On Windows npm is npm.cmd, which Node only spawns via a shell. |
| 59 | + execFileSync( |
| 60 | + isWindows ? 'npm.cmd' : 'npm', |
| 61 | + ['install', '-g', `uipro-cli@${latestVersion}`], |
| 62 | + { stdio: 'inherit', shell: isWindows } |
| 63 | + ); |
| 64 | + } catch { |
| 65 | + console.log(); |
| 66 | + logger.error('Automatic update failed (you may need elevated/admin permissions).'); |
| 67 | + logger.info(`Update manually: ${chalk.cyan(`npm install -g uipro-cli@${latestVersion}`)}`); |
| 68 | + process.exit(1); |
| 69 | + } |
| 70 | + |
| 71 | + console.log(); |
| 72 | + logger.success(`Updated to ${chalk.cyan(latestVersion)}.`); |
| 73 | + logger.info(`Now rerun ${chalk.cyan('uipro init --ai <platform> --force')} to refresh your skill files.`); |
44 | 74 | return; |
45 | 75 | } |
46 | 76 |
|
|
0 commit comments