@@ -11,18 +11,26 @@ export interface HomebrewRelease {
1111 checksums : Record < Platform , string > ;
1212}
1313
14- const releaseURL = ( version : string , platform : Platform ) : string =>
15- `https://github.com/corbitsdev/corbits-code/releases/download/v${ version } /corbits-${ version } -${ platform } .tar.gz` ;
14+ /** Release facts owned by scripts/release.sh; passed in so they live in one place. */
15+ export interface HomebrewPackage {
16+ repo : string ; // GitHub owner/name
17+ binary : string ; // CLI binary, tarball stem, and legacy formula name
18+ formula : string ; // `brew install` name
19+ description : string ;
20+ }
21+
22+ const formulaClass = ( formula : string ) : string =>
23+ formula . replace ( / (?: ^ | - ) ( [ a - z ] ) / g, ( _ , c : string ) => c . toUpperCase ( ) ) ;
1624
17- function renderFormula ( release : HomebrewRelease ) : string {
25+ function renderFormula ( pkg : HomebrewPackage , release : HomebrewRelease ) : string {
1826 const source = (
1927 platform : Platform ,
20- ) : string => ` url "${ releaseURL ( release . version , platform ) } "
28+ ) : string => ` url "https://github.com/ ${ pkg . repo } /releases/download/v ${ release . version } / ${ pkg . binary } - ${ release . version } - ${ platform } .tar.gz "
2129 sha256 "${ release . checksums [ platform ] } "` ;
2230
23- return `class CorbitsCode < Formula
24- desc "Single-process coding agent CLI built on the Interchange runtime "
25- homepage "https://github.com/corbitsdev/corbits-code "
31+ return `class ${ formulaClass ( pkg . formula ) } < Formula
32+ desc "${ pkg . description } "
33+ homepage "https://github.com/${ pkg . repo } "
2634 version "${ release . version } "
2735 license "GPL-2.0-only"
2836
@@ -45,15 +53,15 @@ ${source("linux-x64")}
4553 end
4654
4755 def install
48- bin.install "corbits "
56+ bin.install "${ pkg . binary } "
4957 if File.directory?("plugins")
5058 (bin/"plugins").mkpath
5159 cp_r "plugins/.", bin/"plugins"
5260 end
5361 end
5462
5563 test do
56- assert_predicate bin/"corbits ", :executable?
64+ assert_predicate bin/"${ pkg . binary } ", :executable?
5765 end
5866end
5967` ;
@@ -79,17 +87,21 @@ async function readFormulaRenames(path: string): Promise<Record<string, string>>
7987 return renames ;
8088}
8189
82- export async function generateHomebrewTap ( tapDir : string , release : HomebrewRelease ) : Promise < void > {
90+ export async function generateHomebrewTap (
91+ tapDir : string ,
92+ pkg : HomebrewPackage ,
93+ release : HomebrewRelease ,
94+ ) : Promise < void > {
8395 const formulaDir = join ( tapDir , "Formula" ) ;
8496 const renamesPath = join ( tapDir , "formula_renames.json" ) ;
85- const formula = renderFormula ( release ) ;
97+ const formula = renderFormula ( pkg , release ) ;
8698 const renames = await readFormulaRenames ( renamesPath ) ;
87- renames . corbits = "corbits-code" ;
99+ renames [ pkg . binary ] = pkg . formula ;
88100 const renameMetadata = `${ JSON . stringify ( renames , null , 2 ) } \n` ;
89101
90102 await mkdir ( formulaDir , { recursive : true } ) ;
91- await rm ( join ( formulaDir , "corbits.rb" ) , { force : true } ) ;
92- await writeFile ( join ( formulaDir , "corbits-code.rb" ) , formula ) ;
103+ await rm ( join ( formulaDir , ` ${ pkg . binary } .rb` ) , { force : true } ) ;
104+ await writeFile ( join ( formulaDir , ` ${ pkg . formula } .rb` ) , formula ) ;
93105 await writeFile ( renamesPath , renameMetadata ) ;
94106}
95107
@@ -128,7 +140,22 @@ function parseRelease(args: string[]): { tapDir: string; release: HomebrewReleas
128140 } ;
129141}
130142
143+ function requireEnv ( name : string ) : string {
144+ const value = process . env [ name ] ;
145+ if ( ! value ) throw new Error ( `missing ${ name } (set by scripts/release.sh)` ) ;
146+ return value ;
147+ }
148+
131149if ( import . meta. main ) {
132150 const { tapDir, release } = parseRelease ( process . argv . slice ( 2 ) ) ;
133- await generateHomebrewTap ( tapDir , release ) ;
151+ await generateHomebrewTap (
152+ tapDir ,
153+ {
154+ repo : requireEnv ( "MAIN_REPO" ) ,
155+ binary : requireEnv ( "BINARY" ) ,
156+ formula : requireEnv ( "BREW_FORMULA" ) ,
157+ description : requireEnv ( "DESC" ) ,
158+ } ,
159+ release ,
160+ ) ;
134161}
0 commit comments