@browserless/cli 9.9.8 → 9.10.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -1
- package/package.json +7 -6
- package/src/commands/goto.js +1 -4
- package/src/commands/html.js +2 -2
- package/src/commands/lighthouse.js +9 -4
- package/src/commands/pdf.js +1 -4
- package/src/commands/ping.js +1 -1
- package/src/commands/screenshot.js +5 -5
- package/src/commands/status.js +1 -1
- package/src/commands/text.js +1 -1
- package/src/index.js +28 -30
- package/src/spinner.js +20 -19
package/README.md
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
<div align="center">
|
|
2
2
|
<br>
|
|
3
|
-
<img style="width: 500px; margin:3rem 0 1.5rem;" src="
|
|
3
|
+
<img style="width: 500px; margin:3rem 0 1.5rem;" src="/static/logo-banner.png#gh-light-mode-only" alt="browserless">
|
|
4
|
+
<img style="width: 500px; margin:3rem 0 1.5rem;" src="/static/logo-banner-light.png#gh-dark-mode-only" alt="browserless">
|
|
4
5
|
<br>
|
|
5
6
|
<br>
|
|
6
7
|
<p align="center"><strong>@browserless/cli</strong>: CLI to interact with Browserless capabilities.</p>
|
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "@browserless/cli",
|
|
3
3
|
"description": "CLI to interact with Browserless capabilities",
|
|
4
4
|
"homepage": "https://browserless.js.org",
|
|
5
|
-
"version": "9.
|
|
5
|
+
"version": "9.10.1",
|
|
6
6
|
"bin": {
|
|
7
7
|
"browserless": "src/index.js"
|
|
8
8
|
},
|
|
@@ -32,14 +32,15 @@
|
|
|
32
32
|
],
|
|
33
33
|
"dependencies": {
|
|
34
34
|
"beauty-error": "~1.2.15",
|
|
35
|
-
"browserless": "^9.
|
|
35
|
+
"browserless": "^9.10.1",
|
|
36
36
|
"dark-mode": "~3.0.0",
|
|
37
|
-
"
|
|
38
|
-
"
|
|
39
|
-
"
|
|
37
|
+
"dset": "~3.1.2",
|
|
38
|
+
"mri": "~1.2.0",
|
|
39
|
+
"nanospinner": "~1.1.0",
|
|
40
40
|
"picocolors": "~1.0.0",
|
|
41
41
|
"pretty-bytes": "~5.6.0",
|
|
42
42
|
"process-stats": "~3.7.0",
|
|
43
|
+
"restore-cursor": "~3.1.0",
|
|
43
44
|
"signal-exit": "~4.0.1",
|
|
44
45
|
"term-img": "~5.0.0",
|
|
45
46
|
"unique-random-array": "~2.0.0"
|
|
@@ -55,5 +56,5 @@
|
|
|
55
56
|
"test": "exit 0"
|
|
56
57
|
},
|
|
57
58
|
"license": "MIT",
|
|
58
|
-
"gitHead": "
|
|
59
|
+
"gitHead": "0826317b9edda6f4d77b38d843e6087060876a00"
|
|
59
60
|
}
|
package/src/commands/goto.js
CHANGED
|
@@ -1,9 +1,6 @@
|
|
|
1
1
|
'use strict'
|
|
2
2
|
|
|
3
|
-
const { setTimeout } = require('timers/promises')
|
|
4
|
-
|
|
5
3
|
module.exports = async ({ url, browserless, opts }) => {
|
|
6
4
|
const page = await browserless.page()
|
|
7
|
-
await browserless.goto(page, { url, ...opts })
|
|
8
|
-
await setTimeout(8.64e7)
|
|
5
|
+
return [await browserless.goto(page, { url, ...opts })]
|
|
9
6
|
}
|
package/src/commands/html.js
CHANGED
|
@@ -1,9 +1,14 @@
|
|
|
1
1
|
'use strict'
|
|
2
2
|
|
|
3
|
-
const
|
|
3
|
+
const createLighthouse = require('../../../lighthouse/src')
|
|
4
4
|
|
|
5
5
|
module.exports = async ({ url, browserless, opts }) => {
|
|
6
|
-
const
|
|
7
|
-
|
|
8
|
-
|
|
6
|
+
const lighthouse = createLighthouse(async teardown => {
|
|
7
|
+
teardown(() => browserless.destroyContext())
|
|
8
|
+
return browserless
|
|
9
|
+
})
|
|
10
|
+
|
|
11
|
+
const report = await lighthouse(url)
|
|
12
|
+
|
|
13
|
+
return [JSON.stringify(report), JSON.stringify(report, null, 2)]
|
|
9
14
|
}
|
package/src/commands/pdf.js
CHANGED
package/src/commands/ping.js
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
const uniqueRandomArray = require('unique-random-array')
|
|
4
4
|
const darkMode = require('dark-mode')
|
|
5
5
|
const termImg = require('term-img')
|
|
6
|
-
const {
|
|
6
|
+
const { dset } = require('dset')
|
|
7
7
|
|
|
8
8
|
const BACKGROUNDS = [
|
|
9
9
|
'linear-gradient(225deg, #FF057C 0%, #8D0B93 50%, #321575 100%)',
|
|
@@ -29,15 +29,15 @@ const randBackground = uniqueRandomArray(BACKGROUNDS)
|
|
|
29
29
|
|
|
30
30
|
module.exports = async ({ url, browserless, opts }) => {
|
|
31
31
|
if (opts.background === 'unsplash') {
|
|
32
|
-
|
|
32
|
+
dset(opts, 'overlay.background', 'https://source.unsplash.com/random/1920x1080')
|
|
33
33
|
}
|
|
34
34
|
|
|
35
35
|
if (opts.background === 'gradient') {
|
|
36
|
-
|
|
36
|
+
dset(opts, 'overlay.background', randBackground())
|
|
37
37
|
}
|
|
38
38
|
|
|
39
39
|
if (opts.browser) {
|
|
40
|
-
|
|
40
|
+
dset(opts, 'overlay.browser', opts.browser)
|
|
41
41
|
}
|
|
42
42
|
|
|
43
43
|
if (opts.codeScheme === 'ghcolors') {
|
|
@@ -56,5 +56,5 @@ module.exports = async ({ url, browserless, opts }) => {
|
|
|
56
56
|
|
|
57
57
|
const screenshot = await browserless.screenshot(url, opts)
|
|
58
58
|
|
|
59
|
-
return termImg(screenshot, { width: '50%' })
|
|
59
|
+
return [screenshot, termImg(Buffer.from(screenshot), { width: '50%' })]
|
|
60
60
|
}
|
package/src/commands/status.js
CHANGED
package/src/commands/text.js
CHANGED
package/src/index.js
CHANGED
|
@@ -2,65 +2,63 @@
|
|
|
2
2
|
|
|
3
3
|
'use strict'
|
|
4
4
|
|
|
5
|
+
const restoreCursor = require('restore-cursor')
|
|
5
6
|
const createBrowser = require('browserless')
|
|
6
7
|
const beautyError = require('beauty-error')
|
|
7
8
|
const { onExit } = require('signal-exit')
|
|
8
9
|
const path = require('path')
|
|
10
|
+
const mri = require('mri')
|
|
9
11
|
const fs = require('fs')
|
|
10
12
|
|
|
11
13
|
const commands = fs.readdirSync(path.resolve(__dirname, 'commands'))
|
|
12
14
|
|
|
13
|
-
const {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
flags: {
|
|
19
|
-
headless: {
|
|
20
|
-
type: 'boolean',
|
|
21
|
-
default: HEADLESS !== undefined ? HEADLESS === 'true' : true
|
|
22
|
-
},
|
|
23
|
-
codeScheme: {
|
|
24
|
-
type: 'string',
|
|
25
|
-
default: 'ghcolors'
|
|
26
|
-
},
|
|
27
|
-
verbose: {
|
|
28
|
-
type: 'boolean',
|
|
29
|
-
default: true
|
|
30
|
-
}
|
|
15
|
+
const { _, ...flags } = mri(process.argv.slice(2), {
|
|
16
|
+
boolean: ['headless', 'verbose'],
|
|
17
|
+
default: {
|
|
18
|
+
headless: 'new',
|
|
19
|
+
codeScheme: 'ghcolors'
|
|
31
20
|
}
|
|
32
21
|
})
|
|
33
22
|
|
|
23
|
+
const cli = {
|
|
24
|
+
flags,
|
|
25
|
+
input: _,
|
|
26
|
+
showHelp: () => {
|
|
27
|
+
console.log(require('./help')(commands))
|
|
28
|
+
process.exit(0)
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
|
|
34
32
|
const { verbose, headless } = cli.flags
|
|
35
33
|
|
|
36
34
|
const spinner = verbose ? require('./spinner') : { start: () => {}, stop: () => {} }
|
|
37
35
|
|
|
36
|
+
process.on('SIGINT', () => {
|
|
37
|
+
spinner.stop({ force: true })
|
|
38
|
+
process.exit(1)
|
|
39
|
+
})
|
|
40
|
+
|
|
38
41
|
const run = async () => {
|
|
39
42
|
if (cli.input.length === 0) return cli.showHelp()
|
|
40
43
|
spinner.start()
|
|
41
44
|
const [command, rawUrl] = cli.input
|
|
42
45
|
const url = new URL(rawUrl).toString()
|
|
43
46
|
const fn = require(`./commands/${command}`)
|
|
44
|
-
|
|
45
47
|
const browser = createBrowser({ headless })
|
|
46
|
-
const browserless = await browser.createContext()
|
|
47
|
-
|
|
48
48
|
onExit(browser.close)
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
return result
|
|
49
|
+
const browserless = await browser.createContext()
|
|
50
|
+
return fn({ url, browserless, opts: cli.flags })
|
|
53
51
|
}
|
|
54
52
|
|
|
55
53
|
run()
|
|
56
|
-
.then(result => {
|
|
57
|
-
|
|
58
|
-
if (
|
|
59
|
-
if (stats) console.error(`\n${stats}`)
|
|
54
|
+
.then(([result, preview = result]) => {
|
|
55
|
+
spinner.stop({ result })
|
|
56
|
+
if (typeof preview === 'string') console.log(preview)
|
|
60
57
|
process.exit()
|
|
61
58
|
})
|
|
62
59
|
.catch(error => {
|
|
63
|
-
spinner.
|
|
60
|
+
spinner.clear()
|
|
61
|
+
restoreCursor()
|
|
64
62
|
console.error(beautyError(error))
|
|
65
63
|
process.exit(1)
|
|
66
64
|
})
|
package/src/spinner.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
'use strict'
|
|
2
2
|
|
|
3
3
|
const createProcStats = require('process-stats')
|
|
4
|
+
const { createSpinner } = require('nanospinner')
|
|
4
5
|
const prettyBytes = require('pretty-bytes')
|
|
5
6
|
const { gray } = require('picocolors')
|
|
6
|
-
const ora = require('ora')
|
|
7
7
|
|
|
8
|
-
const TICK_INTERVAL =
|
|
8
|
+
const TICK_INTERVAL = 50
|
|
9
9
|
const procStats = createProcStats({ tick: TICK_INTERVAL })
|
|
10
10
|
|
|
11
11
|
const stats = () => {
|
|
@@ -13,31 +13,32 @@ const stats = () => {
|
|
|
13
13
|
const time = `time${gray(`=${uptime.pretty}`)}`
|
|
14
14
|
const cpu = `cpu${gray(`=${cpuUsage.pretty}`)}`
|
|
15
15
|
const memory = `memory${gray(`=${memUsed.pretty}`)}`
|
|
16
|
-
|
|
17
16
|
return `${time} ${cpu} ${memory}`
|
|
18
17
|
}
|
|
19
18
|
|
|
20
|
-
const spinner =
|
|
21
|
-
|
|
22
|
-
})
|
|
23
|
-
let timer
|
|
19
|
+
const spinner = createSpinner(stats(), { color: 'white' })
|
|
20
|
+
let interval
|
|
24
21
|
|
|
25
22
|
const start = () => {
|
|
26
23
|
console.log()
|
|
27
|
-
spinner.start()
|
|
28
|
-
|
|
29
|
-
timer = setInterval(() => {
|
|
30
|
-
spinner.text = stats()
|
|
31
|
-
}, TICK_INTERVAL)
|
|
24
|
+
spinner.start({ text: stats() })
|
|
25
|
+
interval = setInterval(() => spinner.update({ text: stats() }), TICK_INTERVAL)
|
|
32
26
|
}
|
|
33
27
|
|
|
34
|
-
const stop = (
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
28
|
+
const stop = ({ result, force = false } = {}) => {
|
|
29
|
+
if (force) {
|
|
30
|
+
spinner.error({ text: stats() })
|
|
31
|
+
} else {
|
|
32
|
+
const sizeValue = `=${prettyBytes(Buffer.from(result).length)}`
|
|
33
|
+
const text = `${stats()} size=${gray(sizeValue)}\n`
|
|
34
|
+
spinner.success({ text })
|
|
35
|
+
}
|
|
39
36
|
procStats.destroy()
|
|
40
|
-
|
|
37
|
+
clearInterval(interval)
|
|
41
38
|
}
|
|
42
39
|
|
|
43
|
-
module.exports = {
|
|
40
|
+
module.exports = {
|
|
41
|
+
...spinner,
|
|
42
|
+
start,
|
|
43
|
+
stop
|
|
44
|
+
}
|