@microlink/cli 2.0.15 → 2.1.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/package.json +1 -1
- package/src/api.js +17 -8
package/package.json
CHANGED
package/src/api.js
CHANGED
|
@@ -90,9 +90,12 @@ const fetch = async (cli, gotOpts) => {
|
|
|
90
90
|
const render = ({ body, response, flags }) => {
|
|
91
91
|
const { headers, timings, requestUrl: uri } = response
|
|
92
92
|
if (!flags.pretty) return console.log(body.toString())
|
|
93
|
-
|
|
93
|
+
|
|
94
94
|
const contentType = headers['content-type'].toLowerCase()
|
|
95
|
+
const time = prettyMs(timings.end - timings.start)
|
|
96
|
+
const serverTiming = headers['server-timing']
|
|
95
97
|
const id = headers['x-request-id']
|
|
98
|
+
|
|
96
99
|
const printMode = (() => {
|
|
97
100
|
if (body.toString().startsWith('data:')) return 'base64'
|
|
98
101
|
if (!contentType.includes('utf')) return 'image'
|
|
@@ -112,7 +115,8 @@ const render = ({ body, response, flags }) => {
|
|
|
112
115
|
break
|
|
113
116
|
default: {
|
|
114
117
|
const isText = contentType.includes('text/plain')
|
|
115
|
-
const
|
|
118
|
+
const isHtml = contentType.includes('text/html')
|
|
119
|
+
const output = isText || isHtml ? body.toString() : JSON.parse(body)
|
|
116
120
|
print.json(output, flags)
|
|
117
121
|
break
|
|
118
122
|
}
|
|
@@ -134,6 +138,7 @@ const render = ({ body, response, flags }) => {
|
|
|
134
138
|
const fetchMode = headers['x-fetch-mode']
|
|
135
139
|
const fetchTime = fetchMode && `(${headers['x-fetch-time']})`
|
|
136
140
|
const size = Number(headers['content-length'] || Buffer.byteLength(body))
|
|
141
|
+
|
|
137
142
|
console.log()
|
|
138
143
|
console.log(
|
|
139
144
|
print.label('success', 'green'),
|
|
@@ -141,28 +146,32 @@ const render = ({ body, response, flags }) => {
|
|
|
141
146
|
)
|
|
142
147
|
console.log()
|
|
143
148
|
|
|
149
|
+
if (serverTiming) {
|
|
150
|
+
console.log(' ', print.keyValue(colors.green('timing'), serverTiming))
|
|
151
|
+
}
|
|
152
|
+
|
|
144
153
|
if (cacheStatus) {
|
|
145
154
|
console.log(
|
|
146
|
-
'',
|
|
155
|
+
' ',
|
|
147
156
|
print.keyValue(
|
|
148
157
|
colors.green('cache'),
|
|
149
|
-
`${cacheStatus
|
|
158
|
+
`${cacheStatus} ${colors.gray(expiredAt)}`
|
|
150
159
|
)
|
|
151
160
|
)
|
|
152
161
|
}
|
|
153
162
|
|
|
154
163
|
if (fetchMode) {
|
|
155
164
|
console.log(
|
|
156
|
-
'',
|
|
165
|
+
' ',
|
|
157
166
|
print.keyValue(
|
|
158
|
-
colors.green('
|
|
167
|
+
colors.green('mode'),
|
|
159
168
|
`${fetchMode} ${colors.gray(fetchTime)}`
|
|
160
169
|
)
|
|
161
170
|
)
|
|
162
171
|
}
|
|
163
172
|
|
|
164
|
-
console.log(
|
|
165
|
-
console.log(
|
|
173
|
+
console.log(' ', print.keyValue(colors.green('uri'), uri))
|
|
174
|
+
console.log(' ', print.keyValue(colors.green('id'), id))
|
|
166
175
|
|
|
167
176
|
if (flags.copy) {
|
|
168
177
|
let copiedValue
|