netlify-cli 17.6.0 → 17.7.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/bin/{run.mjs → run.js} +3 -3
- package/npm-shrinkwrap.json +4 -4
- package/package.json +8 -9
- package/scripts/{postinstall.mjs → postinstall.js} +3 -4
- package/src/commands/addons/addons-auth.js +22 -0
- package/src/commands/addons/{addons-config.mjs → addons-config.js} +9 -34
- package/src/commands/addons/{addons-create.mjs → addons-create.js} +7 -33
- package/src/commands/addons/addons-delete.js +33 -0
- package/src/commands/addons/{addons-list.mjs → addons-list.js} +3 -25
- package/src/commands/addons/addons.js +68 -0
- package/src/commands/addons/index.js +1 -0
- package/src/commands/api/{api.mjs → api.js} +2 -24
- package/src/commands/api/index.js +13 -0
- package/src/commands/{base-command.mjs → base-command.js} +7 -7
- package/src/commands/blobs/blobs-delete.js +20 -0
- package/src/commands/blobs/{blobs-get.mjs → blobs-get.js} +2 -15
- package/src/commands/blobs/{blobs-list.mjs → blobs-list.js} +2 -16
- package/src/commands/blobs/{blobs-set.mjs → blobs-set.js} +2 -17
- package/src/commands/blobs/blobs.js +74 -0
- package/src/commands/blobs/index.js +1 -0
- package/src/commands/build/{build.mjs → build.js} +7 -28
- package/src/commands/build/index.js +13 -0
- package/src/commands/completion/completion.js +29 -0
- package/src/commands/completion/index.js +26 -0
- package/src/commands/deploy/{deploy.mjs → deploy.js} +17 -133
- package/src/commands/deploy/index.js +106 -0
- package/src/commands/dev/{dev-exec.mjs → dev-exec.js} +3 -15
- package/src/commands/dev/{dev.mjs → dev.js} +19 -38
- package/src/commands/dev/index.js +1 -0
- package/src/commands/env/{env-clone.mjs → env-clone.js} +71 -94
- package/src/commands/env/env-get.js +34 -0
- package/src/commands/env/{env-import.mjs → env-import.js} +38 -65
- package/src/commands/env/{env-list.mjs → env-list.js} +3 -37
- package/src/commands/env/{env-set.mjs → env-set.js} +36 -81
- package/src/commands/env/{env-unset.mjs → env-unset.js} +30 -62
- package/src/commands/env/env.js +127 -0
- package/src/commands/env/index.js +1 -0
- package/src/commands/functions/{functions-build.mjs → functions-build.js} +3 -22
- package/src/commands/functions/{functions-create.mjs → functions-create.js} +20 -47
- package/src/commands/functions/{functions-invoke.mjs → functions-invoke.js} +3 -41
- package/src/commands/functions/{functions-list.mjs → functions-list.js} +3 -27
- package/src/commands/functions/{functions-serve.mjs → functions-serve.js} +6 -28
- package/src/commands/functions/functions.js +98 -0
- package/src/commands/functions/index.js +1 -0
- package/src/commands/index.js +2 -0
- package/src/commands/init/index.js +12 -0
- package/src/commands/init/{init.mjs → init.js} +10 -31
- package/src/commands/integration/{deploy.mjs → deploy.js} +7 -28
- package/src/commands/integration/index.js +26 -0
- package/src/commands/link/index.js +13 -0
- package/src/commands/link/{link.mjs → link.js} +6 -28
- package/src/commands/lm/index.js +1 -0
- package/src/commands/lm/{lm-info.mjs → lm-info.js} +2 -9
- package/src/commands/lm/lm-install.js +8 -0
- package/src/commands/lm/{lm-setup.mjs → lm-setup.js} +6 -25
- package/src/commands/lm/lm-uninstall.js +7 -0
- package/src/commands/lm/lm.js +46 -0
- package/src/commands/login/index.js +9 -0
- package/src/commands/login/{login.mjs → login.js} +1 -19
- package/src/commands/logout/index.js +7 -0
- package/src/commands/logout/{logout.mjs → logout.js} +3 -16
- package/src/commands/logs/{build.mjs → build.js} +3 -8
- package/src/commands/logs/{functions.mjs → functions.js} +4 -27
- package/src/commands/logs/index.js +39 -0
- package/src/commands/logs/log-levels.js +11 -0
- package/src/commands/{main.mjs → main.js} +32 -32
- package/src/commands/open/index.js +31 -0
- package/src/commands/open/open-admin.js +11 -0
- package/src/commands/open/open-site.js +12 -0
- package/src/commands/open/open.js +13 -0
- package/src/commands/recipes/{common.mjs → common.js} +2 -2
- package/src/commands/recipes/index.js +20 -0
- package/src/commands/recipes/recipes-list.js +14 -0
- package/src/commands/recipes/{recipes.mjs → recipes.js} +8 -32
- package/src/commands/serve/index.js +27 -0
- package/src/commands/serve/{serve.mjs → serve.js} +14 -51
- package/src/commands/sites/index.js +1 -0
- package/src/commands/sites/{sites-create-template.mjs → sites-create-template.js} +9 -38
- package/src/commands/sites/{sites-create.mjs → sites-create.js} +5 -38
- package/src/commands/sites/{sites-delete.mjs → sites-delete.js} +2 -22
- package/src/commands/sites/{sites-list.mjs → sites-list.js} +4 -24
- package/src/commands/sites/sites.js +77 -0
- package/src/commands/status/index.js +19 -0
- package/src/commands/status/{status-hooks.mjs → status-hooks.js} +2 -20
- package/src/commands/status/{status.mjs → status.js} +2 -23
- package/src/commands/switch/index.js +7 -0
- package/src/commands/switch/{switch.mjs → switch.js} +3 -16
- package/src/commands/unlink/index.js +7 -0
- package/src/commands/unlink/unlink.js +21 -0
- package/src/commands/watch/index.js +8 -0
- package/src/commands/watch/{watch.mjs → watch.js} +4 -21
- package/src/lib/{api.mjs → api.js} +1 -1
- package/src/lib/blobs/{blobs.mjs → blobs.js} +2 -2
- package/src/lib/{build.mjs → build.js} +3 -3
- package/src/lib/completion/{constants.mjs → constants.js} +1 -1
- package/src/lib/completion/{generate-autocompletion.mjs → generate-autocompletion.js} +3 -3
- package/src/lib/completion/{index.mjs → index.js} +1 -1
- package/src/lib/completion/{script.mjs → script.js} +3 -3
- package/src/lib/edge-functions/{deploy.mjs → deploy.js} +2 -2
- package/src/lib/edge-functions/{editor-helper.mjs → editor-helper.js} +1 -1
- package/src/lib/edge-functions/{internal.mjs → internal.js} +2 -2
- package/src/lib/edge-functions/{proxy.mjs → proxy.js} +10 -11
- package/src/lib/edge-functions/{registry.mjs → registry.js} +1 -1
- package/src/lib/{exec-fetcher.mjs → exec-fetcher.js} +2 -2
- package/src/lib/functions/{background.mjs → background.js} +2 -2
- package/src/lib/functions/{form-submissions-handler.mjs → form-submissions-handler.js} +3 -3
- package/src/lib/functions/{local-proxy.mjs → local-proxy.js} +1 -1
- package/src/lib/functions/{netlify-function.mjs → netlify-function.js} +3 -3
- package/src/lib/functions/{registry.mjs → registry.js} +9 -9
- package/src/lib/functions/runtimes/go/{index.mjs → index.js} +2 -2
- package/src/lib/functions/runtimes/{index.mjs → index.js} +3 -4
- package/src/lib/functions/runtimes/js/builders/{netlify-lambda.mjs → netlify-lambda.js} +3 -3
- package/src/lib/functions/runtimes/js/builders/{zisi.mjs → zisi.js} +6 -6
- package/src/lib/functions/runtimes/js/{index.mjs → index.js} +4 -4
- package/src/lib/functions/runtimes/rust/{index.mjs → index.js} +4 -4
- package/src/lib/functions/{scheduled.mjs → scheduled.js} +2 -2
- package/src/lib/functions/{server.mjs → server.js} +15 -15
- package/src/lib/functions/{synchronous.mjs → synchronous.js} +3 -3
- package/src/lib/functions/{utils.mjs → utils.js} +2 -2
- package/src/lib/{geo-location.mjs → geo-location.js} +1 -1
- package/src/lib/{http-agent.mjs → http-agent.js} +1 -1
- package/src/lib/images/{proxy.mjs → proxy.js} +2 -2
- package/src/lib/{log.mjs → log.js} +1 -1
- package/src/recipes/vscode/{index.mjs → index.js} +2 -2
- package/src/recipes/vscode/{settings.mjs → settings.js} +0 -1
- package/src/utils/addons/diffs/{index.mjs → index.js} +1 -1
- package/src/utils/addons/diffs/{options.mjs → options.js} +0 -1
- package/src/utils/addons/{prepare.mjs → prepare.js} +2 -2
- package/src/utils/addons/{prompts.mjs → prompts.js} +1 -1
- package/src/utils/addons/{render.mjs → render.js} +1 -1
- package/src/utils/{banner.mjs → banner.js} +1 -1
- package/src/utils/{build-info.mjs → build-info.js} +3 -3
- package/src/utils/{command-helpers.mjs → command-helpers.js} +4 -9
- package/src/utils/deploy/{deploy-site.mjs → deploy-site.js} +8 -8
- package/src/utils/deploy/{hash-files.mjs → hash-files.js} +1 -1
- package/src/utils/deploy/{hash-fns.mjs → hash-fns.js} +3 -3
- package/src/utils/deploy/{hasher-segments.mjs → hasher-segments.js} +1 -1
- package/src/utils/deploy/{upload-files.mjs → upload-files.js} +1 -1
- package/src/utils/deploy/{util.mjs → util.js} +1 -1
- package/src/utils/{detect-server-settings.mjs → detect-server-settings.js} +6 -7
- package/src/utils/{dev.mjs → dev.js} +3 -3
- package/src/utils/{dot-env.mjs → dot-env.js} +2 -2
- package/src/utils/env/{index.mjs → index.js} +1 -1
- package/src/utils/{framework-server.mjs → framework-server.js} +4 -4
- package/src/utils/functions/{functions.mjs → functions.js} +2 -2
- package/src/utils/functions/{get-functions.mjs → get-functions.js} +1 -1
- package/src/utils/functions/index.js +3 -0
- package/src/utils/{get-global-config.mjs → get-global-config.js} +1 -1
- package/src/utils/{get-repo-data.mjs → get-repo-data.js} +1 -1
- package/src/utils/{get-site.mjs → get-site.js} +1 -1
- package/src/utils/{gh-auth.mjs → gh-auth.js} +3 -3
- package/src/utils/{gitignore.mjs → gitignore.js} +2 -2
- package/src/utils/{headers.mjs → headers.js} +1 -1
- package/src/utils/hooks/{requires-site-info.mjs → requires-site-info.js} +1 -1
- package/src/utils/init/{config-github.mjs → config-github.js} +4 -4
- package/src/utils/init/{config-manual.mjs → config-manual.js} +5 -5
- package/src/utils/init/{config.mjs → config.js} +4 -4
- package/src/utils/init/{node-version.mjs → node-version.js} +1 -1
- package/src/utils/init/{utils.mjs → utils.js} +7 -7
- package/src/utils/{live-tunnel.mjs → live-tunnel.js} +4 -4
- package/src/utils/lm/{install.mjs → install.js} +6 -6
- package/src/utils/lm/{requirements.mjs → requirements.js} +1 -1
- package/src/utils/lm/{steps.mjs → steps.js} +2 -2
- package/src/utils/lm/{ui.mjs → ui.js} +2 -2
- package/src/utils/{open-browser.mjs → open-browser.js} +1 -1
- package/src/utils/{proxy-server.mjs → proxy-server.js} +5 -5
- package/src/utils/{proxy.mjs → proxy.js} +11 -11
- package/src/utils/{redirects.mjs → redirects.js} +1 -1
- package/src/utils/{rules-proxy.mjs → rules-proxy.js} +3 -3
- package/src/utils/{run-build.mjs → run-build.js} +8 -8
- package/src/utils/{shell.mjs → shell.js} +2 -2
- package/src/utils/{state-config.mjs → state-config.js} +1 -1
- package/src/utils/{static-server.mjs → static-server.js} +1 -1
- package/src/utils/telemetry/index.js +2 -0
- package/src/utils/telemetry/{report-error.mjs → report-error.js} +4 -4
- package/src/utils/telemetry/{request.mjs → request.js} +1 -1
- package/src/utils/telemetry/{telemetry.mjs → telemetry.js} +5 -5
- package/src/utils/telemetry/{utils.mjs → utils.js} +1 -1
- package/src/utils/telemetry/{validation.mjs → validation.js} +1 -1
- package/src/utils/{validation.mjs → validation.js} +1 -1
- package/src/commands/addons/addons-auth.mjs +0 -45
- package/src/commands/addons/addons-delete.mjs +0 -53
- package/src/commands/addons/addons.mjs +0 -39
- package/src/commands/addons/index.mjs +0 -1
- package/src/commands/api/index.mjs +0 -1
- package/src/commands/blobs/blobs-delete.mjs +0 -35
- package/src/commands/blobs/blobs.mjs +0 -32
- package/src/commands/blobs/index.mjs +0 -1
- package/src/commands/build/index.mjs +0 -1
- package/src/commands/completion/completion.mjs +0 -53
- package/src/commands/completion/index.mjs +0 -1
- package/src/commands/deploy/index.mjs +0 -1
- package/src/commands/dev/index.mjs +0 -1
- package/src/commands/dev/types.d.ts +0 -30
- package/src/commands/env/env-get.mjs +0 -66
- package/src/commands/env/env.mjs +0 -41
- package/src/commands/env/index.mjs +0 -1
- package/src/commands/functions/functions.mjs +0 -39
- package/src/commands/functions/index.mjs +0 -1
- package/src/commands/index.mjs +0 -2
- package/src/commands/init/index.mjs +0 -1
- package/src/commands/integration/index.mjs +0 -24
- package/src/commands/link/index.mjs +0 -1
- package/src/commands/lm/index.mjs +0 -1
- package/src/commands/lm/lm-install.mjs +0 -27
- package/src/commands/lm/lm-uninstall.mjs +0 -18
- package/src/commands/lm/lm.mjs +0 -30
- package/src/commands/login/index.mjs +0 -1
- package/src/commands/logout/index.mjs +0 -1
- package/src/commands/logs/index.mjs +0 -12
- package/src/commands/open/index.mjs +0 -1
- package/src/commands/open/open-admin.mjs +0 -30
- package/src/commands/open/open-site.mjs +0 -31
- package/src/commands/open/open.mjs +0 -36
- package/src/commands/recipes/index.mjs +0 -1
- package/src/commands/recipes/recipes-list.mjs +0 -25
- package/src/commands/serve/index.mjs +0 -1
- package/src/commands/sites/index.mjs +0 -2
- package/src/commands/sites/sites.mjs +0 -30
- package/src/commands/status/index.mjs +0 -1
- package/src/commands/switch/index.mjs +0 -1
- package/src/commands/types.d.ts +0 -31
- package/src/commands/unlink/index.mjs +0 -1
- package/src/commands/unlink/unlink.mjs +0 -34
- package/src/commands/watch/index.mjs +0 -1
- package/src/functions-templates/typescript/abtest/{{name}}.ts +0 -31
- package/src/functions-templates/typescript/geolocation/{{name}}.ts +0 -24
- package/src/functions-templates/typescript/hello-world/{{name}}.ts +0 -12
- package/src/functions-templates/typescript/json/{{name}}.ts +0 -5
- package/src/functions-templates/typescript/log/{{name}}.ts +0 -9
- package/src/functions-templates/typescript/scheduled-function/{{name}}.ts +0 -12
- package/src/functions-templates/typescript/set-cookies/{{name}}.ts +0 -29
- package/src/functions-templates/typescript/set-req-header/{{name}}.ts +0 -5
- package/src/functions-templates/typescript/set-res-header/{{name}}.ts +0 -7
- package/src/functions-templates/typescript/transform-response/{{name}}.ts +0 -13
- package/src/utils/functions/index.mjs +0 -3
- package/src/utils/telemetry/index.mjs +0 -2
- package/src/utils/types.d.ts +0 -46
- /package/src/functions-templates/go/hello-world/{.netlify-function-template.mjs → .netlify-function-template.js} +0 -0
- /package/src/functions-templates/javascript/hello/{.netlify-function-template.mjs → .netlify-function-template.js} +0 -0
- /package/src/functions-templates/javascript/hello-world/{.netlify-function-template.mjs → .netlify-function-template.js} +0 -0
- /package/src/functions-templates/javascript/identity-signup/{.netlify-function-template.mjs → .netlify-function-template.js} +0 -0
- /package/src/functions-templates/javascript/image-external/{.netlify-function-template.mjs → .netlify-function-template.js} +0 -0
- /package/src/functions-templates/javascript/localized-content/{.netlify-function-template.mjs → .netlify-function-template.js} +0 -0
- /package/src/functions-templates/javascript/sanity-create/{.netlify-function-template.mjs → .netlify-function-template.js} +0 -0
- /package/src/functions-templates/javascript/sanity-groq/{.netlify-function-template.mjs → .netlify-function-template.js} +0 -0
- /package/src/functions-templates/javascript/scheduled-function/{.netlify-function-template.mjs → .netlify-function-template.js} +0 -0
- /package/src/functions-templates/javascript/set-cookies/{.netlify-function-template.mjs → .netlify-function-template.js} +0 -0
- /package/src/functions-templates/javascript/set-req-header/{.netlify-function-template.mjs → .netlify-function-template.js} +0 -0
- /package/src/functions-templates/javascript/set-res-header/{.netlify-function-template.mjs → .netlify-function-template.js} +0 -0
- /package/src/functions-templates/javascript/submission-created/{.netlify-function-template.mjs → .netlify-function-template.js} +0 -0
- /package/src/functions-templates/javascript/transform-response/{.netlify-function-template.mjs → .netlify-function-template.js} +0 -0
- /package/src/functions-templates/rust/hello-world/{.netlify-function-template.mjs → .netlify-function-template.js} +0 -0
- /package/src/functions-templates/typescript/abtest/{.netlify-function-template.mjs → .netlify-function-template.js} +0 -0
- /package/src/functions-templates/typescript/geolocation/{.netlify-function-template.mjs → .netlify-function-template.js} +0 -0
- /package/src/functions-templates/typescript/hello-world/{.netlify-function-template.mjs → .netlify-function-template.js} +0 -0
- /package/src/functions-templates/typescript/json/{.netlify-function-template.mjs → .netlify-function-template.js} +0 -0
- /package/src/functions-templates/typescript/log/{.netlify-function-template.mjs → .netlify-function-template.js} +0 -0
- /package/src/functions-templates/typescript/scheduled-function/{.netlify-function-template.mjs → .netlify-function-template.js} +0 -0
- /package/src/functions-templates/typescript/set-cookies/{.netlify-function-template.mjs → .netlify-function-template.js} +0 -0
- /package/src/functions-templates/typescript/set-req-header/{.netlify-function-template.mjs → .netlify-function-template.js} +0 -0
- /package/src/functions-templates/typescript/set-res-header/{.netlify-function-template.mjs → .netlify-function-template.js} +0 -0
- /package/src/functions-templates/typescript/transform-response/{.netlify-function-template.mjs → .netlify-function-template.js} +0 -0
- /package/src/lib/{account.mjs → account.js} +0 -0
- /package/src/lib/completion/{get-autocompletion.mjs → get-autocompletion.js} +0 -0
- /package/src/lib/edge-functions/{bootstrap.mjs → bootstrap.js} +0 -0
- /package/src/lib/edge-functions/{consts.mjs → consts.js} +0 -0
- /package/src/lib/edge-functions/{headers.mjs → headers.js} +0 -0
- /package/src/lib/{fs.mjs → fs.js} +0 -0
- /package/src/lib/functions/{config.mjs → config.js} +0 -0
- /package/src/lib/functions/{memoized-build.mjs → memoized-build.js} +0 -0
- /package/src/lib/functions/runtimes/js/{constants.mjs → constants.js} +0 -0
- /package/src/lib/functions/runtimes/js/{worker.mjs → worker.js} +0 -0
- /package/src/lib/{path.mjs → path.js} +0 -0
- /package/src/lib/{render-error-template.mjs → render-error-template.js} +0 -0
- /package/src/lib/{settings.mjs → settings.js} +0 -0
- /package/src/lib/{spinner.mjs → spinner.js} +0 -0
- /package/src/lib/{string.mjs → string.js} +0 -0
- /package/src/utils/addons/{compare.mjs → compare.js} +0 -0
- /package/src/utils/addons/{validation.mjs → validation.js} +0 -0
- /package/src/utils/{create-deferred.mjs → create-deferred.js} +0 -0
- /package/src/utils/{create-stream-promise.mjs → create-stream-promise.js} +0 -0
- /package/src/utils/deploy/{constants.mjs → constants.js} +0 -0
- /package/src/utils/deploy/{hash-config.mjs → hash-config.js} +0 -0
- /package/src/utils/{execa.mjs → execa.js} +0 -0
- /package/src/utils/{feature-flags.mjs → feature-flags.js} +0 -0
- /package/src/utils/functions/{constants.mjs → constants.js} +0 -0
- /package/src/utils/{get-package-json.mjs → get-package-json.js} +0 -0
- /package/src/utils/init/{plugins.mjs → plugins.js} +0 -0
- /package/src/utils/{parse-raw-flags.mjs → parse-raw-flags.js} +0 -0
- /package/src/utils/{read-repo-url.mjs → read-repo-url.js} +0 -0
- /package/src/utils/{request-id.mjs → request-id.js} +0 -0
- /package/src/utils/{sign-redirect.mjs → sign-redirect.js} +0 -0
- /package/src/utils/sites/{utils.mjs → utils.js} +0 -0
- /package/src/utils/websockets/{index.mjs → index.js} +0 -0
|
@@ -1,41 +1,5 @@
|
|
|
1
|
-
import { chalk, error, log, logJson } from '../../utils/command-helpers.
|
|
2
|
-
import { AVAILABLE_CONTEXTS,
|
|
3
|
-
/**
|
|
4
|
-
* The env:unset command
|
|
5
|
-
* @param {string} key Environment variable key
|
|
6
|
-
* @param {import('commander').OptionValues} options
|
|
7
|
-
* @param {import('../base-command.mjs').default} command
|
|
8
|
-
* @returns {Promise<boolean>}
|
|
9
|
-
*/
|
|
10
|
-
// @ts-expect-error TS(7006) FIXME: Parameter 'key' implicitly has an 'any' type.
|
|
11
|
-
const envUnset = async (key, options, command) => {
|
|
12
|
-
const { context } = options;
|
|
13
|
-
const { api, cachedConfig, site } = command.netlify;
|
|
14
|
-
const siteId = site.id;
|
|
15
|
-
if (!siteId) {
|
|
16
|
-
log('No site id found, please run inside a site folder or `netlify link`');
|
|
17
|
-
return false;
|
|
18
|
-
}
|
|
19
|
-
const { siteInfo } = cachedConfig;
|
|
20
|
-
let finalEnv;
|
|
21
|
-
if (siteInfo.use_envelope) {
|
|
22
|
-
finalEnv = await unsetInEnvelope({ api, context, siteInfo, key });
|
|
23
|
-
}
|
|
24
|
-
else if (context) {
|
|
25
|
-
error(`To specify a context, please run ${chalk.yellow('netlify open:admin')} to open the Netlify UI and opt in to the new environment variables experience from Site settings`);
|
|
26
|
-
return false;
|
|
27
|
-
}
|
|
28
|
-
else {
|
|
29
|
-
finalEnv = await unsetInMongo({ api, siteInfo, key });
|
|
30
|
-
}
|
|
31
|
-
// Return new environment variables of site if using json flag
|
|
32
|
-
if (options.json) {
|
|
33
|
-
logJson(finalEnv);
|
|
34
|
-
return false;
|
|
35
|
-
}
|
|
36
|
-
const contextType = AVAILABLE_CONTEXTS.includes(context || 'all') ? 'context' : 'branch';
|
|
37
|
-
log(`Unset environment variable ${chalk.yellow(key)} in the ${chalk.magenta(context || 'all')} ${contextType}`);
|
|
38
|
-
};
|
|
1
|
+
import { chalk, error, log, logJson } from '../../utils/command-helpers.js';
|
|
2
|
+
import { AVAILABLE_CONTEXTS, translateFromEnvelopeToMongo } from '../../utils/env/index.js';
|
|
39
3
|
/**
|
|
40
4
|
* Deletes a given key from the env of a site record
|
|
41
5
|
* @returns {Promise<object>}
|
|
@@ -109,27 +73,31 @@ const unsetInEnvelope = async ({ api, context, key, siteInfo }) => {
|
|
|
109
73
|
delete env[key];
|
|
110
74
|
return env;
|
|
111
75
|
};
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
//
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
76
|
+
export const envUnset = async (key, options, command) => {
|
|
77
|
+
const { context } = options;
|
|
78
|
+
const { api, cachedConfig, site } = command.netlify;
|
|
79
|
+
const siteId = site.id;
|
|
80
|
+
if (!siteId) {
|
|
81
|
+
log('No site id found, please run inside a site folder or `netlify link`');
|
|
82
|
+
return false;
|
|
83
|
+
}
|
|
84
|
+
const { siteInfo } = cachedConfig;
|
|
85
|
+
let finalEnv;
|
|
86
|
+
if (siteInfo.use_envelope) {
|
|
87
|
+
finalEnv = await unsetInEnvelope({ api, context, siteInfo, key });
|
|
88
|
+
}
|
|
89
|
+
else if (context) {
|
|
90
|
+
error(`To specify a context, please run ${chalk.yellow('netlify open:admin')} to open the Netlify UI and opt in to the new environment variables experience from Site settings`);
|
|
91
|
+
return false;
|
|
92
|
+
}
|
|
93
|
+
else {
|
|
94
|
+
finalEnv = await unsetInMongo({ api, siteInfo, key });
|
|
95
|
+
}
|
|
96
|
+
// Return new environment variables of site if using json flag
|
|
97
|
+
if (options.json) {
|
|
98
|
+
logJson(finalEnv);
|
|
99
|
+
return false;
|
|
100
|
+
}
|
|
101
|
+
const contextType = AVAILABLE_CONTEXTS.includes(context || 'all') ? 'context' : 'branch';
|
|
102
|
+
log(`Unset environment variable ${chalk.yellow(key)} in the ${chalk.magenta(context || 'all')} ${contextType}`);
|
|
103
|
+
};
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
import { Option } from 'commander';
|
|
2
|
+
import { normalizeContext } from '../../utils/env/index.js';
|
|
3
|
+
const env = (options, command) => {
|
|
4
|
+
command.help();
|
|
5
|
+
};
|
|
6
|
+
export const createEnvCommand = (program) => {
|
|
7
|
+
program
|
|
8
|
+
.command('env:get')
|
|
9
|
+
.argument('<name>', 'Environment variable name')
|
|
10
|
+
.option('-c, --context <context>', 'Specify a deploy context or branch (contexts: "production", "deploy-preview", "branch-deploy", "dev")', normalizeContext, 'dev')
|
|
11
|
+
.addOption(new Option('-s, --scope <scope>', 'Specify a scope')
|
|
12
|
+
.choices(['builds', 'functions', 'post-processing', 'runtime', 'any'])
|
|
13
|
+
.default('any'))
|
|
14
|
+
.addExamples([
|
|
15
|
+
'netlify env:get MY_VAR # get value for MY_VAR in dev context',
|
|
16
|
+
'netlify env:get MY_VAR --context production',
|
|
17
|
+
'netlify env:get MY_VAR --context branch:staging',
|
|
18
|
+
'netlify env:get MY_VAR --scope functions',
|
|
19
|
+
])
|
|
20
|
+
.description('Get resolved value of specified environment variable (includes netlify.toml)')
|
|
21
|
+
.action(async (name, options, command) => {
|
|
22
|
+
const { envGet } = await import('./env-get.js');
|
|
23
|
+
await envGet(name, options, command);
|
|
24
|
+
});
|
|
25
|
+
program
|
|
26
|
+
.command('env:import')
|
|
27
|
+
.argument('<fileName>', '.env file to import')
|
|
28
|
+
.addOption(new Option('-r --replaceExisting', 'Old, prefer --replace-existing. Replace all existing variables instead of merging them with the current ones')
|
|
29
|
+
.default(false)
|
|
30
|
+
.hideHelp(true))
|
|
31
|
+
.option('-r, --replace-existing', 'Replace all existing variables instead of merging them with the current ones', false)
|
|
32
|
+
.description('Import and set environment variables from .env file')
|
|
33
|
+
.action(async (fileName, options, command) => {
|
|
34
|
+
const { envImport } = await import('./env-import.js');
|
|
35
|
+
await envImport(fileName, options, command);
|
|
36
|
+
});
|
|
37
|
+
program
|
|
38
|
+
.command('env:list')
|
|
39
|
+
.option('-c, --context <context>', 'Specify a deploy context or branch (contexts: "production", "deploy-preview", "branch-deploy", "dev")', normalizeContext, 'dev')
|
|
40
|
+
.option('--json', 'Output environment variables as JSON')
|
|
41
|
+
.addOption(new Option('--plain', 'Output environment variables as plaintext').conflicts('json'))
|
|
42
|
+
.addOption(new Option('-s, --scope <scope>', 'Specify a scope')
|
|
43
|
+
.choices(['builds', 'functions', 'post-processing', 'runtime', 'any'])
|
|
44
|
+
.default('any'))
|
|
45
|
+
.addExamples([
|
|
46
|
+
'netlify env:list # list variables with values in the dev context and with any scope',
|
|
47
|
+
'netlify env:list --context production',
|
|
48
|
+
'netlify env:list --context branch:staging',
|
|
49
|
+
'netlify env:list --scope functions',
|
|
50
|
+
'netlify env:list --plain',
|
|
51
|
+
])
|
|
52
|
+
.description('Lists resolved environment variables for site (includes netlify.toml)')
|
|
53
|
+
.action(async (options, command) => {
|
|
54
|
+
const { envList } = await import('./env-list.js');
|
|
55
|
+
await envList(options, command);
|
|
56
|
+
});
|
|
57
|
+
program
|
|
58
|
+
.command('env:set')
|
|
59
|
+
.argument('<key>', 'Environment variable key')
|
|
60
|
+
.argument('[value]', 'Value to set to', '')
|
|
61
|
+
.option('-c, --context <context...>', 'Specify a deploy context or branch (contexts: "production", "deploy-preview", "branch-deploy", "dev") (default: all contexts)',
|
|
62
|
+
// spread over an array for variadic options
|
|
63
|
+
// @ts-expect-error TS(7006) FIXME: Parameter 'context' implicitly has an 'any' type.
|
|
64
|
+
(context, previous = []) => [...previous, normalizeContext(context)])
|
|
65
|
+
.addOption(new Option('-s, --scope <scope...>', 'Specify a scope (default: all scopes)').choices([
|
|
66
|
+
'builds',
|
|
67
|
+
'functions',
|
|
68
|
+
'post-processing',
|
|
69
|
+
'runtime',
|
|
70
|
+
]))
|
|
71
|
+
.option('--secret', 'Indicate whether the environment variable value can be read again.')
|
|
72
|
+
.description('Set value of environment variable')
|
|
73
|
+
.addExamples([
|
|
74
|
+
'netlify env:set VAR_NAME value # set in all contexts and scopes',
|
|
75
|
+
'netlify env:set VAR_NAME value --context production',
|
|
76
|
+
'netlify env:set VAR_NAME value --context production deploy-preview',
|
|
77
|
+
'netlify env:set VAR_NAME value --context production --secret',
|
|
78
|
+
'netlify env:set VAR_NAME value --scope builds',
|
|
79
|
+
'netlify env:set VAR_NAME value --scope builds functions',
|
|
80
|
+
'netlify env:set VAR_NAME --secret # convert existing variable to secret',
|
|
81
|
+
])
|
|
82
|
+
.action(async (key, value, options, command) => {
|
|
83
|
+
const { envSet } = await import('./env-set.js');
|
|
84
|
+
await envSet(key, value, options, command);
|
|
85
|
+
});
|
|
86
|
+
program
|
|
87
|
+
.command('env:unset')
|
|
88
|
+
.aliases(['env:delete', 'env:remove'])
|
|
89
|
+
.argument('<key>', 'Environment variable key')
|
|
90
|
+
.option('-c, --context <context...>', 'Specify a deploy context or branch (contexts: "production", "deploy-preview", "branch-deploy", "dev") (default: all contexts)',
|
|
91
|
+
// spread over an array for variadic options
|
|
92
|
+
// @ts-expect-error TS(7006) FIXME: Parameter 'context' implicitly has an 'any' type.
|
|
93
|
+
(context, previous = []) => [...previous, normalizeContext(context)])
|
|
94
|
+
.addExamples([
|
|
95
|
+
'netlify env:unset VAR_NAME # unset in all contexts',
|
|
96
|
+
'netlify env:unset VAR_NAME --context production',
|
|
97
|
+
'netlify env:unset VAR_NAME --context production deploy-preview',
|
|
98
|
+
])
|
|
99
|
+
.description('Unset an environment variable which removes it from the UI')
|
|
100
|
+
.action(async (key, options, command) => {
|
|
101
|
+
const { envUnset } = await import('./env-unset.js');
|
|
102
|
+
await envUnset(key, options, command);
|
|
103
|
+
});
|
|
104
|
+
program
|
|
105
|
+
.command('env:clone')
|
|
106
|
+
.alias('env:migrate')
|
|
107
|
+
.option('-f, --from <from>', 'Site ID (From)')
|
|
108
|
+
.requiredOption('-t, --to <to>', 'Site ID (To)')
|
|
109
|
+
.description(`Clone environment variables from one site to another`)
|
|
110
|
+
.addExamples(['netlify env:clone --to <to-site-id>', 'netlify env:clone --to <to-site-id> --from <from-site-id>'])
|
|
111
|
+
.action(async (options, command) => {
|
|
112
|
+
const { envClone } = await import('./env-clone.js');
|
|
113
|
+
await envClone(options, command);
|
|
114
|
+
});
|
|
115
|
+
return program
|
|
116
|
+
.command('env')
|
|
117
|
+
.description('Control environment variables for the current site')
|
|
118
|
+
.addExamples([
|
|
119
|
+
'netlify env:list',
|
|
120
|
+
'netlify env:get VAR_NAME',
|
|
121
|
+
'netlify env:set VAR_NAME value',
|
|
122
|
+
'netlify env:unset VAR_NAME',
|
|
123
|
+
'netlify env:import fileName',
|
|
124
|
+
'netlify env:clone --to <to-site-id>',
|
|
125
|
+
])
|
|
126
|
+
.action(env);
|
|
127
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { createEnvCommand } from './env.js';
|
|
@@ -1,14 +1,8 @@
|
|
|
1
1
|
import { mkdir } from 'fs/promises';
|
|
2
2
|
import { zipFunctions } from '@netlify/zip-it-and-ship-it';
|
|
3
|
-
import { NETLIFYDEVERR, NETLIFYDEVLOG, exit, log } from '../../utils/command-helpers.
|
|
4
|
-
import { getFunctionsDir } from '../../utils/functions/index.
|
|
5
|
-
|
|
6
|
-
* The functions:build command
|
|
7
|
-
* @param {import('commander').OptionValues} options
|
|
8
|
-
* @param {import('../base-command.mjs').default} command
|
|
9
|
-
*/
|
|
10
|
-
// @ts-expect-error TS(7006) FIXME: Parameter 'options' implicitly has an 'any' type.
|
|
11
|
-
const functionsBuild = async (options, command) => {
|
|
3
|
+
import { NETLIFYDEVERR, NETLIFYDEVLOG, exit, log } from '../../utils/command-helpers.js';
|
|
4
|
+
import { getFunctionsDir } from '../../utils/functions/index.js';
|
|
5
|
+
export const functionsBuild = async (options, command) => {
|
|
12
6
|
const { config } = command.netlify;
|
|
13
7
|
const src = options.src || config.build.functionsSource;
|
|
14
8
|
// @ts-expect-error TS(2554) FIXME: Expected 2 arguments, but got 1.
|
|
@@ -30,16 +24,3 @@ const functionsBuild = async (options, command) => {
|
|
|
30
24
|
zipFunctions(src, dst, { skipGo: true });
|
|
31
25
|
log(`${NETLIFYDEVLOG} Functions built to `, dst);
|
|
32
26
|
};
|
|
33
|
-
/**
|
|
34
|
-
* Creates the `netlify functions:build` command
|
|
35
|
-
* @param {import('../base-command.mjs').default} program
|
|
36
|
-
* @returns
|
|
37
|
-
*/
|
|
38
|
-
// @ts-expect-error TS(7006) FIXME: Parameter 'program' implicitly has an 'any' type.
|
|
39
|
-
export const createFunctionsBuildCommand = (program) => program
|
|
40
|
-
.command('functions:build')
|
|
41
|
-
.alias('function:build')
|
|
42
|
-
.description('Build functions locally')
|
|
43
|
-
.option('-f, --functions <directory>', 'Specify a functions directory to build to')
|
|
44
|
-
.option('-s, --src <directory>', 'Specify the source directory for the functions')
|
|
45
|
-
.action(functionsBuild);
|
|
@@ -14,13 +14,13 @@ import inquirer from 'inquirer';
|
|
|
14
14
|
// @ts-expect-error TS(7016) FIXME: Could not find a declaration file for module 'node... Remove this comment to see the full error message
|
|
15
15
|
import fetch from 'node-fetch';
|
|
16
16
|
import ora from 'ora';
|
|
17
|
-
import { fileExistsAsync } from '../../lib/fs.
|
|
18
|
-
import { getAddons, getCurrentAddon, getSiteData } from '../../utils/addons/prepare.
|
|
19
|
-
import { NETLIFYDEVERR, NETLIFYDEVLOG, NETLIFYDEVWARN, chalk, error, log } from '../../utils/command-helpers.
|
|
20
|
-
import { getDotEnvVariables, injectEnvVariables } from '../../utils/dev.
|
|
17
|
+
import { fileExistsAsync } from '../../lib/fs.js';
|
|
18
|
+
import { getAddons, getCurrentAddon, getSiteData } from '../../utils/addons/prepare.js';
|
|
19
|
+
import { NETLIFYDEVERR, NETLIFYDEVLOG, NETLIFYDEVWARN, chalk, error, log } from '../../utils/command-helpers.js';
|
|
20
|
+
import { getDotEnvVariables, injectEnvVariables } from '../../utils/dev.js';
|
|
21
21
|
// @ts-expect-error TS(7034) FIXME: Variable 'execa' implicitly has type 'any' in some... Remove this comment to see the full error message
|
|
22
|
-
import execa from '../../utils/execa.
|
|
23
|
-
import { readRepoURL, validateRepoURL } from '../../utils/read-repo-url.
|
|
22
|
+
import execa from '../../utils/execa.js';
|
|
23
|
+
import { readRepoURL, validateRepoURL } from '../../utils/read-repo-url.js';
|
|
24
24
|
const copyTemplateDir = promisify(copyTemplateDirOriginal);
|
|
25
25
|
const require = createRequire(import.meta.url);
|
|
26
26
|
const templatesDir = path.resolve(dirname(fileURLToPath(import.meta.url)), '../../functions-templates');
|
|
@@ -97,7 +97,7 @@ const formatRegistryArrayForInquirer = async function (lang, funcType) {
|
|
|
97
97
|
.filter((folder) => Boolean(folder?.isDirectory()))
|
|
98
98
|
.map(async ({ name }) => {
|
|
99
99
|
try {
|
|
100
|
-
const templatePath = path.join(templatesDir, lang, name, '.netlify-function-template.
|
|
100
|
+
const templatePath = path.join(templatesDir, lang, name, '.netlify-function-template.js');
|
|
101
101
|
// @ts-expect-error TS(7036) FIXME: Dynamic import's specifier must be of type 'string... Remove this comment to see the full error message
|
|
102
102
|
const template = await import(pathToFileURL(templatePath));
|
|
103
103
|
return template.default;
|
|
@@ -216,7 +216,7 @@ const selectTypeOfFunc = async () => {
|
|
|
216
216
|
return functionType;
|
|
217
217
|
};
|
|
218
218
|
/**
|
|
219
|
-
* @param {import('../base-command.
|
|
219
|
+
* @param {import('../base-command.js').default} command
|
|
220
220
|
*/
|
|
221
221
|
// @ts-expect-error TS(7006) FIXME: Parameter 'command' implicitly has an 'any' type.
|
|
222
222
|
const ensureEdgeFuncDirExists = function (command) {
|
|
@@ -236,7 +236,7 @@ const ensureEdgeFuncDirExists = function (command) {
|
|
|
236
236
|
};
|
|
237
237
|
/**
|
|
238
238
|
* Prompts the user to choose a functions directory
|
|
239
|
-
* @param {import('../base-command.
|
|
239
|
+
* @param {import('../base-command.js').default} command
|
|
240
240
|
* @returns {Promise<string>} - functions directory or throws an error
|
|
241
241
|
*/
|
|
242
242
|
// @ts-expect-error TS(7006) FIXME: Parameter 'command' implicitly has an 'any' type.
|
|
@@ -273,7 +273,7 @@ const promptFunctionsDirectory = async (command) => {
|
|
|
273
273
|
};
|
|
274
274
|
/**
|
|
275
275
|
* Get functions directory (and make it if necessary)
|
|
276
|
-
* @param {import('../base-command.
|
|
276
|
+
* @param {import('../base-command.js').default} command
|
|
277
277
|
* @returns {Promise<string>} - functions directory or throws an error
|
|
278
278
|
*/
|
|
279
279
|
// @ts-expect-error TS(7006) FIXME: Parameter 'command' implicitly has an 'any' type.
|
|
@@ -290,7 +290,7 @@ const ensureFunctionDirExists = async function (command) {
|
|
|
290
290
|
};
|
|
291
291
|
/**
|
|
292
292
|
* Download files from a given GitHub URL
|
|
293
|
-
* @param {import('../base-command.
|
|
293
|
+
* @param {import('../base-command.js').default} command
|
|
294
294
|
* @param {import('commander').OptionValues} options
|
|
295
295
|
* @param {string} argumentName
|
|
296
296
|
* @param {string} functionsDir
|
|
@@ -329,7 +329,7 @@ const downloadFromURL = async function (command, options, argumentName, function
|
|
|
329
329
|
log(`${NETLIFYDEVLOG} Installing dependencies for ${nameToUse} complete `);
|
|
330
330
|
});
|
|
331
331
|
// read, execute, and delete function template file if exists
|
|
332
|
-
const fnTemplateFile = path.join(fnFolder, '.netlify-function-template.
|
|
332
|
+
const fnTemplateFile = path.join(fnFolder, '.netlify-function-template.js');
|
|
333
333
|
if (await fileExistsAsync(fnTemplateFile)) {
|
|
334
334
|
const { default: { addons = [], onComplete }, } = await import(pathToFileURL(fnTemplateFile).href);
|
|
335
335
|
await installAddons(command, addons, path.resolve(fnFolder));
|
|
@@ -394,7 +394,7 @@ const installDeps = async ({ functionPackageJson, functionPath, functionsDir })
|
|
|
394
394
|
};
|
|
395
395
|
/**
|
|
396
396
|
* no --url flag specified, pick from a provided template
|
|
397
|
-
* @param {import('../base-command.
|
|
397
|
+
* @param {import('../base-command.js').default} command
|
|
398
398
|
* @param {import('commander').OptionValues} options
|
|
399
399
|
* @param {string} argumentName
|
|
400
400
|
* @param {string} functionsDir Absolute path of the functions directory
|
|
@@ -443,7 +443,7 @@ const scaffoldFromTemplate = async function (command, options, argumentName, fun
|
|
|
443
443
|
let functionPackageJson;
|
|
444
444
|
// These files will not be part of the log message because they'll likely
|
|
445
445
|
// be removed before the command finishes.
|
|
446
|
-
const omittedFromOutput = new Set(['.netlify-function-template.
|
|
446
|
+
const omittedFromOutput = new Set(['.netlify-function-template.js', 'package.json', 'package-lock.json']);
|
|
447
447
|
const createdFiles = await copyTemplateDir(pathToTemplate, functionPath, vars);
|
|
448
448
|
// @ts-expect-error TS(7006) FIXME: Parameter 'filePath' implicitly has an 'any' type.
|
|
449
449
|
createdFiles.forEach((filePath) => {
|
|
@@ -457,7 +457,7 @@ const scaffoldFromTemplate = async function (command, options, argumentName, fun
|
|
|
457
457
|
}
|
|
458
458
|
});
|
|
459
459
|
// delete function template file that was copied over by copydir
|
|
460
|
-
await unlink(path.join(functionPath, '.netlify-function-template.
|
|
460
|
+
await unlink(path.join(functionPath, '.netlify-function-template.js'));
|
|
461
461
|
// npm install
|
|
462
462
|
if (functionPackageJson !== undefined) {
|
|
463
463
|
const spinner = ora({
|
|
@@ -499,8 +499,8 @@ const createFunctionAddon = async function ({ addonName, addons, api, siteData,
|
|
|
499
499
|
/**
|
|
500
500
|
*
|
|
501
501
|
* @param {object} config
|
|
502
|
-
* @param {import('../base-command.
|
|
503
|
-
* @param {(command: import('../base-command.
|
|
502
|
+
* @param {import('../base-command.js').default} config.command
|
|
503
|
+
* @param {(command: import('../base-command.js').default) => any} config.onComplete
|
|
504
504
|
*/
|
|
505
505
|
// @ts-expect-error TS(7031) FIXME: Binding element 'command' implicitly has an 'any' ... Remove this comment to see the full error message
|
|
506
506
|
const handleOnComplete = async ({ command, onComplete }) => {
|
|
@@ -520,7 +520,7 @@ const handleOnComplete = async ({ command, onComplete }) => {
|
|
|
520
520
|
* @param {object} config
|
|
521
521
|
* @param {*} config.addonCreated
|
|
522
522
|
* @param {*} config.addonDidInstall
|
|
523
|
-
* @param {import('../base-command.
|
|
523
|
+
* @param {import('../base-command.js').default} config.command
|
|
524
524
|
* @param {string} config.fnPath
|
|
525
525
|
*/
|
|
526
526
|
// @ts-expect-error TS(7031) FIXME: Binding element 'addonCreated' implicitly has an '... Remove this comment to see the full error message
|
|
@@ -549,7 +549,7 @@ const handleAddonDidInstall = async ({ addonCreated, addonDidInstall, command, f
|
|
|
549
549
|
};
|
|
550
550
|
/**
|
|
551
551
|
*
|
|
552
|
-
* @param {import('../base-command.
|
|
552
|
+
* @param {import('../base-command.js').default} command
|
|
553
553
|
* @param {*} functionAddons
|
|
554
554
|
* @param {*} fnPath
|
|
555
555
|
* @returns
|
|
@@ -638,37 +638,10 @@ const ensureFunctionPathIsOk = function (functionsDir, name) {
|
|
|
638
638
|
}
|
|
639
639
|
return functionPath;
|
|
640
640
|
};
|
|
641
|
-
|
|
642
|
-
* The functions:create command
|
|
643
|
-
* @param {string} name
|
|
644
|
-
* @param {import('commander').OptionValues} options
|
|
645
|
-
* @param {import('../base-command.mjs').default} command
|
|
646
|
-
*/
|
|
647
|
-
// @ts-expect-error TS(7006) FIXME: Parameter 'name' implicitly has an 'any' type.
|
|
648
|
-
const functionsCreate = async (name, options, command) => {
|
|
641
|
+
export const functionsCreate = async (name, options, command) => {
|
|
649
642
|
const functionType = await selectTypeOfFunc();
|
|
650
643
|
const functionsDir = functionType === 'edge' ? await ensureEdgeFuncDirExists(command) : await ensureFunctionDirExists(command);
|
|
651
644
|
/* either download from URL or scaffold from template */
|
|
652
645
|
const mainFunc = options.url ? downloadFromURL : scaffoldFromTemplate;
|
|
653
646
|
await mainFunc(command, options, name, functionsDir, functionType);
|
|
654
647
|
};
|
|
655
|
-
/**
|
|
656
|
-
* Creates the `netlify functions:create` command
|
|
657
|
-
* @param {import('../base-command.mjs').default} program
|
|
658
|
-
* @returns
|
|
659
|
-
*/
|
|
660
|
-
// @ts-expect-error TS(7006) FIXME: Parameter 'program' implicitly has an 'any' type.
|
|
661
|
-
export const createFunctionsCreateCommand = (program) => program
|
|
662
|
-
.command('functions:create')
|
|
663
|
-
.alias('function:create')
|
|
664
|
-
.argument('[name]', 'name of your new function file inside your functions directory')
|
|
665
|
-
.description('Create a new function locally')
|
|
666
|
-
.option('-n, --name <name>', 'function name')
|
|
667
|
-
.option('-u, --url <url>', 'pull template from URL')
|
|
668
|
-
.option('-l, --language <lang>', 'function language')
|
|
669
|
-
.addExamples([
|
|
670
|
-
'netlify functions:create',
|
|
671
|
-
'netlify functions:create hello-world',
|
|
672
|
-
'netlify functions:create --name hello-world',
|
|
673
|
-
])
|
|
674
|
-
.action(functionsCreate);
|
|
@@ -4,8 +4,8 @@ import path from 'path';
|
|
|
4
4
|
import inquirer from 'inquirer';
|
|
5
5
|
// @ts-expect-error TS(7016) FIXME: Could not find a declaration file for module 'node... Remove this comment to see the full error message
|
|
6
6
|
import fetch from 'node-fetch';
|
|
7
|
-
import { NETLIFYDEVWARN, chalk, error, exit } from '../../utils/command-helpers.
|
|
8
|
-
import { BACKGROUND, CLOCKWORK_USERAGENT, getFunctions } from '../../utils/functions/index.
|
|
7
|
+
import { NETLIFYDEVWARN, chalk, error, exit } from '../../utils/command-helpers.js';
|
|
8
|
+
import { BACKGROUND, CLOCKWORK_USERAGENT, getFunctions } from '../../utils/functions/index.js';
|
|
9
9
|
const require = createRequire(import.meta.url);
|
|
10
10
|
// https://docs.netlify.com/functions/trigger-on-events/
|
|
11
11
|
const events = [
|
|
@@ -122,14 +122,7 @@ const getFunctionToTrigger = function (options, argumentName) {
|
|
|
122
122
|
}
|
|
123
123
|
return argumentName;
|
|
124
124
|
};
|
|
125
|
-
|
|
126
|
-
* The functions:invoke command
|
|
127
|
-
* @param {string} nameArgument
|
|
128
|
-
* @param {import('commander').OptionValues} options
|
|
129
|
-
* @param {import('../base-command.mjs').default} command
|
|
130
|
-
*/
|
|
131
|
-
// @ts-expect-error TS(7006) FIXME: Parameter 'nameArgument' implicitly has an 'any' t... Remove this comment to see the full error message
|
|
132
|
-
const functionsInvoke = async (nameArgument, options, command) => {
|
|
125
|
+
export const functionsInvoke = async (nameArgument, options, command) => {
|
|
133
126
|
const { config, relConfigFilePath } = command.netlify;
|
|
134
127
|
const functionsDir = options.functions || (config.dev && config.dev.functions) || config.functionsDirectory;
|
|
135
128
|
if (typeof functionsDir === 'undefined') {
|
|
@@ -216,34 +209,3 @@ const functionsInvoke = async (nameArgument, options, command) => {
|
|
|
216
209
|
error(`Ran into an error invoking your function: ${error_.message}`);
|
|
217
210
|
}
|
|
218
211
|
};
|
|
219
|
-
/**
|
|
220
|
-
* Creates the `netlify functions:invoke` command
|
|
221
|
-
* @param {import('../base-command.mjs').default} program
|
|
222
|
-
* @returns
|
|
223
|
-
*/
|
|
224
|
-
// @ts-expect-error TS(7006) FIXME: Parameter 'program' implicitly has an 'any' type.
|
|
225
|
-
export const createFunctionsInvokeCommand = (program) => program
|
|
226
|
-
.command('functions:invoke')
|
|
227
|
-
.alias('function:trigger')
|
|
228
|
-
.argument('[name]', 'function name to invoke')
|
|
229
|
-
.description(`Trigger a function while in netlify dev with simulated data, good for testing function calls including Netlify's Event Triggered Functions`)
|
|
230
|
-
.option('-n, --name <name>', 'function name to invoke')
|
|
231
|
-
.option('-f, --functions <dir>', 'Specify a functions folder to parse, overriding netlify.toml')
|
|
232
|
-
.option('-q, --querystring <query>', 'Querystring to add to your function invocation')
|
|
233
|
-
.option('-p, --payload <data>', 'Supply POST payload in stringified json, or a path to a json file')
|
|
234
|
-
// TODO: refactor to not need the `undefined` state by removing the --identity flag (value `identity` will be then always defined to true or false)
|
|
235
|
-
.option('--identity', 'simulate Netlify Identity authentication JWT. pass --identity to affirm unauthenticated request')
|
|
236
|
-
.option('--no-identity', 'simulate Netlify Identity authentication JWT. pass --no-identity to affirm unauthenticated request')
|
|
237
|
-
// @ts-expect-error TS(7006) FIXME: Parameter 'value' implicitly has an 'any' type.
|
|
238
|
-
.option('--port <port>', 'Port where netlify dev is accessible. e.g. 8888', (value) => Number.parseInt(value))
|
|
239
|
-
.addExamples([
|
|
240
|
-
'netlify functions:invoke',
|
|
241
|
-
'netlify functions:invoke myfunction',
|
|
242
|
-
'netlify functions:invoke --name myfunction',
|
|
243
|
-
'netlify functions:invoke --name myfunction --identity',
|
|
244
|
-
'netlify functions:invoke --name myfunction --no-identity',
|
|
245
|
-
`netlify functions:invoke myfunction --payload '{"foo": 1}'`,
|
|
246
|
-
'netlify functions:invoke myfunction --querystring "foo=1',
|
|
247
|
-
'netlify functions:invoke myfunction --payload "./pathTo.json"',
|
|
248
|
-
])
|
|
249
|
-
.action(functionsInvoke);
|
|
@@ -1,20 +1,13 @@
|
|
|
1
1
|
import AsciiTable from 'ascii-table';
|
|
2
|
-
import { exit, log, logJson } from '../../utils/command-helpers.
|
|
3
|
-
import { getFunctions, getFunctionsDir } from '../../utils/functions/index.
|
|
4
|
-
import requiresSiteInfo from '../../utils/hooks/requires-site-info.mjs';
|
|
2
|
+
import { exit, log, logJson } from '../../utils/command-helpers.js';
|
|
3
|
+
import { getFunctions, getFunctionsDir } from '../../utils/functions/index.js';
|
|
5
4
|
// @ts-expect-error TS(7006) FIXME: Parameter 'deployedFunctions' implicitly has an 'a... Remove this comment to see the full error message
|
|
6
5
|
const normalizeFunction = function (deployedFunctions, { name, urlPath: url }) {
|
|
7
6
|
// @ts-expect-error TS(7006) FIXME: Parameter 'deployedFunction' implicitly has an 'an... Remove this comment to see the full error message
|
|
8
7
|
const isDeployed = deployedFunctions.some((deployedFunction) => deployedFunction.n === name);
|
|
9
8
|
return { name, url, isDeployed };
|
|
10
9
|
};
|
|
11
|
-
|
|
12
|
-
* The functions:list command
|
|
13
|
-
* @param {import('commander').OptionValues} options
|
|
14
|
-
* @param {import('../base-command.mjs').default} command
|
|
15
|
-
*/
|
|
16
|
-
// @ts-expect-error TS(7006) FIXME: Parameter 'options' implicitly has an 'any' type.
|
|
17
|
-
const functionsList = async (options, command) => {
|
|
10
|
+
export const functionsList = async (options, command) => {
|
|
18
11
|
const { config, relConfigFilePath, siteInfo } = command.netlify;
|
|
19
12
|
const deploy = siteInfo.published_deploy || {};
|
|
20
13
|
const deployedFunctions = deploy.available_functions || [];
|
|
@@ -45,20 +38,3 @@ const functionsList = async (options, command) => {
|
|
|
45
38
|
});
|
|
46
39
|
log(table.toString());
|
|
47
40
|
};
|
|
48
|
-
/**
|
|
49
|
-
* Creates the `netlify functions:list` command
|
|
50
|
-
* @param {import('../base-command.mjs').default} program
|
|
51
|
-
* @returns
|
|
52
|
-
*/
|
|
53
|
-
// @ts-expect-error TS(7006) FIXME: Parameter 'program' implicitly has an 'any' type.
|
|
54
|
-
export const createFunctionsListCommand = (program) => program
|
|
55
|
-
.command('functions:list')
|
|
56
|
-
.alias('function:list')
|
|
57
|
-
.description(`List functions that exist locally
|
|
58
|
-
Helpful for making sure that you have formatted your functions correctly
|
|
59
|
-
|
|
60
|
-
NOT the same as listing the functions that have been deployed. For that info you need to go to your Netlify deploy log.`)
|
|
61
|
-
.option('-f, --functions <dir>', 'Specify a functions directory to list')
|
|
62
|
-
.option('--json', 'Output function data as JSON')
|
|
63
|
-
.hook('preAction', requiresSiteInfo)
|
|
64
|
-
.action(functionsList);
|
|
@@ -1,17 +1,11 @@
|
|
|
1
1
|
import { join } from 'path';
|
|
2
|
-
import { startFunctionsServer } from '../../lib/functions/server.
|
|
3
|
-
import { printBanner } from '../../utils/banner.
|
|
4
|
-
import { acquirePort, getDotEnvVariables, getSiteInformation, injectEnvVariables } from '../../utils/dev.
|
|
5
|
-
import { getFunctionsDir } from '../../utils/functions/index.
|
|
6
|
-
import { getProxyUrl } from '../../utils/proxy.
|
|
2
|
+
import { startFunctionsServer } from '../../lib/functions/server.js';
|
|
3
|
+
import { printBanner } from '../../utils/banner.js';
|
|
4
|
+
import { acquirePort, getDotEnvVariables, getSiteInformation, injectEnvVariables } from '../../utils/dev.js';
|
|
5
|
+
import { getFunctionsDir } from '../../utils/functions/index.js';
|
|
6
|
+
import { getProxyUrl } from '../../utils/proxy.js';
|
|
7
7
|
const DEFAULT_PORT = 9999;
|
|
8
|
-
|
|
9
|
-
* The functions:serve command
|
|
10
|
-
* @param {import('commander').OptionValues} options
|
|
11
|
-
* @param {import('../base-command.mjs').default} command
|
|
12
|
-
*/
|
|
13
|
-
// @ts-expect-error TS(7006) FIXME: Parameter 'options' implicitly has an 'any' type.
|
|
14
|
-
const functionsServe = async (options, command) => {
|
|
8
|
+
export const functionsServe = async (options, command) => {
|
|
15
9
|
const { api, config, site, siteInfo, state } = command.netlify;
|
|
16
10
|
const functionsDir = getFunctionsDir({ options, config }, join('netlify', 'functions'));
|
|
17
11
|
let { env } = command.netlify.cachedConfig;
|
|
@@ -51,19 +45,3 @@ const functionsServe = async (options, command) => {
|
|
|
51
45
|
const url = getProxyUrl({ port: functionsPort });
|
|
52
46
|
printBanner({ url });
|
|
53
47
|
};
|
|
54
|
-
/**
|
|
55
|
-
* Creates the `netlify functions:serve` command
|
|
56
|
-
* @param {import('../base-command.mjs').default} program
|
|
57
|
-
* @returns
|
|
58
|
-
*/
|
|
59
|
-
// @ts-expect-error TS(7006) FIXME: Parameter 'program' implicitly has an 'any' type.
|
|
60
|
-
export const createFunctionsServeCommand = (program) => program
|
|
61
|
-
.command('functions:serve')
|
|
62
|
-
.alias('function:serve')
|
|
63
|
-
.description('Serve functions locally')
|
|
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.
|
|
66
|
-
.option('-p, --port <port>', 'Specify a port for the functions server', (value) => Number.parseInt(value))
|
|
67
|
-
.option('-o, --offline', 'disables any features that require network access')
|
|
68
|
-
.addHelpText('after', 'Helpful for debugging functions.')
|
|
69
|
-
.action(functionsServe);
|