Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,17 @@ npm run capture
```
npm run capture-with-deafult-config
```

### To Create Web config for multiple browser and viewports
```
npm run config:create-web
or
npm run config:create-web smartui-web.json
```

### To Create Static config for multiple URLs
```
npm run config:web-static
or
npm run config:web-static urls.json
```
59 changes: 57 additions & 2 deletions packages/cli/src/config.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
import fs from 'fs';
import { ABNORMAL_EXIT } from './constant.js';
import path from 'path';

export const defaultScreenshotConfig = [
{
"name": "lambdatest-home-page",
"url": "https://www.lambdatest.com"
"url": "https://www.lambdatest.com",
"waitForTimeout": 1000
},
{
"name": "example-page",
Expand All @@ -18,9 +23,59 @@ export const defaultSmartUIWebConfig = {
'edge'
],
resolutions: [
[1920, 1080]
[1920, 1080],
[1366, 768],
[360, 640],
],
include: [],
exclude: []
}
};

export function createWebConfig(filepath, log) {
// default filepath
filepath = filepath || 'smartui-web.json';
let filetype = path.extname(filepath);
if (filetype != '.json') {
log.error(`Error: Web Config file must have .json extension`);
process.exitCode = ABNORMAL_EXIT;
return
}

// verify the file does not already exist
if (fs.existsSync(filepath)) {
log.error(`Error: SmartUI Web Config already exists: ${filepath}`);
log.error(`To create a new file, please specify the file name like: 'smartui config:create-web webConfig.json'`);
process.exitCode = ABNORMAL_EXIT;
return
}

// write stringified default config options to the filepath
fs.mkdirSync(path.dirname(filepath), { recursive: true });
fs.writeFileSync(filepath, JSON.stringify(defaultSmartUIWebConfig, null, 2) + '\n');
log.info(`Created SmartUI Web Config: ${filepath}`);
};

export function createWebStaticConfig(filepath, log) {
// default filepath
filepath = filepath || 'url.json';
let filetype = path.extname(filepath);
if (filetype != '.json') {
log.error(`Error: Config file must have .json extension`);
process.exitCode = ABNORMAL_EXIT;
return
}

// verify the file does not already exist
if (fs.existsSync(filepath)) {
log.error(`Error: web-static config already exists: ${filepath}`);
log.error(`To create a new file, please specify the file name like: 'smartui config:create-web links.json'`);
process.exitCode = ABNORMAL_EXIT;
return
}

// write stringified default config options to the filepath
fs.mkdirSync(path.dirname(filepath), { recursive: true });
fs.writeFileSync(filepath, JSON.stringify(defaultScreenshotConfig, null, 2) + '\n');
log.info(`Created web-static config: ${filepath}`);
};
30 changes: 25 additions & 5 deletions packages/cli/src/index.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import { Command,Option } from 'commander';
// import { version } from '../package.json';
import { Command, Option } from 'commander';
import { capture } from './capture.js';
import { logger } from '@smartui/logger';
import { validateScreenshotConfig } from './validate.js';
import packageJson from '../package.json' assert { type: 'json' };
import { createWebConfig, createWebStaticConfig } from './config.js';

const program = new Command();

program
.name('smartui')
.description('CLI to help you to take screenshot SmartUI on LambdaTest platform')
.addOption(new Option('--env <prod|stage>', 'Runtime environment option').choices(['prod', 'stage']));
.name('smartui')
.description('CLI to help you to take screenshot SmartUI on LambdaTest platform')
.addOption(new Option('--env <prod|stage>', 'Runtime environment option').choices(['prod', 'stage']));

program
.command('capture <file>')
Expand All @@ -26,4 +26,24 @@ program
capture(file, options, log);
});

program.command('config:create-web')
.description('Create SmartUI Web config file')
.argument('[filepath]', 'Optional config filepath')
.action(async function (filepath, options) {
const log = await logger();
log.info('SmartUI Config CLI v' + packageJson.version);
log.info('\n');
createWebConfig(filepath, log);
});

program.command('config:web-static')
.description('Create Web Static config file')
.argument('[filepath]', 'Optional config filepath')
.action(async function (filepath, options) {
const log = await logger();
log.info('SmartUI Config CLI v' + packageJson.version);
log.info('\n');
createWebStaticConfig(filepath, log);
});

program.parse();
2 changes: 1 addition & 1 deletion packages/cli/src/validate.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ export function validateScreenshotConfig(configFile, options, log) {
// Parse JSON
let webConfig;
try {
webConfig = JSON.parse(fs.readFileSync(webConfigFile)).web;
webConfig = JSON.parse(fs.readFileSync(webConfigFile));
} catch (error) {
log.error('Error: ', error.message);
process.exit(ABNORMAL_EXIT);
Expand Down
4 changes: 3 additions & 1 deletion packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"capture": "NODE_NO_WARNINGS=1 node packages/cli/src/index.js capture url.json --config smartui-web.json --env stage",
"capture-with-deafult-config": "NODE_NO_WARNINGS=1 node packages/cli/src/index.js capture url.json --env stage"
"capture-with-deafult-config": "NODE_NO_WARNINGS=1 node packages/cli/src/index.js capture url.json --env stage",
"config:create-web": "NODE_NO_WARNINGS=1 node packages/cli/src/index.js config:create-web",
"config:web-static": "NODE_NO_WARNINGS=1 node packages/cli/src/index.js config:web-static"
},
"author": "",
"license": "ISC",
Expand Down