@@ -85,4 +85,47 @@ async function validateLatestBuild(options) {
8585 } ) ;
8686}
8787
88- module . exports = { validateProjectToken, validateStorybookUrl, validateStorybookDir, validateLatestBuild } ;
88+ function validateConfig ( configFile ) {
89+ // Verify config file exists
90+ if ( ! fs . existsSync ( configFile ) ) {
91+ console . log ( `[smartui] Error: Config file ${ configFile } not found.` ) ;
92+ process . exit ( 1 ) ;
93+ }
94+
95+ // Parse JSON
96+ let storybookConfig ;
97+ try {
98+ storybookConfig = JSON . parse ( fs . readFileSync ( configFile ) ) . storybook ;
99+ } catch ( error ) {
100+ console . log ( '[smartui] Error: ' , error . message ) ;
101+ process . exit ( 1 ) ;
102+ }
103+
104+ // Sanity check browsers
105+ if ( storybookConfig . browsers . length == 0 ) {
106+ console . log ( '[smartui] Error: Empty browsers list in config.' )
107+ }
108+ storybookConfig . browsers . forEach ( element => {
109+ if ( ! ( [ 'chrome' , 'safari' , 'firefox' ] . includes ( element . toLowerCase ( ) ) ) ) {
110+ console . log ( '[smartui] Error: Invalid value for browser. Accepted browsers are chrome, safari and firefox' ) ;
111+ process . exit ( 0 ) ;
112+ }
113+ } ) ;
114+
115+ // Sanity check resolutions
116+ if ( storybookConfig . resolutions . length == 0 ) {
117+ console . log ( '[smartui] Error: Invalid number of resolutions. Min. required - 1' )
118+ }
119+ if ( storybookConfig . resolutions . length > 5 ) {
120+ console . log ( '[smartui] Error: Invalid number of resolutions. Max allowed - 5' )
121+ }
122+ storybookConfig . resolutions . forEach ( element => {
123+ if ( element . length != 2 || element [ 0 ] <= 0 || element [ 1 ] <= 0 ) {
124+ console . log ( '[smartui] Error: Invalid resolutions.' )
125+ }
126+ } ) ;
127+
128+ return storybookConfig
129+ }
130+
131+ module . exports = { validateProjectToken, validateStorybookUrl, validateStorybookDir, validateLatestBuild, validateConfig } ;
0 commit comments