Skip to content

Commit

Permalink
Require Node.js 8 and upgrade pageres
Browse files Browse the repository at this point in the history
  • Loading branch information
sindresorhus committed Feb 9, 2019
1 parent 934df00 commit cdd006a
Show file tree
Hide file tree
Showing 6 changed files with 91 additions and 122 deletions.
3 changes: 1 addition & 2 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
* text=auto
*.js text eol=lf
* text=auto eol=lf
3 changes: 1 addition & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
language: node_js
node_js:
- '10'
- '8'
- '6'
- '4'
90 changes: 40 additions & 50 deletions cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,21 +34,21 @@ const cli = meow(`
Screenshots are saved in the current directory.
Usage
pageres <url> <resolution>
pageres [ <url> <resolution> ] [ <url> <resolution> ]
$ pageres <url> <resolution>
$ pageres [ <url> <resolution> ] [ <url> <resolution> ]
Example
pageres todomvc.com yeoman.io 1366x768 1600x900
pageres todomvc.com yeoman.io 1366x768 1600x900 --overwrite
pageres [ yeoman.io 1366x768 1600x900 --no-crop ] [ todomvc.com 1024x768 480x320 ] --crop
pageres todomvc.com 1024x768 --filename='<%= date %> - <%= url %>'
pageres yeoman.io 1366x768 --selector='.page-header'
pageres unicorn.html 1366x768
Examples
$ pageres https://sindresorhus.com https://example.com 1366x768 1600x900
$ pageres https://sindresorhus.com https://example.com 1366x768 1600x900 --overwrite
$ pageres [ https://example.com 1366x768 1600x900 --no-crop ] [ https://sindresorhus.com 1024x768 480x320 ] --crop
$ pageres https://sindresorhus.com 1024x768 --filename='<%= date %> - <%= url %>'
$ pageres https://example.com 1366x768 --selector='.page-header'
$ pageres unicorn.html 1366x768
Options
-v, --verbose Verbose output
-c, --crop Crop to the set height
-d, --delay=<seconds> Delay screenshot capture
--verbose, -v Verbose output
--crop, -c Crop to the set height
--delay=<seconds>, -d Delay screenshot capture
--filename=<template> Custom filename
--overwrite Overwrite file if it exists
--selector=<element> Capture DOM element
Expand All @@ -61,67 +61,54 @@ const cli = meow(`
--format=<string> Image format
--css=<string> Apply custom CSS
<url> can also be a local file path.
<url> can also be a local file path
`, options);

function generate(args, options) {
const pageres = new Pageres({incrementalName: !options.overwrite})
.dest(process.cwd());
async function generate(args, options) {
const pageres = new Pageres({
incrementalName: !options.overwrite
}).dest(process.cwd());

args.forEach(arg => {
pageres.src(arg.url, arg.sizes, arg.options);
});

if (options.verbose) {
pageres.on('warn', console.error.bind(console));
for (const argument of args) {
pageres.src(argument.url, argument.sizes, argument.options);
}

pageres.run()
.then(() => {
pageres.successMessage();
})
.catch(err => {
if (err.noStack) {
console.error(err.message);
process.exit(1);
} else {
throw err;
}
});
await pageres.run();
pageres.successMessage();
}

function get(args) {
const ret = [];

args.forEach(arg => {
if (arg.url.length === 0) {
for (const argument of args) {
if (argument.url.length === 0) {
console.error(logSymbols.warning, 'Specify a url');
process.exit(1);
}

if (arg.sizes.length === 0 && arg.keywords.length === 0) {
arg.sizes = ['1366x768'];
if (argument.sizes.length === 0 && argument.keywords.length === 0) {
argument.sizes = ['1366x768'];
}

if (arg.keywords.length > 0) {
arg.sizes = arg.sizes.concat(arg.keywords);
if (argument.keywords.length > 0) {
argument.sizes = argument.sizes.concat(argument.keywords);
}

arg.url.forEach(el => {
for (const url of argument.url) {
ret.push({
url: el,
sizes: arg.sizes,
options: arg.options
url,
sizes: argument.sizes,
options: argument.options
});
});
});
}
}

return ret;
}

function parse(args, globalOptions) {
return args.map(arg => {
const options = Object.assign({}, globalOptions, arg);
const options = {...globalOptions, ...arg};

arg = arg._;
delete options._;
Expand Down Expand Up @@ -159,7 +146,7 @@ function parse(args, globalOptions) {
});
}

function init(args, options) {
async function init(args, options) {
if (args.length === 0) {
cli.showHelp(1);
}
Expand All @@ -176,10 +163,13 @@ function init(args, options) {
const parsedArgs = parse(args, options);
const items = get(parsedArgs);

generate(items, options);
await generate(items, options);
}

sudoBlock();
updateNotifier({pkg: cli.pkg}).notify();

init(subarg(cli.input, options)._, cli.flags);
init(subarg(cli.input, options)._, cli.flags).catch(error => {
console.error(error);
process.exit(1);
});
25 changes: 9 additions & 16 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,11 @@
"email": "[email protected]",
"url": "sindresorhus.com"
},
"maintainers": [
{
"name": "Kevin Mårtensson",
"email": "[email protected]",
"url": "github.com/kevva"
}
],
"bin": {
"pageres": "cli.js"
},
"engines": {
"node": ">=4"
"node": ">=8"
},
"scripts": {
"test": "xo && ava"
Expand All @@ -46,8 +39,8 @@
"shot",
"responsive",
"gulpfriendly",
"phantom",
"phantomjs",
"puppeteer",
"chrome",
"image",
"svg",
"render",
Expand All @@ -61,20 +54,20 @@
"jpeg"
],
"dependencies": {
"array-differ": "^1.0.0",
"array-uniq": "^1.0.2",
"array-differ": "^2.0.3",
"array-uniq": "^2.0.0",
"arrify": "^1.0.0",
"log-symbols": "^2.1.0",
"meow": "^3.5.0",
"pageres": "^4.3.0",
"pageres": "^5.0.0",
"parse-headers": "^2.0.0",
"subarg": "^1.0.0",
"sudo-block": "^2.0.0",
"update-notifier": "^2.3.0"
},
"devDependencies": {
"ava": "*",
"execa": "^0.8.0",
"xo": "*"
"ava": "^1.2.0",
"execa": "^1.0.0",
"xo": "^0.24.0"
}
}
Loading

0 comments on commit cdd006a

Please sign in to comment.