@@ -17,11 +17,12 @@ class ValidationError extends Error {
1717}
1818
1919function validateProjectToken ( options ) {
20- if ( process . env . PROJECT_TOKEN ) {
20+ if ( process . env . PROJECT_TOKEN ) {
2121 return axios . get ( constants [ options . env ] . AUTH_URL , {
2222 headers : {
2323 projectToken : process . env . PROJECT_TOKEN
24- } } )
24+ }
25+ } )
2526 . then ( function ( response ) {
2627 console . log ( '[smartui] Project Token Validated' ) ;
2728 } )
@@ -34,9 +35,9 @@ function validateProjectToken(options) {
3435 console . log ( '[smartui] Project Token not validated. Error: ' , error . message ) ;
3536 }
3637 process . exit ( constants . ERROR_CATCHALL ) ;
37- } ) ;
38+ } ) ;
3839 }
39- else {
40+ else {
4041 console . log ( '[smartui] Error: No PROJECT_TOKEN set' ) ;
4142 process . exit ( constants . ERROR_CATCHALL ) ;
4243 }
@@ -92,7 +93,8 @@ async function validateLatestBuild(options) {
9293 params : {
9394 branch : commit . branch ,
9495 commitId : commit . shortHash
95- } } )
96+ }
97+ } )
9698 . then ( function ( response ) {
9799 if ( response . data . status === 'Failure' ) {
98100 console . log ( `[smartui] Build with commit '${ commit . shortHash } ' on branch '${ commit . branch } ' already exists.` ) ;
@@ -185,7 +187,7 @@ function validateConfigResolutions(resolutions) {
185187 if ( width && width < MIN_RESOLUTION_WIDTH || width > MAX_RESOLUTION_WIDTH ) {
186188 throw new ValidationError ( `width must be > ${ MIN_RESOLUTION_WIDTH } , < ${ MAX_RESOLUTION_WIDTH } ` ) ;
187189 }
188- if ( height & ( height < MIN_RESOLUTION_WIDTH || height > MAX_RESOLUTION_WIDTH ) ) {
190+ if ( height & ( height < MIN_RESOLUTION_WIDTH || height > MAX_RESOLUTION_WIDTH ) ) {
189191 throw new ValidationError ( `height must be > ${ MIN_RESOLUTION_HEIGHT } , < ${ MAX_RESOLUTION_HEIGHT } ` ) ;
190192 }
191193 res . push ( [ width , height || 0 ] ) ;
@@ -206,31 +208,37 @@ function validateCustomViewPorts(customViewports) {
206208 if ( ! Array . isArray ( element . stories ) || element . stories == 0 ) {
207209 throw new ValidationError ( 'Missing `stories` in customViewports config. please check the config file' ) ;
208210 }
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+ }
211235 }
212236
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 ;
229237 } ) ;
230238 return
231239}
232240
233- module . exports = {
241+ module . exports = {
234242 ValidationError,
235243 validateProjectToken,
236244 validateStorybookUrl,
0 commit comments