1
1
#!/usr/bin/env node
2
- import fs from "fs" ;
3
- import { spawn , spawnSync } from " child_process" ;
4
- import path from " path" ;
5
- import { arch , platform } from "os" ;
6
- import { version } from " ./package.json" ;
2
+ import fs from 'fs' ;
3
+ import { spawn , spawnSync } from ' child_process' ;
4
+ import path from ' path' ;
5
+ import { arch , platform } from 'os' ;
6
+ import { version } from ' ./package.json' ;
7
7
8
8
const PACKAGE_VERSION = `bolt-cli ${ version } ` ;
9
9
10
10
function getBinaryVersion ( location : string ) : [ string | null , string | null ] {
11
- const result = spawnSync ( location , [ " --version" ] ) ;
11
+ const result = spawnSync ( location , [ ' --version' ] ) ;
12
12
const error : string | null =
13
13
( result . error && result . error . toString ( ) ) ||
14
14
( result . stderr . length > 0 && result . stderr . toString ( ) . trim ( ) ) ||
@@ -18,26 +18,26 @@ function getBinaryVersion(location: string): [string | null, string | null] {
18
18
19
19
function getExePath ( ) : string {
20
20
let os : string = platform ( ) ;
21
- let extension = "" ;
22
- if ( [ " win32" , " cygwin" ] . includes ( os ) ) {
23
- os = " windows" ;
24
- extension = " .exe" ;
21
+ let extension = '' ;
22
+ if ( [ ' win32' , ' cygwin' ] . includes ( os ) ) {
23
+ os = ' windows' ;
24
+ extension = ' .exe' ;
25
25
}
26
26
const binaryName = `@magicblock-labs/bolt-cli-${ os } -${ arch ( ) } /bin/bolt${ extension } ` ;
27
27
try {
28
28
return require . resolve ( binaryName ) ;
29
29
} catch ( e ) {
30
30
throw new Error (
31
- `Couldn't find application binary inside node_modules for ${ os } -${ arch ( ) } `
31
+ `Couldn't find application binary inside node_modules for ${ os } -${ arch ( ) } ` ,
32
32
) ;
33
33
}
34
34
}
35
35
36
36
function runBolt ( location : string ) : void {
37
37
const args = process . argv . slice ( 2 ) ;
38
- const bolt = spawn ( location , args , { stdio : " inherit" } ) ;
39
- bolt . on ( " exit" , ( code : number | null , signal : NodeJS . Signals | null ) => {
40
- process . on ( " exit" , ( ) => {
38
+ const bolt = spawn ( location , args , { stdio : ' inherit' } ) ;
39
+ bolt . on ( ' exit' , ( code : number | null , signal : NodeJS . Signals | null ) => {
40
+ process . on ( ' exit' , ( ) => {
41
41
if ( signal ) {
42
42
process . kill ( process . pid , signal ) ;
43
43
} else if ( code !== null ) {
@@ -46,9 +46,9 @@ function runBolt(location: string): void {
46
46
} ) ;
47
47
} ) ;
48
48
49
- process . on ( " SIGINT" , ( ) => {
50
- bolt . kill ( " SIGINT" ) ;
51
- bolt . kill ( " SIGTERM" ) ;
49
+ process . on ( ' SIGINT' , ( ) => {
50
+ bolt . kill ( ' SIGINT' ) ;
51
+ bolt . kill ( ' SIGTERM' ) ;
52
52
} ) ;
53
53
}
54
54
@@ -59,8 +59,8 @@ function tryPackageBolt(): boolean {
59
59
return true ;
60
60
} catch ( e ) {
61
61
console . error (
62
- " Failed to run bolt from package:" ,
63
- e instanceof Error ? e . message : e
62
+ ' Failed to run bolt from package:' ,
63
+ e instanceof Error ? e . message : e ,
64
64
) ;
65
65
return false ;
66
66
}
@@ -80,7 +80,7 @@ function trySystemBolt(): void {
80
80
81
81
if ( ! absolutePath ) {
82
82
console . error (
83
- `Could not find globally installed bolt, please install with cargo.`
83
+ `Could not find globally installed bolt, please install with cargo.` ,
84
84
) ;
85
85
process . exit ( 1 ) ;
86
86
}
@@ -94,7 +94,7 @@ function trySystemBolt(): void {
94
94
}
95
95
if ( binaryVersion !== PACKAGE_VERSION ) {
96
96
console . error (
97
- `Globally installed bolt version is not correct. Expected "${ PACKAGE_VERSION } ", found "${ binaryVersion } ".`
97
+ `Globally installed bolt version is not correct. Expected "${ PACKAGE_VERSION } ", found "${ binaryVersion } ".` ,
98
98
) ;
99
99
return ;
100
100
}
0 commit comments