Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
251 additions
and
207 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,35 @@ | ||
'use strict' | ||
|
||
const beautyError = require('beauty-error') | ||
const procStats = require('process-stats') | ||
const { URL } = require('url') | ||
const meow = require('meow') | ||
const ora = require('ora') | ||
|
||
module.exports = fn => | ||
fn(new URL(process.argv[2])) | ||
.then(output => { | ||
if (output) console.log(output) | ||
process.exit() | ||
}) | ||
.catch(err => { | ||
console.error('ERROR', err) | ||
process.exit(1) | ||
}) | ||
const cli = meow() | ||
|
||
module.exports = async fn => { | ||
const spinner = ora().start() | ||
try { | ||
const url = new URL(cli.input[0]).toString() | ||
const output = await fn(url, cli.flags) | ||
|
||
spinner.stop() | ||
|
||
if (output) console.log(output) | ||
|
||
if (!cli.flags.quiet) { | ||
const { cpu, uptime, memUsed } = procStats() | ||
console.log() | ||
console.log(` time : ${uptime.pretty}`) | ||
console.log(` memory : ${memUsed.pretty}`) | ||
console.log(` cpu : ${cpu}`) | ||
} | ||
|
||
process.exit() | ||
} catch (err) { | ||
spinner.stop() | ||
console.error(beautyError(err)) | ||
process.exit(1) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,44 +1,51 @@ | ||
'use strict' | ||
|
||
// const uniqueRandomArray = require('unique-random-array') | ||
const uniqueRandomArray = require('unique-random-array') | ||
const createBrowserless = require('browserless') | ||
const termImg = require('term-img') | ||
|
||
const browserless = createBrowserless() | ||
|
||
// const BACKGROUNDS = [ | ||
// 'linear-gradient(225deg, #FF057C 0%, #8D0B93 50%, #321575 100%)', | ||
// 'linear-gradient(225deg, #A445B2 0%, #D41872 52%, #FF0066 100%)', | ||
// 'linear-gradient(225deg, #AC32E4 0%, #7918F2 48%, #4801FF 100%)', | ||
// 'linear-gradient(225deg, #22E1FF 0%, #1D8FE1 48%, #625EB1 100%)', | ||
// 'linear-gradient(225deg, #2CD8D5 0%, #6B8DD6 48%, #8E37D7 100%)', | ||
// 'linear-gradient(90deg, #495AFF 0%, #0ACFFE 100%)', | ||
// 'linear-gradient(0deg, #6713D2 0%, #CC208E 100%)', | ||
// 'linear-gradient(270deg, #EC8C69 0%, #ED6EA0 100%)', | ||
// 'linear-gradient(0deg, #FE5196 0%, #F77062 100%)', | ||
// 'linear-gradient(270deg, #F9D423 0%, #F83600 100%)', | ||
// 'linear-gradient(270deg, #FE9A8B 0%, #FD868C 41%, #F9748F 73%, #F78CA0 100%)', | ||
// 'linear-gradient(0deg, #6F86D6 0%, #48C6EF 100%)', | ||
// 'linear-gradient(0deg, #FA71CD 0%, #C471F5 100%)', | ||
// 'linear-gradient(270deg, #6A11CB 0%, #2575FC 100%)', | ||
// 'linear-gradient(270deg, #B465DA 0%, #CF6CC9 28%, #EE609C 68%, #EE609C 100%)', | ||
// 'linear-gradient(0deg, #330867 0%, #30CFD0 100%)', | ||
// 'linear-gradient(270deg, #FEE140 0%, #FA709A 100%)' | ||
// ] | ||
// const randBackground = uniqueRandomArray(BACKGROUNDS) | ||
|
||
require('./main')(async url => { | ||
const buffer = await browserless.screenshot(url.toString(), { | ||
hide: ['.crisp-client', '#cookies-policy'], | ||
disableAnimations: true, | ||
overlay: { | ||
browser: 'safari-dark', | ||
// background: '#c1c' | ||
const BACKGROUNDS = [ | ||
'linear-gradient(225deg, #FF057C 0%, #8D0B93 50%, #321575 100%)', | ||
'linear-gradient(225deg, #A445B2 0%, #D41872 52%, #FF0066 100%)', | ||
'linear-gradient(225deg, #AC32E4 0%, #7918F2 48%, #4801FF 100%)', | ||
'linear-gradient(225deg, #22E1FF 0%, #1D8FE1 48%, #625EB1 100%)', | ||
'linear-gradient(225deg, #2CD8D5 0%, #6B8DD6 48%, #8E37D7 100%)', | ||
'linear-gradient(90deg, #495AFF 0%, #0ACFFE 100%)', | ||
'linear-gradient(0deg, #6713D2 0%, #CC208E 100%)', | ||
'linear-gradient(270deg, #EC8C69 0%, #ED6EA0 100%)', | ||
'linear-gradient(0deg, #FE5196 0%, #F77062 100%)', | ||
'linear-gradient(270deg, #F9D423 0%, #F83600 100%)', | ||
'linear-gradient(270deg, #FE9A8B 0%, #FD868C 41%, #F9748F 73%, #F78CA0 100%)', | ||
'linear-gradient(0deg, #6F86D6 0%, #48C6EF 100%)', | ||
'linear-gradient(0deg, #FA71CD 0%, #C471F5 100%)', | ||
'linear-gradient(270deg, #6A11CB 0%, #2575FC 100%)', | ||
'linear-gradient(270deg, #B465DA 0%, #CF6CC9 28%, #EE609C 68%, #EE609C 100%)', | ||
'linear-gradient(0deg, #330867 0%, #30CFD0 100%)', | ||
'linear-gradient(270deg, #FEE140 0%, #FA709A 100%)' | ||
] | ||
|
||
const randBackground = uniqueRandomArray(BACKGROUNDS) | ||
|
||
require('./main')(async (url, opts) => { | ||
if (opts.background === 'unsplash') { | ||
opts.overlay = { | ||
background: 'https://source.unsplash.com/random/1920x1080' | ||
// background: randBackground() | ||
} | ||
}) | ||
} | ||
|
||
if (opts.background === 'gradient') { | ||
opts.overlay = { | ||
background: randBackground() | ||
} | ||
} | ||
|
||
const buffer = await browserless.screenshot(url, opts) | ||
termImg(buffer) | ||
// require('fs').writeFileSync('screenshot.png', buffer) | ||
|
||
if (opts.save) { | ||
require('fs').writeFileSync('screenshot.png', buffer) | ||
console.log('image saved!') | ||
} | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.