import { InstallationManager } from '../core/desktop/install-manager.mjs'; const args = process.argv.slice(2), command = args.shift(), options = {}; if (!['preflight', 'activate', 'uninstall', 'cancel'].includes(command)) throw new Error('Unsupported installation operation.'); while (args.length) { const flag = args.shift(); if (flag === '--stage-only' && !options.stageOnly) { options.stageOnly = true; continue; } if (!['--install-root', '--data-root', '--candidate-root', '--port', '--operation-id', '--expected-manifest-sha256'].includes(flag) || !args.length || options[flag] !== undefined) throw new Error('Unsupported or repeated installation field.'); options[flag] = args.shift(); } try { const manager = new InstallationManager({ installRoot: options['--install-root'], dataRoot: options['--data-root'], candidateRoot: options['--candidate-root'], port: Number(options['--port'] || 4318), operationId: options['--operation-id'] ?? null, expectedManifestSha256: options['--expected-manifest-sha256'] ?? null, onProgress: value => { const counts = value.counts; console.log('AWBPROGRESS ' + (value.label + (counts ? ` · ${counts.completedFiles}/${counts.totalFiles} 文件` + (counts.completedBytes !== null ? ` · ${counts.completedBytes}/${counts.totalBytes} 字节` : '') + (counts.currentPath ? ' · ' + counts.currentPath : '') : '')).replace(/[\r\n]/g, ' ')); console.log('AWBFILES ' + (counts ? counts.completedFiles + '/' + counts.totalFiles : '-')); } }); const result = command === 'preflight' ? await manager.preflight({ stageOnly: !!options.stageOnly }) : command === 'activate' ? await manager.activate({ stageOnly: !!options.stageOnly }) : command === 'cancel' ? await manager.cancelPreparation() : await manager.prepareUninstall(); console.log(JSON.stringify(result)); } catch (error) { console.error('AWBERROR ' + error.message); console.error(JSON.stringify({ success: false, code: error.code || 'INSTALLATION_FAILED', message: error.message })); process.exitCode = 1; }