11#!/usr/bin/env node
22
3- const { execSync } = require ( ' child_process' ) ;
4- const fs = require ( 'fs' ) ;
5- const path = require ( ' path' ) ;
6- const os = require ( 'os' ) ;
3+ const { execSync } = require ( " child_process" ) ;
4+ const fs = require ( "fs" ) ;
5+ const path = require ( " path" ) ;
6+ const os = require ( "os" ) ;
77
88// Define target platforms and architectures
99const targets = [
10- { platform : ' darwin' , arch : ' amd64' , goarch : ' amd64' } ,
11- { platform : ' darwin' , arch : ' arm64' , goarch : ' arm64' } ,
12- { platform : ' linux' , arch : ' x64' , goarch : ' amd64' } ,
13- { platform : ' linux' , arch : ' arm64' , goarch : ' arm64' } ,
14- { platform : ' win32' , arch : ' x64' , goarch : ' amd64' }
10+ { platform : " darwin" , arch : " amd64" , goarch : " amd64" } ,
11+ { platform : " darwin" , arch : " arm64" , goarch : " arm64" } ,
12+ { platform : " linux" , arch : " x64" , goarch : " amd64" } ,
13+ { platform : " linux" , arch : " arm64" , goarch : " arm64" } ,
14+ { platform : " win32" , arch : " x64" , goarch : " amd64" } ,
1515] ;
1616
1717// Get package version from package.json
18- const packageJson = JSON . parse ( fs . readFileSync ( ' package.json' , ' utf8' ) ) ;
18+ const packageJson = JSON . parse ( fs . readFileSync ( " package.json" , " utf8" ) ) ;
1919const version = packageJson . version ;
2020
2121// Create bin directory if it doesn't exist
22- if ( ! fs . existsSync ( ' bin' ) ) {
23- fs . mkdirSync ( ' bin' ) ;
22+ if ( ! fs . existsSync ( " bin" ) ) {
23+ fs . mkdirSync ( " bin" ) ;
2424}
2525
2626// Build for each target
2727for ( const target of targets ) {
2828 const { platform, arch, goarch } = target ;
29-
29+
3030 // Set binary name based on platform
31- const binaryName = platform === ' win32' ? ' rules-cli.exe' : ' rules-cli' ;
32-
31+ const binaryName = platform === " win32" ? " rules-cli.exe" : " rules-cli" ;
32+
3333 // Create output directory
34- const outputDir = path . join ( ' bin' , `${ platform } -${ arch } ` ) ;
34+ const outputDir = path . join ( " bin" , `${ platform } -${ arch } ` ) ;
3535 if ( ! fs . existsSync ( outputDir ) ) {
3636 fs . mkdirSync ( outputDir , { recursive : true } ) ;
3737 }
38-
38+
3939 const outputPath = path . join ( outputDir , binaryName ) ;
40-
40+
4141 // Set environment variables for cross-compilation
4242 const env = {
4343 ...process . env ,
44- GOOS : platform === ' win32' ? ' windows' : platform ,
44+ GOOS : platform === " win32" ? " windows" : platform ,
4545 GOARCH : goarch ,
46- CGO_ENABLED : '0'
46+ CGO_ENABLED : "0" ,
4747 } ;
48-
48+
4949 console . log ( `Building for ${ platform } -${ arch } ...` ) ;
50-
50+
5151 try {
5252 // Build the binary with version info
5353 execSync (
54- `go build -ldflags="-s -w -X main.Version=${ version } " -o ${ outputPath } ` ,
55- { env, stdio : ' inherit' }
54+ `go build -ldflags="-s -w -X main.Version=${ version } -X rules-cli/internal/utils.Version= ${ version } " -o ${ outputPath } ` ,
55+ { env, stdio : " inherit" }
5656 ) ;
57-
57+
5858 console . log ( `Built ${ outputPath } ` ) ;
59-
59+
6060 // Make binary executable (not needed for Windows)
61- if ( platform !== ' win32' ) {
62- fs . chmodSync ( outputPath , ' 755' ) ;
61+ if ( platform !== " win32" ) {
62+ fs . chmodSync ( outputPath , " 755" ) ;
6363 }
6464 } catch ( error ) {
6565 console . error ( `Failed to build for ${ platform } -${ arch } : ${ error . message } ` ) ;
6666 process . exit ( 1 ) ;
6767 }
6868}
6969
70- console . log ( ' Build completed successfully!' ) ;
70+ console . log ( " Build completed successfully!" ) ;
0 commit comments