netlify-cli 17.3.2 → 17.4.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.
Files changed (210) hide show
  1. package/README.md +2 -138
  2. package/npm-shrinkwrap.json +76 -76
  3. package/package.json +16 -15
  4. package/src/commands/addons/addons-auth.mjs +27 -30
  5. package/src/commands/addons/addons-config.mjs +145 -154
  6. package/src/commands/addons/addons-create.mjs +94 -108
  7. package/src/commands/addons/addons-delete.mjs +36 -41
  8. package/src/commands/addons/addons-list.mjs +38 -42
  9. package/src/commands/addons/addons.mjs +26 -28
  10. package/src/commands/addons/index.mjs +1 -1
  11. package/src/commands/api/api.mjs +45 -53
  12. package/src/commands/api/index.mjs +1 -1
  13. package/src/commands/base-command.mjs +597 -684
  14. package/src/commands/blobs/blobs-delete.mjs +35 -0
  15. package/src/commands/blobs/blobs-get.mjs +44 -0
  16. package/src/commands/blobs/blobs-list.mjs +48 -0
  17. package/src/commands/blobs/blobs-set.mjs +54 -0
  18. package/src/commands/blobs/blobs.mjs +32 -0
  19. package/src/commands/blobs/index.mjs +1 -0
  20. package/src/commands/build/build.mjs +55 -67
  21. package/src/commands/build/index.mjs +1 -1
  22. package/src/commands/completion/completion.mjs +41 -46
  23. package/src/commands/completion/index.mjs +1 -1
  24. package/src/commands/deploy/deploy.mjs +675 -710
  25. package/src/commands/deploy/index.mjs +1 -1
  26. package/src/commands/dev/dev-exec.mjs +20 -32
  27. package/src/commands/dev/dev.mjs +217 -302
  28. package/src/commands/dev/index.mjs +1 -1
  29. package/src/commands/dev/types.d.ts +30 -0
  30. package/src/commands/env/env-clone.mjs +157 -184
  31. package/src/commands/env/env-get.mjs +49 -68
  32. package/src/commands/env/env-import.mjs +100 -119
  33. package/src/commands/env/env-list.mjs +104 -129
  34. package/src/commands/env/env-set.mjs +160 -185
  35. package/src/commands/env/env-unset.mjs +104 -122
  36. package/src/commands/env/env.mjs +28 -30
  37. package/src/commands/env/index.mjs +1 -1
  38. package/src/commands/functions/functions-build.mjs +29 -41
  39. package/src/commands/functions/functions-create.mjs +533 -601
  40. package/src/commands/functions/functions-invoke.mjs +193 -216
  41. package/src/commands/functions/functions-list.mjs +45 -55
  42. package/src/commands/functions/functions-serve.mjs +51 -61
  43. package/src/commands/functions/functions.mjs +26 -32
  44. package/src/commands/functions/index.mjs +1 -1
  45. package/src/commands/index.mjs +2 -2
  46. package/src/commands/init/index.mjs +1 -1
  47. package/src/commands/init/init.mjs +138 -167
  48. package/src/commands/integration/deploy.mjs +337 -399
  49. package/src/commands/integration/index.mjs +12 -13
  50. package/src/commands/link/index.mjs +1 -1
  51. package/src/commands/link/link.mjs +298 -317
  52. package/src/commands/lm/index.mjs +1 -1
  53. package/src/commands/lm/lm-info.mjs +23 -31
  54. package/src/commands/lm/lm-install.mjs +13 -17
  55. package/src/commands/lm/lm-setup.mjs +80 -84
  56. package/src/commands/lm/lm-uninstall.mjs +7 -12
  57. package/src/commands/lm/lm.mjs +18 -22
  58. package/src/commands/login/index.mjs +1 -1
  59. package/src/commands/login/login.mjs +35 -41
  60. package/src/commands/logout/index.mjs +1 -1
  61. package/src/commands/logout/logout.mjs +25 -31
  62. package/src/commands/main.mjs +166 -201
  63. package/src/commands/open/index.mjs +1 -1
  64. package/src/commands/open/open-admin.mjs +15 -18
  65. package/src/commands/open/open-site.mjs +16 -19
  66. package/src/commands/open/open.mjs +24 -27
  67. package/src/commands/recipes/common.mjs +23 -34
  68. package/src/commands/recipes/index.mjs +1 -1
  69. package/src/commands/recipes/recipes-list.mjs +13 -20
  70. package/src/commands/recipes/recipes.mjs +59 -72
  71. package/src/commands/serve/index.mjs +1 -1
  72. package/src/commands/serve/serve.mjs +142 -189
  73. package/src/commands/sites/index.mjs +2 -2
  74. package/src/commands/sites/sites-create-template.mjs +214 -236
  75. package/src/commands/sites/sites-create.mjs +145 -157
  76. package/src/commands/sites/sites-delete.mjs +75 -81
  77. package/src/commands/sites/sites-list.mjs +63 -66
  78. package/src/commands/sites/sites.mjs +18 -20
  79. package/src/commands/status/index.mjs +1 -1
  80. package/src/commands/status/status-hooks.mjs +32 -34
  81. package/src/commands/status/status.mjs +99 -106
  82. package/src/commands/switch/index.mjs +1 -1
  83. package/src/commands/switch/switch.mjs +32 -37
  84. package/src/commands/types.d.ts +31 -0
  85. package/src/commands/unlink/index.mjs +1 -1
  86. package/src/commands/unlink/unlink.mjs +23 -29
  87. package/src/commands/watch/index.mjs +1 -1
  88. package/src/commands/watch/watch.mjs +91 -105
  89. package/src/functions-templates/javascript/hello/{{name}}.js +2 -3
  90. package/src/lib/account.mjs +4 -5
  91. package/src/lib/api.mjs +22 -20
  92. package/src/lib/blobs/blobs.mjs +36 -45
  93. package/src/lib/build.mjs +82 -85
  94. package/src/lib/completion/constants.mjs +2 -4
  95. package/src/lib/completion/generate-autocompletion.mjs +33 -36
  96. package/src/lib/completion/get-autocompletion.mjs +31 -35
  97. package/src/lib/completion/index.mjs +1 -1
  98. package/src/lib/completion/script.mjs +12 -19
  99. package/src/lib/edge-functions/bootstrap.mjs +3 -5
  100. package/src/lib/edge-functions/consts.mjs +9 -10
  101. package/src/lib/edge-functions/deploy.mjs +28 -34
  102. package/src/lib/edge-functions/editor-helper.mjs +29 -42
  103. package/src/lib/edge-functions/headers.mjs +24 -26
  104. package/src/lib/edge-functions/internal.mjs +38 -44
  105. package/src/lib/edge-functions/proxy.mjs +229 -228
  106. package/src/lib/edge-functions/registry.mjs +473 -574
  107. package/src/lib/exec-fetcher.mjs +115 -122
  108. package/src/lib/fs.mjs +28 -27
  109. package/src/lib/functions/background.mjs +16 -20
  110. package/src/lib/functions/config.mjs +12 -9
  111. package/src/lib/functions/form-submissions-handler.mjs +143 -149
  112. package/src/lib/functions/local-proxy.mjs +40 -44
  113. package/src/lib/functions/memoized-build.mjs +19 -21
  114. package/src/lib/functions/netlify-function.mjs +269 -249
  115. package/src/lib/functions/registry.mjs +509 -568
  116. package/src/lib/functions/runtimes/go/index.mjs +62 -71
  117. package/src/lib/functions/runtimes/index.mjs +8 -15
  118. package/src/lib/functions/runtimes/js/builders/netlify-lambda.mjs +55 -64
  119. package/src/lib/functions/runtimes/js/builders/zisi.mjs +135 -154
  120. package/src/lib/functions/runtimes/js/constants.mjs +1 -1
  121. package/src/lib/functions/runtimes/js/index.mjs +92 -109
  122. package/src/lib/functions/runtimes/js/worker.mjs +43 -45
  123. package/src/lib/functions/runtimes/rust/index.mjs +64 -73
  124. package/src/lib/functions/scheduled.mjs +70 -88
  125. package/src/lib/functions/server.mjs +269 -327
  126. package/src/lib/functions/synchronous.mjs +118 -147
  127. package/src/lib/functions/utils.mjs +38 -46
  128. package/src/lib/geo-location.mjs +69 -81
  129. package/src/lib/http-agent.mjs +87 -90
  130. package/src/lib/images/proxy.mjs +97 -99
  131. package/src/lib/log.mjs +6 -9
  132. package/src/lib/path.mjs +2 -1
  133. package/src/lib/render-error-template.mjs +19 -20
  134. package/src/lib/settings.mjs +17 -19
  135. package/src/lib/spinner.mjs +21 -23
  136. package/src/lib/string.mjs +4 -2
  137. package/src/recipes/vscode/index.mjs +69 -85
  138. package/src/recipes/vscode/settings.mjs +53 -58
  139. package/src/utils/addons/compare.mjs +31 -32
  140. package/src/utils/addons/diffs/index.mjs +16 -17
  141. package/src/utils/addons/diffs/options.mjs +99 -101
  142. package/src/utils/addons/prepare.mjs +100 -97
  143. package/src/utils/addons/prompts.mjs +73 -76
  144. package/src/utils/addons/render.mjs +33 -36
  145. package/src/utils/addons/validation.mjs +19 -15
  146. package/src/utils/banner.mjs +11 -16
  147. package/src/utils/build-info.mjs +65 -66
  148. package/src/utils/command-helpers.mjs +185 -199
  149. package/src/utils/create-deferred.mjs +9 -12
  150. package/src/utils/create-stream-promise.mjs +54 -47
  151. package/src/utils/deploy/constants.mjs +9 -11
  152. package/src/utils/deploy/deploy-site.mjs +162 -182
  153. package/src/utils/deploy/hash-config.mjs +21 -21
  154. package/src/utils/deploy/hash-files.mjs +34 -38
  155. package/src/utils/deploy/hash-fns.mjs +149 -154
  156. package/src/utils/deploy/hasher-segments.mjs +58 -52
  157. package/src/utils/deploy/upload-files.mjs +99 -113
  158. package/src/utils/deploy/util.mjs +85 -91
  159. package/src/utils/detect-server-settings.mjs +236 -268
  160. package/src/utils/dev.mjs +163 -178
  161. package/src/utils/dot-env.mjs +37 -42
  162. package/src/utils/env/index.mjs +148 -148
  163. package/src/utils/execa.mjs +9 -13
  164. package/src/utils/feature-flags.mjs +6 -5
  165. package/src/utils/framework-server.mjs +43 -52
  166. package/src/utils/functions/constants.mjs +1 -1
  167. package/src/utils/functions/functions.mjs +30 -40
  168. package/src/utils/functions/get-functions.mjs +28 -29
  169. package/src/utils/functions/index.mjs +3 -3
  170. package/src/utils/get-global-config.mjs +33 -36
  171. package/src/utils/get-package-json.mjs +14 -15
  172. package/src/utils/get-repo-data.mjs +54 -64
  173. package/src/utils/get-site.mjs +14 -14
  174. package/src/utils/gh-auth.mjs +79 -100
  175. package/src/utils/gitignore.mjs +37 -40
  176. package/src/utils/headers.mjs +33 -35
  177. package/src/utils/hooks/requires-site-info.mjs +26 -22
  178. package/src/utils/init/config-github.mjs +207 -219
  179. package/src/utils/init/config-manual.mjs +83 -100
  180. package/src/utils/init/config.mjs +25 -26
  181. package/src/utils/init/node-version.mjs +23 -30
  182. package/src/utils/init/plugins.mjs +12 -8
  183. package/src/utils/init/utils.mjs +152 -172
  184. package/src/utils/live-tunnel.mjs +118 -141
  185. package/src/utils/lm/install.mjs +220 -259
  186. package/src/utils/lm/requirements.mjs +54 -63
  187. package/src/utils/lm/steps.mjs +31 -31
  188. package/src/utils/lm/ui.mjs +13 -20
  189. package/src/utils/open-browser.mjs +31 -32
  190. package/src/utils/parse-raw-flags.mjs +39 -35
  191. package/src/utils/proxy-server.mjs +84 -71
  192. package/src/utils/proxy.mjs +696 -750
  193. package/src/utils/read-repo-url.mjs +48 -47
  194. package/src/utils/redirects.mjs +49 -49
  195. package/src/utils/request-id.mjs +2 -4
  196. package/src/utils/rules-proxy.mjs +96 -100
  197. package/src/utils/run-build.mjs +109 -132
  198. package/src/utils/shell.mjs +99 -106
  199. package/src/utils/sign-redirect.mjs +14 -14
  200. package/src/utils/sites/utils.mjs +48 -55
  201. package/src/utils/state-config.mjs +101 -101
  202. package/src/utils/static-server.mjs +28 -34
  203. package/src/utils/telemetry/index.mjs +2 -2
  204. package/src/utils/telemetry/report-error.mjs +45 -49
  205. package/src/utils/telemetry/request.mjs +36 -43
  206. package/src/utils/telemetry/telemetry.mjs +90 -105
  207. package/src/utils/telemetry/utils.mjs +5 -6
  208. package/src/utils/telemetry/validation.mjs +55 -53
  209. package/src/utils/types.d.ts +46 -0
  210. package/src/utils/validation.mjs +10 -13
@@ -1,8 +1,6 @@
1
- // @ts-check
2
- import { ADDON_VALIDATION, prepareAddonCommand } from '../../utils/addons/prepare.mjs'
3
- import { exit, log } from '../../utils/command-helpers.mjs'
4
- import openBrowser from '../../utils/open-browser.mjs'
5
-
1
+ import { ADDON_VALIDATION, prepareAddonCommand } from '../../utils/addons/prepare.mjs';
2
+ import { exit, log } from '../../utils/command-helpers.mjs';
3
+ import openBrowser from '../../utils/open-browser.mjs';
6
4
  /**
7
5
  * The addons:auth command
8
6
  * @param {string} addonName
@@ -10,39 +8,38 @@ import openBrowser from '../../utils/open-browser.mjs'
10
8
  * @param {import('../base-command.mjs').default} command
11
9
  * @returns {Promise<boolean>}
12
10
  */
11
+ // @ts-expect-error TS(7006) FIXME: Parameter 'addonName' implicitly has an 'any' type... Remove this comment to see the full error message
13
12
  const addonsAuth = async (addonName, options, command) => {
14
- const { addon } = await prepareAddonCommand({
15
- command,
16
- addonName,
17
- // @ts-ignore when migrating to typescript this should be a const enum
18
- validation: ADDON_VALIDATION.EXISTS,
19
- })
20
-
21
- if (!addon.auth_url) {
22
- log(`No Admin URL found for the "${addonName} add-on"`)
23
- return false
24
- }
25
-
26
- log()
27
- log(`Opening ${addonName} add-on admin URL:`)
28
- log()
29
- log(addon.auth_url)
30
- log()
31
- await openBrowser({ url: addon.auth_url })
32
- exit()
33
- }
34
-
13
+ const { addon } = await prepareAddonCommand({
14
+ command,
15
+ addonName,
16
+ validation: ADDON_VALIDATION.EXISTS,
17
+ });
18
+ if (!addon.auth_url) {
19
+ log(`No Admin URL found for the "${addonName} add-on"`);
20
+ return false;
21
+ }
22
+ log();
23
+ log(`Opening ${addonName} add-on admin URL:`);
24
+ log();
25
+ log(addon.auth_url);
26
+ log();
27
+ // @ts-expect-error TS(2345) FIXME: Argument of type '{ url: any; }' is not assignable... Remove this comment to see the full error message
28
+ await openBrowser({ url: addon.auth_url });
29
+ exit();
30
+ };
35
31
  /**
36
32
  * Creates the `netlify addons:auth` command
37
33
  * @param {import('../base-command.mjs').default} program
38
34
  * @returns
39
35
  */
40
- export const createAddonsAuthCommand = (program) =>
41
- program
36
+ // @ts-expect-error TS(7006) FIXME: Parameter 'program' implicitly has an 'any' type.
37
+ export const createAddonsAuthCommand = (program) => program
42
38
  .command('addons:auth', { hidden: true })
43
39
  .alias('addon:auth')
44
40
  .argument('<name>', 'Add-on slug')
45
41
  .description('Login to add-on provider')
42
+ // @ts-expect-error TS(7006) FIXME: Parameter 'addonName' implicitly has an 'any' type... Remove this comment to see the full error message
46
43
  .action(async (addonName, options, command) => {
47
- await addonsAuth(addonName, options, command)
48
- })
44
+ await addonsAuth(addonName, options, command);
45
+ });
@@ -1,42 +1,40 @@
1
- // @ts-check
2
- import inquirer from 'inquirer'
3
- import isEmpty from 'lodash/isEmpty.js'
4
-
5
- import compare from '../../utils/addons/compare.mjs'
6
- import diffValues from '../../utils/addons/diffs/index.mjs'
7
- import { ADDON_VALIDATION, prepareAddonCommand } from '../../utils/addons/prepare.mjs'
8
- import generatePrompts from '../../utils/addons/prompts.mjs'
9
- import { renderConfigValues } from '../../utils/addons/render.mjs'
10
- import { missingConfigValues, requiredConfigValues, updateConfigValues } from '../../utils/addons/validation.mjs'
11
- import { chalk, error, log } from '../../utils/command-helpers.mjs'
12
- import { parseRawFlags } from '../../utils/parse-raw-flags.mjs'
13
-
1
+ import inquirer from 'inquirer';
2
+ import isEmpty from 'lodash/isEmpty.js';
3
+ import compare from '../../utils/addons/compare.mjs';
4
+ import diffValues from '../../utils/addons/diffs/index.mjs';
5
+ import { ADDON_VALIDATION, prepareAddonCommand } from '../../utils/addons/prepare.mjs';
6
+ import generatePrompts from '../../utils/addons/prompts.mjs';
7
+ import { renderConfigValues } from '../../utils/addons/render.mjs';
8
+ import { missingConfigValues, requiredConfigValues, updateConfigValues } from '../../utils/addons/validation.mjs';
9
+ import { chalk, error, log } from '../../utils/command-helpers.mjs';
10
+ import { parseRawFlags } from '../../utils/parse-raw-flags.mjs';
11
+ // @ts-expect-error TS(7031) FIXME: Binding element 'addonName' implicitly has an 'any... Remove this comment to see the full error message
14
12
  const update = async function ({ addonName, api, currentConfig, instanceId, newConfig, siteId }) {
15
- const codeDiff = diffValues(currentConfig, newConfig)
16
- if (!codeDiff) {
17
- log('No changes, exiting early')
18
- return false
19
- }
20
- log()
21
- const msg = `Updating ${addonName} add-on config values...`
22
- log(`${chalk.white.bold(msg)}`)
23
- log()
24
- log(`${codeDiff}\n`)
25
- log()
26
-
27
- try {
28
- await api.updateServiceInstance({
29
- siteId,
30
- addon: addonName,
31
- instanceId,
32
- body: { config: newConfig },
33
- })
34
- log(`Add-on "${addonName}" successfully updated`)
35
- } catch (error_) {
36
- error(error_.message)
37
- }
38
- }
39
-
13
+ const codeDiff = diffValues(currentConfig, newConfig);
14
+ if (!codeDiff) {
15
+ log('No changes, exiting early');
16
+ return false;
17
+ }
18
+ log();
19
+ const msg = `Updating ${addonName} add-on config values...`;
20
+ log(`${chalk.white.bold(msg)}`);
21
+ log();
22
+ log(`${codeDiff}\n`);
23
+ log();
24
+ try {
25
+ await api.updateServiceInstance({
26
+ siteId,
27
+ addon: addonName,
28
+ instanceId,
29
+ body: { config: newConfig },
30
+ });
31
+ log(`Add-on "${addonName}" successfully updated`);
32
+ }
33
+ catch (error_) {
34
+ // @ts-expect-error TS(2571) FIXME: Object is of type 'unknown'.
35
+ error(error_.message);
36
+ }
37
+ };
40
38
  /**
41
39
  * The addons:config command
42
40
  * @param {string} addonName
@@ -44,136 +42,129 @@ const update = async function ({ addonName, api, currentConfig, instanceId, newC
44
42
  * @param {import('../base-command.mjs').default} command
45
43
  * @returns {Promise<boolean>}
46
44
  */
45
+ // @ts-expect-error TS(7006) FIXME: Parameter 'addonName' implicitly has an 'any' type... Remove this comment to see the full error message
47
46
  const addonsConfig = async (addonName, options, command) => {
48
- const { addon, manifest, siteData } = await prepareAddonCommand({
49
- command,
50
- addonName,
51
- // @ts-ignore
52
- validation: ADDON_VALIDATION.EXISTS,
53
- })
54
-
55
- const { api, site } = command.netlify
56
- const siteId = site.id
57
-
58
- const hasConfig = !isEmpty(manifest.config)
59
- // Parse flags
60
- const rawFlags = parseRawFlags(command.args)
61
- // Get Existing Config
62
- const currentConfig = addon.config || {}
63
-
64
- const words = `Current "${addonName} add-on" Settings:`
65
- log(` ${chalk.yellowBright.bold(words)}`)
66
- if (hasConfig) {
67
- if (!rawFlags.silent) {
68
- renderConfigValues(addonName, manifest.config, currentConfig)
69
- }
70
- } else {
71
- // For addons without manifest. TODO remove once we enforce manifests
72
- Object.keys(currentConfig).forEach((key) => {
73
- log(`${key} - ${currentConfig[key]}`)
74
- })
75
- }
76
-
77
- if (hasConfig) {
78
- const required = requiredConfigValues(manifest.config)
79
- const missingValues = missingConfigValues(required, rawFlags)
80
-
81
- /* Config set by command line flags */
82
- if (rawFlags && missingValues.length === 0) {
83
- const newConfig = updateConfigValues(manifest.config, currentConfig, rawFlags)
84
-
85
- await update({
47
+ const { addon, manifest, siteData } = await prepareAddonCommand({
48
+ command,
86
49
  addonName,
87
- currentConfig,
88
- newConfig,
89
- siteId,
90
- instanceId: addon.id,
91
- api,
92
- })
93
- return false
94
- }
95
-
96
- const updatePrompt = await inquirer.prompt([
97
- {
98
- type: 'confirm',
99
- name: 'updateNow',
100
- message: `Do you want to update config values?`,
101
- default: false,
102
- },
103
- ])
104
- if (!updatePrompt.updateNow) {
105
- log('Sounds good! Exiting configuration...')
106
- return false
50
+ validation: ADDON_VALIDATION.EXISTS,
51
+ });
52
+ const { api, site } = command.netlify;
53
+ const siteId = site.id;
54
+ const hasConfig = !isEmpty(manifest.config);
55
+ // Parse flags
56
+ const rawFlags = parseRawFlags(command.args);
57
+ // Get Existing Config
58
+ const currentConfig = addon.config || {};
59
+ const words = `Current "${addonName} add-on" Settings:`;
60
+ log(` ${chalk.yellowBright.bold(words)}`);
61
+ if (hasConfig) {
62
+ if (!rawFlags.silent) {
63
+ renderConfigValues(addonName, manifest.config, currentConfig);
64
+ }
107
65
  }
108
- log()
109
- log(` - Hit ${chalk.white.bold('enter')} to keep the existing value in (parentheses)`)
110
- log(` - Hit ${chalk.white.bold('down arrow')} to remove the value`)
111
- log(` - Hit ${chalk.white.bold('ctrl + C')} to cancel & exit configuration`)
112
- log()
113
- log(` You will need to verify the changed before we push them to your live site!`)
114
- log()
115
- const prompts = generatePrompts({
116
- config: manifest.config,
117
- configValues: currentConfig,
118
- })
119
- const userInput = await inquirer.prompt(prompts)
120
- // Merge user input with the flags specified
121
- const newConfig = updateConfigValues(manifest.config, currentConfig, userInput)
122
-
123
- const diffs = compare(currentConfig, newConfig)
124
- // log('compare', diffs)
125
- if (diffs.isEqual) {
126
- log(`No changes. exiting early`)
127
- return false
66
+ else {
67
+ // For addons without manifest. TODO remove once we enforce manifests
68
+ Object.keys(currentConfig).forEach((key) => {
69
+ log(`${key} - ${currentConfig[key]}`);
70
+ });
128
71
  }
129
- log()
130
- log(`${chalk.yellowBright.bold.underline('Confirm your updates:')}`)
131
- log()
132
- diffs.keys.forEach((key) => {
133
- const { newValue, oldValue } = diffs.diffs[key]
134
- const oldVal = oldValue || 'NO VALUE'
135
- log(`${chalk.cyan(key)} changed from ${chalk.whiteBright(oldVal)} to ${chalk.green(newValue)}`)
136
- })
137
- log()
138
-
139
- const confirmPrompt = await inquirer.prompt([
140
- {
141
- type: 'confirm',
142
- name: 'confirmChange',
143
- message: `Do you want to publish the updated "${addonName} add-on" settings for ${chalk.cyan(siteData.name)}?`,
144
- default: false,
145
- },
146
- ])
147
-
148
- if (!confirmPrompt.confirmChange) {
149
- log('Canceling changes... You are good to go!')
150
- return false
72
+ if (hasConfig) {
73
+ const required = requiredConfigValues(manifest.config);
74
+ const missingValues = missingConfigValues(required, rawFlags);
75
+ /* Config set by command line flags */
76
+ if (rawFlags && missingValues.length === 0) {
77
+ const newConfig = updateConfigValues(manifest.config, currentConfig, rawFlags);
78
+ await update({
79
+ addonName,
80
+ currentConfig,
81
+ newConfig,
82
+ siteId,
83
+ instanceId: addon.id,
84
+ api,
85
+ });
86
+ return false;
87
+ }
88
+ const updatePrompt = await inquirer.prompt([
89
+ {
90
+ type: 'confirm',
91
+ name: 'updateNow',
92
+ message: `Do you want to update config values?`,
93
+ default: false,
94
+ },
95
+ ]);
96
+ if (!updatePrompt.updateNow) {
97
+ log('Sounds good! Exiting configuration...');
98
+ return false;
99
+ }
100
+ log();
101
+ log(` - Hit ${chalk.white.bold('enter')} to keep the existing value in (parentheses)`);
102
+ log(` - Hit ${chalk.white.bold('down arrow')} to remove the value`);
103
+ log(` - Hit ${chalk.white.bold('ctrl + C')} to cancel & exit configuration`);
104
+ log();
105
+ log(` You will need to verify the changed before we push them to your live site!`);
106
+ log();
107
+ const prompts = generatePrompts({
108
+ config: manifest.config,
109
+ configValues: currentConfig,
110
+ });
111
+ const userInput = await inquirer.prompt(prompts);
112
+ // Merge user input with the flags specified
113
+ const newConfig = updateConfigValues(manifest.config, currentConfig, userInput);
114
+ const diffs = compare(currentConfig, newConfig);
115
+ // log('compare', diffs)
116
+ // @ts-expect-error TS(2339) FIXME: Property 'isEqual' does not exist on type 'string'... Remove this comment to see the full error message
117
+ if (diffs.isEqual) {
118
+ log(`No changes. exiting early`);
119
+ return false;
120
+ }
121
+ log();
122
+ log(`${chalk.yellowBright.bold.underline('Confirm your updates:')}`);
123
+ log();
124
+ // @ts-expect-error TS(2339) FIXME: Property 'keys' does not exist on type 'string'.
125
+ diffs.keys.forEach((key) => {
126
+ // @ts-expect-error TS(2339) FIXME: Property 'diffs' does not exist on type 'string'.
127
+ const { newValue, oldValue } = diffs.diffs[key];
128
+ const oldVal = oldValue || 'NO VALUE';
129
+ log(`${chalk.cyan(key)} changed from ${chalk.whiteBright(oldVal)} to ${chalk.green(newValue)}`);
130
+ });
131
+ log();
132
+ const confirmPrompt = await inquirer.prompt([
133
+ {
134
+ type: 'confirm',
135
+ name: 'confirmChange',
136
+ message: `Do you want to publish the updated "${addonName} add-on" settings for ${chalk.cyan(siteData.name)}?`,
137
+ default: false,
138
+ },
139
+ ]);
140
+ if (!confirmPrompt.confirmChange) {
141
+ log('Canceling changes... You are good to go!');
142
+ return false;
143
+ }
144
+ await update({
145
+ addonName,
146
+ currentConfig,
147
+ newConfig,
148
+ siteId,
149
+ instanceId: addon.id,
150
+ api,
151
+ });
151
152
  }
152
-
153
- await update({
154
- addonName,
155
- currentConfig,
156
- newConfig,
157
- siteId,
158
- instanceId: addon.id,
159
- api,
160
- })
161
- }
162
- }
163
-
153
+ };
164
154
  /**
165
155
  * Creates the `netlify addons:config` command
166
156
  * @param {import('../base-command.mjs').default} program
167
157
  * @returns
168
158
  */
169
- export const createAddonsConfigCommand = (program) =>
170
- program
159
+ // @ts-expect-error TS(7006) FIXME: Parameter 'program' implicitly has an 'any' type.
160
+ export const createAddonsConfigCommand = (program) => program
171
161
  .command('addons:config', { hidden: true })
172
162
  .alias('addon:config')
173
163
  .argument('<name>', 'Add-on namespace')
174
164
  .description('Configure add-on settings')
175
165
  // allow for any flags. Handy for variadic configuration options
176
166
  .allowUnknownOption(true)
167
+ // @ts-expect-error TS(7006) FIXME: Parameter 'addonName' implicitly has an 'any' type... Remove this comment to see the full error message
177
168
  .action(async (addonName, options, command) => {
178
- await addonsConfig(addonName, options, command)
179
- })
169
+ await addonsConfig(addonName, options, command);
170
+ });
@@ -1,31 +1,30 @@
1
- // @ts-check
2
- import inquirer from 'inquirer'
3
- import isEmpty from 'lodash/isEmpty.js'
4
-
5
- import { ADDON_VALIDATION, prepareAddonCommand } from '../../utils/addons/prepare.mjs'
6
- import generatePrompts from '../../utils/addons/prompts.mjs'
7
- import { renderConfigValues, renderMissingValues } from '../../utils/addons/render.mjs'
8
- import { missingConfigValues, requiredConfigValues, updateConfigValues } from '../../utils/addons/validation.mjs'
9
- import { chalk, error, log } from '../../utils/command-helpers.mjs'
10
- import { parseRawFlags } from '../../utils/parse-raw-flags.mjs'
11
-
1
+ import inquirer from 'inquirer';
2
+ import isEmpty from 'lodash/isEmpty.js';
3
+ import { ADDON_VALIDATION, prepareAddonCommand } from '../../utils/addons/prepare.mjs';
4
+ import generatePrompts from '../../utils/addons/prompts.mjs';
5
+ import { renderConfigValues, renderMissingValues } from '../../utils/addons/render.mjs';
6
+ import { missingConfigValues, requiredConfigValues, updateConfigValues } from '../../utils/addons/validation.mjs';
7
+ import { chalk, error, log } from '../../utils/command-helpers.mjs';
8
+ import { parseRawFlags } from '../../utils/parse-raw-flags.mjs';
9
+ // @ts-expect-error TS(7031) FIXME: Binding element 'addonName' implicitly has an 'any... Remove this comment to see the full error message
12
10
  const createAddon = async ({ addonName, api, config, siteData, siteId }) => {
13
- try {
14
- const response = await api.createServiceInstance({
15
- siteId,
16
- addon: addonName,
17
- body: { config },
18
- })
19
- log(`Add-on "${addonName}" created for ${siteData.name}`)
20
- if (response.config && response.config.message) {
21
- log()
22
- log(`${response.config.message}`)
11
+ try {
12
+ const response = await api.createServiceInstance({
13
+ siteId,
14
+ addon: addonName,
15
+ body: { config },
16
+ });
17
+ log(`Add-on "${addonName}" created for ${siteData.name}`);
18
+ if (response.config && response.config.message) {
19
+ log();
20
+ log(`${response.config.message}`);
21
+ }
23
22
  }
24
- } catch (error_) {
25
- error(error_.message)
26
- }
27
- }
28
-
23
+ catch (error_) {
24
+ // @ts-expect-error TS(2571) FIXME: Object is of type 'unknown'.
25
+ error(error_.message);
26
+ }
27
+ };
29
28
  /**
30
29
  * The addons:create command
31
30
  * @param {string} addonName
@@ -33,98 +32,85 @@ const createAddon = async ({ addonName, api, config, siteData, siteId }) => {
33
32
  * @param {import('../base-command.mjs').default} command
34
33
  * @returns {Promise<boolean>}
35
34
  */
35
+ // @ts-expect-error TS(7006) FIXME: Parameter 'addonName' implicitly has an 'any' type... Remove this comment to see the full error message
36
36
  const addonsCreate = async (addonName, options, command) => {
37
- const { manifest, siteData } = await prepareAddonCommand({
38
- command,
39
- addonName,
40
- // @ts-ignore
41
- validation: ADDON_VALIDATION.NOT_EXISTS,
42
- })
43
-
44
- const { api, site } = command.netlify
45
- const siteId = site.id
46
-
47
- // GET flags from `raw` data
48
- const rawFlags = parseRawFlags(command.args)
49
- const hasConfig = !isEmpty(manifest.config)
50
-
51
- let configValues = rawFlags
52
-
53
- if (hasConfig) {
54
- const required = requiredConfigValues(manifest.config)
55
- const missingValues = missingConfigValues(required, rawFlags)
56
- log(`Starting the setup for "${addonName} add-on"`)
57
- log()
58
-
59
- if (Object.keys(rawFlags).length !== 0) {
60
- const newConfig = updateConfigValues(manifest.config, {}, rawFlags)
61
-
62
- if (missingValues.length !== 0) {
63
- /* Warn user of missing required values */
64
- log(`${chalk.redBright.underline.bold(`Error: Missing required configuration for "${addonName} add-on"`)}`)
65
- log()
66
- renderMissingValues(missingValues, manifest)
67
- log()
68
- const msg = `netlify addons:create ${addonName}`
69
- log(`Please supply the configuration values as CLI flags`)
70
- log()
71
- log(`Alternatively, you can run ${chalk.cyan(msg)} with no flags to walk through the setup steps`)
72
- log()
73
- return false
74
- }
75
-
76
- await createAddon({ api, siteId, addonName, config: newConfig, siteData })
77
-
78
- return false
79
- }
80
-
81
- const words = `The ${addonName} add-on has the following configurable options:`
82
- log(` ${chalk.yellowBright.bold(words)}`)
83
- renderConfigValues(addonName, manifest.config)
84
- log()
85
- log(` ${chalk.greenBright.bold('Lets configure those!')}`)
86
-
87
- log()
88
- log(` - Hit ${chalk.white.bold('enter')} to confirm value or set empty value`)
89
- log(` - Hit ${chalk.white.bold('ctrl + C')} to cancel & exit configuration`)
90
- log()
91
-
92
- const prompts = generatePrompts({
93
- config: manifest.config,
94
- configValues: rawFlags,
95
- })
96
-
97
- const userInput = await inquirer.prompt(prompts)
98
- // Merge user input with the flags specified
99
- configValues = updateConfigValues(manifest.config, rawFlags, userInput)
100
- const missingRequiredValues = missingConfigValues(required, configValues)
101
- if (missingRequiredValues && missingRequiredValues.length !== 0) {
102
- missingRequiredValues.forEach((val) => {
103
- log(`Missing required value "${val}". Please run the command again`)
104
- })
105
- return false
37
+ const { manifest, siteData } = await prepareAddonCommand({
38
+ command,
39
+ addonName,
40
+ validation: ADDON_VALIDATION.NOT_EXISTS,
41
+ });
42
+ const { api, site } = command.netlify;
43
+ const siteId = site.id;
44
+ // GET flags from `raw` data
45
+ const rawFlags = parseRawFlags(command.args);
46
+ const hasConfig = !isEmpty(manifest.config);
47
+ let configValues = rawFlags;
48
+ if (hasConfig) {
49
+ const required = requiredConfigValues(manifest.config);
50
+ const missingValues = missingConfigValues(required, rawFlags);
51
+ log(`Starting the setup for "${addonName} add-on"`);
52
+ log();
53
+ if (Object.keys(rawFlags).length !== 0) {
54
+ const newConfig = updateConfigValues(manifest.config, {}, rawFlags);
55
+ if (missingValues.length !== 0) {
56
+ /* Warn user of missing required values */
57
+ log(`${chalk.redBright.underline.bold(`Error: Missing required configuration for "${addonName} add-on"`)}`);
58
+ log();
59
+ renderMissingValues(missingValues, manifest);
60
+ log();
61
+ const msg = `netlify addons:create ${addonName}`;
62
+ log(`Please supply the configuration values as CLI flags`);
63
+ log();
64
+ log(`Alternatively, you can run ${chalk.cyan(msg)} with no flags to walk through the setup steps`);
65
+ log();
66
+ return false;
67
+ }
68
+ await createAddon({ api, siteId, addonName, config: newConfig, siteData });
69
+ return false;
70
+ }
71
+ const words = `The ${addonName} add-on has the following configurable options:`;
72
+ log(` ${chalk.yellowBright.bold(words)}`);
73
+ // @ts-expect-error TS(2554) FIXME: Expected 3 arguments, but got 2.
74
+ renderConfigValues(addonName, manifest.config);
75
+ log();
76
+ log(` ${chalk.greenBright.bold('Lets configure those!')}`);
77
+ log();
78
+ log(` - Hit ${chalk.white.bold('enter')} to confirm value or set empty value`);
79
+ log(` - Hit ${chalk.white.bold('ctrl + C')} to cancel & exit configuration`);
80
+ log();
81
+ const prompts = generatePrompts({
82
+ config: manifest.config,
83
+ configValues: rawFlags,
84
+ });
85
+ const userInput = await inquirer.prompt(prompts);
86
+ // Merge user input with the flags specified
87
+ configValues = updateConfigValues(manifest.config, rawFlags, userInput);
88
+ const missingRequiredValues = missingConfigValues(required, configValues);
89
+ if (missingRequiredValues && missingRequiredValues.length !== 0) {
90
+ // @ts-expect-error TS(7006) FIXME: Parameter 'val' implicitly has an 'any' type.
91
+ missingRequiredValues.forEach((val) => {
92
+ log(`Missing required value "${val}". Please run the command again`);
93
+ });
94
+ return false;
95
+ }
106
96
  }
107
- }
108
-
109
- await createAddon({ api, siteId, addonName, config: configValues, siteData })
110
- }
111
-
97
+ await createAddon({ api, siteId, addonName, config: configValues, siteData });
98
+ };
112
99
  /**
113
100
  * Creates the `netlify addons:create` command
114
101
  * @param {import('../base-command.mjs').default} program
115
102
  * @returns
116
103
  */
117
- export const createAddonsCreateCommand = (program) =>
118
- program
104
+ // @ts-expect-error TS(7006) FIXME: Parameter 'program' implicitly has an 'any' type.
105
+ export const createAddonsCreateCommand = (program) => program
119
106
  .command('addons:create', { hidden: true })
120
107
  .alias('addon:create')
121
108
  .argument('<name>', 'Add-on namespace')
122
- .description(
123
- `Add an add-on extension to your site
124
- Add-ons are a way to extend the functionality of your Netlify site`,
125
- )
109
+ .description(`Add an add-on extension to your site
110
+ Add-ons are a way to extend the functionality of your Netlify site`)
126
111
  // allow for any flags. Handy for variadic configuration options
127
112
  .allowUnknownOption(true)
113
+ // @ts-expect-error TS(7006) FIXME: Parameter 'addonName' implicitly has an 'any' type... Remove this comment to see the full error message
128
114
  .action(async (addonName, options, command) => {
129
- await addonsCreate(addonName, options, command)
130
- })
115
+ await addonsCreate(addonName, options, command);
116
+ });