diff --git a/apps/detail-agent-pi/scripts/package-client.mjs b/apps/detail-agent-pi/scripts/package-client.mjs index 1fd47724..4b8f000d 100644 --- a/apps/detail-agent-pi/scripts/package-client.mjs +++ b/apps/detail-agent-pi/scripts/package-client.mjs @@ -82,7 +82,7 @@ export async function packageClient({ return { destination, ...await checkClientPackage({ destination }), node: version, pi: piVersion }; } -export async function packageRelease({ binary, destination, node, nodeLicense, version, notes }) { +export async function packageRelease({ binary, destination, node, nodeLicense, version, notes, minimum = '0.0.0' }) { const official = (await fs.readFile(path.join(root, '../detail-photocraft/client-version.txt'), 'utf8')).trim(); if (version !== official && version !== official + '-test') throw Error('发布版本与源码版本不一致'); const executable = await fs.readFile(binary); @@ -127,7 +127,7 @@ export async function packageRelease({ binary, destination, node, nodeLicense, v const hash = createHash('sha256'); for await (const chunk of createReadStream(archive)) hash.update(chunk); const metadata = { - ...release, notes: releaseNotes, minimumVersion: null, + ...release, notes: releaseNotes, minimumVersion: minimum, file: { name, size: (await fs.stat(archive)).size, sha256: hash.digest('hex') }, }; await fs.writeFile(path.join(destination, 'release.json'), JSON.stringify(metadata, null, 2)); @@ -139,9 +139,11 @@ if (process.argv[1] && path.resolve(process.argv[1]) === fileURLToPath(import.me const flag = args.indexOf('--release'); if (flag !== -1) { const [binary, destination, node, nodeLicense] = args.slice(0, flag); - const [version, notesFlag, notes] = args.slice(flag + 1); - if (notesFlag !== '--notes' || !notes) throw Error('发布模式需要 --release <版本> --notes <说明文件>'); - console.log(JSON.stringify(await packageRelease({ binary, destination, node, nodeLicense, version, notes }))); + const [version, notesFlag, notes, minimumFlag, minimum] = args.slice(flag + 1); + if (notesFlag !== '--notes' || !notes || minimumFlag !== undefined && (minimumFlag !== '--minimum' || !minimum)) { + throw Error('发布模式需要 --release <版本> --notes <说明文件> [--minimum <最低可用版本>]'); + } + console.log(JSON.stringify(await packageRelease({ binary, destination, node, nodeLicense, version, notes, minimum }))); } else { const [binary, destination, node, nodeLicense] = args; const result = await packageClient({ binary, destination, node, nodeLicense });