netlify-cli 8.1.0 → 8.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.
Files changed (193) hide show
  1. package/README.md +12 -13
  2. package/bin/run +38 -2
  3. package/npm-shrinkwrap.json +1256 -4181
  4. package/package.json +15 -39
  5. package/scripts/postinstall.js +13 -0
  6. package/src/commands/addons/addons-auth.js +50 -0
  7. package/src/commands/addons/addons-config.js +180 -0
  8. package/src/commands/addons/addons-create.js +131 -0
  9. package/src/commands/addons/addons-delete.js +60 -0
  10. package/src/commands/addons/addons-list.js +62 -0
  11. package/src/commands/addons/addons.js +44 -0
  12. package/src/commands/addons/index.js +3 -24
  13. package/src/commands/api/api.js +75 -0
  14. package/src/commands/api/index.js +5 -0
  15. package/src/commands/base-command.js +502 -0
  16. package/src/commands/build/build.js +58 -0
  17. package/src/commands/build/index.js +3 -61
  18. package/src/commands/completion/completion.js +56 -0
  19. package/src/commands/completion/index.js +5 -0
  20. package/src/commands/{deploy.js → deploy/deploy.js} +295 -275
  21. package/src/commands/deploy/index.js +5 -0
  22. package/src/commands/dev/dev-exec.js +35 -0
  23. package/src/commands/dev/dev-trace.js +47 -0
  24. package/src/commands/dev/dev.js +340 -0
  25. package/src/commands/dev/index.js +3 -335
  26. package/src/commands/env/env-get.js +51 -0
  27. package/src/commands/env/env-import.js +93 -0
  28. package/src/commands/env/env-list.js +63 -0
  29. package/src/commands/env/env-set.js +67 -0
  30. package/src/commands/env/env-unset.js +66 -0
  31. package/src/commands/env/env.js +42 -0
  32. package/src/commands/env/index.js +3 -23
  33. package/src/commands/functions/functions-build.js +59 -0
  34. package/src/commands/functions/{create.js → functions-create.js} +130 -94
  35. package/src/commands/functions/functions-invoke.js +273 -0
  36. package/src/commands/functions/functions-list.js +106 -0
  37. package/src/commands/functions/functions-serve.js +63 -0
  38. package/src/commands/functions/functions.js +47 -0
  39. package/src/commands/functions/index.js +3 -45
  40. package/src/commands/index.js +7 -0
  41. package/src/commands/init/index.js +6 -0
  42. package/src/commands/{init.js → init/init.js} +79 -68
  43. package/src/commands/link/index.js +6 -0
  44. package/src/{utils/link/link-by-prompt.js → commands/link/link.js} +141 -14
  45. package/src/commands/lm/index.js +3 -19
  46. package/src/commands/lm/lm-info.js +42 -0
  47. package/src/commands/lm/lm-install.js +33 -0
  48. package/src/commands/lm/lm-setup.js +106 -0
  49. package/src/commands/lm/lm-uninstall.js +25 -0
  50. package/src/commands/lm/lm.js +34 -0
  51. package/src/commands/login/index.js +6 -0
  52. package/src/commands/login/login.js +55 -0
  53. package/src/commands/logout/index.js +5 -0
  54. package/src/commands/logout/logout.js +43 -0
  55. package/src/commands/main.js +206 -0
  56. package/src/commands/open/index.js +3 -39
  57. package/src/commands/open/open-admin.js +60 -0
  58. package/src/commands/open/open-site.js +53 -0
  59. package/src/commands/open/open.js +40 -0
  60. package/src/commands/sites/index.js +5 -20
  61. package/src/commands/sites/sites-create.js +187 -0
  62. package/src/commands/sites/sites-delete.js +104 -0
  63. package/src/commands/sites/sites-list.js +90 -0
  64. package/src/commands/sites/sites.js +32 -0
  65. package/src/commands/status/index.js +3 -118
  66. package/src/commands/status/status-hooks.js +69 -0
  67. package/src/commands/status/status.js +124 -0
  68. package/src/commands/switch/index.js +5 -0
  69. package/src/commands/switch/switch.js +50 -0
  70. package/src/commands/unlink/index.js +5 -0
  71. package/src/commands/unlink/unlink.js +48 -0
  72. package/src/commands/watch/index.js +5 -0
  73. package/src/commands/watch/watch.js +131 -0
  74. package/src/functions-templates/javascript/stripe-charge/package-lock.json +13 -13
  75. package/src/functions-templates/javascript/stripe-subscription/package-lock.json +13 -13
  76. package/src/functions-templates/rust/hello-world/Cargo.toml +1 -1
  77. package/src/functions-templates/typescript/hello-world/package-lock.json +6 -6
  78. package/src/lib/build.js +21 -7
  79. package/src/lib/completion/constants.js +6 -0
  80. package/src/lib/completion/generate-autocompletion.js +36 -0
  81. package/src/lib/completion/index.js +5 -0
  82. package/src/lib/completion/script.js +72 -0
  83. package/src/lib/exec-fetcher.js +5 -3
  84. package/src/lib/fs.js +54 -36
  85. package/src/lib/functions/background.js +1 -1
  86. package/src/lib/functions/form-submissions-handler.js +2 -1
  87. package/src/lib/functions/local-proxy.js +2 -1
  88. package/src/lib/functions/netlify-function.js +4 -1
  89. package/src/lib/functions/registry.js +4 -6
  90. package/src/lib/functions/runtimes/go/index.js +2 -1
  91. package/src/lib/functions/runtimes/js/builders/netlify-lambda.js +6 -4
  92. package/src/lib/functions/runtimes/js/builders/zisi.js +3 -3
  93. package/src/lib/functions/runtimes/rust/index.js +4 -3
  94. package/src/lib/functions/server.js +2 -3
  95. package/src/lib/functions/synchronous.js +2 -1
  96. package/src/lib/functions/utils.js +2 -3
  97. package/src/lib/functions/watcher.js +1 -0
  98. package/src/lib/http-agent.js +5 -5
  99. package/src/lib/log.js +2 -1
  100. package/src/lib/settings.js +16 -1
  101. package/src/lib/spinner.js +22 -0
  102. package/src/utils/addons/diffs/index.js +1 -0
  103. package/src/utils/addons/diffs/options.js +3 -1
  104. package/src/utils/addons/prepare.js +13 -6
  105. package/src/utils/addons/prompts.js +2 -1
  106. package/src/utils/addons/render.js +3 -1
  107. package/src/utils/command-helpers.js +136 -42
  108. package/src/utils/create-stream-promise.js +5 -5
  109. package/src/utils/deferred.js +1 -0
  110. package/src/utils/deploy/deploy-site.js +1 -1
  111. package/src/utils/deploy/index.js +4 -0
  112. package/src/utils/detect-server-settings.js +10 -12
  113. package/src/utils/dev.js +18 -10
  114. package/src/utils/dot-env.js +4 -2
  115. package/src/utils/{edge-handlers.js → functions/edge-handlers.js} +8 -7
  116. package/src/utils/functions/functions.js +36 -0
  117. package/src/utils/{get-functions.js → functions/get-functions.js} +2 -1
  118. package/src/utils/functions/index.js +8 -26
  119. package/src/utils/get-global-config.js +3 -2
  120. package/src/utils/get-repo-data.js +8 -1
  121. package/src/utils/gh-auth.js +1 -0
  122. package/src/utils/gitignore.js +7 -5
  123. package/src/utils/headers.js +1 -2
  124. package/src/utils/index.js +42 -0
  125. package/src/utils/init/config-github.js +12 -5
  126. package/src/utils/init/config-manual.js +9 -2
  127. package/src/utils/init/config.js +13 -7
  128. package/src/utils/init/frameworks.js +1 -0
  129. package/src/utils/init/node-version.js +4 -2
  130. package/src/utils/init/utils.js +10 -6
  131. package/src/utils/live-tunnel.js +3 -4
  132. package/src/utils/lm/install.js +10 -15
  133. package/src/utils/lm/requirements.js +3 -1
  134. package/src/utils/lm/steps.js +1 -1
  135. package/src/utils/lm/ui.js +7 -3
  136. package/src/utils/open-browser.js +8 -2
  137. package/src/utils/parse-raw-flags.js +4 -4
  138. package/src/utils/proxy.js +6 -5
  139. package/src/utils/read-repo-url.js +1 -0
  140. package/src/utils/redirects.js +2 -2
  141. package/src/utils/rules-proxy.js +2 -1
  142. package/src/utils/state-config.js +1 -1
  143. package/src/utils/telemetry/index.js +2 -113
  144. package/src/utils/telemetry/request.js +3 -1
  145. package/src/utils/telemetry/telemetry.js +117 -0
  146. package/src/utils/telemetry/validation.js +13 -12
  147. package/src/utils/traffic-mesh.js +3 -3
  148. package/oclif.manifest.json +0 -1
  149. package/src/commands/addons/auth.js +0 -42
  150. package/src/commands/addons/config.js +0 -177
  151. package/src/commands/addons/create.js +0 -127
  152. package/src/commands/addons/delete.js +0 -69
  153. package/src/commands/addons/list.js +0 -54
  154. package/src/commands/api.js +0 -84
  155. package/src/commands/dev/exec.js +0 -32
  156. package/src/commands/dev/trace.js +0 -61
  157. package/src/commands/env/get.js +0 -44
  158. package/src/commands/env/import.js +0 -90
  159. package/src/commands/env/list.js +0 -49
  160. package/src/commands/env/set.js +0 -64
  161. package/src/commands/env/unset.js +0 -58
  162. package/src/commands/functions/build.js +0 -60
  163. package/src/commands/functions/invoke.js +0 -277
  164. package/src/commands/functions/list.js +0 -102
  165. package/src/commands/functions/serve.js +0 -70
  166. package/src/commands/link.js +0 -133
  167. package/src/commands/lm/info.js +0 -36
  168. package/src/commands/lm/install.js +0 -30
  169. package/src/commands/lm/setup.js +0 -107
  170. package/src/commands/lm/uninstall.js +0 -17
  171. package/src/commands/login.js +0 -54
  172. package/src/commands/logout.js +0 -37
  173. package/src/commands/open/admin.js +0 -51
  174. package/src/commands/open/site.js +0 -43
  175. package/src/commands/sites/create.js +0 -191
  176. package/src/commands/sites/delete.js +0 -116
  177. package/src/commands/sites/list.js +0 -84
  178. package/src/commands/status/hooks.js +0 -60
  179. package/src/commands/switch.js +0 -44
  180. package/src/commands/unlink.js +0 -38
  181. package/src/commands/watch.js +0 -115
  182. package/src/hooks/init.js +0 -46
  183. package/src/index.js +0 -25
  184. package/src/lib/help.js +0 -26
  185. package/src/utils/chalk.js +0 -16
  186. package/src/utils/check-command-inputs.js +0 -21
  187. package/src/utils/command.js +0 -261
  188. package/src/utils/detect-functions-builder.js +0 -25
  189. package/src/utils/difference.js +0 -4
  190. package/src/utils/header.js +0 -18
  191. package/src/utils/logo.js +0 -11
  192. package/src/utils/show-help.js +0 -5
  193. package/src/utils/telemetry/tracked-command.js +0 -51
@@ -1,127 +0,0 @@
1
- const chalk = require('chalk')
2
- const inquirer = require('inquirer')
3
- const isEmpty = require('lodash/isEmpty')
4
-
5
- const { ADDON_VALIDATION, prepareAddonCommand } = require('../../utils/addons/prepare')
6
- const generatePrompts = require('../../utils/addons/prompts')
7
- const render = require('../../utils/addons/render')
8
- const { missingConfigValues, requiredConfigValues, updateConfigValues } = require('../../utils/addons/validation')
9
- const Command = require('../../utils/command')
10
- const { error, log } = require('../../utils/command-helpers')
11
- const { parseRawFlags } = require('../../utils/parse-raw-flags')
12
-
13
- const createAddon = async ({ addonName, api, config, siteData, siteId }) => {
14
- try {
15
- const response = await api.createServiceInstance({
16
- siteId,
17
- addon: addonName,
18
- body: { config },
19
- })
20
- log(`Add-on "${addonName}" created for ${siteData.name}`)
21
- if (response.config && response.config.message) {
22
- log()
23
- log(`${response.config.message}`)
24
- }
25
- } catch (error_) {
26
- error(error_.message)
27
- }
28
- }
29
-
30
- class AddonsCreateCommand extends Command {
31
- async run() {
32
- const { args, raw } = this.parse(AddonsCreateCommand)
33
-
34
- const addonName = args.name
35
- const { manifest, siteData } = await prepareAddonCommand({
36
- context: this,
37
- addonName,
38
- validation: ADDON_VALIDATION.NOT_EXISTS,
39
- })
40
-
41
- const { netlify } = this
42
- const { api, site } = netlify
43
- const siteId = site.id
44
-
45
- // GET flags from `raw` data
46
- const rawFlags = parseRawFlags(raw)
47
- const hasConfig = !isEmpty(manifest.config)
48
-
49
- let configValues = rawFlags
50
-
51
- if (hasConfig) {
52
- const required = requiredConfigValues(manifest.config)
53
- const missingValues = missingConfigValues(required, rawFlags)
54
- log(`Starting the setup for "${addonName} add-on"`)
55
- log()
56
-
57
- if (Object.keys(rawFlags).length !== 0) {
58
- const newConfig = updateConfigValues(manifest.config, {}, rawFlags)
59
-
60
- if (missingValues.length !== 0) {
61
- /* Warn user of missing required values */
62
- log(`${chalk.redBright.underline.bold(`Error: Missing required configuration for "${addonName} add-on"`)}`)
63
- log()
64
- render.missingValues(missingValues, manifest)
65
- log()
66
- const msg = `netlify addons:create ${addonName}`
67
- log(`Please supply the configuration values as CLI flags`)
68
- log()
69
- log(`Alternatively, you can run ${chalk.cyan(msg)} with no flags to walk through the setup steps`)
70
- log()
71
- return false
72
- }
73
-
74
- await createAddon({ api, siteId, addonName, config: newConfig, siteData })
75
-
76
- return false
77
- }
78
-
79
- const words = `The ${addonName} add-on has the following configurable options:`
80
- log(` ${chalk.yellowBright.bold(words)}`)
81
- render.configValues(addonName, manifest.config)
82
- log()
83
- log(` ${chalk.greenBright.bold('Lets configure those!')}`)
84
-
85
- log()
86
- log(` - Hit ${chalk.white.bold('enter')} to confirm value or set empty value`)
87
- log(` - Hit ${chalk.white.bold('ctrl + C')} to cancel & exit configuration`)
88
- log()
89
-
90
- const prompts = generatePrompts({
91
- config: manifest.config,
92
- configValues: rawFlags,
93
- })
94
-
95
- const userInput = await inquirer.prompt(prompts)
96
- // Merge user input with the flags specified
97
- configValues = updateConfigValues(manifest.config, rawFlags, userInput)
98
- const missingRequiredValues = missingConfigValues(required, configValues)
99
- if (missingRequiredValues && missingRequiredValues.length !== 0) {
100
- missingRequiredValues.forEach((val) => {
101
- log(`Missing required value "${val}". Please run the command again`)
102
- })
103
- return false
104
- }
105
- }
106
-
107
- await createAddon({ api, siteId, addonName, config: configValues, siteData })
108
- }
109
- }
110
-
111
- AddonsCreateCommand.description = `Add an add-on extension to your site
112
- ...
113
- Add-ons are a way to extend the functionality of your Netlify site
114
- `
115
- AddonsCreateCommand.aliases = ['addon:create']
116
- AddonsCreateCommand.args = [
117
- {
118
- name: 'name',
119
- required: true,
120
- description: 'Add-on namespace',
121
- },
122
- ]
123
-
124
- // allow for any flags. Handy for variadic configuration options
125
- AddonsCreateCommand.strict = false
126
-
127
- module.exports = AddonsCreateCommand
@@ -1,69 +0,0 @@
1
- const { flags: flagsLib } = require('@oclif/command')
2
- const inquirer = require('inquirer')
3
-
4
- const { ADDON_VALIDATION, prepareAddonCommand } = require('../../utils/addons/prepare')
5
- const Command = require('../../utils/command')
6
- const { error, exit, log } = require('../../utils/command-helpers')
7
- const { parseRawFlags } = require('../../utils/parse-raw-flags')
8
-
9
- class AddonsDeleteCommand extends Command {
10
- async run() {
11
- const { args, raw } = this.parse(AddonsDeleteCommand)
12
-
13
- const addonName = args.name
14
- const { addon } = await prepareAddonCommand({
15
- context: this,
16
- addonName,
17
- validation: ADDON_VALIDATION.EXISTS,
18
- })
19
-
20
- const rawFlags = parseRawFlags(raw)
21
- if (!rawFlags.force && !rawFlags.f) {
22
- const { wantsToDelete } = await inquirer.prompt({
23
- type: 'confirm',
24
- name: 'wantsToDelete',
25
- message: `Are you sure you want to delete the ${addonName} add-on? (to skip this prompt, pass a --force flag)`,
26
- default: false,
27
- })
28
- if (!wantsToDelete) {
29
- exit()
30
- }
31
- }
32
-
33
- try {
34
- await this.netlify.api.deleteServiceInstance({
35
- siteId: this.netlify.site.id,
36
- addon: addonName,
37
- instanceId: addon.id,
38
- })
39
- log(`Addon "${addonName}" deleted`)
40
- } catch (error_) {
41
- error(error_.message)
42
- }
43
- }
44
- }
45
-
46
- AddonsDeleteCommand.description = `Remove an add-on extension to your site
47
- ...
48
- Add-ons are a way to extend the functionality of your Netlify site
49
- `
50
-
51
- // allow for any flags. Handy for variadic configuration options
52
- AddonsDeleteCommand.strict = false
53
- AddonsDeleteCommand.aliases = ['addon:delete']
54
- AddonsDeleteCommand.flags = {
55
- force: flagsLib.boolean({
56
- char: 'f',
57
- description: 'delete without prompting (useful for CI)',
58
- }),
59
- ...AddonsDeleteCommand.flags,
60
- }
61
- AddonsDeleteCommand.args = [
62
- {
63
- name: 'name',
64
- required: true,
65
- description: 'Add-on namespace',
66
- },
67
- ]
68
-
69
- module.exports = AddonsDeleteCommand
@@ -1,54 +0,0 @@
1
- const { flags: flagsLib } = require('@oclif/command')
2
- const AsciiTable = require('ascii-table')
3
-
4
- const { prepareAddonCommand } = require('../../utils/addons/prepare')
5
- const Command = require('../../utils/command')
6
- const { log, logJson } = require('../../utils/command-helpers')
7
-
8
- class AddonsListCommand extends Command {
9
- async run() {
10
- const { flags } = this.parse(AddonsListCommand)
11
-
12
- const { addons, siteData } = await prepareAddonCommand({ context: this })
13
- // Return json response for piping commands
14
- if (flags.json) {
15
- logJson(addons)
16
- return false
17
- }
18
-
19
- if (!addons || addons.length === 0) {
20
- log(`No addons currently installed for ${siteData.name}`)
21
- log(`> Run \`netlify addons:create addon-namespace\` to install an addon`)
22
- return false
23
- }
24
-
25
- const addonData = addons.map((addon) => ({
26
- namespace: addon.service_path.replace('/.netlify/', ''),
27
- name: addon.service_name,
28
- id: addon.id,
29
- }))
30
-
31
- // Build a table out of addons
32
- log(`site: ${siteData.name}`)
33
- const table = new AsciiTable(`Currently Installed addons`)
34
-
35
- table.setHeading('NameSpace', 'Name', 'Instance Id')
36
-
37
- addonData.forEach(({ id, name, namespace }) => {
38
- table.addRow(namespace, name, id)
39
- })
40
- // Log da addons
41
- log(table.toString())
42
- }
43
- }
44
-
45
- AddonsListCommand.description = `List currently installed add-ons for site`
46
- AddonsListCommand.aliases = ['addon:list']
47
- AddonsListCommand.flags = {
48
- json: flagsLib.boolean({
49
- description: 'Output add-on data as JSON',
50
- }),
51
- ...AddonsListCommand.flags,
52
- }
53
-
54
- module.exports = AddonsListCommand
@@ -1,84 +0,0 @@
1
- const oclif = require('@oclif/command')
2
- const AsciiTable = require('ascii-table')
3
- const chalk = require('chalk')
4
-
5
- // TODO: use static `import` after migrating this repository to pure ES modules
6
- const jsClient = import('netlify')
7
-
8
- const { isEmptyCommand } = require('../utils/check-command-inputs')
9
- const Command = require('../utils/command')
10
- const { error, exit, log, logJson } = require('../utils/command-helpers')
11
-
12
- class APICommand extends Command {
13
- async run() {
14
- const { api } = this.netlify
15
- const { args, flags } = this.parse(APICommand)
16
-
17
- const { apiMethod } = args
18
-
19
- if (isEmptyCommand(flags, args) || flags.list) {
20
- const table = new AsciiTable(`Netlify API Methods`)
21
- table.setHeading('API Method', 'Docs Link')
22
- const { methods } = await jsClient
23
- methods.forEach((method) => {
24
- const { operationId } = method
25
- table.addRow(operationId, `https://open-api.netlify.com/#operation/${operationId}`)
26
- })
27
- log(table.toString())
28
- log()
29
- log('Above is a list of available API methods')
30
- log(`To run a method use "${chalk.cyanBright('netlify api methodName')}"`)
31
- exit()
32
- }
33
-
34
- if (!apiMethod) {
35
- error(`You must provide an API method. Run "netlify api --list" to see available methods`)
36
- }
37
-
38
- if (!api[apiMethod] || typeof api[apiMethod] !== 'function') {
39
- error(`"${apiMethod}"" is not a valid api method. Run "netlify api --list" to see available methods`)
40
- }
41
-
42
- let payload
43
- if (flags.data) {
44
- payload = typeof flags.data === 'string' ? JSON.parse(flags.data) : flags.data
45
- } else {
46
- payload = {}
47
- }
48
- try {
49
- const apiResponse = await api[apiMethod](payload)
50
- logJson(apiResponse)
51
- } catch (error_) {
52
- error(error_)
53
- }
54
- }
55
- }
56
-
57
- APICommand.description = `Run any Netlify API method
58
-
59
- For more information on available methods checkout https://open-api.netlify.com/ or run "netlify api --list"
60
- `
61
-
62
- APICommand.args = [
63
- {
64
- name: 'apiMethod',
65
- description: 'Open API method to run',
66
- },
67
- ]
68
-
69
- APICommand.examples = ['netlify api --list', 'netlify api getSite --data \'{ "site_id": "123456"}\'']
70
-
71
- APICommand.flags = {
72
- data: oclif.flags.string({
73
- char: 'd',
74
- description: 'Data to use',
75
- }),
76
- list: oclif.flags.boolean({
77
- description: 'List out available API methods',
78
- }),
79
- ...APICommand.flags,
80
- }
81
-
82
- APICommand.strict = false
83
-
84
- module.exports = APICommand
@@ -1,32 +0,0 @@
1
- const execa = require('execa')
2
-
3
- const Command = require('../../utils/command')
4
- const { injectEnvVariables } = require('../../utils/dev')
5
-
6
- class ExecCommand extends Command {
7
- async init() {
8
- this.commandContext = 'dev'
9
- await super.init()
10
- }
11
-
12
- async run() {
13
- const { netlify } = this
14
- const { cachedConfig, site } = netlify
15
- await injectEnvVariables({ env: cachedConfig.env, site })
16
-
17
- execa(this.argv[0], this.argv.slice(1), {
18
- stdio: 'inherit',
19
- })
20
- }
21
- }
22
-
23
- ExecCommand.description = `Exec command
24
- Runs a command within the netlify dev environment, e.g. with env variables from any installed addons
25
- `
26
-
27
- ExecCommand.examples = ['$ netlify dev:exec npm run bootstrap']
28
-
29
- ExecCommand.strict = false
30
- ExecCommand.parse = false
31
-
32
- module.exports = ExecCommand
@@ -1,61 +0,0 @@
1
- const { flags } = require('@oclif/command')
2
-
3
- const Command = require('../../utils/command')
4
- const { runProcess } = require('../../utils/traffic-mesh')
5
-
6
- class TraceCommand extends Command {
7
- async init() {
8
- this.commandContext = 'dev'
9
- await super.init()
10
- }
11
-
12
- async run() {
13
- this.parse(TraceCommand)
14
-
15
- const args = ['trace', ...this.argv]
16
- const { subprocess } = runProcess({ args })
17
- await subprocess
18
- }
19
- }
20
-
21
- TraceCommand.description = `Trace command
22
- Simulates Netlify's Edge routing logic to match specific requests.
23
- This command is designed to mimic cURL's command line, so the flags are more familiar.
24
- `
25
-
26
- TraceCommand.examples = [
27
- '$ netlify dev:trace http://localhost/routing-path',
28
- '$ netlify dev:trace -w dist-directory http://localhost/routing-path',
29
- '$ netlify dev:trace -X POST http://localhost/routing-path',
30
- '$ netlify dev:trace -H "Accept-Language es" http://localhost/routing-path',
31
- '$ netlify dev:trace --cookie nf_jwt=token http://localhost/routing-path',
32
- ]
33
- TraceCommand.strict = false
34
- TraceCommand.args = [
35
- {
36
- name: 'url',
37
- required: true,
38
- description: 'Sets the request URL',
39
- },
40
- ]
41
- TraceCommand.flags = {
42
- request: flags.string({
43
- char: 'X',
44
- description: 'Specifies a custom request method [default: GET]',
45
- }),
46
- cookie: flags.string({
47
- char: 'b',
48
- description: 'Request cookie, this flag can be used multiple times. Example: "nf_jwt=token"',
49
- }),
50
- header: flags.string({
51
- char: 'H',
52
- description: 'Request header, this flag can be used multiple times. Example: "Host: netlify.test"',
53
- }),
54
- watch: flags.string({
55
- char: 'w',
56
- description: 'Path to the publish directory',
57
- }),
58
- debug: TraceCommand.flags.debug,
59
- }
60
-
61
- module.exports = TraceCommand
@@ -1,44 +0,0 @@
1
- const Command = require('../../utils/command')
2
- const { log, logJson } = require('../../utils/command-helpers')
3
-
4
- class EnvGetCommand extends Command {
5
- async run() {
6
- const { args, flags } = this.parse(EnvGetCommand)
7
- const { api, cachedConfig, site } = this.netlify
8
- const siteId = site.id
9
-
10
- if (!siteId) {
11
- log('No site id found, please run inside a site folder or `netlify link`')
12
- return false
13
- }
14
-
15
- const siteData = await api.getSite({ siteId })
16
-
17
- const { name } = args
18
- const { value } = cachedConfig.env[name] || {}
19
-
20
- // Return json response for piping commands
21
- if (flags.json) {
22
- logJson(value ? { [name]: value } : {})
23
- return false
24
- }
25
-
26
- if (!value) {
27
- log(`Environment variable ${name} not set for site ${siteData.name}`)
28
- return false
29
- }
30
-
31
- log(value)
32
- }
33
- }
34
-
35
- EnvGetCommand.description = `Get resolved value of specified environment variable (includes netlify.toml)`
36
- EnvGetCommand.args = [
37
- {
38
- name: 'name',
39
- required: true,
40
- description: 'Environment variable name',
41
- },
42
- ]
43
-
44
- module.exports = EnvGetCommand
@@ -1,90 +0,0 @@
1
- const fs = require('fs')
2
-
3
- const { flags: flagsLib } = require('@oclif/command')
4
- const AsciiTable = require('ascii-table')
5
- const dotenv = require('dotenv')
6
- const isEmpty = require('lodash/isEmpty')
7
-
8
- const Command = require('../../utils/command')
9
- const { exit, log, logJson } = require('../../utils/command-helpers')
10
-
11
- class EnvImportCommand extends Command {
12
- async run() {
13
- const { args, flags } = this.parse(EnvImportCommand)
14
- const { api, site } = this.netlify
15
- const siteId = site.id
16
-
17
- if (!siteId) {
18
- log('No site id found, please run inside a site folder or `netlify link`')
19
- return false
20
- }
21
-
22
- const siteData = await api.getSite({ siteId })
23
-
24
- // Get current environment variables set in the UI
25
- const {
26
- build_settings: { env = {} },
27
- } = siteData
28
-
29
- // Import environment variables from specified .env file
30
- const { fileName } = args
31
- let importedEnv = {}
32
- try {
33
- const envFileContents = fs.readFileSync(fileName)
34
- importedEnv = dotenv.parse(envFileContents)
35
- } catch (error) {
36
- log(error.message)
37
- exit(1)
38
- }
39
-
40
- if (isEmpty(importedEnv)) {
41
- log(`No environment variables found in file ${fileName} to import`)
42
- return false
43
- }
44
-
45
- // Apply environment variable updates
46
- const siteResult = await api.updateSite({
47
- siteId,
48
- body: {
49
- build_settings: {
50
- // Only set imported variables if --replaceExisting or otherwise merge
51
- // imported ones with the current environment variables.
52
- env: flags.replaceExisting ? importedEnv : { ...env, ...importedEnv },
53
- },
54
- },
55
- })
56
-
57
- // Return new environment variables of site if using json flag
58
- if (flags.json) {
59
- logJson(siteResult.build_settings.env)
60
- return false
61
- }
62
-
63
- // List newly imported environment variables in a table
64
- log(`site: ${siteData.name}`)
65
- const table = new AsciiTable(`Imported environment variables`)
66
-
67
- table.setHeading('Key', 'Value')
68
- table.addRowMatrix(Object.entries(importedEnv))
69
- log(table.toString())
70
- }
71
- }
72
-
73
- EnvImportCommand.description = `Import and set environment variables from .env file`
74
- EnvImportCommand.flags = {
75
- replaceExisting: flagsLib.boolean({
76
- char: 'r',
77
- description: 'Replace all existing variables instead of merging them with the current ones',
78
- default: false,
79
- }),
80
- ...EnvImportCommand.flags,
81
- }
82
- EnvImportCommand.args = [
83
- {
84
- name: 'fileName',
85
- required: true,
86
- description: '.env file to import',
87
- },
88
- ]
89
-
90
- module.exports = EnvImportCommand
@@ -1,49 +0,0 @@
1
- const AsciiTable = require('ascii-table')
2
- const isEmpty = require('lodash/isEmpty')
3
-
4
- const Command = require('../../utils/command')
5
- const { log, logJson } = require('../../utils/command-helpers')
6
-
7
- class EnvListCommand extends Command {
8
- async run() {
9
- const { flags } = this.parse(EnvListCommand)
10
- const { api, cachedConfig, site } = this.netlify
11
- const siteId = site.id
12
-
13
- if (!siteId) {
14
- log('No site id found, please run inside a site folder or `netlify link`')
15
- return false
16
- }
17
-
18
- const siteData = await api.getSite({ siteId })
19
- const environment = Object.fromEntries(
20
- Object.entries(cachedConfig.env)
21
- // Omitting general variables to reduce noise.
22
- .filter(([, variable]) => variable.sources[0] !== 'general')
23
- .map(([key, variable]) => [key, variable.value]),
24
- )
25
-
26
- // Return json response for piping commands
27
- if (flags.json) {
28
- logJson(environment)
29
- return false
30
- }
31
-
32
- if (isEmpty(environment)) {
33
- log(`No environment variables set for site ${siteData.name}`)
34
- return false
35
- }
36
-
37
- // List environment variables using a table
38
- log(`site: ${siteData.name}`)
39
- const table = new AsciiTable(`Environment variables`)
40
-
41
- table.setHeading('Key', 'Value')
42
- table.addRowMatrix(Object.entries(environment))
43
- log(table.toString())
44
- }
45
- }
46
-
47
- EnvListCommand.description = `Lists resolved environment variables for site (includes netlify.toml)`
48
-
49
- module.exports = EnvListCommand
@@ -1,64 +0,0 @@
1
- const Command = require('../../utils/command')
2
- const { log, logJson } = require('../../utils/command-helpers')
3
-
4
- class EnvSetCommand extends Command {
5
- async run() {
6
- const { args, flags } = this.parse(EnvSetCommand)
7
- const { api, site } = this.netlify
8
- const siteId = site.id
9
-
10
- if (!siteId) {
11
- log('No site id found, please run inside a site folder or `netlify link`')
12
- return false
13
- }
14
-
15
- const siteData = await api.getSite({ siteId })
16
-
17
- // Get current environment variables set in the UI
18
- const {
19
- build_settings: { env = {} },
20
- } = siteData
21
-
22
- // Merge new enviroment variable with currently set variables
23
- const { name, value } = args
24
- const newEnv = {
25
- ...env,
26
- [name]: value,
27
- }
28
-
29
- // Apply environment variable updates
30
- const siteResult = await api.updateSite({
31
- siteId,
32
- body: {
33
- build_settings: {
34
- env: newEnv,
35
- },
36
- },
37
- })
38
-
39
- // Return new environment variables of site if using json flag
40
- if (flags.json) {
41
- logJson(siteResult.build_settings.env)
42
- return false
43
- }
44
-
45
- log(`Set environment variable ${name}=${value} for site ${siteData.name}`)
46
- }
47
- }
48
-
49
- EnvSetCommand.description = `Set value of environment variable`
50
- EnvSetCommand.args = [
51
- {
52
- name: 'name',
53
- required: true,
54
- description: 'Environment variable name',
55
- },
56
- {
57
- name: 'value',
58
- required: false,
59
- default: '',
60
- description: 'Value to set to',
61
- },
62
- ]
63
-
64
- module.exports = EnvSetCommand