@browserless/cli 9.9.8 → 9.10.0
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/LICENSE.md +21 -0
- package/package.json +4 -3
- 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 +1 -1
- package/src/commands/status.js +1 -1
- package/src/commands/text.js +1 -1
- package/src/index.js +14 -16
- package/src/spinner.js +18 -15
package/LICENSE.md
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright © 2019 Microlink <hello@microlink.io> (microlink.io)
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
|
13
|
+
all copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
21
|
+
THE SOFTWARE.
|
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.0",
|
|
6
6
|
"bin": {
|
|
7
7
|
"browserless": "src/index.js"
|
|
8
8
|
},
|
|
@@ -36,10 +36,11 @@
|
|
|
36
36
|
"dark-mode": "~3.0.0",
|
|
37
37
|
"lodash": "~4.17.21",
|
|
38
38
|
"meow": "~9.0.0",
|
|
39
|
-
"
|
|
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": "c7e170ee4c1ab15de1031d9e6f7af4f04b7a03ab"
|
|
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
package/src/commands/status.js
CHANGED
package/src/commands/text.js
CHANGED
package/src/index.js
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
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')
|
|
@@ -10,15 +11,12 @@ const fs = require('fs')
|
|
|
10
11
|
|
|
11
12
|
const commands = fs.readdirSync(path.resolve(__dirname, 'commands'))
|
|
12
13
|
|
|
13
|
-
const { HEADLESS } = process.env
|
|
14
|
-
|
|
15
14
|
const cli = require('meow')({
|
|
16
15
|
pkg: require('../package.json'),
|
|
17
16
|
help: require('./help')(commands),
|
|
18
17
|
flags: {
|
|
19
18
|
headless: {
|
|
20
|
-
|
|
21
|
-
default: HEADLESS !== undefined ? HEADLESS === 'true' : true
|
|
19
|
+
default: 'new'
|
|
22
20
|
},
|
|
23
21
|
codeScheme: {
|
|
24
22
|
type: 'string',
|
|
@@ -35,32 +33,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,9 +1,9 @@
|
|
|
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
8
|
const TICK_INTERVAL = 100
|
|
9
9
|
const procStats = createProcStats({ tick: TICK_INTERVAL })
|
|
@@ -13,31 +13,34 @@ 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
|
-
color: 'white'
|
|
22
|
-
})
|
|
19
|
+
const spinner = createSpinner(stats(), { color: 'white' })
|
|
23
20
|
let timer
|
|
24
21
|
|
|
25
22
|
const start = () => {
|
|
26
23
|
console.log()
|
|
27
|
-
spinner.start()
|
|
28
|
-
|
|
24
|
+
spinner.start(stats())
|
|
29
25
|
timer = setInterval(() => {
|
|
30
|
-
spinner.text
|
|
26
|
+
spinner.update({ text: stats() })
|
|
31
27
|
}, TICK_INTERVAL)
|
|
32
28
|
}
|
|
33
29
|
|
|
34
|
-
const stop = (
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
30
|
+
const stop = ({ result, force = false } = {}) => {
|
|
31
|
+
if (force) {
|
|
32
|
+
spinner.error({ text: stats() })
|
|
33
|
+
} else {
|
|
34
|
+
const sizeValue = `=${prettyBytes(Buffer.from(result).length)}`
|
|
35
|
+
const text = `${stats()} size=${gray(sizeValue)}\n`
|
|
36
|
+
spinner.success({ text })
|
|
37
|
+
}
|
|
39
38
|
procStats.destroy()
|
|
40
|
-
|
|
39
|
+
clearInterval(timer)
|
|
41
40
|
}
|
|
42
41
|
|
|
43
|
-
module.exports = {
|
|
42
|
+
module.exports = {
|
|
43
|
+
...spinner,
|
|
44
|
+
start,
|
|
45
|
+
stop
|
|
46
|
+
}
|