netlify-cli 17.3.1 → 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 +3 -139
  2. package/npm-shrinkwrap.json +82 -82
  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 -89
  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,79 +1,69 @@
1
- // @ts-check
2
- import { join } from 'path'
3
-
4
- import { startFunctionsServer } from '../../lib/functions/server.mjs'
5
- import { printBanner } from '../../utils/banner.mjs'
6
- import { acquirePort, getDotEnvVariables, getSiteInformation, injectEnvVariables } from '../../utils/dev.mjs'
7
- import { getFunctionsDir } from '../../utils/functions/index.mjs'
8
- import { getProxyUrl } from '../../utils/proxy.mjs'
9
-
10
- const DEFAULT_PORT = 9999
11
-
1
+ import { join } from 'path';
2
+ import { startFunctionsServer } from '../../lib/functions/server.mjs';
3
+ import { printBanner } from '../../utils/banner.mjs';
4
+ import { acquirePort, getDotEnvVariables, getSiteInformation, injectEnvVariables } from '../../utils/dev.mjs';
5
+ import { getFunctionsDir } from '../../utils/functions/index.mjs';
6
+ import { getProxyUrl } from '../../utils/proxy.mjs';
7
+ const DEFAULT_PORT = 9999;
12
8
  /**
13
9
  * The functions:serve command
14
10
  * @param {import('commander').OptionValues} options
15
11
  * @param {import('../base-command.mjs').default} command
16
12
  */
13
+ // @ts-expect-error TS(7006) FIXME: Parameter 'options' implicitly has an 'any' type.
17
14
  const functionsServe = async (options, command) => {
18
- const { api, config, site, siteInfo, state } = command.netlify
19
-
20
- const functionsDir = getFunctionsDir({ options, config }, join('netlify', 'functions'))
21
- let { env } = command.netlify.cachedConfig
22
-
23
- env.NETLIFY_DEV = { sources: ['internal'], value: 'true' }
24
-
25
- env = await getDotEnvVariables({ devConfig: { ...config.dev }, env, site })
26
- injectEnvVariables(env)
27
-
28
- const { accountId, capabilities, siteUrl, timeouts } = await getSiteInformation({
29
- offline: options.offline,
30
- api,
31
- site,
32
- siteInfo,
33
- })
34
-
35
- const functionsPort = await acquirePort({
36
- configuredPort: options.port || (config.dev && config.dev.functionsPort),
37
- defaultPort: DEFAULT_PORT,
38
- errorMessage: 'Could not acquire configured functions port',
39
- })
40
-
41
- await startFunctionsServer({
42
- config,
43
- debug: options.debug,
44
- command,
45
- api,
46
- settings: { functions: functionsDir, functionsPort },
47
- site,
48
- siteInfo,
49
- siteUrl,
50
- capabilities,
51
- timeouts,
52
- functionsPrefix: '/.netlify/functions/',
53
- buildersPrefix: '/.netlify/builders/',
54
- geolocationMode: options.geo,
55
- geoCountry: options.country,
56
- offline: options.offline,
57
- state,
58
- accountId,
59
- })
60
-
61
- const url = getProxyUrl({ port: functionsPort })
62
- printBanner({ url })
63
- }
64
-
15
+ const { api, config, site, siteInfo, state } = command.netlify;
16
+ const functionsDir = getFunctionsDir({ options, config }, join('netlify', 'functions'));
17
+ let { env } = command.netlify.cachedConfig;
18
+ env.NETLIFY_DEV = { sources: ['internal'], value: 'true' };
19
+ env = await getDotEnvVariables({ devConfig: { ...config.dev }, env, site });
20
+ injectEnvVariables(env);
21
+ const { accountId, capabilities, siteUrl, timeouts } = await getSiteInformation({
22
+ offline: options.offline,
23
+ api,
24
+ site,
25
+ siteInfo,
26
+ });
27
+ const functionsPort = await acquirePort({
28
+ configuredPort: options.port || (config.dev && config.dev.functionsPort),
29
+ defaultPort: DEFAULT_PORT,
30
+ errorMessage: 'Could not acquire configured functions port',
31
+ });
32
+ await startFunctionsServer({
33
+ config,
34
+ debug: options.debug,
35
+ command,
36
+ api,
37
+ settings: { functions: functionsDir, functionsPort },
38
+ site,
39
+ siteInfo,
40
+ siteUrl,
41
+ capabilities,
42
+ timeouts,
43
+ functionsPrefix: '/.netlify/functions/',
44
+ buildersPrefix: '/.netlify/builders/',
45
+ geolocationMode: options.geo,
46
+ geoCountry: options.country,
47
+ offline: options.offline,
48
+ state,
49
+ accountId,
50
+ });
51
+ const url = getProxyUrl({ port: functionsPort });
52
+ printBanner({ url });
53
+ };
65
54
  /**
66
55
  * Creates the `netlify functions:serve` command
67
56
  * @param {import('../base-command.mjs').default} program
68
57
  * @returns
69
58
  */
70
- export const createFunctionsServeCommand = (program) =>
71
- program
59
+ // @ts-expect-error TS(7006) FIXME: Parameter 'program' implicitly has an 'any' type.
60
+ export const createFunctionsServeCommand = (program) => program
72
61
  .command('functions:serve')
73
62
  .alias('function:serve')
74
63
  .description('Serve functions locally')
75
64
  .option('-f, --functions <dir>', 'Specify a functions directory to serve')
65
+ // @ts-expect-error TS(7006) FIXME: Parameter 'value' implicitly has an 'any' type.
76
66
  .option('-p, --port <port>', 'Specify a port for the functions server', (value) => Number.parseInt(value))
77
67
  .option('-o, --offline', 'disables any features that require network access')
78
68
  .addHelpText('after', 'Helpful for debugging functions.')
79
- .action(functionsServe)
69
+ .action(functionsServe);
@@ -1,45 +1,39 @@
1
- // @ts-check
2
- import { chalk } from '../../utils/command-helpers.mjs'
3
-
4
- import { createFunctionsBuildCommand } from './functions-build.mjs'
5
- import { createFunctionsCreateCommand } from './functions-create.mjs'
6
- import { createFunctionsInvokeCommand } from './functions-invoke.mjs'
7
- import { createFunctionsListCommand } from './functions-list.mjs'
8
- import { createFunctionsServeCommand } from './functions-serve.mjs'
9
-
1
+ import { chalk } from '../../utils/command-helpers.mjs';
2
+ import { createFunctionsBuildCommand } from './functions-build.mjs';
3
+ import { createFunctionsCreateCommand } from './functions-create.mjs';
4
+ import { createFunctionsInvokeCommand } from './functions-invoke.mjs';
5
+ import { createFunctionsListCommand } from './functions-list.mjs';
6
+ import { createFunctionsServeCommand } from './functions-serve.mjs';
10
7
  /**
11
8
  * The functions command
12
9
  * @param {import('commander').OptionValues} options
13
10
  * @param {import('../base-command.mjs').default} command
14
11
  */
12
+ // @ts-expect-error TS(7006) FIXME: Parameter 'options' implicitly has an 'any' type.
15
13
  const functions = (options, command) => {
16
- command.help()
17
- }
18
-
14
+ command.help();
15
+ };
19
16
  /**
20
17
  * Creates the `netlify functions` command
21
18
  * @param {import('../base-command.mjs').default} program
22
19
  * @returns
23
20
  */
21
+ // @ts-expect-error TS(7006) FIXME: Parameter 'program' implicitly has an 'any' type.
24
22
  export const createFunctionsCommand = (program) => {
25
- createFunctionsBuildCommand(program)
26
- createFunctionsCreateCommand(program)
27
- createFunctionsInvokeCommand(program)
28
- createFunctionsListCommand(program)
29
- createFunctionsServeCommand(program)
30
-
31
- const name = chalk.greenBright('`functions`')
32
-
33
- return program
34
- .command('functions')
35
- .alias('function')
36
- .description(
37
- `Manage netlify functions
38
- The ${name} command will help you manage the functions in this site`,
39
- )
40
- .addExamples([
41
- 'netlify functions:create --name function-xyz',
42
- 'netlify functions:build --functions build/to/directory --src source/directory',
23
+ createFunctionsBuildCommand(program);
24
+ createFunctionsCreateCommand(program);
25
+ createFunctionsInvokeCommand(program);
26
+ createFunctionsListCommand(program);
27
+ createFunctionsServeCommand(program);
28
+ const name = chalk.greenBright('`functions`');
29
+ return program
30
+ .command('functions')
31
+ .alias('function')
32
+ .description(`Manage netlify functions
33
+ The ${name} command will help you manage the functions in this site`)
34
+ .addExamples([
35
+ 'netlify functions:create --name function-xyz',
36
+ 'netlify functions:build --functions build/to/directory --src source/directory',
43
37
  ])
44
- .action(functions)
45
- }
38
+ .action(functions);
39
+ };
@@ -1 +1 @@
1
- export { createFunctionsCommand } from './functions.mjs'
1
+ export { createFunctionsCommand } from './functions.mjs';
@@ -1,2 +1,2 @@
1
- export { default as BaseCommand } from './base-command.mjs'
2
- export { createMainCommand } from './main.mjs'
1
+ export { default as BaseCommand } from './base-command.mjs';
2
+ export { createMainCommand } from './main.mjs';
@@ -1 +1 @@
1
- export { createInitCommand, init } from './init.mjs'
1
+ export { createInitCommand, init } from './init.mjs';
@@ -1,64 +1,59 @@
1
- // @ts-check
2
- import { Option } from 'commander'
3
- import inquirer from 'inquirer'
4
- import isEmpty from 'lodash/isEmpty.js'
5
-
6
- import { chalk, exit, log } from '../../utils/command-helpers.mjs'
7
- import getRepoData from '../../utils/get-repo-data.mjs'
8
- import { ensureNetlifyIgnore } from '../../utils/gitignore.mjs'
9
- import { configureRepo } from '../../utils/init/config.mjs'
10
- import { track } from '../../utils/telemetry/index.mjs'
11
- import { link } from '../link/index.mjs'
12
- import { sitesCreate } from '../sites/index.mjs'
13
-
1
+ import { Option } from 'commander';
2
+ import inquirer from 'inquirer';
3
+ import isEmpty from 'lodash/isEmpty.js';
4
+ import { chalk, exit, log } from '../../utils/command-helpers.mjs';
5
+ import getRepoData from '../../utils/get-repo-data.mjs';
6
+ import { ensureNetlifyIgnore } from '../../utils/gitignore.mjs';
7
+ import { configureRepo } from '../../utils/init/config.mjs';
8
+ import { track } from '../../utils/telemetry/index.mjs';
9
+ import { link } from '../link/index.mjs';
10
+ import { sitesCreate } from '../sites/index.mjs';
11
+ // @ts-expect-error TS(7031) FIXME: Binding element 'siteInfo' implicitly has an 'any'... Remove this comment to see the full error message
14
12
  const persistState = ({ siteInfo, state }) => {
15
- // Save to .netlify/state.json file
16
- state.set('siteId', siteInfo.id)
17
- }
18
-
13
+ // Save to .netlify/state.json file
14
+ state.set('siteId', siteInfo.id);
15
+ };
19
16
  /**
20
17
  * @param {{} | undefined} siteInfo
21
18
  * @returns {string | undefined}
22
19
  */
23
- const getRepoUrl = (siteInfo) => siteInfo?.build_settings?.repo_url
24
-
20
+ // @ts-expect-error TS(7006) FIXME: Parameter 'siteInfo' implicitly has an 'any' type.
21
+ const getRepoUrl = (siteInfo) => siteInfo?.build_settings?.repo_url;
22
+ // @ts-expect-error TS(7031) FIXME: Binding element 'siteInfo' implicitly has an 'any'... Remove this comment to see the full error message
25
23
  const logExistingAndExit = ({ siteInfo }) => {
26
- log()
27
- log(`This site has been initialized`)
28
- log()
29
- log(`Site Name: ${chalk.cyan(siteInfo.name)}`)
30
- log(`Site Url: ${chalk.cyan(siteInfo.ssl_url || siteInfo.url)}`)
31
- log(`Site Repo: ${chalk.cyan(getRepoUrl({ siteInfo }))}`)
32
- log(`Site Id: ${chalk.cyan(siteInfo.id)}`)
33
- log(`Admin URL: ${chalk.cyan(siteInfo.admin_url)}`)
34
- log()
35
- log(`To disconnect this directory and create a new site (or link to another siteId)`)
36
- log(`1. Run ${chalk.cyanBright.bold('netlify unlink')}`)
37
- log(`2. Then run ${chalk.cyanBright.bold('netlify init')} again`)
38
- exit()
39
- }
40
-
24
+ log();
25
+ log(`This site has been initialized`);
26
+ log();
27
+ log(`Site Name: ${chalk.cyan(siteInfo.name)}`);
28
+ log(`Site Url: ${chalk.cyan(siteInfo.ssl_url || siteInfo.url)}`);
29
+ log(`Site Repo: ${chalk.cyan(getRepoUrl({ siteInfo }))}`);
30
+ log(`Site Id: ${chalk.cyan(siteInfo.id)}`);
31
+ log(`Admin URL: ${chalk.cyan(siteInfo.admin_url)}`);
32
+ log();
33
+ log(`To disconnect this directory and create a new site (or link to another siteId)`);
34
+ log(`1. Run ${chalk.cyanBright.bold('netlify unlink')}`);
35
+ log(`2. Then run ${chalk.cyanBright.bold('netlify init')} again`);
36
+ exit();
37
+ };
41
38
  /**
42
39
  * Creates and new site and exits the process
43
40
  * @param {object} config
44
41
  * @param {*} config.state
45
42
  * @param {import('../base-command.mjs').default} config.command
46
43
  */
44
+ // @ts-expect-error TS(7031) FIXME: Binding element 'command' implicitly has an 'any' ... Remove this comment to see the full error message
47
45
  const createNewSiteAndExit = async ({ command, state }) => {
48
- const siteInfo = await sitesCreate({}, command)
49
-
50
- log(`"${siteInfo.name}" site was created`)
51
- log()
52
- log(`To deploy to this site. Run your site build and then ${chalk.cyanBright.bold('netlify deploy')}`)
53
-
54
- persistState({ state, siteInfo })
55
-
56
- exit()
57
- }
58
-
46
+ const siteInfo = await sitesCreate({}, command);
47
+ // @ts-expect-error TS(2532) FIXME: Object is possibly 'undefined'.
48
+ log(`"${siteInfo.name}" site was created`);
49
+ log();
50
+ log(`To deploy to this site. Run your site build and then ${chalk.cyanBright.bold('netlify deploy')}`);
51
+ persistState({ state, siteInfo });
52
+ exit();
53
+ };
59
54
  const logGitSetupInstructionsAndExit = () => {
60
- log()
61
- log(`${chalk.bold('To initialize a new git repo follow the steps below.')}
55
+ log();
56
+ log(`${chalk.bold('To initialize a new git repo follow the steps below.')}
62
57
 
63
58
  1. Initialize a new repo:
64
59
 
@@ -85,10 +80,9 @@ const logGitSetupInstructionsAndExit = () => {
85
80
  7. Initialize your Netlify Site
86
81
 
87
82
  ${chalk.cyanBright.bold('netlify init')}
88
- `)
89
- exit()
90
- }
91
-
83
+ `);
84
+ exit();
85
+ };
92
86
  /**
93
87
  * Handles the case where no git remote was found.
94
88
  * @param {object} config
@@ -96,148 +90,125 @@ const logGitSetupInstructionsAndExit = () => {
96
90
  * @param {object} config.error
97
91
  * @param {object} config.state
98
92
  */
93
+ // @ts-expect-error TS(7031) FIXME: Binding element 'command' implicitly has an 'any' ... Remove this comment to see the full error message
99
94
  const handleNoGitRemoteAndExit = async ({ command, error, state }) => {
100
- log()
101
- log(`${chalk.yellow('No git remote was found, would you like to set one up?')}`)
102
- log(`
95
+ log();
96
+ log(`${chalk.yellow('No git remote was found, would you like to set one up?')}`);
97
+ log(`
103
98
  It is recommended that you initialize a site that has a remote repository in GitHub.
104
99
 
105
100
  This will allow for Netlify Continuous deployment to build branch & PR previews.
106
101
 
107
102
  For more details on Netlify CI checkout the docs: http://bit.ly/2N0Jhy5
108
- `)
109
- if (error === "Couldn't find origin url") {
110
- log(`Unable to find a remote origin URL. Please add a git remote.
103
+ `);
104
+ if (error === "Couldn't find origin url") {
105
+ log(`Unable to find a remote origin URL. Please add a git remote.
111
106
 
112
107
  git remote add origin https://github.com/YourUserName/RepoName.git
113
- `)
114
- }
115
-
116
- const NEW_SITE_NO_GIT = 'Yes, create and deploy site manually'
117
- const NO_ABORT = 'No, I will connect this directory with GitHub first'
118
-
119
- const { noGitRemoteChoice } = await inquirer.prompt([
120
- {
121
- type: 'list',
122
- name: 'noGitRemoteChoice',
123
- message: 'Do you want to create a Netlify site without a git repository?',
124
- choices: [NEW_SITE_NO_GIT, NO_ABORT],
125
- },
126
- ])
127
-
128
- if (noGitRemoteChoice === NEW_SITE_NO_GIT) {
129
- await createNewSiteAndExit({ state, command })
130
- } else if (noGitRemoteChoice === NO_ABORT) {
131
- logGitSetupInstructionsAndExit()
132
- }
133
- }
134
-
108
+ `);
109
+ }
110
+ const NEW_SITE_NO_GIT = 'Yes, create and deploy site manually';
111
+ const NO_ABORT = 'No, I will connect this directory with GitHub first';
112
+ const { noGitRemoteChoice } = await inquirer.prompt([
113
+ {
114
+ type: 'list',
115
+ name: 'noGitRemoteChoice',
116
+ message: 'Do you want to create a Netlify site without a git repository?',
117
+ choices: [NEW_SITE_NO_GIT, NO_ABORT],
118
+ },
119
+ ]);
120
+ if (noGitRemoteChoice === NEW_SITE_NO_GIT) {
121
+ await createNewSiteAndExit({ state, command });
122
+ }
123
+ else if (noGitRemoteChoice === NO_ABORT) {
124
+ logGitSetupInstructionsAndExit();
125
+ }
126
+ };
135
127
  /**
136
128
  * Creates a new site or links an existing one to the repository
137
129
  * @param {import('../base-command.mjs').default} command
138
130
  */
131
+ // @ts-expect-error TS(7006) FIXME: Parameter 'command' implicitly has an 'any' type.
139
132
  const createOrLinkSiteToRepo = async (command) => {
140
- const NEW_SITE = '+ Create & configure a new site'
141
- const EXISTING_SITE = '⇄ Connect this directory to an existing Netlify site'
142
-
143
- const initializeOpts = [EXISTING_SITE, NEW_SITE]
144
-
145
- const { initChoice } = await inquirer.prompt([
146
- {
147
- type: 'list',
148
- name: 'initChoice',
149
- message: 'What would you like to do?',
150
- choices: initializeOpts,
151
- },
152
- ])
153
-
154
- // create site or search for one
155
- if (initChoice === NEW_SITE) {
156
- await track('sites_initStarted', {
157
- type: 'new site',
158
- })
159
- // run site:create command
160
- return await sitesCreate({}, command)
161
- }
162
- if (initChoice === EXISTING_SITE) {
163
- // run link command
164
- return await link({}, command)
165
- }
166
- }
167
-
133
+ const NEW_SITE = '+ Create & configure a new site';
134
+ const EXISTING_SITE = '⇄ Connect this directory to an existing Netlify site';
135
+ const initializeOpts = [EXISTING_SITE, NEW_SITE];
136
+ const { initChoice } = await inquirer.prompt([
137
+ {
138
+ type: 'list',
139
+ name: 'initChoice',
140
+ message: 'What would you like to do?',
141
+ choices: initializeOpts,
142
+ },
143
+ ]);
144
+ // create site or search for one
145
+ if (initChoice === NEW_SITE) {
146
+ await track('sites_initStarted', {
147
+ type: 'new site',
148
+ });
149
+ // run site:create command
150
+ return await sitesCreate({}, command);
151
+ }
152
+ if (initChoice === EXISTING_SITE) {
153
+ // run link command
154
+ return await link({}, command);
155
+ }
156
+ };
157
+ // @ts-expect-error TS(7031) FIXME: Binding element 'repoUrl' implicitly has an 'any' ... Remove this comment to see the full error message
168
158
  const logExistingRepoSetupAndExit = ({ repoUrl, siteName }) => {
169
- log()
170
- log(chalk.underline.bold(`Success`))
171
- log(`This site "${siteName}" is configured to automatically deploy via ${repoUrl}`)
172
- // TODO add support for changing GitHub repo in site:config command
173
- exit()
174
- }
175
-
159
+ log();
160
+ log(chalk.underline.bold(`Success`));
161
+ log(`This site "${siteName}" is configured to automatically deploy via ${repoUrl}`);
162
+ // TODO add support for changing GitHub repo in site:config command
163
+ exit();
164
+ };
176
165
  /**
177
166
  * The init command
178
167
  * @param {import('commander').OptionValues} options
179
168
  * @param {import('../base-command.mjs').default} command
180
169
  */
170
+ // @ts-expect-error TS(7006) FIXME: Parameter 'options' implicitly has an 'any' type.
181
171
  export const init = async (options, command) => {
182
- command.setAnalyticsPayload({ manual: options.manual, force: options.force })
183
-
184
- const { repositoryRoot, state } = command.netlify
185
- let { siteInfo } = command.netlify
186
-
187
- // Check logged in status
188
- await command.authenticate()
189
-
190
- // Add .netlify to .gitignore file
191
- await ensureNetlifyIgnore(repositoryRoot)
192
-
193
- const repoUrl = getRepoUrl(siteInfo)
194
- if (repoUrl && !options.force) {
195
- logExistingAndExit({ siteInfo })
196
- }
197
-
198
- // Look for local repo
199
- const repoData = await getRepoData({ workingDir: command.workingDir, remoteName: options.gitRemoteName })
200
- if (repoData.error) {
201
- await handleNoGitRemoteAndExit({ command, error: repoData.error, state })
202
- }
203
-
204
- if (isEmpty(siteInfo)) {
205
- siteInfo = await createOrLinkSiteToRepo(command)
206
- }
207
-
208
- log()
209
-
210
- // Check for existing CI setup
211
- const remoteBuildRepo = getRepoUrl(siteInfo)
212
- if (remoteBuildRepo && !options.force) {
213
- logExistingRepoSetupAndExit({ siteName: siteInfo.name, repoUrl: remoteBuildRepo })
214
- }
215
-
216
- persistState({ state, siteInfo })
217
-
218
- await configureRepo({ command, siteId: siteInfo.id, repoData, manual: options.manual })
219
-
220
- return siteInfo
221
- }
222
-
172
+ command.setAnalyticsPayload({ manual: options.manual, force: options.force });
173
+ const { repositoryRoot, state } = command.netlify;
174
+ let { siteInfo } = command.netlify;
175
+ // Check logged in status
176
+ await command.authenticate();
177
+ // Add .netlify to .gitignore file
178
+ await ensureNetlifyIgnore(repositoryRoot);
179
+ const repoUrl = getRepoUrl(siteInfo);
180
+ if (repoUrl && !options.force) {
181
+ logExistingAndExit({ siteInfo });
182
+ }
183
+ // Look for local repo
184
+ const repoData = await getRepoData({ workingDir: command.workingDir, remoteName: options.gitRemoteName });
185
+ if (repoData.error) {
186
+ await handleNoGitRemoteAndExit({ command, error: repoData.error, state });
187
+ }
188
+ if (isEmpty(siteInfo)) {
189
+ siteInfo = await createOrLinkSiteToRepo(command);
190
+ }
191
+ log();
192
+ // Check for existing CI setup
193
+ const remoteBuildRepo = getRepoUrl(siteInfo);
194
+ if (remoteBuildRepo && !options.force) {
195
+ logExistingRepoSetupAndExit({ siteName: siteInfo.name, repoUrl: remoteBuildRepo });
196
+ }
197
+ persistState({ state, siteInfo });
198
+ await configureRepo({ command, siteId: siteInfo.id, repoData, manual: options.manual });
199
+ return siteInfo;
200
+ };
223
201
  /**
224
202
  * Creates the `netlify init` command
225
203
  * @param {import('../base-command.mjs').default} program
226
204
  * @returns
227
205
  */
228
- export const createInitCommand = (program) =>
229
- program
206
+ // @ts-expect-error TS(7006) FIXME: Parameter 'program' implicitly has an 'any' type.
207
+ export const createInitCommand = (program) => program
230
208
  .command('init')
231
- .description(
232
- 'Configure continuous deployment for a new or existing site. To create a new site without continuous deployment, use `netlify sites:create`',
233
- )
209
+ .description('Configure continuous deployment for a new or existing site. To create a new site without continuous deployment, use `netlify sites:create`')
234
210
  .option('-m, --manual', 'Manually configure a git remote for CI')
235
211
  .option('--force', 'Reinitialize CI hooks if the linked site is already configured to use CI')
236
- .addOption(
237
- new Option(
238
- '--gitRemoteName <name>',
239
- 'Old, prefer --git-remote-name. Name of Git remote to use. e.g. "origin"',
240
- ).hideHelp(true),
241
- )
212
+ .addOption(new Option('--gitRemoteName <name>', 'Old, prefer --git-remote-name. Name of Git remote to use. e.g. "origin"').hideHelp(true))
242
213
  .option('--git-remote-name <name>', 'Name of Git remote to use. e.g. "origin"')
243
- .action(init)
214
+ .action(init);