@@ -16,12 +16,11 @@ import { fileURLToPath } from "node:url";
1616import { spawnSync } from "node:child_process" ;
1717import { parseArgs } from "node:util" ;
1818import { ROOT , readPackageJson , PACKAGES } from "./packages.mjs" ;
19- import { assertChannel } from "./validate .mjs" ;
19+ import { manifestFileName , normalizeModeChannel } from "./binary-options .mjs" ;
2020
2121const BINARY_COMPILE = fileURLToPath ( new URL ( "./binary-compile.mjs" , import . meta. url ) ) ;
2222const CLI_ENTRY = join ( ROOT , "packages/cli/src/main.ts" ) ;
2323const DEFAULT_OUTDIR = join ( ROOT , "dist-bin" ) ;
24- const DEFAULT_CDN = "https://github.com/modelstudioai/cli/releases" ;
2524const USAGE =
2625 "Usage: node tools/release/lib/binary-build.mjs [--mode stable|channel] [--channel <name>] [--host] [--target <bun-target>] [--outdir <dir>]\n" ;
2726
@@ -33,6 +32,16 @@ export const BINARY_TARGETS = [
3332 { bunTarget : "bun-windows-x64" , os : "windows" , arch : "x64" , exe : true } ,
3433] ;
3534
35+ /** Asset basename for a matrix row: `bl-<ver>-<os>-<arch>[.exe]`. */
36+ export function binaryAssetName ( version , { os, arch, exe } ) {
37+ return `bl-${ version } -${ os } -${ arch } ${ exe ? ".exe" : "" } ` ;
38+ }
39+
40+ /** Full matrix basenames for a version (order matches BINARY_TARGETS). */
41+ export function matrixAssetNames ( version ) {
42+ return BINARY_TARGETS . map ( ( target ) => binaryAssetName ( version , target ) ) ;
43+ }
44+
3645function log ( message = "" ) {
3746 process . stdout . write ( `${ message } \n` ) ;
3847}
@@ -41,10 +50,6 @@ function writeJson(path, value) {
4150 writeFileSync ( path , `${ JSON . stringify ( value , null , 2 ) } \n` ) ;
4251}
4352
44- function cdnBase ( ) {
45- return ( process . env . BAILIAN_CLI_CDN || DEFAULT_CDN ) . replace ( / \/ $ / , "" ) ;
46- }
47-
4853function parseCliArgs ( argv ) {
4954 const { values } = parseArgs ( {
5055 args : argv ,
@@ -78,22 +83,12 @@ function normalizeBuildOptions({
7883 mode = "stable" ,
7984 channel = null ,
8085} ) {
81- if ( mode !== "stable" && mode !== "channel" ) {
82- throw new Error ( `--mode must be stable or channel, got: ${ mode } ` ) ;
83- }
84- if ( mode === "channel" ) {
85- if ( ! channel ) throw new Error ( "--mode channel requires --channel <name>" ) ;
86- assertChannel ( channel ) ;
87- if ( channel === "stable" ) {
88- throw new Error ( `--channel cannot be "stable"; use --mode stable` ) ;
89- }
90- }
86+ const modeChannel = normalizeModeChannel ( mode , channel ) ;
9187 return {
9288 outdir : outdir ?? DEFAULT_OUTDIR ,
9389 onlyTarget,
9490 hostOnly : Boolean ( hostOnly ) ,
95- mode,
96- channel : mode === "channel" ? channel : null ,
91+ ...modeChannel ,
9792 } ;
9893}
9994
@@ -133,16 +128,12 @@ function sha256File(path) {
133128 return createHash ( "sha256" ) . update ( readFileSync ( path ) ) . digest ( "hex" ) ;
134129}
135130
136- function assetFileName ( version , os , arch , exe ) {
137- return `bl-${ version } -${ os } -${ arch } ${ exe ? ".exe" : "" } ` ;
138- }
139-
140131function compileOne ( { bunTarget, os, arch, exe } , version , outdir , entry ) {
141- const fileName = assetFileName ( version , os , arch , exe ) ;
132+ const fileName = binaryAssetName ( version , { os, arch, exe } ) ;
142133 const outfile = join ( outdir , fileName ) ;
143134 log ( `compile ${ bunTarget } → ${ fileName } ` ) ;
144135
145- // Bun.build() lives in binary-compile.mjs (must run under Bun ); this file stays Node.
136+ // binary-compile.mjs shells out to `bun build --compile` (CLI ); this file stays Node.
146137 const result = spawnSync (
147138 "bun" ,
148139 [ BINARY_COMPILE , "--entry" , entry , "--outfile" , outfile , "--target" , bunTarget ] ,
@@ -165,15 +156,19 @@ function writeChecksums(outdir, artifacts) {
165156 writeFileSync ( join ( outdir , "SHA256SUMS" ) , `${ lines . join ( "\n" ) } \n` ) ;
166157}
167158
168- function writeChannelManifest ( outdir , version , artifacts , mode , channel ) {
169- const base = cdnBase ( ) ;
159+ /**
160+ * Write latest.json (stable) or <channel>.json (channel).
161+ * Asset entries carry file + sha256 only — no baked download URL.
162+ * Consumers (bl update / install scripts) resolve via BAILIAN_CLI_CDN +
163+ * `{base}/releases/{version}/{file}` (see packages/core releaseAssetUrl).
164+ */
165+ function writeManifest ( outdir , version , artifacts , mode , channel ) {
170166 const assets = Object . fromEntries (
171167 artifacts . map ( ( item ) => [
172168 `${ item . os } -${ item . arch } ` ,
173169 {
174170 file : item . fileName ,
175171 sha256 : item . sha256 ,
176- url : `${ base } /download/v${ version } /${ item . fileName } ` ,
177172 } ,
178173 ] ) ,
179174 ) ;
@@ -184,9 +179,9 @@ function writeChannelManifest(outdir, version, artifacts, mode, channel) {
184179 releasedAt : new Date ( ) . toISOString ( ) ,
185180 assets,
186181 } ;
187- const names = mode === "stable" ? [ "latest.json" ] : [ ` ${ channel } .json` ] ;
188- for ( const name of names ) writeJson ( join ( outdir , name ) , manifest ) ;
189- return names ;
182+ const name = manifestFileName ( mode , channel ) ;
183+ writeJson ( join ( outdir , name ) , manifest ) ;
184+ return [ name ] ;
190185}
191186
192187function cliVersion ( ) {
@@ -207,7 +202,7 @@ function smokeTestHostBinary(artifacts, outdir) {
207202 }
208203}
209204
210- /** Compile binaries into `outdir` and write checksums + channel manifest. */
205+ /** Compile binaries into `outdir` and write checksums + manifest. */
211206export function buildBinaryArtifacts ( rawOptions = { } ) {
212207 const options = normalizeBuildOptions ( rawOptions ) ;
213208 const { outdir, mode, channel } = options ;
@@ -223,7 +218,7 @@ export function buildBinaryArtifacts(rawOptions = {}) {
223218
224219 const artifacts = targets . map ( ( target ) => compileOne ( target , version , outdir , CLI_ENTRY ) ) ;
225220 writeChecksums ( outdir , artifacts ) ;
226- const manifests = writeChannelManifest ( outdir , version , artifacts , mode , channel ) ;
221+ const manifests = writeManifest ( outdir , version , artifacts , mode , channel ) ;
227222 smokeTestHostBinary ( artifacts , outdir ) ;
228223
229224 log ( `\nBuilt ${ artifacts . length } binary(ies):` ) ;
0 commit comments