@@ -16,21 +16,24 @@ const hashFns = require('./hash_fns')
1616const uploadFiles = require ( './upload_files' )
1717const { waitForDiff, waitForDeploy, getUploadList, defaultFilter } = require ( './util' )
1818
19- const deploySite = async ( api , siteId , dir , opts ) => {
20- opts = {
21- fnDir : null ,
22- configPath : null ,
23- draft : false ,
19+ const deploySite = async (
20+ api ,
21+ siteId ,
22+ dir ,
23+ {
24+ fnDir = null ,
25+ configPath = null ,
26+ draft = false ,
2427 // API calls this the 'title'
25- message : undefined ,
26- tmpDir : tempy . directory ( ) ,
27- deployTimeout : DEFAULT_DEPLOY_TIMEOUT ,
28- concurrentHash : DEFAULT_CONCURRENT_HASH ,
29- concurrentUpload : DEFAULT_CONCURRENT_UPLOAD ,
30- filter : defaultFilter ,
31- syncFileLimit : DEFAULT_SYNC_LIMIT ,
32- maxRetry : DEFAULT_MAX_RETRY ,
33- statusCb : ( ) => {
28+ message : title ,
29+ tmpDir = tempy . directory ( ) ,
30+ deployTimeout = DEFAULT_DEPLOY_TIMEOUT ,
31+ concurrentHash = DEFAULT_CONCURRENT_HASH ,
32+ concurrentUpload = DEFAULT_CONCURRENT_UPLOAD ,
33+ filter = defaultFilter ,
34+ syncFileLimit = DEFAULT_SYNC_LIMIT ,
35+ maxRetry = DEFAULT_MAX_RETRY ,
36+ statusCb = ( ) => {
3437 /* default to noop */
3538 // statusObj: {
3639 // type: name-of-step
@@ -39,22 +42,21 @@ const deploySite = async (api, siteId, dir, opts) => {
3942 // spinner: a spinner from cli-spinners package
4043 // }
4144 } ,
42- // allows updating an existing deploy
43- deployId : null ,
44- ...opts ,
45- }
46-
47- const { fnDir, configPath, statusCb, message : title } = opts
48-
45+ deployId : deployIdOpt = null ,
46+ hashAlgorithm,
47+ assetType,
48+ branch,
49+ } = { } ,
50+ ) => {
4951 statusCb ( {
5052 type : 'hashing' ,
5153 msg : `Hashing files...` ,
5254 phase : 'start' ,
5355 } )
5456
5557 const [ { files, filesShaMap } , { functions, fnShaMap } ] = await Promise . all ( [
56- hashFiles ( dir , configPath , opts ) ,
57- hashFns ( fnDir , opts ) ,
58+ hashFiles ( dir , configPath , { concurrentHash , hashAlgorithm , assetType , statusCb , filter } ) ,
59+ hashFns ( fnDir , { tmpDir , concurrentHash , hashAlgorithm , statusCb , assetType } ) ,
5860 ] )
5961
6062 const filesCount = Object . keys ( files ) . length
@@ -82,22 +84,22 @@ const deploySite = async (api, siteId, dir, opts) => {
8284 body : {
8385 files,
8486 functions,
85- async : Object . keys ( files ) . length > opts . syncFileLimit ,
86- branch : opts . branch ,
87- draft : opts . draft ,
87+ async : Object . keys ( files ) . length > syncFileLimit ,
88+ branch,
89+ draft,
8890 } ,
8991 } )
90- if ( opts . deployId === null ) {
92+ if ( deployIdOpt === null ) {
9193 if ( title ) {
9294 deployParams = { ...deployParams , title }
9395 }
9496 deploy = await api . createSiteDeploy ( deployParams )
9597 } else {
96- deployParams = { ...deployParams , deploy_id : opts . deployId }
98+ deployParams = { ...deployParams , deploy_id : deployIdOpt }
9799 deploy = await api . updateSiteDeploy ( deployParams )
98100 }
99101
100- if ( deployParams . body . async ) deploy = await waitForDiff ( api , deploy . id , siteId , opts . deployTimeout )
102+ if ( deployParams . body . async ) deploy = await waitForDiff ( api , deploy . id , siteId , deployTimeout )
101103
102104 const { id : deployId , required : requiredFiles , required_functions : requiredFns } = deploy
103105
@@ -111,22 +113,22 @@ const deploySite = async (api, siteId, dir, opts) => {
111113
112114 const uploadList = getUploadList ( requiredFiles , filesShaMap ) . concat ( getUploadList ( requiredFns , fnShaMap ) )
113115
114- await uploadFiles ( api , deployId , uploadList , opts )
116+ await uploadFiles ( api , deployId , uploadList , { concurrentUpload , statusCb , maxRetry } )
115117
116118 statusCb ( {
117119 type : 'wait-for-deploy' ,
118120 msg : 'Waiting for deploy to go live...' ,
119121 phase : 'start' ,
120122 } )
121- deploy = await waitForDeploy ( api , deployId , siteId , opts . deployTimeout )
123+ deploy = await waitForDeploy ( api , deployId , siteId , deployTimeout )
122124
123125 statusCb ( {
124126 type : 'wait-for-deploy' ,
125- msg : opts . draft ? 'Draft deploy is live!' : 'Deploy is live!' ,
127+ msg : draft ? 'Draft deploy is live!' : 'Deploy is live!' ,
126128 phase : 'stop' ,
127129 } )
128130
129- await rimraf ( opts . tmpDir )
131+ await rimraf ( tmpDir )
130132
131133 const deployManifest = {
132134 deployId,
0 commit comments