Skip to content

Commit

Permalink
Merge pull request #132 from reg-viz/show-mobile-descriptors
Browse files Browse the repository at this point in the history
feat: add command to list device descriptors
  • Loading branch information
Quramy committed Oct 21, 2019
2 parents 0d90023 + f9acd20 commit 2967ecc
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,7 @@ Options:
--metricsWatchRetryCount Number of count to retry until browser metrics stable. [number] [default: 1000]
--viewportDelay Delay time [msec] between changing viewport and capturing. [number] [default: 300]
--reloadAfterChangeViewport Whether to reload after viewport changed. [boolean] [default: false]
--listDevices List available device descriptors. [boolean] [default: false]
--puppeteerLaunchConfig JSON string of launch config for Puppeteer.
[string] [default: "{ "args": ["--no-sandbox", "--disable-setuid-sandbox", "--disable-dev-shm-usage"] }"]
Expand Down
16 changes: 16 additions & 0 deletions packages/storycap/src/node/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ import { MainOptions } from './types';
import yargs from 'yargs';
import { Logger } from './logger';

function showDevices(logger: Logger) {
const dd = require('puppeteer/DeviceDescriptors') as { name: string; viewport: any }[];
dd.map(device => logger.log(device.name, JSON.stringify(device.viewport)));
}

function createOptions(): MainOptions {
const setting = yargs
.locale('en')
Expand Down Expand Up @@ -49,6 +54,11 @@ function createOptions(): MainOptions {
default: false,
description: 'Whether to reload after viewport changed.',
})
.option('listDevices', {
boolean: true,
default: false,
description: 'List available device descriptors.',
})
.option('puppeteerLaunchConfig', {
string: true,
default: '{ "args": ["--no-sandbox", "--disable-setuid-sandbox", "--disable-dev-shm-usage"] }',
Expand Down Expand Up @@ -85,11 +95,17 @@ function createOptions(): MainOptions {
viewportDelay,
reloadAfterChangeViewport,
disableCssAnimation,
listDevices,
puppeteerLaunchConfig: puppeteerLaunchConfigString,
} = setting.argv;

const logger = new Logger(verbose ? 'verbose' : silent ? 'silent' : 'normal');

if (listDevices) {
showDevices(logger);
process.exit(0);
}

let puppeteerLaunchConfig: string;
try {
puppeteerLaunchConfig = {
Expand Down

0 comments on commit 2967ecc

Please sign in to comment.