Skip to content

Commit

Permalink
refactor: change varFile parameter name to varfile
Browse files Browse the repository at this point in the history
  • Loading branch information
edvald committed Sep 11, 2019
1 parent 545b469 commit 71e37fb
Show file tree
Hide file tree
Showing 5 changed files with 74 additions and 74 deletions.
18 changes: 9 additions & 9 deletions docs/reference/config.md
Original file line number Diff line number Diff line change
Expand Up @@ -132,9 +132,9 @@ environmentDefaults:
- stage
```

### `environmentDefaults.varFile`
### `environmentDefaults.varfile`

[environmentDefaults](#environmentdefaults) > varFile
[environmentDefaults](#environmentdefaults) > varfile

Specify a path (relative to the project root) to a file containing variables, that we apply on top of the
_environment-specific_ `variables` field. The file should be in a standard "dotenv" format, specified
Expand Down Expand Up @@ -288,7 +288,7 @@ sources:
- repositoryUrl: "git+https://github.com/org/repo.git#v2.0"
```

### `varFile`
### `varfile`

Specify a path (relative to the project root) to a file containing variables, that we apply on top of the
project-wide `variables` field. The file should be in a standard "dotenv" format, specified
Expand All @@ -298,7 +298,7 @@ If you don't set the field and the `garden.env` file does not exist, we simply i
If you do override the default value and the file doesn't exist, an error will be thrown.

_Note that in many cases it is advisable to only use environment-specific var files, instead of combining
multiple ones. See the `environments[].varFile` field for this option._
multiple ones. See the `environments[].varfile` field for this option._

| Type | Required | Default |
| -------- | -------- | -------------- |
Expand Down Expand Up @@ -366,9 +366,9 @@ environments:
- stage
```

### `environments[].varFile`
### `environments[].varfile`

[environments](#environments) > varFile
[environments](#environments) > varfile

Specify a path (relative to the project root) to a file containing variables, that we apply on top of the
_environment-specific_ `variables` field. The file should be in a standard "dotenv" format, specified
Expand Down Expand Up @@ -415,7 +415,7 @@ environmentDefaults:
providers:
- name:
environments:
varFile: garden.<env-name>.env
varfile: garden.<env-name>.env
variables: {}
modules:
include:
Expand All @@ -426,13 +426,13 @@ providers:
sources:
- name:
repositoryUrl:
varFile: garden.env
varfile: garden.env
variables: {}
environments:
- providers:
- name:
environments:
- varFile: garden.<env-name>.env
- varfile: garden.<env-name>.env
variables: {}
name:
```
Expand Down
46 changes: 23 additions & 23 deletions garden-service/src/config/project.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ import { defaultDotIgnoreFiles } from "../util/fs"
import { pathExists, readFile } from "fs-extra"
import { resolve } from "path"

export const defaultVarFilePath = "garden.env"
export const defaultEnvVarFilePath = (environmentName: string) => `garden.${environmentName}.env`
export const defaultVarfilePath = "garden.env"
export const defaultEnvVarfilePath = (environmentName: string) => `garden.${environmentName}.env`

export interface CommonEnvironmentConfig {
providers?: ProviderConfig[] // further validated by each plugin
Expand All @@ -51,17 +51,17 @@ export const environmentConfigSchema = joi.object()
DEPRECATED - Please use the top-level \`providers\` field instead, and if needed use the \`environments\` key
on the provider configurations to limit them to specific environments.
`),
varFile: joi.string()
varfile: joi.string()
.posixPath()
.default(
(context: any) => defaultEnvVarFilePath(context.name || "<env-name>"), defaultEnvVarFilePath("<env-name>"),
(context: any) => defaultEnvVarfilePath(context.name || "<env-name>"), defaultEnvVarfilePath("<env-name>"),
)
.description(dedent`
Specify a path (relative to the project root) to a file containing variables, that we apply on top of the
_environment-specific_ \`variables\` field. The file should be in a standard "dotenv" format, specified
[here](https://github.com/motdotla/dotenv#rules).
If you don't set the field and the \`${defaultEnvVarFilePath("<env-name>")}\` file does not exist,
If you don't set the field and the \`${defaultEnvVarfilePath("<env-name>")}\` file does not exist,
we simply ignore it. If you do override the default value and the file doesn't exist, an error will be thrown.
`),
variables: joiVariables()
Expand All @@ -73,7 +73,7 @@ export const environmentConfigSchema = joi.object()

export interface EnvironmentConfig extends CommonEnvironmentConfig {
name: string
varFile?: string
varfile?: string
}

export interface Environment extends EnvironmentConfig {
Expand Down Expand Up @@ -129,7 +129,7 @@ export interface ProjectConfig {
},
providers: ProviderConfig[]
sources?: SourceConfig[]
varFile?: string
varfile?: string
variables: PrimitiveMap
}

Expand All @@ -146,7 +146,7 @@ export const defaultEnvironments: EnvironmentConfig[] = [
environments: [],
},
],
varFile: defaultEnvVarFilePath("local"),
varfile: defaultEnvVarfilePath("local"),
variables: {},
},
]
Expand Down Expand Up @@ -236,9 +236,9 @@ export const projectSchema = joi.object()
"Please refer to individual plugins/providers for details on how to configure them.",
),
sources: projectSourcesSchema,
varFile: joi.string()
varfile: joi.string()
.posixPath()
.default(defaultVarFilePath)
.default(defaultVarfilePath)
.description(dedent`
Specify a path (relative to the project root) to a file containing variables, that we apply on top of the
project-wide \`variables\` field. The file should be in a standard "dotenv" format, specified
Expand All @@ -248,7 +248,7 @@ export const projectSchema = joi.object()
If you do override the default value and the file doesn't exist, an error will be thrown.
_Note that in many cases it is advisable to only use environment-specific var files, instead of combining
multiple ones. See the \`environments[].varFile\` field for this option._
multiple ones. See the \`environments[].varfile\` field for this option._
`),
variables: joiVariables()
.description("Variables to configure for all environments."),
Expand Down Expand Up @@ -276,7 +276,7 @@ export async function resolveProjectConfig(config: ProjectConfig): Promise<Proje
environmentDefaults: { variables: {}, ...environmentDefaults || {}, providers: <ProviderConfig[]>[] },
name: config.name,
sources: config.sources,
varFile: config.varFile,
varfile: config.varfile,
variables: config.variables,
environments: environments.map(e => omit(e, ["providers"])),
},
Expand Down Expand Up @@ -354,8 +354,8 @@ export async function resolveProjectConfig(config: ProjectConfig): Promise<Proje
*
* For project variables, we apply the variables specified to the selected environment on the global variables
* specified on the top-level `variables` key using a JSON Merge Patch (https://tools.ietf.org/html/rfc7396).
* We also attempt to load the configured varFiles, and include those in the merge. The precedence order is as follows:
* environment.varFile > environment.variables > project.varFile > project.variables
* We also attempt to load the configured varfiles, and include those in the merge. The precedence order is as follows:
* environment.varfile > environment.variables > project.varfile > project.variables
*
* For provider configuration, we filter down to the providers that are enabled for all environments (no `environments`
* key specified) and those that explicitly list the specified environments. Then we merge any provider configs with
Expand Down Expand Up @@ -400,16 +400,16 @@ export async function pickEnvironment(config: ProjectConfig, environmentName: st
}
}

const projectVarFileVars = await loadVarFile(
config.path, config.varFile, defaultVarFilePath,
const projectVarfileVars = await loadVarfile(
config.path, config.varfile, defaultVarfilePath,
)
const envVarFileVars = await loadVarFile(
config.path, environmentConfig.varFile, defaultEnvVarFilePath(environmentName),
const envVarfileVars = await loadVarfile(
config.path, environmentConfig.varfile, defaultEnvVarfilePath(environmentName),
)

const variables: PrimitiveMap = <any>merge(
merge(config.variables, projectVarFileVars),
merge(environmentConfig.variables, envVarFileVars),
merge(config.variables, projectVarfileVars),
merge(environmentConfig.variables, envVarfileVars),
)

return {
Expand All @@ -418,12 +418,12 @@ export async function pickEnvironment(config: ProjectConfig, environmentName: st
}
}

async function loadVarFile(projectRoot: string, path: string | undefined, defaultPath: string): Promise<PrimitiveMap> {
async function loadVarfile(projectRoot: string, path: string | undefined, defaultPath: string): Promise<PrimitiveMap> {
const resolvedPath = resolve(projectRoot, path || defaultPath)
const exists = await pathExists(resolvedPath)

if (!exists && path && path !== defaultPath) {
throw new ConfigurationError(`Could not find varFile at path '${path}'`, {
throw new ConfigurationError(`Could not find varfile at path '${path}'`, {
path,
resolvedPath,
})
Expand All @@ -436,7 +436,7 @@ async function loadVarFile(projectRoot: string, path: string | undefined, defaul
try {
return dotenv.parse(await readFile(resolvedPath))
} catch (error) {
throw new ConfigurationError(`Unable to load varFile at '${path}': ${error}`, {
throw new ConfigurationError(`Unable to load varfile at '${path}': ${error}`, {
error,
path,
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ kind: Project
name: varfiles-custom
environments:
- name: default
varFile: foo.default.env
varFile: foo.env
varfile: foo.default.env
varfile: foo.env
Loading

0 comments on commit 71e37fb

Please sign in to comment.