@@ -16,21 +16,24 @@ const hashFns = require('./hash_fns')
16
16
const uploadFiles = require ( './upload_files' )
17
17
const { waitForDiff, waitForDeploy, getUploadList, defaultFilter } = require ( './util' )
18
18
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 ,
24
27
// 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 = ( ) => {
34
37
/* default to noop */
35
38
// statusObj: {
36
39
// type: name-of-step
@@ -39,22 +42,21 @@ const deploySite = async (api, siteId, dir, opts) => {
39
42
// spinner: a spinner from cli-spinners package
40
43
// }
41
44
} ,
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
+ ) => {
49
51
statusCb ( {
50
52
type : 'hashing' ,
51
53
msg : `Hashing files...` ,
52
54
phase : 'start' ,
53
55
} )
54
56
55
57
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 } ) ,
58
60
] )
59
61
60
62
const filesCount = Object . keys ( files ) . length
@@ -82,22 +84,22 @@ const deploySite = async (api, siteId, dir, opts) => {
82
84
body : {
83
85
files,
84
86
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,
88
90
} ,
89
91
} )
90
- if ( opts . deployId === null ) {
92
+ if ( deployIdOpt === null ) {
91
93
if ( title ) {
92
94
deployParams = { ...deployParams , title }
93
95
}
94
96
deploy = await api . createSiteDeploy ( deployParams )
95
97
} else {
96
- deployParams = { ...deployParams , deploy_id : opts . deployId }
98
+ deployParams = { ...deployParams , deploy_id : deployIdOpt }
97
99
deploy = await api . updateSiteDeploy ( deployParams )
98
100
}
99
101
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 )
101
103
102
104
const { id : deployId , required : requiredFiles , required_functions : requiredFns } = deploy
103
105
@@ -111,22 +113,22 @@ const deploySite = async (api, siteId, dir, opts) => {
111
113
112
114
const uploadList = getUploadList ( requiredFiles , filesShaMap ) . concat ( getUploadList ( requiredFns , fnShaMap ) )
113
115
114
- await uploadFiles ( api , deployId , uploadList , opts )
116
+ await uploadFiles ( api , deployId , uploadList , { concurrentUpload , statusCb , maxRetry } )
115
117
116
118
statusCb ( {
117
119
type : 'wait-for-deploy' ,
118
120
msg : 'Waiting for deploy to go live...' ,
119
121
phase : 'start' ,
120
122
} )
121
- deploy = await waitForDeploy ( api , deployId , siteId , opts . deployTimeout )
123
+ deploy = await waitForDeploy ( api , deployId , siteId , deployTimeout )
122
124
123
125
statusCb ( {
124
126
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!' ,
126
128
phase : 'stop' ,
127
129
} )
128
130
129
- await rimraf ( opts . tmpDir )
131
+ await rimraf ( tmpDir )
130
132
131
133
const deployManifest = {
132
134
deployId,
0 commit comments