1
+ // @ts -check
1
2
import util from 'node:util' ;
2
3
import process from 'node:process' ;
3
4
import fs from 'node:fs/promises' ;
@@ -23,7 +24,7 @@ async function parseArguments() {
23
24
libVersion : { short : 'l' , type : 'string' , default : pkg [ 'mongodb:libmongocrypt' ] } ,
24
25
clean : { short : 'c' , type : 'boolean' , default : false } ,
25
26
build : { short : 'b' , type : 'boolean' , default : false } ,
26
- crypto : { type : 'boolean' , default : false } , // Use Node.js builtin crypto
27
+ 'no- crypto' : { type : 'boolean' , default : false } , // Use Node.js builtin crypto
27
28
fastDownload : { type : 'boolean' , default : false } , // Potentially incorrect download, only for the brave and impatient
28
29
help : { short : 'h' , type : 'boolean' , default : false }
29
30
} ;
@@ -41,11 +42,9 @@ async function parseArguments() {
41
42
}
42
43
43
44
return {
44
- libmongocrypt : {
45
- url : args . values . gitURL ,
46
- ref : args . values . libVersion ,
47
- crypto : args . values . crypto
48
- } ,
45
+ url : args . values . gitURL ,
46
+ ref : args . values . libVersion ,
47
+ crypto : ! args . values [ 'no-crypto' ] ,
49
48
fastDownload : args . values . fastDownload ,
50
49
clean : args . values . clean ,
51
50
build : args . values . build
@@ -142,7 +141,7 @@ export async function buildLibMongoCrypt(libmongocryptRoot, nodeDepsRoot, option
142
141
} ) ;
143
142
}
144
143
145
- export async function downloadLibMongoCrypt ( nodeDepsRoot , { ref, crypto } , fastDownload ) {
144
+ export async function downloadLibMongoCrypt ( nodeDepsRoot , { ref, crypto, fastDownload } ) {
146
145
const downloadURL =
147
146
ref === 'latest'
148
147
? 'https://mciuploads.s3.amazonaws.com/libmongocrypt/all/master/latest/libmongocrypt-all.tar.gz'
@@ -230,35 +229,36 @@ export async function downloadLibMongoCrypt(nodeDepsRoot, { ref, crypto }, fastD
230
229
}
231
230
232
231
async function main ( ) {
233
- const { libmongocrypt, build, clean, fastDownload } = await parseArguments ( ) ;
232
+ const args = await parseArguments ( ) ;
233
+ console . log ( args ) ;
234
234
235
235
const nodeDepsDir = resolveRoot ( 'deps' ) ;
236
236
237
- if ( build ) {
237
+ if ( args . build ) {
238
238
const libmongocryptCloneDir = resolveRoot ( '_libmongocrypt' ) ;
239
239
240
240
const currentLibMongoCryptBranch = await fs
241
241
. readFile ( path . join ( libmongocryptCloneDir , '.git' , 'HEAD' ) , 'utf8' )
242
242
. catch ( ( ) => '' ) ;
243
243
const isClonedAndCheckedOut = currentLibMongoCryptBranch
244
244
. trim ( )
245
- . endsWith ( `r-${ libmongocrypt . ref } ` ) ;
245
+ . endsWith ( `r-${ args . ref } ` ) ;
246
246
247
- if ( clean || ! isClonedAndCheckedOut ) {
248
- await cloneLibMongoCrypt ( libmongocryptCloneDir , libmongocrypt ) ;
247
+ if ( args . clean || ! isClonedAndCheckedOut ) {
248
+ await cloneLibMongoCrypt ( libmongocryptCloneDir , args ) ;
249
249
}
250
250
251
251
const libmongocryptBuiltVersion = await fs
252
252
. readFile ( path . join ( libmongocryptCloneDir , 'VERSION_CURRENT' ) , 'utf8' )
253
253
. catch ( ( ) => '' ) ;
254
- const isBuilt = libmongocryptBuiltVersion . trim ( ) === libmongocrypt . ref ;
254
+ const isBuilt = libmongocryptBuiltVersion . trim ( ) === args . ref ;
255
255
256
- if ( clean || ! isBuilt ) {
257
- await buildLibMongoCrypt ( libmongocryptCloneDir , nodeDepsDir , libmongocrypt ) ;
256
+ if ( args . clean || ! isBuilt ) {
257
+ await buildLibMongoCrypt ( libmongocryptCloneDir , nodeDepsDir , args ) ;
258
258
}
259
259
} else {
260
260
// Download
261
- await downloadLibMongoCrypt ( nodeDepsDir , libmongocrypt , fastDownload ) ;
261
+ await downloadLibMongoCrypt ( nodeDepsDir , args ) ;
262
262
}
263
263
264
264
await fs . rm ( resolveRoot ( 'build' ) , { force : true , recursive : true } ) ;
0 commit comments