@microlink/cli 2.1.1 → 2.1.3
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/bin/microlink-beta +11 -0
- package/bin/microlink-dev +12 -0
- package/bin/microlink-next +11 -0
- package/bin/microlink-vercel +5 -0
- package/package.json +7 -7
- package/src/api.js +17 -45
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
const cli = require('../src/cli')
|
|
4
|
+
cli.flags.endpoint = 'https://beta.microlink.io'
|
|
5
|
+
delete cli.flags.apiKey
|
|
6
|
+
|
|
7
|
+
require('../src/api')(cli, {
|
|
8
|
+
headers: {
|
|
9
|
+
authorization: require('../../api/src/constant').MICROLINK_API_AUTHORIZATION
|
|
10
|
+
}
|
|
11
|
+
})
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
const cli = require('../src/cli')
|
|
4
|
+
cli.flags.endpoint = 'http://localhost:3000'
|
|
5
|
+
delete cli.flags.apiKey
|
|
6
|
+
|
|
7
|
+
require('../src/api')(cli, {
|
|
8
|
+
retry: 0,
|
|
9
|
+
headers: {
|
|
10
|
+
authorization: require('../../api/src/constant').MICROLINK_API_AUTHORIZATION
|
|
11
|
+
}
|
|
12
|
+
})
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
const cli = require('../src/cli')
|
|
4
|
+
cli.flags.endpoint = 'https://next.microlink.io'
|
|
5
|
+
delete cli.flags.apiKey
|
|
6
|
+
|
|
7
|
+
require('../src/api')(cli, {
|
|
8
|
+
headers: {
|
|
9
|
+
authorization: require('../../api/src/constant').MICROLINK_API_AUTHORIZATION
|
|
10
|
+
}
|
|
11
|
+
})
|
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.3",
|
|
6
6
|
"main": "src/index.js",
|
|
7
7
|
"bin": {
|
|
8
8
|
"microlink": "bin/microlink"
|
|
@@ -33,9 +33,8 @@
|
|
|
33
33
|
"dependencies": {
|
|
34
34
|
"@microlink/mql": "~0.10.26",
|
|
35
35
|
"clipboardy": "~2.3.0",
|
|
36
|
-
"escape-string-regexp": "~4.0.0",
|
|
37
|
-
"got": "~11.8.5",
|
|
38
36
|
"jsome": "~2.5.0",
|
|
37
|
+
"localhost-url-regex": "~1.0.4",
|
|
39
38
|
"meow": "~9.0.0",
|
|
40
39
|
"ora": "~5.4.0",
|
|
41
40
|
"picocolors": "~1.0.0",
|
|
@@ -49,11 +48,12 @@
|
|
|
49
48
|
"devDependencies": {
|
|
50
49
|
"@commitlint/cli": "latest",
|
|
51
50
|
"@commitlint/config-conventional": "latest",
|
|
51
|
+
"ava": "latest",
|
|
52
|
+
"c8": "latest",
|
|
52
53
|
"ci-publish": "latest",
|
|
53
54
|
"conventional-github-releaser": "latest",
|
|
54
55
|
"finepack": "latest",
|
|
55
56
|
"git-authors-cli": "latest",
|
|
56
|
-
"git-dirty": "latest",
|
|
57
57
|
"nano-staged": "latest",
|
|
58
58
|
"npm-check-updates": "latest",
|
|
59
59
|
"prettier-standard": "latest",
|
|
@@ -71,15 +71,15 @@
|
|
|
71
71
|
],
|
|
72
72
|
"scripts": {
|
|
73
73
|
"clean": "rm -rf node_modules",
|
|
74
|
-
"contributors": "(git-authors-cli && finepack && git add package.json && git commit -m 'build: contributors' --no-verify) || true",
|
|
74
|
+
"contributors": "(npx git-authors-cli && npx finepack && git add package.json && git commit -m 'build: contributors' --no-verify) || true",
|
|
75
75
|
"lint": "standard-markdown README.md && standard",
|
|
76
76
|
"postrelease": "npm run release:tags && npm run release:github && (ci-publish || npm publish --access=public)",
|
|
77
|
-
"prerelease": "npm run update:check
|
|
77
|
+
"prerelease": "npm run update:check",
|
|
78
78
|
"pretest": "npm run lint",
|
|
79
79
|
"release": "standard-version -a",
|
|
80
80
|
"release:github": "conventional-github-releaser -p angular",
|
|
81
81
|
"release:tags": "git push --follow-tags origin HEAD:master",
|
|
82
|
-
"test": "
|
|
82
|
+
"test": "c8 ava",
|
|
83
83
|
"update": "ncu -u",
|
|
84
84
|
"update:check": "ncu -- --error-level 2"
|
|
85
85
|
},
|
package/src/api.js
CHANGED
|
@@ -4,48 +4,27 @@
|
|
|
4
4
|
|
|
5
5
|
require('update-notifier')({ pkg: require('../package.json') }).notify()
|
|
6
6
|
|
|
7
|
-
const
|
|
7
|
+
const localhostUrl = require('localhost-url-regex')
|
|
8
8
|
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
12
|
const colors = require('picocolors')
|
|
13
13
|
const temp = require('temperment')
|
|
14
|
-
const got = require('got')
|
|
15
14
|
const fs = require('fs')
|
|
16
15
|
const os = require('os')
|
|
17
16
|
|
|
18
17
|
const print = require('./print')
|
|
19
18
|
const exit = require('./exit')
|
|
20
19
|
|
|
21
|
-
const
|
|
22
|
-
'api.microlink.io',
|
|
23
|
-
'next.microlink.io',
|
|
24
|
-
'pro.microlink.io',
|
|
25
|
-
'localhost:3000'
|
|
26
|
-
].reduce(
|
|
27
|
-
(acc, endpoint) => [
|
|
28
|
-
...acc,
|
|
29
|
-
escapeStringRegexp(`http://${endpoint}`),
|
|
30
|
-
escapeStringRegexp(`https://${endpoint}`)
|
|
31
|
-
],
|
|
32
|
-
[]
|
|
33
|
-
)
|
|
34
|
-
|
|
35
|
-
const createEndpointRegex = endpoints =>
|
|
36
|
-
new RegExp(`^(${endpoints.map(endpoint => endpoint).join('|')})`, 'i')
|
|
37
|
-
|
|
38
|
-
const sanetizeInput = (input, endpoint) => {
|
|
39
|
-
if (!input) return input
|
|
40
|
-
const difference = ALL_ENDPOINTS.filter(elem => ![endpoint].includes(elem))
|
|
41
|
-
const endpointRegex = createEndpointRegex(difference)
|
|
42
|
-
return input.replace(/^url=/, '').replace(endpointRegex, endpoint)
|
|
43
|
-
}
|
|
20
|
+
const microlinkUrl = () => /^https?.*\.microlink\.io/gi
|
|
44
21
|
|
|
45
|
-
const
|
|
46
|
-
if (input
|
|
47
|
-
|
|
48
|
-
|
|
22
|
+
const normalizeInput = input => {
|
|
23
|
+
if (!input) return input
|
|
24
|
+
;[microlinkUrl, localhostUrl].forEach(
|
|
25
|
+
regex => (input = input.replace(regex(), ''))
|
|
26
|
+
)
|
|
27
|
+
return input.replace(/^\??url=/, '')
|
|
49
28
|
}
|
|
50
29
|
|
|
51
30
|
const getInput = input => {
|
|
@@ -53,31 +32,22 @@ const getInput = input => {
|
|
|
53
32
|
return collection.reduce((acc, item) => acc + item.trim(), '')
|
|
54
33
|
}
|
|
55
34
|
|
|
56
|
-
const
|
|
35
|
+
const toPlainObject = input => Object.fromEntries(new URLSearchParams(input))
|
|
57
36
|
|
|
58
37
|
const fetch = async (cli, gotOpts) => {
|
|
59
38
|
const { pretty, color, copy, endpoint, ...flags } = cli.flags
|
|
60
39
|
const input = getInput(cli.input, endpoint)
|
|
61
|
-
const
|
|
62
|
-
const prefixedInput = prefixInput(sanetizedInput, endpoint)
|
|
63
|
-
const { url, ...queryParams } = toHeaders(prefixedInput)
|
|
40
|
+
const { url, ...queryParams } = toPlainObject(`url=${normalizeInput(input)}`)
|
|
64
41
|
const mqlOpts = { endpoint, ...queryParams, ...flags }
|
|
65
42
|
const spinner = print.spinner()
|
|
66
43
|
|
|
67
44
|
try {
|
|
68
45
|
console.log()
|
|
69
46
|
spinner.start()
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
return { body, response }
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
const response = await got(endpoint, mqlOpts)
|
|
78
|
-
return { response, body: response.body }
|
|
79
|
-
})()
|
|
80
|
-
|
|
47
|
+
const { body, response } = await mql.buffer(url, mqlOpts, {
|
|
48
|
+
retry: 0,
|
|
49
|
+
...gotOpts
|
|
50
|
+
})
|
|
81
51
|
spinner.stop()
|
|
82
52
|
return { body, response, flags: { copy, pretty } }
|
|
83
53
|
} catch (error) {
|
|
@@ -93,7 +63,7 @@ const render = ({ body, response, flags }) => {
|
|
|
93
63
|
|
|
94
64
|
const contentType = headers['content-type'].toLowerCase()
|
|
95
65
|
const time = prettyMs(timings.phases.total)
|
|
96
|
-
const serverTiming = headers['
|
|
66
|
+
const serverTiming = headers['server-timing']
|
|
97
67
|
const id = headers['x-request-id']
|
|
98
68
|
|
|
99
69
|
const printMode = (() => {
|
|
@@ -187,3 +157,5 @@ const render = ({ body, response, flags }) => {
|
|
|
187
157
|
|
|
188
158
|
module.exports = (cli, gotOpts = {}) =>
|
|
189
159
|
exit(fetch(cli, gotOpts).then(render), cli)
|
|
160
|
+
|
|
161
|
+
module.exports.normalizeInput = normalizeInput
|