1
1
import { createWriteStream } from "fs" ;
2
- import * as fs from "fs" ;
3
-
4
-
2
+ import * as fs from "fs/promises" ;
5
3
import fetch from "node-fetch" ;
6
4
import { pipeline } from "stream/promises" ;
7
5
import tar from "tar" ;
8
- import AdmZip from 'adm-zip'
9
6
import { execSync } from "child_process" ;
10
7
11
8
import { ARCH_MAPPING , CONFIG , PLATFORM_MAPPING } from "./config.js" ;
12
9
13
10
async function install ( ) {
14
11
if ( process . platform === "android" ) {
15
- console . log ( "Installing openapi-changes , may take a moment..." ) ;
12
+ console . log ( "Installing, may take a moment..." ) ;
16
13
const cmd =
17
14
"pkg upgrade && pkg install golang git -y && git clone https://github.com/pb33f/openapi-changes.git && cd cli/ && go build -o $PREFIX/bin/openapi-changes" ;
18
15
execSync ( cmd , { encoding : "utf-8" } ) ;
19
- console . log ( "openapi-changes installation successful!" ) ;
16
+ console . log ( "Installation successful!" ) ;
20
17
return ;
21
18
}
22
- const packageJson = await fs . promises . readFile ( "package.json" ) . then ( JSON . parse ) ;
19
+ const packageJson = await fs . readFile ( "package.json" ) . then ( JSON . parse ) ;
23
20
let version = packageJson . version ;
24
21
25
22
if ( typeof version !== "string" ) {
@@ -42,18 +39,12 @@ async function install() {
42
39
throw new Error ( "Failed fetching the binary: " + response . statusText ) ;
43
40
}
44
41
45
- const zipFile = "downloaded.zip" ;
46
- await fs . promises . mkdir ( binPath , { recursive : true } ) ;
47
- await pipeline ( response . body , createWriteStream ( zipFile ) ) ;
48
-
49
- // unzip binary
50
- const zip = new AdmZip ( zipFile ) ;
51
- zip . extractAllTo ( binPath , true ) ;
42
+ const tarFile = "downloaded.tar.gz" ;
52
43
53
- // make the binary executable.
54
- await fs . chmodSync ( ` ${ binPath } /openapi-changes` , 0o755 ) ;
55
- await fs . promises . rm ( zipFile ) ;
56
- console . log ( "openapi-changes installation successful!" ) ;
44
+ await fs . mkdir ( binPath , { recursive : true } ) ;
45
+ await pipeline ( response . body , createWriteStream ( tarFile ) ) ;
46
+ await tar . x ( { file : tarFile , cwd : binPath } ) ;
47
+ await fs . rm ( tarFile ) ;
57
48
}
58
49
59
50
install ( )
0 commit comments