@microlink/cli 2.1.4 → 2.1.5
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/package.json +3 -2
- package/src/api.js +9 -10
- package/src/print.js +17 -13
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "@microlink/cli",
|
|
3
3
|
"description": "Interacting with Microlink API from your terminal.",
|
|
4
4
|
"homepage": "https://nicedoc.io/microlinkhq/cli",
|
|
5
|
-
"version": "2.1.
|
|
5
|
+
"version": "2.1.5",
|
|
6
6
|
"main": "src/index.js",
|
|
7
7
|
"bin": {
|
|
8
8
|
"microlink": "bin/microlink"
|
|
@@ -36,10 +36,11 @@
|
|
|
36
36
|
"jsome": "~2.5.0",
|
|
37
37
|
"localhost-url-regex": "~1.0.7",
|
|
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
|
"pretty-ms": "~7.0.1",
|
|
43
|
+
"restore-cursor": "~3.1.0",
|
|
43
44
|
"temperment": "~1.0.0",
|
|
44
45
|
"term-img": "~5.0.0",
|
|
45
46
|
"terminal-link": "~2.1.1",
|
package/src/api.js
CHANGED
|
@@ -42,7 +42,6 @@ const fetch = async (cli, gotOpts) => {
|
|
|
42
42
|
const spinner = print.spinner()
|
|
43
43
|
|
|
44
44
|
try {
|
|
45
|
-
console.log()
|
|
46
45
|
spinner.start()
|
|
47
46
|
const { body, response } = await mql.buffer(url, mqlOpts, {
|
|
48
47
|
retry: 0,
|
|
@@ -109,19 +108,19 @@ const render = ({ body, response, flags }) => {
|
|
|
109
108
|
const fetchTime = fetchMode && `(${headers['x-fetch-time']})`
|
|
110
109
|
const size = Number(headers['content-length'] || Buffer.byteLength(body))
|
|
111
110
|
|
|
112
|
-
console.
|
|
113
|
-
console.
|
|
111
|
+
console.error()
|
|
112
|
+
console.error(
|
|
114
113
|
print.label('success', 'green'),
|
|
115
114
|
colors.gray(`${print.bytes(size)} in ${time}`)
|
|
116
115
|
)
|
|
117
|
-
console.
|
|
116
|
+
console.error()
|
|
118
117
|
|
|
119
118
|
if (serverTiming) {
|
|
120
|
-
console.
|
|
119
|
+
console.error(' ', print.keyValue(colors.green('timing'), serverTiming))
|
|
121
120
|
}
|
|
122
121
|
|
|
123
122
|
if (cacheStatus) {
|
|
124
|
-
console.
|
|
123
|
+
console.error(
|
|
125
124
|
' ',
|
|
126
125
|
print.keyValue(
|
|
127
126
|
colors.green('cache'),
|
|
@@ -131,7 +130,7 @@ const render = ({ body, response, flags }) => {
|
|
|
131
130
|
}
|
|
132
131
|
|
|
133
132
|
if (fetchMode) {
|
|
134
|
-
console.
|
|
133
|
+
console.error(
|
|
135
134
|
' ',
|
|
136
135
|
print.keyValue(
|
|
137
136
|
colors.green('mode'),
|
|
@@ -140,8 +139,8 @@ const render = ({ body, response, flags }) => {
|
|
|
140
139
|
)
|
|
141
140
|
}
|
|
142
141
|
|
|
143
|
-
console.
|
|
144
|
-
console.
|
|
142
|
+
console.error(' ', print.keyValue(colors.green('uri'), uri))
|
|
143
|
+
console.error(' ', print.keyValue(colors.green('id'), id))
|
|
145
144
|
|
|
146
145
|
if (flags.copy) {
|
|
147
146
|
let copiedValue
|
|
@@ -151,7 +150,7 @@ const render = ({ body, response, flags }) => {
|
|
|
151
150
|
copiedValue = body
|
|
152
151
|
}
|
|
153
152
|
clipboardy.writeSync(JSON.stringify(copiedValue, null, 2))
|
|
154
|
-
console.
|
|
153
|
+
console.error(`\n ${colors.gray('Copied to clipboard!')}`)
|
|
155
154
|
}
|
|
156
155
|
}
|
|
157
156
|
|
package/src/print.js
CHANGED
|
@@ -1,12 +1,15 @@
|
|
|
1
1
|
'use strict'
|
|
2
2
|
|
|
3
|
+
const { createSpinner } = require('nanospinner')
|
|
4
|
+
const restoreCursor = require('restore-cursor')
|
|
3
5
|
const terminalLink = require('terminal-link')
|
|
4
6
|
const prettyBytes = require('pretty-bytes')
|
|
5
7
|
const prettyMs = require('pretty-ms')
|
|
6
8
|
const colors = require('picocolors')
|
|
7
9
|
const termImg = require('term-img')
|
|
8
10
|
const jsome = require('jsome')
|
|
9
|
-
|
|
11
|
+
|
|
12
|
+
const TICK_INTERVAL = 100
|
|
10
13
|
|
|
11
14
|
jsome.colors = {
|
|
12
15
|
num: 'cyan',
|
|
@@ -22,24 +25,25 @@ jsome.colors = {
|
|
|
22
25
|
}
|
|
23
26
|
|
|
24
27
|
module.exports = {
|
|
25
|
-
spinner: (
|
|
26
|
-
const spinner = ora({ color: 'white', text })
|
|
28
|
+
spinner: () => {
|
|
27
29
|
const now = Date.now()
|
|
28
|
-
const elapsedTime = () => Date.now() - now
|
|
29
|
-
|
|
30
|
+
const elapsedTime = () => prettyMs(Date.now() - now)
|
|
31
|
+
const spinner = createSpinner(elapsedTime(), { color: 'white' })
|
|
32
|
+
let timer
|
|
30
33
|
|
|
31
34
|
const start = () => {
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
35
|
+
console.error()
|
|
36
|
+
spinner.start({ text: elapsedTime() })
|
|
37
|
+
timer = setInterval(
|
|
38
|
+
() => spinner.update({ text: elapsedTime() }),
|
|
39
|
+
TICK_INTERVAL
|
|
40
|
+
)
|
|
37
41
|
}
|
|
38
42
|
|
|
39
43
|
const stop = () => {
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
44
|
+
clearInterval(timer)
|
|
45
|
+
spinner.clear()
|
|
46
|
+
restoreCursor()
|
|
43
47
|
}
|
|
44
48
|
|
|
45
49
|
return { start, stop }
|