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 ,
@@ -143,7 +142,7 @@ export async function buildLibMongoCrypt(libmongocryptRoot, nodeDepsRoot, option
143
142
} ) ;
144
143
}
145
144
146
- export async function downloadLibMongoCrypt ( nodeDepsRoot , { ref, crypto } , fastDownload ) {
145
+ export async function downloadLibMongoCrypt ( nodeDepsRoot , { ref, crypto, fastDownload } ) {
147
146
const downloadURL =
148
147
ref === 'latest'
149
148
? 'https://mciuploads.s3.amazonaws.com/libmongocrypt/all/master/latest/libmongocrypt-all.tar.gz'
@@ -231,35 +230,36 @@ export async function downloadLibMongoCrypt(nodeDepsRoot, { ref, crypto }, fastD
231
230
}
232
231
233
232
async function main ( ) {
234
- const { libmongocrypt, build, clean, pkg } = await parseArguments ( ) ;
233
+ const args = await parseArguments ( ) ;
234
+ console . log ( args ) ;
235
235
236
236
const nodeDepsDir = resolveRoot ( 'deps' ) ;
237
237
238
- if ( build ) {
238
+ if ( args . build ) {
239
239
const libmongocryptCloneDir = resolveRoot ( '_libmongocrypt' ) ;
240
240
241
241
const currentLibMongoCryptBranch = await fs
242
242
. readFile ( path . join ( libmongocryptCloneDir , '.git' , 'HEAD' ) , 'utf8' )
243
243
. catch ( ( ) => '' ) ;
244
244
const isClonedAndCheckedOut = currentLibMongoCryptBranch
245
245
. trim ( )
246
- . endsWith ( `r-${ libmongocrypt . ref } ` ) ;
246
+ . endsWith ( `r-${ args . ref } ` ) ;
247
247
248
- if ( clean || ! isClonedAndCheckedOut ) {
249
- await cloneLibMongoCrypt ( libmongocryptCloneDir , libmongocrypt ) ;
248
+ if ( args . clean || ! isClonedAndCheckedOut ) {
249
+ await cloneLibMongoCrypt ( libmongocryptCloneDir , args ) ;
250
250
}
251
251
252
252
const libmongocryptBuiltVersion = await fs
253
253
. readFile ( path . join ( libmongocryptCloneDir , 'VERSION_CURRENT' ) , 'utf8' )
254
254
. catch ( ( ) => '' ) ;
255
- const isBuilt = libmongocryptBuiltVersion . trim ( ) === libmongocrypt . ref ;
255
+ const isBuilt = libmongocryptBuiltVersion . trim ( ) === args . ref ;
256
256
257
- if ( clean || ! isBuilt ) {
258
- await buildLibMongoCrypt ( libmongocryptCloneDir , nodeDepsDir , libmongocrypt ) ;
257
+ if ( args . clean || ! isBuilt ) {
258
+ await buildLibMongoCrypt ( libmongocryptCloneDir , nodeDepsDir , args ) ;
259
259
}
260
260
} else {
261
261
// Download
262
- await downloadLibMongoCrypt ( nodeDepsDir , libmongocrypt , fastDownload ) ;
262
+ await downloadLibMongoCrypt ( nodeDepsDir , args ) ;
263
263
}
264
264
265
265
await fs . rm ( resolveRoot ( 'build' ) , { force : true , recursive : true } ) ;
@@ -274,8 +274,8 @@ async function main() {
274
274
if ( process . platform === 'darwin' ) {
275
275
// The "arm64" build is actually a universal binary
276
276
await fs . copyFile (
277
- resolveRoot ( 'prebuilds' , `mongodb-client-encryption-v${ pkg . version } -napi-v4-darwin-arm64.tar.gz` ) ,
278
- resolveRoot ( 'prebuilds' , `mongodb-client-encryption-v${ pkg . version } -napi-v4-darwin-x64.tar.gz` )
277
+ resolveRoot ( 'prebuilds' , `mongodb-client-encryption-v${ args . pkg . version } -napi-v4-darwin-arm64.tar.gz` ) ,
278
+ resolveRoot ( 'prebuilds' , `mongodb-client-encryption-v${ args . pkg . version } -napi-v4-darwin-x64.tar.gz` )
279
279
) ;
280
280
}
281
281
}
0 commit comments