Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 10 additions & 5 deletions docs/commands/env.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,10 @@
- `context` (*string*) - Specify a deploy context for environment variables (”production”, ”deploy-preview”, ”branch-deploy”, ”dev”) or `branch:your-branch` where `your-branch` is the name of a branch
- `filter` (*string*) - For monorepos, specify the name of the application to run the command in
- `json` (*boolean*) - Output environment variables as JSON
- `scope` (*builds | functions | post-processing | runtime | any*) - Specify a scope
- `debug` (*boolean*) - Print debugging information
- `auth` (*string*) - Netlify auth token - can be used to run this command without logging in
- `scope` (*builds | functions | post-processing | runtime | any*) - Specify a scope
- `site` (*string*) - A project name or ID to target

**Examples**

Expand Down Expand Up @@ -125,6 +126,7 @@
- `replace-existing` (*boolean*) - Replace all existing variables instead of merging them with the current ones
- `debug` (*boolean*) - Print debugging information
- `auth` (*string*) - Netlify auth token - can be used to run this command without logging in
- `site` (*string*) - A project name or ID to target

---
## `env:list`
Expand All @@ -142,10 +144,11 @@
- `context` (*string*) - Specify a deploy context for environment variables (”production”, ”deploy-preview”, ”branch-deploy”, ”dev”) or `branch:your-branch` where `your-branch` is the name of a branch (default: all contexts)
- `filter` (*string*) - For monorepos, specify the name of the application to run the command in
- `json` (*boolean*) - Output environment variables as JSON
- `scope` (*builds | functions | post-processing | runtime | any*) - Specify a scope
- `plain` (*boolean*) - Output environment variables as plaintext

Check warning on line 147 in docs/commands/env.md

View workflow job for this annotation

GitHub Actions / lint-docs

[vale] reported by reviewdog 🐶 [base.spelling] Spellcheck: did you really mean 'plaintext'? Raw Output: {"message": "[base.spelling] Spellcheck: did you really mean 'plaintext'?", "location": {"path": "docs/commands/env.md", "range": {"start": {"line": 147, "column": 57}}}, "severity": "WARNING"}
- `debug` (*boolean*) - Print debugging information
- `auth` (*string*) - Netlify auth token - can be used to run this command without logging in
- `plain` (*boolean*) - Output environment variables as plaintext
- `scope` (*builds | functions | post-processing | runtime | any*) - Specify a scope
- `site` (*string*) - A project name or ID to target

**Examples**

Expand Down Expand Up @@ -179,10 +182,11 @@
- `filter` (*string*) - For monorepos, specify the name of the application to run the command in
- `force` (*boolean*) - Bypasses prompts & Force the command to run.
- `json` (*boolean*) - Output environment variables as JSON
- `secret` (*boolean*) - Indicate whether the environment variable value can be read again.
- `scope` (*builds | functions | post-processing | runtime*) - Specify a scope (default: all scopes)
- `debug` (*boolean*) - Print debugging information
- `auth` (*string*) - Netlify auth token - can be used to run this command without logging in
- `scope` (*builds | functions | post-processing | runtime*) - Specify a scope (default: all scopes)
- `secret` (*boolean*) - Indicate whether the environment variable value can be read again.
- `site` (*string*) - A project name or ID to target

**Examples**

Expand Down Expand Up @@ -220,6 +224,7 @@
- `json` (*boolean*) - Output environment variables as JSON
- `debug` (*boolean*) - Print debugging information
- `auth` (*string*) - Netlify auth token - can be used to run this command without logging in
- `site` (*string*) - A project name or ID to target

**Examples**

Expand Down
1 change: 1 addition & 0 deletions src/commands/env/env-clone.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ export const envClone = async (options: OptionValues, command: BaseCommand) => {
}

log(`Successfully cloned environment variables from ${chalk.green(siteFrom.name)} to ${chalk.green(siteTo.name)}`)
log(`Changes will require a redeploy to take effect on any deployed versions of your project.`)

return true
}
3 changes: 2 additions & 1 deletion src/commands/env/env-get.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { OptionValues } from 'commander'
import { chalk, log, logJson } from '../../utils/command-helpers.js'
import { SUPPORTED_CONTEXTS, getEnvelopeEnv } from '../../utils/env/index.js'
import BaseCommand from '../base-command.js'
import { getSiteInfo } from './utils.js'

export const envGet = async (name: string, options: OptionValues, command: BaseCommand) => {
const { context, scope } = options
Expand All @@ -14,7 +15,7 @@ export const envGet = async (name: string, options: OptionValues, command: BaseC
return false
}

const { siteInfo } = cachedConfig
const siteInfo = await getSiteInfo(api, siteId, cachedConfig)
const env = await getEnvelopeEnv({ api, context, env: cachedConfig.env, key: name, scope, siteInfo })

// @ts-expect-error FIXME(ndhoule)
Expand Down
6 changes: 4 additions & 2 deletions src/commands/env/env-import.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import dotenv from 'dotenv'
import { exit, log, logJson } from '../../utils/command-helpers.js'
import { translateFromEnvelopeToMongo, translateFromMongoToEnvelope } from '../../utils/env/index.js'
import BaseCommand from '../base-command.js'
import { getSiteInfo } from './utils.js'

/**
* Saves the imported env in the Envelope service
Expand Down Expand Up @@ -58,6 +59,8 @@ export const envImport = async (fileName: string, options: OptionValues, command
return false
}

const siteInfo = await getSiteInfo(api, siteId, cachedConfig)

let importedEnv = {}
try {
const envFileContents = await readFile(fileName, 'utf-8')
Expand All @@ -73,8 +76,6 @@ export const envImport = async (fileName: string, options: OptionValues, command
return false
}

const { siteInfo } = cachedConfig

const finalEnv = await importDotEnv({ api, importedEnv, options, siteInfo })

// Return new environment variables of site if using json flag
Expand All @@ -90,4 +91,5 @@ export const envImport = async (fileName: string, options: OptionValues, command
table.setHeading('Key', 'Value')
table.addRowMatrix(Object.entries(importedEnv))
log(table.toString())
log(`Changes will require a redeploy to take effect on any deployed versions of your project.`)
}
4 changes: 3 additions & 1 deletion src/commands/env/env-list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { chalk, log, logJson } from '../../utils/command-helpers.js'
import { SUPPORTED_CONTEXTS, getEnvelopeEnv, getHumanReadableScopes } from '../../utils/env/index.js'
import type BaseCommand from '../base-command.js'
import { EnvironmentVariables } from '../../utils/types.js'
import { getSiteInfo } from './utils.js'

const MASK_LENGTH = 50
const MASK = '*'.repeat(MASK_LENGTH)
Expand Down Expand Up @@ -50,7 +51,8 @@ export const envList = async (options: OptionValues, command: BaseCommand) => {
return false
}

const { env, siteInfo } = cachedConfig
const siteInfo = await getSiteInfo(api, siteId, cachedConfig)
const { env } = cachedConfig
let environment = await getEnvelopeEnv({ api, context, env, scope, siteInfo })

// filter out general sources
Expand Down
4 changes: 3 additions & 1 deletion src/commands/env/env-set.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { chalk, logAndThrowError, log, logJson } from '../../utils/command-helpe
import { SUPPORTED_CONTEXTS, ALL_ENVELOPE_SCOPES, translateFromEnvelopeToMongo } from '../../utils/env/index.js'
import { promptOverwriteEnvVariable } from '../../utils/prompts/env-set-prompts.js'
import BaseCommand from '../base-command.js'
import { getSiteInfo } from './utils.js'

/**
* Updates the env for a site configured with Envelope with a new key/value pair
Expand Down Expand Up @@ -115,7 +116,7 @@ export const envSet = async (key: string, value: string, options: OptionValues,
log('No project id found, please run inside a project folder or `netlify link`')
return false
}
const { siteInfo } = cachedConfig
const siteInfo = await getSiteInfo(api, siteId, cachedConfig)

// Get current environment variables set in the UI
const finalEnv = await setInEnvelope({ api, siteInfo, force, key, value, context, scope, secret })
Expand All @@ -138,4 +139,5 @@ export const envSet = async (key: string, value: string, options: OptionValues,
`${key}${value && !secret ? `=${value}` : ''}`,
)}${withScope}${withSecret} in the ${chalk.magenta(context || 'all')} ${contextType}`,
)
log(`Changes will require a redeploy to take effect on any deployed versions of your project.`)
}
4 changes: 3 additions & 1 deletion src/commands/env/env-unset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { chalk, log, logJson } from '../../utils/command-helpers.js'
import { SUPPORTED_CONTEXTS, translateFromEnvelopeToMongo } from '../../utils/env/index.js'
import { promptOverwriteEnvVariable } from '../../utils/prompts/env-unset-prompts.js'
import BaseCommand from '../base-command.js'
import { getSiteInfo } from './utils.js'
/**
* Deletes a given key from the env of a site configured with Envelope
* @returns {Promise<object>}
Expand Down Expand Up @@ -77,7 +78,7 @@ export const envUnset = async (key: string, options: OptionValues, command: Base
return false
}

const { siteInfo } = cachedConfig
const siteInfo = await getSiteInfo(api, siteId, cachedConfig)

const finalEnv = await unsetInEnvelope({ api, context, force, siteInfo, key })

Expand All @@ -89,4 +90,5 @@ export const envUnset = async (key: string, options: OptionValues, command: Base

const contextType = SUPPORTED_CONTEXTS.includes(context || 'all') ? 'context' : 'branch'
log(`Unset environment variable ${chalk.yellow(key)} in the ${chalk.magenta(context || 'all')} ${contextType}`)
log(`Changes will require a redeploy to take effect on any deployed versions of your project.`)
}
5 changes: 5 additions & 0 deletions src/commands/env/env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export const createEnvCommand = (program: BaseCommand) => {
'dev',
)
.option('--json', 'Output environment variables as JSON')
.option('--site <name-or-id>', 'A project name or ID to target')
.addOption(
new Option('-s, --scope <scope>', 'Specify a scope')
.choices(['builds', 'functions', 'post-processing', 'runtime', 'any'])
Expand All @@ -45,6 +46,7 @@ export const createEnvCommand = (program: BaseCommand) => {
false,
)
.option('--json', 'Output environment variables as JSON')
.option('-s, --site <name-or-id>', 'A project name or ID to target')
.description('Import and set environment variables from .env file')
.action(async (fileName: string, options: OptionValues, command: BaseCommand) => {
const { envImport } = await import('./env-import.js')
Expand All @@ -60,6 +62,7 @@ export const createEnvCommand = (program: BaseCommand) => {
'dev',
)
.option('--json', 'Output environment variables as JSON')
.option('--site <name-or-id>', 'A project name or ID to target')
.addOption(new Option('--plain', 'Output environment variables as plaintext').conflicts('json'))
.addOption(
new Option('-s, --scope <scope>', 'Specify a scope')
Expand Down Expand Up @@ -90,6 +93,7 @@ export const createEnvCommand = (program: BaseCommand) => {
(context: string, previous: string[] = []) => [...previous, normalizeContext(context)],
)
.option('--json', 'Output environment variables as JSON')
.option('--site <name-or-id>', 'A project name or ID to target')
.addOption(
new Option('-s, --scope <scope...>', 'Specify a scope (default: all scopes)').choices([
'builds',
Expand Down Expand Up @@ -126,6 +130,7 @@ export const createEnvCommand = (program: BaseCommand) => {
(context: string, previous: string[] = []) => [...previous, normalizeContext(context)],
)
.option('--json', 'Output environment variables as JSON')
.option('-s, --site <name-or-id>', 'A project name or ID to target')
.addExamples([
'netlify env:unset VAR_NAME # unset in all contexts',
'netlify env:unset VAR_NAME --context production',
Expand Down
12 changes: 12 additions & 0 deletions src/commands/env/utils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import type { NetlifyAPI } from '@netlify/api'

import type { CachedConfig } from '../../lib/build.js'
import type { SiteInfo } from '../../utils/types.js'

export const getSiteInfo = async (api: NetlifyAPI, siteId: string, cachedConfig: CachedConfig): Promise<SiteInfo> => {
const { siteInfo: cachedSiteInfo } = cachedConfig
if (siteId !== cachedSiteInfo.id) {
return (await api.getSite({ siteId })) as unknown as SiteInfo
}
return cachedSiteInfo
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@

exports[`commands/env > env:clone > should exit if the folder is not linked to a project, and --from is not provided 1`] = `"Please include the source project ID as the \`--from\` option, or run \`netlify link\` to link this folder to a Netlify project"`;

exports[`commands/env > env:clone > should return success message 1`] = `"Successfully cloned environment variables from site-name to site-name-a"`;
exports[`commands/env > env:clone > should return success message 1`] = `
"Successfully cloned environment variables from site-name to site-name-a
Changes will require a redeploy to take effect on any deployed versions of your project."
`;

exports[`commands/env > env:clone > should return without clone if there's no env in source project 1`] = `"site-name has no environment variables, nothing to clone"`;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html

exports[`command/envelope > env:clone should return success message 1`] = `"Successfully cloned environment variables from site-name-a to site-name-b"`;
exports[`command/envelope > env:clone should return success message 1`] = `
"Successfully cloned environment variables from site-name-a to site-name-b
Changes will require a redeploy to take effect on any deployed versions of your project."
`;
Loading