1+ import fs from 'fs' ;
2+ import { ABNORMAL_EXIT } from './constant.js' ;
3+ import path from 'path' ;
4+
15export const defaultScreenshotConfig = [
26 {
37 "name" : "lambdatest-home-page" ,
4- "url" : "https://www.lambdatest.com"
8+ "url" : "https://www.lambdatest.com" ,
9+ "waitForTimeout" : 1000
510 } ,
611 {
712 "name" : "example-page" ,
@@ -18,9 +23,59 @@ export const defaultSmartUIWebConfig = {
1823 'edge'
1924 ] ,
2025 resolutions : [
21- [ 1920 , 1080 ]
26+ [ 1920 , 1080 ] ,
27+ [ 1366 , 768 ] ,
28+ [ 360 , 640 ] ,
2229 ] ,
2330 include : [ ] ,
2431 exclude : [ ]
2532 }
2633} ;
34+
35+ export function createWebConfig ( filepath , log ) {
36+ // default filepath
37+ filepath = filepath || 'smartui-web.json' ;
38+ let filetype = path . extname ( filepath ) ;
39+ if ( filetype != '.json' ) {
40+ log . error ( `Error: Web Config file must have .json extension` ) ;
41+ process . exitCode = ABNORMAL_EXIT ;
42+ return
43+ }
44+
45+ // verify the file does not already exist
46+ if ( fs . existsSync ( filepath ) ) {
47+ log . error ( `Error: SmartUI Web Config already exists: ${ filepath } ` ) ;
48+ log . error ( `To create a new file, please specify the file name like: 'smartui config:create-web webConfig.json'` ) ;
49+ process . exitCode = ABNORMAL_EXIT ;
50+ return
51+ }
52+
53+ // write stringified default config options to the filepath
54+ fs . mkdirSync ( path . dirname ( filepath ) , { recursive : true } ) ;
55+ fs . writeFileSync ( filepath , JSON . stringify ( defaultSmartUIWebConfig , null , 2 ) + '\n' ) ;
56+ log . info ( `Created SmartUI Web Config: ${ filepath } ` ) ;
57+ } ;
58+
59+ export function createWebStaticConfig ( filepath , log ) {
60+ // default filepath
61+ filepath = filepath || 'url.json' ;
62+ let filetype = path . extname ( filepath ) ;
63+ if ( filetype != '.json' ) {
64+ log . error ( `Error: Config file must have .json extension` ) ;
65+ process . exitCode = ABNORMAL_EXIT ;
66+ return
67+ }
68+
69+ // verify the file does not already exist
70+ if ( fs . existsSync ( filepath ) ) {
71+ log . error ( `Error: web-static config already exists: ${ filepath } ` ) ;
72+ log . error ( `To create a new file, please specify the file name like: 'smartui config:create-web links.json'` ) ;
73+ process . exitCode = ABNORMAL_EXIT ;
74+ return
75+ }
76+
77+ // write stringified default config options to the filepath
78+ fs . mkdirSync ( path . dirname ( filepath ) , { recursive : true } ) ;
79+ fs . writeFileSync ( filepath , JSON . stringify ( defaultScreenshotConfig , null , 2 ) + '\n' ) ;
80+ log . info ( `Created web-static config: ${ filepath } ` ) ;
81+ } ;
0 commit comments