@@ -17,11 +17,12 @@ class ValidationError extends Error {
17
17
}
18
18
19
19
function validateProjectToken ( options ) {
20
- if ( process . env . PROJECT_TOKEN ) {
20
+ if ( process . env . PROJECT_TOKEN ) {
21
21
return axios . get ( constants [ options . env ] . AUTH_URL , {
22
22
headers : {
23
23
projectToken : process . env . PROJECT_TOKEN
24
- } } )
24
+ }
25
+ } )
25
26
. then ( function ( response ) {
26
27
console . log ( '[smartui] Project Token Validated' ) ;
27
28
} )
@@ -34,9 +35,9 @@ function validateProjectToken(options) {
34
35
console . log ( '[smartui] Project Token not validated. Error: ' , error . message ) ;
35
36
}
36
37
process . exit ( constants . ERROR_CATCHALL ) ;
37
- } ) ;
38
+ } ) ;
38
39
}
39
- else {
40
+ else {
40
41
console . log ( '[smartui] Error: No PROJECT_TOKEN set' ) ;
41
42
process . exit ( constants . ERROR_CATCHALL ) ;
42
43
}
@@ -92,7 +93,8 @@ async function validateLatestBuild(options) {
92
93
params : {
93
94
branch : commit . branch ,
94
95
commitId : commit . shortHash
95
- } } )
96
+ }
97
+ } )
96
98
. then ( function ( response ) {
97
99
if ( response . data . status === 'Failure' ) {
98
100
console . log ( `[smartui] Build with commit '${ commit . shortHash } ' on branch '${ commit . branch } ' already exists.` ) ;
@@ -185,7 +187,7 @@ function validateConfigResolutions(resolutions) {
185
187
if ( width && width < MIN_RESOLUTION_WIDTH || width > MAX_RESOLUTION_WIDTH ) {
186
188
throw new ValidationError ( `width must be > ${ MIN_RESOLUTION_WIDTH } , < ${ MAX_RESOLUTION_WIDTH } ` ) ;
187
189
}
188
- if ( height & ( height < MIN_RESOLUTION_WIDTH || height > MAX_RESOLUTION_WIDTH ) ) {
190
+ if ( height & ( height < MIN_RESOLUTION_WIDTH || height > MAX_RESOLUTION_WIDTH ) ) {
189
191
throw new ValidationError ( `height must be > ${ MIN_RESOLUTION_HEIGHT } , < ${ MAX_RESOLUTION_HEIGHT } ` ) ;
190
192
}
191
193
res . push ( [ width , height || 0 ] ) ;
@@ -206,31 +208,37 @@ function validateCustomViewPorts(customViewports) {
206
208
if ( ! Array . isArray ( element . stories ) || element . stories == 0 ) {
207
209
throw new ValidationError ( 'Missing `stories` in customViewports config. please check the config file' ) ;
208
210
}
209
- if ( ! element . styles || ! element . styles ?. width ) {
210
- throw new ValidationError ( 'Missing `styles` in customViewports key. Please check the config file' ) ;
211
+ if ( element . styles ) {
212
+ if ( ! element . styles ?. width ) {
213
+ throw new ValidationError ( 'Missing width in styles. please check the config file' ) ;
214
+ }
215
+ let width = element . styles . width ;
216
+ let height = element . styles . height ;
217
+ if ( width && typeof width != 'number' ) {
218
+ width = Number ( width ) ;
219
+ }
220
+ if ( height && typeof height != 'number' ) {
221
+ height = Number ( height ) ;
222
+ }
223
+ if ( width && width < MIN_RESOLUTION_WIDTH || width > MAX_RESOLUTION_WIDTH ) {
224
+ throw new ValidationError ( `customViewports.styles width must be > ${ MIN_RESOLUTION_WIDTH } , < ${ MAX_RESOLUTION_WIDTH } ` ) ;
225
+ }
226
+ if ( height & ( height < MIN_RESOLUTION_WIDTH || height > MAX_RESOLUTION_WIDTH ) ) {
227
+ throw new ValidationError ( `customViewports.styles height must be > ${ MIN_RESOLUTION_HEIGHT } , < ${ MAX_RESOLUTION_HEIGHT } ` ) ;
228
+ }
229
+ element . styles . width = width ;
230
+ element . styles . height = height ;
231
+ } else {
232
+ if ( ! element . waitForTimeout ) {
233
+ throw new ValidationError ( 'Missing styles and waitForTimeout. Specify either of them. please check the config file' ) ;
234
+ }
211
235
}
212
236
213
- let width = element . styles . width ;
214
- let height = element . styles . height ;
215
- if ( width && typeof width != 'number' ) {
216
- width = Number ( width ) ;
217
- }
218
- if ( height && typeof height != 'number' ) {
219
- height = Number ( height ) ;
220
- }
221
- if ( width && width < MIN_RESOLUTION_WIDTH || width > MAX_RESOLUTION_WIDTH ) {
222
- throw new ValidationError ( `customViewports.styles width must be > ${ MIN_RESOLUTION_WIDTH } , < ${ MAX_RESOLUTION_WIDTH } ` ) ;
223
- }
224
- if ( height & ( height < MIN_RESOLUTION_WIDTH || height > MAX_RESOLUTION_WIDTH ) ) {
225
- throw new ValidationError ( `customViewports.styles height must be > ${ MIN_RESOLUTION_HEIGHT } , < ${ MAX_RESOLUTION_HEIGHT } ` ) ;
226
- }
227
- element . styles . width = width ;
228
- element . styles . height = height ;
229
237
} ) ;
230
238
return
231
239
}
232
240
233
- module . exports = {
241
+ module . exports = {
234
242
ValidationError,
235
243
validateProjectToken,
236
244
validateStorybookUrl,
0 commit comments