| 1 | #!/usr/bin/env node |
| 2 | |
| 3 | const crypto = require("crypto"); |
| 4 | const fs = require("fs/promises"); |
| 5 | const path = require("path"); |
| 6 | |
| 7 | const { |
| 8 | allAssetNames, |
| 9 | CHECKSUM_MANIFEST, |
| 10 | detectBinaryNames, |
| 11 | } = require("../../npm/deepseek-tui/scripts/artifacts"); |
| 12 | |
| 13 | async function sha256(filePath) { |
| 14 | const content = await fs.readFile(filePath); |
| 15 | return crypto.createHash("sha256").update(content).digest("hex"); |
| 16 | } |
| 17 | |
| 18 | async function main() { |
| 19 | const prepareAllAssets = |
| 20 | process.env.DEEPSEEK_TUI_PREPARE_ALL_ASSETS === "1" || |
| 21 | process.env.DEEPSEEK_PREPARE_ALL_ASSETS === "1"; |
| 22 | const outputDir = path.resolve( |
| 23 | process.argv[2] || path.join("target", "npm-release-assets"), |
| 24 | ); |
| 25 | const buildDir = path.resolve( |
| 26 | process.argv[3] || path.join("target", "release"), |
| 27 | ); |
| 28 | const { deepseek, tui } = detectBinaryNames(); |
| 29 | const isWindows = process.platform === "win32"; |
| 30 | |
| 31 | const assets = [ |
| 32 | { |
| 33 | source: path.join(buildDir, isWindows ? "deepseek.exe" : "deepseek"), |
| 34 | target: deepseek, |
| 35 | }, |
| 36 | { |
| 37 | source: path.join(buildDir, isWindows ? "deepseek-tui.exe" : "deepseek-tui"), |
| 38 | target: tui, |
| 39 | }, |
| 40 | ]; |
| 41 | |
| 42 | if (prepareAllAssets) { |
| 43 | for (const assetName of allAssetNames()) { |
| 44 | if (assets.some((asset) => asset.target === assetName)) { |
| 45 | continue; |
| 46 | } |
| 47 | assets.push({ |
| 48 | source: assetName.startsWith("deepseek-tui") |
| 49 | ? path.join(buildDir, isWindows ? "deepseek-tui.exe" : "deepseek-tui") |
| 50 | : path.join(buildDir, isWindows ? "deepseek.exe" : "deepseek"), |
| 51 | target: assetName, |
| 52 | }); |
| 53 | } |
| 54 | } |
| 55 | |
| 56 | await fs.mkdir(outputDir, { recursive: true }); |
| 57 | |
| 58 | const manifestLines = []; |
| 59 | for (const asset of assets) { |
| 60 | const outputPath = path.join(outputDir, asset.target); |
| 61 | await fs.copyFile(asset.source, outputPath); |
| 62 | manifestLines.push(`${await sha256(outputPath)} ${asset.target}`); |
| 63 | } |
| 64 | |
| 65 | manifestLines.sort(); |
| 66 | const manifestPath = path.join(outputDir, CHECKSUM_MANIFEST); |
| 67 | await fs.writeFile(manifestPath, `${manifestLines.join("\n")}\n`, "utf8"); |
| 68 | |
| 69 | console.log(`Prepared ${assets.length} assets in ${outputDir}`); |
| 70 | console.log(`Wrote checksum manifest ${manifestPath}`); |
| 71 | } |
| 72 | |
| 73 | main().catch((error) => { |
| 74 | console.error("Failed to prepare local release assets:", error.message); |
| 75 | process.exit(1); |
| 76 | }); |
| 77 |