1
- const { Binary } = require ( 'binary-install-raw' )
2
1
const os = require ( 'os' )
3
2
const chalk = require ( 'chalk' )
4
3
const fetch = require ( 'node-fetch' )
4
+ const semver = require ( 'semver' )
5
5
const { exec } = require ( 'child_process' )
6
6
const fs = require ( 'fs' )
7
- const semver = require ( 'semver' )
8
7
9
8
const HELP = `
10
9
${ chalk . bold ( 'graph test' ) } ${ chalk . dim ( '[options]' ) } ${ chalk . bold ( '<datasource>' ) }
11
10
12
11
${ chalk . dim ( 'Options:' ) }
13
-
14
- -f --force Overwrite folder + file when downloading
15
12
-h, --help Show usage information
16
- -l, --logs Logs to the console information about the OS, CPU model and download url (debugging purposes)
17
13
-v, --version <tag> Choose the version of the rust binary that you want to be downloaded/used
18
- -d, --docker Launches Matchstick in a docker container
19
- -c, --coverage (Docker) Runs in coverage mode
14
+ -c, --flags <flags>
20
15
`
21
16
22
17
module . exports = {
@@ -26,168 +21,101 @@ module.exports = {
26
21
let { print } = toolbox
27
22
28
23
// Read CLI parameters
29
- let { f , force , h, help, l , logs , v, version, c, coverage, d , docker } = toolbox . parameters . options
24
+ let { h, help, v, version, c, coverage, l , lib } = toolbox . parameters . options
30
25
let datasource = toolbox . parameters . first
31
26
32
27
// Support both long and short option variants
33
- force = force || f
34
28
help = help || h
35
- logs = logs || l
36
29
version = version || v
37
30
coverage = coverage || c
38
- docker = docker || d
39
31
40
32
// Show help text if requested
41
33
if ( help ) {
42
34
print . info ( HELP )
43
35
return
44
36
}
45
37
46
- if ( docker ) {
47
- let url = `https://github.com/LimeChain/matchstick/releases/download/${ version || '0.2.0a' } /binary-linux-20`
48
-
49
- if ( version ) {
50
- await fetch ( url )
51
- . then ( response => {
52
- if ( response . status === 404 ) {
53
- print . info ( `Error: Invalid Matchstick version '${ version } '` )
54
- process . exit ( 1 )
55
- }
56
- } )
57
- }
38
+ if ( version ) {
39
+ let url = `https://github.com/LimeChain/matchstick/releases/download/${ version || "0.2.2a" } /binary-linux-20` ;
40
+
41
+ await fetch ( url )
42
+ . then ( response => {
43
+ if ( response . status === 404 ) {
44
+ print . info ( `Error: Invalid Matchstick version '${ version } '` ) ;
45
+ process . exit ( 1 ) ;
46
+ }
47
+ } )
48
+ }
58
49
59
- // TODO: Move these in separate file (in a function maybe)
60
- let contents = `FROM ubuntu:20.04
50
+ // TODO: Move these in separate file (in a function maybe)
51
+ let contents = `FROM ubuntu:20.04
61
52
ENV ARGS=""
62
53
RUN apt update
63
54
RUN apt install -y nodejs
64
55
RUN apt install -y npm
65
- RUN apt install -y cmake
66
- RUN apt install -y git
67
56
COPY ./ ./
68
- RUN mkdir -p ./tests/.tools
69
- WORKDIR ./tests/.tools
70
- RUN git clone --recursive https://github.com/WebAssembly/wabt
71
- WORKDIR wabt
72
- RUN git submodule update --init
73
- RUN mkdir -p build
74
- WORKDIR build
75
- RUN cmake ..
76
- RUN cmake --build .
77
- WORKDIR /
78
57
RUN npm run codegen
79
58
RUN npm run build
80
59
RUN apt install -y postgresql
81
60
RUN apt install -y curl
82
- RUN curl -OL ${ url }
61
+ RUN apt-get update && apt-get -y install cmake protobuf-compiler
62
+ RUN curl -OL https://github.com/LimeChain/matchstick/releases/download/${ version || "0.2.1a" } /binary-linux-20
83
63
RUN mv binary-linux-20 matchstick
64
+ RUN chmod a+x matchstick
84
65
CMD ./matchstick \${ARGS}`
85
66
86
- let dir = 'tests/.docker'
67
+ let dir = 'tests/.docker' ;
68
+
69
+ if ( ! fs . existsSync ( dir ) ) {
70
+ fs . mkdirSync ( dir , { recursive : true } ) ;
71
+ }
87
72
88
- if ( ! fs . existsSync ( dir ) ) {
89
- fs . mkdirSync ( dir , { recursive : true } )
73
+ fs . writeFileSync ( 'tests/.docker/Dockerfile' , contents , ( err ) => {
74
+ if ( err ) {
75
+ print . info ( 'A problem occurred while generating the Dockerfile. Please attend to the errors below.' ) ;
76
+ print . info ( err ) ;
90
77
}
78
+ else {
79
+ print . info ( 'Successfully generated Dockerfile.' )
80
+ }
81
+ } )
91
82
92
- fs . writeFileSync ( 'tests/.docker/Dockerfile' , contents , ( err ) => {
93
- if ( err ) {
94
- print . info ( 'A problem occurred while generating the Dockerfile. Please attend to the errors below.' )
95
- print . info ( err )
96
- } else {
97
- print . info ( 'Successfully generated Dockerfile.' )
98
- }
99
- } )
83
+ exec ( `docker build -f tests/.docker/Dockerfile -t matchstick . ` , ( error , stdout , stderr ) => {
84
+ print . info ( 'Building Matchstick image...' ) ;
100
85
101
- exec ( `docker build -f tests/.docker/Dockerfile -t matchstick . ` , ( error , stdout , stderr ) => {
102
- print . info ( 'Building Matchstick image...' )
86
+ if ( error ) {
87
+ print . info ( 'A problem occurred while trying to build the Matchstick Docker image. Please attend to the errors below.' ) ;
88
+ print . info ( `error: ${ error . message } ` )
89
+ }
90
+ if ( stderr ) {
91
+ print . info ( 'A problem occurred while trying to build the Matchstick Docker image. Please attend to the errors below.' ) ;
92
+ print . info ( `stderr: ${ stderr } ` )
93
+ }
94
+
95
+ let runCommand = `docker run -e ARGS="${ datasource || "" } ${ coverage ? "-c" : "" } " --rm matchstick` ;
96
+
97
+ console . log ( "runCommand output" ) ;
98
+ console . log ( runCommand ) ;
99
+ print . info ( "runCommand output" ) ;
100
+ print . info ( runCommand ) ;
101
+
102
+ exec ( runCommand , ( error , stdout , stderr ) => {
103
+ print . info ( 'Running Matchstick image...' ) ;
103
104
104
105
if ( error ) {
105
- print . info ( 'A problem occurred while trying to build the Matchstick Docker image. Please attend to the errors below.' )
106
+ print . info ( 'A problem occurred while trying to run the Matchstick Docker image. Please attend to the errors below.' ) ;
106
107
print . info ( `error: ${ error . message } ` )
108
+ process . exit ( 1 ) ;
107
109
}
108
110
if ( stderr ) {
109
- print . info ( 'A problem occurred while trying to build the Matchstick Docker image. Please attend to the errors below.' )
111
+ print . info ( 'A problem occurred while trying to run the Matchstick Docker image. Please attend to the errors below.' ) ;
110
112
print . info ( `stderr: ${ stderr } ` )
113
+ process . exit ( 1 ) ;
111
114
}
112
-
113
- let runCommand = `docker run -e ARGS="${ datasource || '' } ${ coverage ? '-c' : '' } " --rm matchstick`
114
-
115
- console . log ( 'runCommand output' )
116
- console . log ( runCommand )
117
- print . info ( 'runCommand output' )
118
- print . info ( runCommand )
119
-
120
- exec ( runCommand , ( error , stdout , stderr ) => {
121
- print . info ( 'Running Matchstick image...' )
122
-
123
- if ( error ) {
124
- print . info ( 'A problem occurred while trying to run the Matchstick Docker image. Please attend to the errors below.' )
125
- print . info ( `error: ${ error . message } ` )
126
- process . exit ( 1 )
127
- }
128
- if ( stderr ) {
129
- print . info ( 'A problem occurred while trying to run the Matchstick Docker image. Please attend to the errors below.' )
130
- print . info ( `stderr: ${ stderr } ` )
131
- process . exit ( 1 )
132
- }
133
- print . info ( stdout )
134
- process . exit ( )
135
- } )
115
+ print . info ( stdout )
116
+ process . exit ( ) ;
136
117
} )
118
+ } )
137
119
138
- return
139
- }
140
-
141
- const platform = getPlatform ( logs )
142
- if ( ! version ) {
143
- let result = await fetch ( 'https://api.github.com/repos/LimeChain/matchstick/releases/latest' )
144
- let json = await result . json ( )
145
- version = json . tag_name
146
- }
147
-
148
- const url = `https://github.com/LimeChain/matchstick/releases/download/${ version } /${ platform } `
149
-
150
- if ( logs ) {
151
- console . log ( `Download link: ${ url } ` )
152
- }
153
-
154
- let binary = new Binary ( platform , url , version )
155
- await binary . install ( force )
156
- datasource ? binary . run ( datasource ) : binary . run ( )
157
120
} ,
158
- }
159
-
160
- function getPlatform ( logs ) {
161
- const type = os . type ( )
162
- const arch = os . arch ( )
163
- const release = os . release ( )
164
- const cpuCore = os . cpus ( ) [ 0 ]
165
- const majorVersion = semver . major ( release )
166
- const isM1 = cpuCore . model . includes ( 'Apple M1' )
167
-
168
- if ( logs ) {
169
- console . log ( `OS type: ${ type } \nOS arch: ${ arch } \nOS release: ${ release } \nOS major version: ${ majorVersion } \nCPU model: ${ cpuCore . model } ` )
170
- }
171
-
172
- if ( arch === 'x64' || ( arch === 'arm64' && isM1 ) ) {
173
- if ( type === 'Darwin' ) {
174
- if ( majorVersion === 19 ) {
175
- return 'binary-macos-10.15'
176
- } else if ( majorVersion === 18 ) {
177
- return 'binary-macos-10.14'
178
- } else if ( isM1 ) {
179
- return 'binary-macos-11-m1'
180
- }
181
- return 'binary-macos-11'
182
- } else if ( type === 'Linux' ) {
183
- if ( majorVersion === 18 ) {
184
- return 'binary-linux-18'
185
- }
186
- return 'binary-linux-20'
187
- } else if ( type === 'Windows_NT' ) {
188
- return 'binary-windows'
189
- }
190
- }
191
-
192
- throw new Error ( `Unsupported platform: ${ type } ${ arch } ${ majorVersion } ` )
193
- }
121
+ }
0 commit comments