netlify-cli 8.0.10 → 8.1.0-rc
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/run +81 -3
- package/npm-shrinkwrap.json +471 -2182
- package/package.json +12 -35
- package/src/commands/addons/addons-auth.js +50 -0
- package/src/commands/addons/addons-config.js +180 -0
- package/src/commands/addons/addons-create.js +129 -0
- package/src/commands/addons/addons-delete.js +59 -0
- package/src/commands/addons/addons-list.js +62 -0
- package/src/commands/addons/addons.js +49 -0
- package/src/commands/addons/index.js +3 -24
- package/src/commands/api/api.js +83 -0
- package/src/commands/api/index.js +5 -0
- package/src/commands/base-command.js +322 -0
- package/src/commands/build/build.js +58 -0
- package/src/commands/build/index.js +3 -61
- package/src/commands/completion/completion.js +18 -0
- package/src/commands/completion/index.js +5 -0
- package/src/commands/{deploy.js → deploy/deploy.js} +306 -278
- package/src/commands/deploy/index.js +5 -0
- package/src/commands/dev/dev-exec.js +39 -0
- package/src/commands/dev/dev-trace.js +50 -0
- package/src/commands/dev/dev.js +349 -0
- package/src/commands/dev/index.js +3 -335
- package/src/commands/env/env-get.js +51 -0
- package/src/commands/env/env-import.js +93 -0
- package/src/commands/env/env-list.js +63 -0
- package/src/commands/env/env-set.js +67 -0
- package/src/commands/env/env-unset.js +66 -0
- package/src/commands/env/env.js +47 -0
- package/src/commands/env/index.js +3 -23
- package/src/commands/functions/functions-build.js +59 -0
- package/src/commands/functions/{create.js → functions-create.js} +133 -94
- package/src/commands/functions/functions-invoke.js +276 -0
- package/src/commands/functions/functions-list.js +107 -0
- package/src/commands/functions/functions-serve.js +63 -0
- package/src/commands/functions/functions.js +53 -0
- package/src/commands/functions/index.js +3 -45
- package/src/commands/index.js +5 -0
- package/src/commands/init/index.js +6 -0
- package/src/commands/{init.js → init/init.js} +79 -68
- package/src/commands/link/index.js +6 -0
- package/src/{utils/link/link-by-prompt.js → commands/link/link.js} +153 -14
- package/src/commands/lm/index.js +3 -19
- package/src/commands/lm/lm-info.js +42 -0
- package/src/commands/lm/lm-install.js +36 -0
- package/src/commands/lm/lm-setup.js +106 -0
- package/src/commands/lm/lm-uninstall.js +25 -0
- package/src/commands/lm/lm.js +39 -0
- package/src/commands/login/index.js +6 -0
- package/src/commands/login/login.js +52 -0
- package/src/commands/logout/index.js +5 -0
- package/src/commands/logout/logout.js +43 -0
- package/src/commands/main.js +117 -0
- package/src/commands/open/index.js +3 -39
- package/src/commands/open/open-admin.js +56 -0
- package/src/commands/open/open-site.js +49 -0
- package/src/commands/open/open.js +42 -0
- package/src/commands/sites/index.js +5 -20
- package/src/commands/sites/sites-create.js +184 -0
- package/src/commands/sites/sites-delete.js +108 -0
- package/src/commands/sites/sites-list.js +89 -0
- package/src/commands/sites/sites.js +36 -0
- package/src/commands/status/index.js +3 -118
- package/src/commands/status/status-hooks.js +73 -0
- package/src/commands/status/status.js +125 -0
- package/src/commands/switch/index.js +5 -0
- package/src/commands/switch/switch.js +50 -0
- package/src/commands/unlink/index.js +5 -0
- package/src/commands/unlink/unlink.js +48 -0
- package/src/commands/watch/index.js +5 -0
- package/src/commands/watch/watch.js +121 -0
- package/src/lib/build.js +21 -7
- package/src/lib/exec-fetcher.js +5 -3
- package/src/lib/fs.js +54 -36
- package/src/lib/functions/background.js +1 -1
- package/src/lib/functions/form-submissions-handler.js +2 -1
- package/src/lib/functions/local-proxy.js +2 -1
- package/src/lib/functions/netlify-function.js +4 -1
- package/src/lib/functions/registry.js +4 -6
- package/src/lib/functions/runtimes/go/index.js +2 -1
- package/src/lib/functions/runtimes/js/builders/netlify-lambda.js +6 -4
- package/src/lib/functions/runtimes/js/builders/zisi.js +3 -3
- package/src/lib/functions/runtimes/rust/index.js +4 -3
- package/src/lib/functions/server.js +2 -3
- package/src/lib/functions/synchronous.js +2 -1
- package/src/lib/functions/utils.js +2 -3
- package/src/lib/functions/watcher.js +1 -0
- package/src/lib/http-agent.js +5 -5
- package/src/lib/log.js +2 -1
- package/src/lib/spinner.js +22 -0
- package/src/utils/addons/diffs/index.js +1 -0
- package/src/utils/addons/diffs/options.js +3 -1
- package/src/utils/addons/prepare.js +13 -6
- package/src/utils/addons/prompts.js +2 -1
- package/src/utils/addons/render.js +3 -1
- package/src/utils/command-helpers.js +156 -43
- package/src/utils/create-stream-promise.js +5 -5
- package/src/utils/deferred.js +1 -0
- package/src/utils/deploy/deploy-site.js +1 -1
- package/src/utils/deploy/index.js +4 -0
- package/src/utils/detect-server-settings.js +10 -12
- package/src/utils/dev.js +18 -10
- package/src/utils/dot-env.js +4 -2
- package/src/utils/{edge-handlers.js → functions/edge-handlers.js} +8 -7
- package/src/utils/functions/functions.js +36 -0
- package/src/utils/{get-functions.js → functions/get-functions.js} +2 -1
- package/src/utils/functions/index.js +8 -26
- package/src/utils/get-global-config.js +3 -2
- package/src/utils/get-repo-data.js +1 -0
- package/src/utils/gh-auth.js +1 -0
- package/src/utils/gitignore.js +7 -5
- package/src/utils/header.js +2 -2
- package/src/utils/headers.js +1 -2
- package/src/utils/index.js +42 -0
- package/src/utils/init/config-github.js +12 -5
- package/src/utils/init/config-manual.js +9 -2
- package/src/utils/init/config.js +13 -7
- package/src/utils/init/frameworks.js +1 -0
- package/src/utils/init/node-version.js +4 -2
- package/src/utils/init/plugins.js +1 -0
- package/src/utils/init/utils.js +10 -6
- package/src/utils/live-tunnel.js +3 -4
- package/src/utils/lm/install.js +10 -15
- package/src/utils/lm/requirements.js +3 -1
- package/src/utils/lm/steps.js +1 -1
- package/src/utils/lm/ui.js +7 -3
- package/src/utils/open-browser.js +8 -2
- package/src/utils/parse-raw-flags.js +4 -4
- package/src/utils/proxy.js +7 -5
- package/src/utils/read-repo-url.js +1 -0
- package/src/utils/redirects.js +2 -2
- package/src/utils/rules-proxy.js +4 -2
- package/src/utils/state-config.js +1 -1
- package/src/utils/telemetry/index.js +2 -113
- package/src/utils/telemetry/request.js +3 -1
- package/src/utils/telemetry/telemetry.js +117 -0
- package/src/utils/telemetry/validation.js +13 -12
- package/src/utils/traffic-mesh.js +3 -3
- package/oclif.manifest.json +0 -1
- package/src/commands/addons/auth.js +0 -42
- package/src/commands/addons/config.js +0 -177
- package/src/commands/addons/create.js +0 -127
- package/src/commands/addons/delete.js +0 -69
- package/src/commands/addons/list.js +0 -54
- package/src/commands/api.js +0 -84
- package/src/commands/dev/exec.js +0 -32
- package/src/commands/dev/trace.js +0 -61
- package/src/commands/env/get.js +0 -44
- package/src/commands/env/import.js +0 -90
- package/src/commands/env/list.js +0 -49
- package/src/commands/env/set.js +0 -64
- package/src/commands/env/unset.js +0 -58
- package/src/commands/functions/build.js +0 -60
- package/src/commands/functions/invoke.js +0 -277
- package/src/commands/functions/list.js +0 -102
- package/src/commands/functions/serve.js +0 -70
- package/src/commands/link.js +0 -133
- package/src/commands/lm/info.js +0 -36
- package/src/commands/lm/install.js +0 -30
- package/src/commands/lm/setup.js +0 -107
- package/src/commands/lm/uninstall.js +0 -17
- package/src/commands/login.js +0 -54
- package/src/commands/logout.js +0 -37
- package/src/commands/open/admin.js +0 -51
- package/src/commands/open/site.js +0 -43
- package/src/commands/sites/create.js +0 -191
- package/src/commands/sites/delete.js +0 -116
- package/src/commands/sites/list.js +0 -84
- package/src/commands/status/hooks.js +0 -60
- package/src/commands/switch.js +0 -44
- package/src/commands/unlink.js +0 -38
- package/src/commands/watch.js +0 -115
- package/src/hooks/init.js +0 -46
- package/src/index.js +0 -25
- package/src/lib/help.js +0 -26
- package/src/utils/chalk.js +0 -16
- package/src/utils/check-command-inputs.js +0 -21
- package/src/utils/command.js +0 -261
- package/src/utils/detect-functions-builder.js +0 -25
- package/src/utils/difference.js +0 -4
- package/src/utils/logo.js +0 -11
- package/src/utils/show-help.js +0 -5
- package/src/utils/telemetry/tracked-command.js +0 -51
package/src/utils/command.js
DELETED
|
@@ -1,261 +0,0 @@
|
|
|
1
|
-
const process = require('process')
|
|
2
|
-
|
|
3
|
-
const resolveConfig = require('@netlify/config')
|
|
4
|
-
const { flags: flagsLib } = require('@oclif/command')
|
|
5
|
-
const oclifParser = require('@oclif/parser')
|
|
6
|
-
const merge = require('lodash/merge')
|
|
7
|
-
|
|
8
|
-
// TODO: use static `import` after migrating this repository to pure ES modules
|
|
9
|
-
const jsClient = import('netlify')
|
|
10
|
-
|
|
11
|
-
const { getAgent } = require('../lib/http-agent')
|
|
12
|
-
|
|
13
|
-
const { argv, chalk, error, exit, getCwd, getToken, log, normalizeConfig, pollForToken } = require('./command-helpers')
|
|
14
|
-
const getGlobalConfig = require('./get-global-config')
|
|
15
|
-
const { openBrowser } = require('./open-browser')
|
|
16
|
-
const StateConfig = require('./state-config')
|
|
17
|
-
const { identify, track } = require('./telemetry')
|
|
18
|
-
const { TrackedCommand } = require('./telemetry/tracked-command')
|
|
19
|
-
|
|
20
|
-
const { NETLIFY_API_URL } = process.env
|
|
21
|
-
|
|
22
|
-
// Netlify CLI client id. Lives in bot@netlify.com
|
|
23
|
-
// Todo setup client for multiple environments
|
|
24
|
-
const CLIENT_ID = 'd6f37de6614df7ae58664cfca524744d73807a377f5ee71f1a254f78412e3750'
|
|
25
|
-
|
|
26
|
-
class BaseCommand extends TrackedCommand {
|
|
27
|
-
// Initialize context
|
|
28
|
-
async init() {
|
|
29
|
-
await super.init()
|
|
30
|
-
|
|
31
|
-
const cwd = getCwd()
|
|
32
|
-
|
|
33
|
-
const [token] = await getToken()
|
|
34
|
-
|
|
35
|
-
// Get site id & build state
|
|
36
|
-
const state = new StateConfig(cwd)
|
|
37
|
-
|
|
38
|
-
const apiUrlOpts = {
|
|
39
|
-
userAgent: this.config.userAgent,
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
if (NETLIFY_API_URL) {
|
|
43
|
-
const apiUrl = new URL(NETLIFY_API_URL)
|
|
44
|
-
apiUrlOpts.scheme = apiUrl.protocol.slice(0, -1)
|
|
45
|
-
apiUrlOpts.host = apiUrl.host
|
|
46
|
-
apiUrlOpts.pathPrefix = NETLIFY_API_URL === `${apiUrl.protocol}//${apiUrl.host}` ? '/api/v1' : apiUrl.pathname
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
const cachedConfig = await this.getConfig({ cwd, state, token, ...apiUrlOpts })
|
|
50
|
-
const { buildDir, config, configPath, repositoryRoot, siteInfo } = cachedConfig
|
|
51
|
-
const normalizedConfig = normalizeConfig(config)
|
|
52
|
-
|
|
53
|
-
const { flags } = this.parse(BaseCommand)
|
|
54
|
-
const agent = await getAgent({
|
|
55
|
-
httpProxy: flags.httpProxy,
|
|
56
|
-
certificateFile: flags.httpProxyCertificateFilename,
|
|
57
|
-
})
|
|
58
|
-
const apiOpts = { ...apiUrlOpts, agent }
|
|
59
|
-
const globalConfig = await getGlobalConfig()
|
|
60
|
-
|
|
61
|
-
const { NetlifyAPI } = await jsClient
|
|
62
|
-
this.netlify = {
|
|
63
|
-
// api methods
|
|
64
|
-
api: new NetlifyAPI(token || '', apiOpts),
|
|
65
|
-
repositoryRoot,
|
|
66
|
-
// current site context
|
|
67
|
-
site: {
|
|
68
|
-
root: buildDir,
|
|
69
|
-
configPath,
|
|
70
|
-
get id() {
|
|
71
|
-
return state.get('siteId')
|
|
72
|
-
},
|
|
73
|
-
set id(id) {
|
|
74
|
-
state.set('siteId', id)
|
|
75
|
-
},
|
|
76
|
-
},
|
|
77
|
-
// Site information retrieved using the API
|
|
78
|
-
siteInfo,
|
|
79
|
-
// Configuration from netlify.[toml/yml]
|
|
80
|
-
config: normalizedConfig,
|
|
81
|
-
// Used to avoid calling @netlify/config again
|
|
82
|
-
cachedConfig,
|
|
83
|
-
// global cli config
|
|
84
|
-
globalConfig,
|
|
85
|
-
// state of current site dir
|
|
86
|
-
state,
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
// Find and resolve the Netlify configuration
|
|
91
|
-
async getConfig({ cwd, host, offline = argv.offline || argv.o, pathPrefix, scheme, state, token }) {
|
|
92
|
-
try {
|
|
93
|
-
return await resolveConfig({
|
|
94
|
-
config: argv.config,
|
|
95
|
-
cwd,
|
|
96
|
-
context: argv.context || this.commandContext,
|
|
97
|
-
debug: argv.debug,
|
|
98
|
-
siteId: argv.siteId || (typeof argv.site === 'string' && argv.site) || state.get('siteId'),
|
|
99
|
-
token,
|
|
100
|
-
mode: 'cli',
|
|
101
|
-
host,
|
|
102
|
-
pathPrefix,
|
|
103
|
-
scheme,
|
|
104
|
-
offline,
|
|
105
|
-
})
|
|
106
|
-
} catch (error_) {
|
|
107
|
-
const isUserError = error_.customErrorInfo !== undefined && error_.customErrorInfo.type === 'resolveConfig'
|
|
108
|
-
|
|
109
|
-
// If we're failing due to an error thrown by us, it might be because the token we're using is invalid.
|
|
110
|
-
// To account for that, we try to retrieve the config again, this time without a token, to avoid making
|
|
111
|
-
// any API calls.
|
|
112
|
-
//
|
|
113
|
-
// @todo Replace this with a mechanism for calling `resolveConfig` with more granularity (i.e. having
|
|
114
|
-
// the option to say that we don't need API data.)
|
|
115
|
-
if (isUserError && !offline && token) {
|
|
116
|
-
return this.getConfig({ cwd, offline: true, state, token })
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
const message = isUserError ? error_.message : error_.stack
|
|
120
|
-
console.error(message)
|
|
121
|
-
exit(1)
|
|
122
|
-
}
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
async isLoggedIn() {
|
|
126
|
-
try {
|
|
127
|
-
await this.netlify.api.getCurrentUser()
|
|
128
|
-
return true
|
|
129
|
-
} catch {
|
|
130
|
-
return false
|
|
131
|
-
}
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
/* Modified flag parser to support global --auth, --json, & --silent flags */
|
|
135
|
-
parse(opts, args = this.argv) {
|
|
136
|
-
/* Set flags object for commands without flags */
|
|
137
|
-
if (!opts.flags) {
|
|
138
|
-
opts.flags = {}
|
|
139
|
-
}
|
|
140
|
-
/* enrich parse with global flags */
|
|
141
|
-
const globalFlags = {}
|
|
142
|
-
if (!opts.flags.silent) {
|
|
143
|
-
globalFlags.silent = {
|
|
144
|
-
parse: (value) => value,
|
|
145
|
-
description: 'Silence CLI output',
|
|
146
|
-
allowNo: false,
|
|
147
|
-
type: 'boolean',
|
|
148
|
-
}
|
|
149
|
-
}
|
|
150
|
-
if (!opts.flags.json) {
|
|
151
|
-
globalFlags.json = {
|
|
152
|
-
parse: (value) => value,
|
|
153
|
-
description: 'Output return values as JSON',
|
|
154
|
-
allowNo: false,
|
|
155
|
-
type: 'boolean',
|
|
156
|
-
}
|
|
157
|
-
}
|
|
158
|
-
if (!opts.flags.auth) {
|
|
159
|
-
globalFlags.auth = {
|
|
160
|
-
parse: (value) => value,
|
|
161
|
-
description: 'Netlify auth token',
|
|
162
|
-
input: [],
|
|
163
|
-
multiple: false,
|
|
164
|
-
type: 'option',
|
|
165
|
-
}
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
// enrich with flags here
|
|
169
|
-
opts.flags = { ...opts.flags, ...globalFlags }
|
|
170
|
-
|
|
171
|
-
return oclifParser.parse(args, {
|
|
172
|
-
context: this,
|
|
173
|
-
...opts,
|
|
174
|
-
})
|
|
175
|
-
}
|
|
176
|
-
|
|
177
|
-
async authenticate(tokenFromFlag) {
|
|
178
|
-
const [token] = await getToken(tokenFromFlag)
|
|
179
|
-
if (token) {
|
|
180
|
-
return token
|
|
181
|
-
}
|
|
182
|
-
return this.expensivelyAuthenticate()
|
|
183
|
-
}
|
|
184
|
-
|
|
185
|
-
async expensivelyAuthenticate() {
|
|
186
|
-
const webUI = process.env.NETLIFY_WEB_UI || 'https://app.netlify.com'
|
|
187
|
-
log(`Logging into your Netlify account...`)
|
|
188
|
-
|
|
189
|
-
// Create ticket for auth
|
|
190
|
-
const ticket = await this.netlify.api.createTicket({
|
|
191
|
-
clientId: CLIENT_ID,
|
|
192
|
-
})
|
|
193
|
-
|
|
194
|
-
// Open browser for authentication
|
|
195
|
-
const authLink = `${webUI}/authorize?response_type=ticket&ticket=${ticket.id}`
|
|
196
|
-
|
|
197
|
-
log(`Opening ${authLink}`)
|
|
198
|
-
await openBrowser({ url: authLink })
|
|
199
|
-
|
|
200
|
-
const accessToken = await pollForToken({
|
|
201
|
-
api: this.netlify.api,
|
|
202
|
-
ticket,
|
|
203
|
-
exitWithError: error,
|
|
204
|
-
})
|
|
205
|
-
|
|
206
|
-
const { email, full_name: name, id: userId } = await this.netlify.api.getCurrentUser()
|
|
207
|
-
|
|
208
|
-
const userData = merge(this.netlify.globalConfig.get(`users.${userId}`), {
|
|
209
|
-
id: userId,
|
|
210
|
-
name,
|
|
211
|
-
email,
|
|
212
|
-
auth: {
|
|
213
|
-
token: accessToken,
|
|
214
|
-
github: {
|
|
215
|
-
user: undefined,
|
|
216
|
-
token: undefined,
|
|
217
|
-
},
|
|
218
|
-
},
|
|
219
|
-
})
|
|
220
|
-
// Set current userId
|
|
221
|
-
this.netlify.globalConfig.set('userId', userId)
|
|
222
|
-
// Set user data
|
|
223
|
-
this.netlify.globalConfig.set(`users.${userId}`, userData)
|
|
224
|
-
|
|
225
|
-
await identify({
|
|
226
|
-
name,
|
|
227
|
-
email,
|
|
228
|
-
userId,
|
|
229
|
-
})
|
|
230
|
-
await track('user_login', {
|
|
231
|
-
email,
|
|
232
|
-
})
|
|
233
|
-
|
|
234
|
-
// Log success
|
|
235
|
-
log()
|
|
236
|
-
log(`${chalk.greenBright('You are now logged into your Netlify account!')}`)
|
|
237
|
-
log()
|
|
238
|
-
log(`Run ${chalk.cyanBright('netlify status')} for account details`)
|
|
239
|
-
log()
|
|
240
|
-
log(`To see all available commands run: ${chalk.cyanBright('netlify help')}`)
|
|
241
|
-
log()
|
|
242
|
-
return accessToken
|
|
243
|
-
}
|
|
244
|
-
}
|
|
245
|
-
|
|
246
|
-
BaseCommand.strict = false
|
|
247
|
-
BaseCommand.flags = {
|
|
248
|
-
debug: flagsLib.boolean({
|
|
249
|
-
description: 'Print debugging information',
|
|
250
|
-
}),
|
|
251
|
-
httpProxy: flagsLib.string({
|
|
252
|
-
description: 'Proxy server address to route requests through.',
|
|
253
|
-
default: process.env.HTTP_PROXY || process.env.HTTPS_PROXY,
|
|
254
|
-
}),
|
|
255
|
-
httpProxyCertificateFilename: flagsLib.string({
|
|
256
|
-
description: 'Certificate file to use when connecting using a proxy server',
|
|
257
|
-
default: process.env.NETLIFY_PROXY_CERTIFICATE_FILENAME,
|
|
258
|
-
}),
|
|
259
|
-
}
|
|
260
|
-
|
|
261
|
-
module.exports = BaseCommand
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
const fs = require('fs')
|
|
2
|
-
const path = require('path')
|
|
3
|
-
|
|
4
|
-
const detectFunctionsBuilder = async function (parameters) {
|
|
5
|
-
const buildersPath = path.join(__dirname, '..', 'lib', 'functions', 'runtimes', 'js', 'builders')
|
|
6
|
-
const detectors = fs
|
|
7
|
-
.readdirSync(buildersPath)
|
|
8
|
-
// only accept .js detector files
|
|
9
|
-
.filter((filename) => filename.endsWith('.js'))
|
|
10
|
-
// Sorting by filename
|
|
11
|
-
.sort()
|
|
12
|
-
// eslint-disable-next-line node/global-require, import/no-dynamic-require
|
|
13
|
-
.map((det) => require(path.join(buildersPath, det)))
|
|
14
|
-
|
|
15
|
-
// eslint-disable-next-line fp/no-loops
|
|
16
|
-
for (const detector of detectors) {
|
|
17
|
-
// eslint-disable-next-line no-await-in-loop
|
|
18
|
-
const settings = await detector(parameters)
|
|
19
|
-
if (settings) {
|
|
20
|
-
return settings
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
module.exports = { detectFunctionsBuilder }
|
package/src/utils/difference.js
DELETED
package/src/utils/logo.js
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
const chalk = require('chalk')
|
|
2
|
-
|
|
3
|
-
// eslint-disable-next-line no-magic-numbers
|
|
4
|
-
const NETLIFY_CYAN = chalk.rgb(40, 180, 170)
|
|
5
|
-
|
|
6
|
-
module.exports = {
|
|
7
|
-
NETLIFYDEV: `${chalk.greenBright('◈')} ${NETLIFY_CYAN('Netlify Dev')} ${chalk.greenBright('◈')}`,
|
|
8
|
-
NETLIFYDEVLOG: `${chalk.greenBright('◈')}`,
|
|
9
|
-
NETLIFYDEVWARN: `${chalk.yellowBright('◈')}`,
|
|
10
|
-
NETLIFYDEVERR: `${chalk.redBright('◈')}`,
|
|
11
|
-
}
|
package/src/utils/show-help.js
DELETED
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
const { hrtime } = require('process')
|
|
2
|
-
|
|
3
|
-
const { Command } = require('@oclif/command')
|
|
4
|
-
const { ExitError } = require('@oclif/errors')
|
|
5
|
-
|
|
6
|
-
const { track } = require('.')
|
|
7
|
-
|
|
8
|
-
const NANO_SECS_TO_MSECS = 1e6
|
|
9
|
-
|
|
10
|
-
const getDuration = function (startTime) {
|
|
11
|
-
const durationNs = hrtime.bigint() - startTime
|
|
12
|
-
return Math.round(Number(durationNs / BigInt(NANO_SECS_TO_MSECS)))
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
const isSafeError = function (error) {
|
|
16
|
-
// The `exit` oclif utility returns an ExitError even when the exit code is 0
|
|
17
|
-
return error instanceof ExitError && error.oclif && error.oclif.exit === 0
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
const getStatus = function (error) {
|
|
21
|
-
if (error === undefined || isSafeError(error)) {
|
|
22
|
-
return 'success'
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
return 'error'
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
class TrackedCommand extends Command {
|
|
29
|
-
async init() {
|
|
30
|
-
this.analytics = { startTime: hrtime.bigint() }
|
|
31
|
-
await super.init()
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
setAnalyticsPayload(payload) {
|
|
35
|
-
this.analytics = { ...this.analytics, payload }
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
async finally(error) {
|
|
39
|
-
const { payload, startTime } = this.analytics
|
|
40
|
-
const duration = getDuration(startTime)
|
|
41
|
-
const status = getStatus(error)
|
|
42
|
-
await track('command', {
|
|
43
|
-
...payload,
|
|
44
|
-
command: this.id,
|
|
45
|
-
duration,
|
|
46
|
-
status,
|
|
47
|
-
})
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
module.exports = { TrackedCommand }
|