@microlink/cli 2.1.47 → 2.1.49
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 +1 -2
- package/src/api.js +8 -14
- package/src/cli.js +1 -2
- package/src/colors.js +18 -0
- package/src/exit.js +6 -10
- package/src/help.js +1 -1
- package/src/print.js +5 -5
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://github.com/microlinkhq/cli",
|
|
5
|
-
"version": "2.1.
|
|
5
|
+
"version": "2.1.49",
|
|
6
6
|
"main": "src/index.js",
|
|
7
7
|
"bin": {
|
|
8
8
|
"microlink": "bin/microlink",
|
|
@@ -40,7 +40,6 @@
|
|
|
40
40
|
"jsome": "~2.5.0",
|
|
41
41
|
"mri": "~1.2.0",
|
|
42
42
|
"nanospinner": "~1.2.2",
|
|
43
|
-
"picocolors": "~1.1.1",
|
|
44
43
|
"pretty-bytes": "5",
|
|
45
44
|
"pretty-ms": "~7.0.1",
|
|
46
45
|
"restore-cursor": "~3.1.0",
|
package/src/api.js
CHANGED
|
@@ -9,11 +9,11 @@ const { URLSearchParams } = require('url')
|
|
|
9
9
|
const clipboardy = require('clipboardy')
|
|
10
10
|
const mql = require('@microlink/mql')
|
|
11
11
|
const prettyMs = require('pretty-ms')
|
|
12
|
-
const colors = require('picocolors')
|
|
13
12
|
const temp = require('temperment')
|
|
14
13
|
const fs = require('fs')
|
|
15
14
|
const os = require('os')
|
|
16
15
|
|
|
16
|
+
const { gray, green } = require('./colors')
|
|
17
17
|
const print = require('./print')
|
|
18
18
|
const exit = require('./exit')
|
|
19
19
|
|
|
@@ -113,36 +113,30 @@ const render = ({ response, flags }) => {
|
|
|
113
113
|
console.error()
|
|
114
114
|
console.error(
|
|
115
115
|
print.label('success', 'green'),
|
|
116
|
-
|
|
116
|
+
gray(`${print.bytes(size)} in ${time}`)
|
|
117
117
|
)
|
|
118
118
|
console.error()
|
|
119
119
|
|
|
120
120
|
if (serverTiming) {
|
|
121
|
-
console.error(' ', print.keyValue(
|
|
121
|
+
console.error(' ', print.keyValue(green('timing'), serverTiming))
|
|
122
122
|
}
|
|
123
123
|
|
|
124
124
|
if (cacheStatus) {
|
|
125
125
|
console.error(
|
|
126
126
|
' ',
|
|
127
|
-
print.keyValue(
|
|
128
|
-
colors.green('cache'),
|
|
129
|
-
`${cacheStatus} ${colors.gray(expiredAt)}`
|
|
130
|
-
)
|
|
127
|
+
print.keyValue(green('cache'), `${cacheStatus} ${gray(expiredAt)}`)
|
|
131
128
|
)
|
|
132
129
|
}
|
|
133
130
|
|
|
134
131
|
if (fetchMode) {
|
|
135
132
|
console.error(
|
|
136
133
|
' ',
|
|
137
|
-
print.keyValue(
|
|
138
|
-
colors.green('mode'),
|
|
139
|
-
`${fetchMode} ${colors.gray(fetchTime)}`
|
|
140
|
-
)
|
|
134
|
+
print.keyValue(green('mode'), `${fetchMode} ${gray(fetchTime)}`)
|
|
141
135
|
)
|
|
142
136
|
}
|
|
143
137
|
|
|
144
|
-
console.error(' ', print.keyValue(
|
|
145
|
-
console.error(' ', print.keyValue(
|
|
138
|
+
console.error(' ', print.keyValue(green('uri'), uri))
|
|
139
|
+
console.error(' ', print.keyValue(green('id'), id))
|
|
146
140
|
|
|
147
141
|
if (flags.copy) {
|
|
148
142
|
let copiedValue
|
|
@@ -152,7 +146,7 @@ const render = ({ response, flags }) => {
|
|
|
152
146
|
copiedValue = body
|
|
153
147
|
}
|
|
154
148
|
clipboardy.writeSync(JSON.stringify(copiedValue, null, 2))
|
|
155
|
-
console.error(`\n ${
|
|
149
|
+
console.error(`\n ${gray('Copied to clipboard!')}`)
|
|
156
150
|
}
|
|
157
151
|
}
|
|
158
152
|
|
package/src/cli.js
CHANGED
package/src/colors.js
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
const { styleText } = require('node:util')
|
|
4
|
+
|
|
5
|
+
const gray = str => styleText('gray', str)
|
|
6
|
+
|
|
7
|
+
const white = str => styleText('white', str)
|
|
8
|
+
|
|
9
|
+
const green = str => styleText('green', str)
|
|
10
|
+
|
|
11
|
+
const red = str => styleText('red', str)
|
|
12
|
+
|
|
13
|
+
const yellow = str => styleText('yellow', str)
|
|
14
|
+
|
|
15
|
+
const label = (text, color) =>
|
|
16
|
+
styleText(['inverse', 'bold', color], ` ${text.toUpperCase()} `)
|
|
17
|
+
|
|
18
|
+
module.exports = { gray, white, green, red, yellow, label }
|
package/src/exit.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
'use strict'
|
|
2
2
|
|
|
3
|
-
const
|
|
3
|
+
const { gray, red } = require('./colors')
|
|
4
4
|
|
|
5
5
|
const print = require('./print')
|
|
6
6
|
|
|
@@ -15,31 +15,27 @@ module.exports = async (promise, { flags }) => {
|
|
|
15
15
|
console.log(
|
|
16
16
|
' ',
|
|
17
17
|
print.label((error.status || 'fail').toUpperCase(), 'red'),
|
|
18
|
-
|
|
18
|
+
gray(error.message.replace(`${error.code}, `, ''))
|
|
19
19
|
)
|
|
20
20
|
console.log()
|
|
21
21
|
if (error.data) {
|
|
22
22
|
console.log(print.keyValue(' ', JSON.stringify(error.data)))
|
|
23
23
|
console.log()
|
|
24
24
|
}
|
|
25
|
-
id && console.log(' ', print.keyValue(
|
|
26
|
-
error.url &&
|
|
27
|
-
console.log(' ', print.keyValue(colors.red('uri'), error.url))
|
|
25
|
+
id && console.log(' ', print.keyValue(red('id'), id))
|
|
26
|
+
error.url && console.log(' ', print.keyValue(red('uri'), error.url))
|
|
28
27
|
error.code &&
|
|
29
28
|
console.log(
|
|
30
29
|
' ',
|
|
31
30
|
print.keyValue(
|
|
32
|
-
|
|
31
|
+
red('code'),
|
|
33
32
|
`${error.code} ${error.statusCode ? `(${error.statusCode})` : ''}`
|
|
34
33
|
)
|
|
35
34
|
)
|
|
36
35
|
error.more &&
|
|
37
36
|
console.log(
|
|
38
37
|
' ',
|
|
39
|
-
print.keyValue(
|
|
40
|
-
colors.red('more'),
|
|
41
|
-
print.link('click to report', error.more)
|
|
42
|
-
)
|
|
38
|
+
print.keyValue(red('more'), print.link('click to report', error.more))
|
|
43
39
|
)
|
|
44
40
|
|
|
45
41
|
process.exit(1)
|
package/src/help.js
CHANGED
package/src/print.js
CHANGED
|
@@ -5,10 +5,11 @@ const restoreCursor = require('restore-cursor')
|
|
|
5
5
|
const terminalLink = require('terminal-link')
|
|
6
6
|
const prettyBytes = require('pretty-bytes')
|
|
7
7
|
const prettyMs = require('pretty-ms')
|
|
8
|
-
const colors = require('picocolors')
|
|
9
8
|
const termImg = require('term-img')
|
|
10
9
|
const jsome = require('jsome')
|
|
11
10
|
|
|
11
|
+
const { gray, yellow, label } = require('./colors')
|
|
12
|
+
|
|
12
13
|
const TICK_INTERVAL = 50
|
|
13
14
|
|
|
14
15
|
jsome.colors = {
|
|
@@ -55,19 +56,18 @@ module.exports = {
|
|
|
55
56
|
json: (payload, { color: colorize = true } = {}) =>
|
|
56
57
|
colorize ? jsome(payload) : console.log(payload),
|
|
57
58
|
|
|
58
|
-
label
|
|
59
|
-
colors.inverse(colors.bold(colors[color](` ${text.toUpperCase()} `))),
|
|
59
|
+
label,
|
|
60
60
|
|
|
61
61
|
bytes: prettyBytes,
|
|
62
62
|
|
|
63
|
-
keyValue: (key, value) => key + ' ' +
|
|
63
|
+
keyValue: (key, value) => key + ' ' + gray(value),
|
|
64
64
|
|
|
65
65
|
image: filepath =>
|
|
66
66
|
console.log(
|
|
67
67
|
termImg(filepath, {
|
|
68
68
|
width: '50%',
|
|
69
69
|
fallback: () =>
|
|
70
|
-
`\n${
|
|
70
|
+
`\n${yellow(' tip:')} ${gray(
|
|
71
71
|
'use iTerm >=3 to see the image here!'
|
|
72
72
|
)}`
|
|
73
73
|
})
|