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.
- package/README.md +3 -139
- package/npm-shrinkwrap.json +82 -82
- package/package.json +16 -15
- package/src/commands/addons/addons-auth.mjs +27 -30
- package/src/commands/addons/addons-config.mjs +145 -154
- package/src/commands/addons/addons-create.mjs +94 -108
- package/src/commands/addons/addons-delete.mjs +36 -41
- package/src/commands/addons/addons-list.mjs +38 -42
- package/src/commands/addons/addons.mjs +26 -28
- package/src/commands/addons/index.mjs +1 -1
- package/src/commands/api/api.mjs +45 -53
- package/src/commands/api/index.mjs +1 -1
- package/src/commands/base-command.mjs +597 -684
- package/src/commands/blobs/blobs-delete.mjs +35 -0
- package/src/commands/blobs/blobs-get.mjs +44 -0
- package/src/commands/blobs/blobs-list.mjs +48 -0
- package/src/commands/blobs/blobs-set.mjs +54 -0
- package/src/commands/blobs/blobs.mjs +32 -0
- package/src/commands/blobs/index.mjs +1 -0
- package/src/commands/build/build.mjs +55 -67
- package/src/commands/build/index.mjs +1 -1
- package/src/commands/completion/completion.mjs +41 -46
- package/src/commands/completion/index.mjs +1 -1
- package/src/commands/deploy/deploy.mjs +675 -710
- package/src/commands/deploy/index.mjs +1 -1
- package/src/commands/dev/dev-exec.mjs +20 -32
- package/src/commands/dev/dev.mjs +217 -302
- package/src/commands/dev/index.mjs +1 -1
- package/src/commands/dev/types.d.ts +30 -0
- package/src/commands/env/env-clone.mjs +157 -184
- package/src/commands/env/env-get.mjs +49 -68
- package/src/commands/env/env-import.mjs +100 -119
- package/src/commands/env/env-list.mjs +104 -129
- package/src/commands/env/env-set.mjs +160 -185
- package/src/commands/env/env-unset.mjs +104 -122
- package/src/commands/env/env.mjs +28 -30
- package/src/commands/env/index.mjs +1 -1
- package/src/commands/functions/functions-build.mjs +29 -41
- package/src/commands/functions/functions-create.mjs +533 -601
- package/src/commands/functions/functions-invoke.mjs +193 -216
- package/src/commands/functions/functions-list.mjs +45 -55
- package/src/commands/functions/functions-serve.mjs +51 -61
- package/src/commands/functions/functions.mjs +26 -32
- package/src/commands/functions/index.mjs +1 -1
- package/src/commands/index.mjs +2 -2
- package/src/commands/init/index.mjs +1 -1
- package/src/commands/init/init.mjs +138 -167
- package/src/commands/integration/deploy.mjs +337 -399
- package/src/commands/integration/index.mjs +12 -13
- package/src/commands/link/index.mjs +1 -1
- package/src/commands/link/link.mjs +298 -317
- package/src/commands/lm/index.mjs +1 -1
- package/src/commands/lm/lm-info.mjs +23 -31
- package/src/commands/lm/lm-install.mjs +13 -17
- package/src/commands/lm/lm-setup.mjs +80 -84
- package/src/commands/lm/lm-uninstall.mjs +7 -12
- package/src/commands/lm/lm.mjs +18 -22
- package/src/commands/login/index.mjs +1 -1
- package/src/commands/login/login.mjs +35 -41
- package/src/commands/logout/index.mjs +1 -1
- package/src/commands/logout/logout.mjs +25 -31
- package/src/commands/main.mjs +166 -201
- package/src/commands/open/index.mjs +1 -1
- package/src/commands/open/open-admin.mjs +15 -18
- package/src/commands/open/open-site.mjs +16 -19
- package/src/commands/open/open.mjs +24 -27
- package/src/commands/recipes/common.mjs +23 -34
- package/src/commands/recipes/index.mjs +1 -1
- package/src/commands/recipes/recipes-list.mjs +13 -20
- package/src/commands/recipes/recipes.mjs +59 -72
- package/src/commands/serve/index.mjs +1 -1
- package/src/commands/serve/serve.mjs +142 -189
- package/src/commands/sites/index.mjs +2 -2
- package/src/commands/sites/sites-create-template.mjs +214 -236
- package/src/commands/sites/sites-create.mjs +145 -157
- package/src/commands/sites/sites-delete.mjs +75 -81
- package/src/commands/sites/sites-list.mjs +63 -66
- package/src/commands/sites/sites.mjs +18 -20
- package/src/commands/status/index.mjs +1 -1
- package/src/commands/status/status-hooks.mjs +32 -34
- package/src/commands/status/status.mjs +99 -106
- package/src/commands/switch/index.mjs +1 -1
- package/src/commands/switch/switch.mjs +32 -37
- package/src/commands/types.d.ts +31 -0
- package/src/commands/unlink/index.mjs +1 -1
- package/src/commands/unlink/unlink.mjs +23 -29
- package/src/commands/watch/index.mjs +1 -1
- package/src/commands/watch/watch.mjs +91 -105
- package/src/functions-templates/javascript/hello/{{name}}.js +2 -3
- package/src/lib/account.mjs +4 -5
- package/src/lib/api.mjs +22 -20
- package/src/lib/blobs/blobs.mjs +36 -45
- package/src/lib/build.mjs +82 -85
- package/src/lib/completion/constants.mjs +2 -4
- package/src/lib/completion/generate-autocompletion.mjs +33 -36
- package/src/lib/completion/get-autocompletion.mjs +31 -35
- package/src/lib/completion/index.mjs +1 -1
- package/src/lib/completion/script.mjs +12 -19
- package/src/lib/edge-functions/bootstrap.mjs +3 -5
- package/src/lib/edge-functions/consts.mjs +9 -10
- package/src/lib/edge-functions/deploy.mjs +28 -34
- package/src/lib/edge-functions/editor-helper.mjs +29 -42
- package/src/lib/edge-functions/headers.mjs +24 -26
- package/src/lib/edge-functions/internal.mjs +38 -44
- package/src/lib/edge-functions/proxy.mjs +229 -228
- package/src/lib/edge-functions/registry.mjs +473 -574
- package/src/lib/exec-fetcher.mjs +115 -122
- package/src/lib/fs.mjs +28 -27
- package/src/lib/functions/background.mjs +16 -20
- package/src/lib/functions/config.mjs +12 -9
- package/src/lib/functions/form-submissions-handler.mjs +143 -149
- package/src/lib/functions/local-proxy.mjs +40 -44
- package/src/lib/functions/memoized-build.mjs +19 -21
- package/src/lib/functions/netlify-function.mjs +269 -249
- package/src/lib/functions/registry.mjs +509 -568
- package/src/lib/functions/runtimes/go/index.mjs +62 -71
- package/src/lib/functions/runtimes/index.mjs +8 -15
- package/src/lib/functions/runtimes/js/builders/netlify-lambda.mjs +55 -64
- package/src/lib/functions/runtimes/js/builders/zisi.mjs +135 -154
- package/src/lib/functions/runtimes/js/constants.mjs +1 -1
- package/src/lib/functions/runtimes/js/index.mjs +92 -109
- package/src/lib/functions/runtimes/js/worker.mjs +43 -45
- package/src/lib/functions/runtimes/rust/index.mjs +64 -73
- package/src/lib/functions/scheduled.mjs +70 -88
- package/src/lib/functions/server.mjs +269 -327
- package/src/lib/functions/synchronous.mjs +118 -147
- package/src/lib/functions/utils.mjs +38 -46
- package/src/lib/geo-location.mjs +69 -81
- package/src/lib/http-agent.mjs +87 -90
- package/src/lib/images/proxy.mjs +97 -89
- package/src/lib/log.mjs +6 -9
- package/src/lib/path.mjs +2 -1
- package/src/lib/render-error-template.mjs +19 -20
- package/src/lib/settings.mjs +17 -19
- package/src/lib/spinner.mjs +21 -23
- package/src/lib/string.mjs +4 -2
- package/src/recipes/vscode/index.mjs +69 -85
- package/src/recipes/vscode/settings.mjs +53 -58
- package/src/utils/addons/compare.mjs +31 -32
- package/src/utils/addons/diffs/index.mjs +16 -17
- package/src/utils/addons/diffs/options.mjs +99 -101
- package/src/utils/addons/prepare.mjs +100 -97
- package/src/utils/addons/prompts.mjs +73 -76
- package/src/utils/addons/render.mjs +33 -36
- package/src/utils/addons/validation.mjs +19 -15
- package/src/utils/banner.mjs +11 -16
- package/src/utils/build-info.mjs +65 -66
- package/src/utils/command-helpers.mjs +185 -199
- package/src/utils/create-deferred.mjs +9 -12
- package/src/utils/create-stream-promise.mjs +54 -47
- package/src/utils/deploy/constants.mjs +9 -11
- package/src/utils/deploy/deploy-site.mjs +162 -182
- package/src/utils/deploy/hash-config.mjs +21 -21
- package/src/utils/deploy/hash-files.mjs +34 -38
- package/src/utils/deploy/hash-fns.mjs +149 -154
- package/src/utils/deploy/hasher-segments.mjs +58 -52
- package/src/utils/deploy/upload-files.mjs +99 -113
- package/src/utils/deploy/util.mjs +85 -91
- package/src/utils/detect-server-settings.mjs +236 -268
- package/src/utils/dev.mjs +163 -178
- package/src/utils/dot-env.mjs +37 -42
- package/src/utils/env/index.mjs +148 -148
- package/src/utils/execa.mjs +9 -13
- package/src/utils/feature-flags.mjs +6 -5
- package/src/utils/framework-server.mjs +43 -52
- package/src/utils/functions/constants.mjs +1 -1
- package/src/utils/functions/functions.mjs +30 -40
- package/src/utils/functions/get-functions.mjs +28 -29
- package/src/utils/functions/index.mjs +3 -3
- package/src/utils/get-global-config.mjs +33 -36
- package/src/utils/get-package-json.mjs +14 -15
- package/src/utils/get-repo-data.mjs +54 -64
- package/src/utils/get-site.mjs +14 -14
- package/src/utils/gh-auth.mjs +79 -100
- package/src/utils/gitignore.mjs +37 -40
- package/src/utils/headers.mjs +33 -35
- package/src/utils/hooks/requires-site-info.mjs +26 -22
- package/src/utils/init/config-github.mjs +207 -219
- package/src/utils/init/config-manual.mjs +83 -100
- package/src/utils/init/config.mjs +25 -26
- package/src/utils/init/node-version.mjs +23 -30
- package/src/utils/init/plugins.mjs +12 -8
- package/src/utils/init/utils.mjs +152 -172
- package/src/utils/live-tunnel.mjs +118 -141
- package/src/utils/lm/install.mjs +220 -259
- package/src/utils/lm/requirements.mjs +54 -63
- package/src/utils/lm/steps.mjs +31 -31
- package/src/utils/lm/ui.mjs +13 -20
- package/src/utils/open-browser.mjs +31 -32
- package/src/utils/parse-raw-flags.mjs +39 -35
- package/src/utils/proxy-server.mjs +84 -71
- package/src/utils/proxy.mjs +696 -750
- package/src/utils/read-repo-url.mjs +48 -47
- package/src/utils/redirects.mjs +49 -49
- package/src/utils/request-id.mjs +2 -4
- package/src/utils/rules-proxy.mjs +96 -100
- package/src/utils/run-build.mjs +109 -132
- package/src/utils/shell.mjs +99 -106
- package/src/utils/sign-redirect.mjs +14 -14
- package/src/utils/sites/utils.mjs +48 -55
- package/src/utils/state-config.mjs +101 -101
- package/src/utils/static-server.mjs +28 -34
- package/src/utils/telemetry/index.mjs +2 -2
- package/src/utils/telemetry/report-error.mjs +45 -49
- package/src/utils/telemetry/request.mjs +36 -43
- package/src/utils/telemetry/telemetry.mjs +90 -105
- package/src/utils/telemetry/utils.mjs +5 -6
- package/src/utils/telemetry/validation.mjs +55 -53
- package/src/utils/types.d.ts +46 -0
- package/src/utils/validation.mjs +10 -13
|
@@ -1,79 +1,69 @@
|
|
|
1
|
-
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
|
|
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
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
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
|
-
|
|
71
|
-
|
|
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
|
-
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
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
|
-
|
|
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
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
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
|
-
|
|
45
|
-
}
|
|
38
|
+
.action(functions);
|
|
39
|
+
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export { createFunctionsCommand } from './functions.mjs'
|
|
1
|
+
export { createFunctionsCommand } from './functions.mjs';
|
package/src/commands/index.mjs
CHANGED
|
@@ -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
|
-
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import
|
|
5
|
-
|
|
6
|
-
import {
|
|
7
|
-
import
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
11
|
-
|
|
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
|
-
|
|
16
|
-
|
|
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
|
-
|
|
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
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
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
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
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
|
-
|
|
61
|
-
|
|
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
|
-
|
|
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
|
-
|
|
101
|
-
|
|
102
|
-
|
|
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
|
-
|
|
110
|
-
|
|
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
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
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
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
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
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
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
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
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
|
-
|
|
229
|
-
|
|
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);
|