@@ -10,26 +10,29 @@ const uploadFiles = require('./upload_files')
10
10
const { waitForDiff } = require ( './util' )
11
11
const { waitForDeploy, getUploadList, defaultFilter } = require ( './util' )
12
12
13
- const deploySite = async ( api , siteId , dir , opts ) => {
14
- opts = {
15
- fnDir : null ,
16
- configPath : null ,
17
- draft : false ,
13
+ const deploySite = async (
14
+ api ,
15
+ siteId ,
16
+ dir ,
17
+ {
18
+ fnDir = null ,
19
+ configPath = null ,
20
+ draft = false ,
18
21
// API calls this the 'title'
19
- message : undefined ,
20
- tmpDir : tempy . directory ( ) ,
22
+ message : title ,
23
+ tmpDir = tempy . directory ( ) ,
21
24
// local deploy timeout: 20 mins
22
- deployTimeout : 1.2e6 ,
25
+ deployTimeout = 1.2e6 ,
23
26
// concurrent file hash calls
24
- concurrentHash : 100 ,
27
+ concurrentHash = 100 ,
25
28
// Number of concurrent uploads
26
- concurrentUpload : 5 ,
27
- filter : defaultFilter ,
29
+ concurrentUpload = 5 ,
30
+ filter = defaultFilter ,
28
31
// number of files
29
- syncFileLimit : 100 ,
32
+ syncFileLimit = 100 ,
30
33
// number of times to retry an upload
31
- maxRetry : 5 ,
32
- statusCb : ( ) => {
34
+ maxRetry = 5 ,
35
+ statusCb = ( ) => {
33
36
/* default to noop */
34
37
// statusObj: {
35
38
// type: name-of-step
@@ -38,22 +41,21 @@ const deploySite = async (api, siteId, dir, opts) => {
38
41
// spinner: a spinner from cli-spinners package
39
42
// }
40
43
} ,
41
- // allows updating an existing deploy
42
- deployId : null ,
43
- ...opts ,
44
- }
45
-
46
- const { fnDir, configPath, statusCb, message : title } = opts
47
-
44
+ deployId : deployIdOpt = null ,
45
+ hashAlgorithm,
46
+ assetType,
47
+ branch,
48
+ } = { } ,
49
+ ) => {
48
50
statusCb ( {
49
51
type : 'hashing' ,
50
52
msg : `Hashing files...` ,
51
53
phase : 'start' ,
52
54
} )
53
55
54
56
const [ { files, filesShaMap } , { functions, fnShaMap } ] = await Promise . all ( [
55
- hashFiles ( dir , configPath , opts ) ,
56
- hashFns ( fnDir , opts ) ,
57
+ hashFiles ( dir , configPath , { concurrentHash , hashAlgorithm , assetType , statusCb , filter } ) ,
58
+ hashFns ( fnDir , { tmpDir , concurrentHash , hashAlgorithm , statusCb , assetType } ) ,
57
59
] )
58
60
59
61
const filesCount = Object . keys ( files ) . length
@@ -81,22 +83,22 @@ const deploySite = async (api, siteId, dir, opts) => {
81
83
body : {
82
84
files,
83
85
functions,
84
- async : Object . keys ( files ) . length > opts . syncFileLimit ,
85
- branch : opts . branch ,
86
- draft : opts . draft ,
86
+ async : Object . keys ( files ) . length > syncFileLimit ,
87
+ branch,
88
+ draft,
87
89
} ,
88
90
} )
89
- if ( opts . deployId === null ) {
91
+ if ( deployIdOpt === null ) {
90
92
if ( title ) {
91
93
deployParams = { ...deployParams , title }
92
94
}
93
95
deploy = await api . createSiteDeploy ( deployParams )
94
96
} else {
95
- deployParams = { ...deployParams , deploy_id : opts . deployId }
97
+ deployParams = { ...deployParams , deploy_id : deployIdOpt }
96
98
deploy = await api . updateSiteDeploy ( deployParams )
97
99
}
98
100
99
- if ( deployParams . body . async ) deploy = await waitForDiff ( api , deploy . id , siteId , opts . deployTimeout )
101
+ if ( deployParams . body . async ) deploy = await waitForDiff ( api , deploy . id , siteId , deployTimeout )
100
102
101
103
const { id : deployId , required : requiredFiles , required_functions : requiredFns } = deploy
102
104
@@ -110,22 +112,22 @@ const deploySite = async (api, siteId, dir, opts) => {
110
112
111
113
const uploadList = getUploadList ( requiredFiles , filesShaMap ) . concat ( getUploadList ( requiredFns , fnShaMap ) )
112
114
113
- await uploadFiles ( api , deployId , uploadList , opts )
115
+ await uploadFiles ( api , deployId , uploadList , { concurrentUpload , statusCb , maxRetry } )
114
116
115
117
statusCb ( {
116
118
type : 'wait-for-deploy' ,
117
119
msg : 'Waiting for deploy to go live...' ,
118
120
phase : 'start' ,
119
121
} )
120
- deploy = await waitForDeploy ( api , deployId , siteId , opts . deployTimeout )
122
+ deploy = await waitForDeploy ( api , deployId , siteId , deployTimeout )
121
123
122
124
statusCb ( {
123
125
type : 'wait-for-deploy' ,
124
- msg : opts . draft ? 'Draft deploy is live!' : 'Deploy is live!' ,
126
+ msg : draft ? 'Draft deploy is live!' : 'Deploy is live!' ,
125
127
phase : 'stop' ,
126
128
} )
127
129
128
- await rimraf ( opts . tmpDir )
130
+ await rimraf ( tmpDir )
129
131
130
132
const deployManifest = {
131
133
deployId,
0 commit comments