(
targetPath: string,
options: UpdateOptions = {},
)
| 227 | } |
| 228 | |
| 229 | export async function updateCommand( |
| 230 | targetPath: string, |
| 231 | options: UpdateOptions = {}, |
| 232 | ): Promise<void> { |
| 233 | const projectPath = path.resolve(targetPath); |
| 234 | const log = options.json ? () => undefined : console.log; |
| 235 | |
| 236 | const lang = options.language ?? 'en'; |
| 237 | |
| 238 | log(`\n ${t(lang, 'updateTitle')}`); |
| 239 | if (!options.json) { |
| 240 | await printVersionInfo(log); |
| 241 | } |
| 242 | log(''); |
| 243 | |
| 244 | const packageScope = options.scope ?? (await detectCometPackageScope(projectPath)); |
| 245 | let npmStatus: 'updated' | 'failed' | 'skipped' = 'skipped'; |
| 246 | if (!options.skipNpm) { |
| 247 | log(` ${t(lang, 'updatingNpmPackage')} (${packageScope} scope)...`); |
| 248 | log(` $ ${formatNpmUpdateCommand(packageScope)}`); |
| 249 | const npmUpdated = await updateCometNpmPackage( |
| 250 | packageScope, |
| 251 | projectPath, |
| 252 | log, |
| 253 | options.json === true, |
| 254 | ); |
| 255 | if (npmUpdated) { |
| 256 | npmStatus = 'updated'; |
| 257 | log(` ${t(lang, 'npmPackageUpdated')} ${PACKAGE_NAME}`); |
| 258 | } else { |
| 259 | npmStatus = 'failed'; |
| 260 | log(` ${t(lang, 'npmPackageFailed')}`); |
| 261 | } |
| 262 | } |
| 263 | |
| 264 | const targets = await detectInstalledCometTargets(projectPath, { |
| 265 | scopes: options.scope ? [options.scope] : undefined, |
| 266 | }); |
| 267 | |
| 268 | if (targets.length === 0) { |
| 269 | if (options.json) { |
| 270 | console.log( |
| 271 | JSON.stringify( |
| 272 | { |
| 273 | npm: { |
| 274 | scope: options.skipNpm ? 'skipped' : packageScope, |
| 275 | status: npmStatus, |
| 276 | command: options.skipNpm ? null : formatNpmUpdateCommand(packageScope), |
| 277 | }, |
| 278 | skills: { totalCopied: 0, targets: [] }, |
| 279 | rules: { totalCopied: 0 }, |
| 280 | hooks: { totalInstalled: 0 }, |
| 281 | codegraph: 'skipped', |
| 282 | }, |
| 283 | null, |
| 284 | 2, |
| 285 | ), |
| 286 | ); |
no test coverage detected