-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add --env-path option to load env file
- Loading branch information
Showing
6 changed files
with
91 additions
and
56 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,52 +1,58 @@ | ||
import * as yaml from "js-yaml"; | ||
|
||
export function customYamlLoad(str: string) { | ||
return yaml.load(str, { schema: customYamlSchema }); | ||
} | ||
export function customYamlLoad({extraEnv, yamlString}: {extraEnv: { [name: string]: string }, yamlString: string}) { | ||
const concatYamlType = new yaml.Type('!concat', { | ||
kind: 'sequence', | ||
resolve(data) { | ||
return Array.isArray(data); | ||
}, | ||
construct(data) { | ||
return data.join(""); | ||
}, | ||
}); | ||
|
||
const concatYamlType = new yaml.Type('!concat', { | ||
kind: 'sequence', | ||
resolve(data) { | ||
return Array.isArray(data); | ||
}, | ||
construct(data) { | ||
return data.join(""); | ||
}, | ||
}); | ||
const envYamlType = new yaml.Type('!env', { | ||
kind: 'scalar', | ||
resolve(data) { | ||
return typeof data === "string"; | ||
}, | ||
construct(data) { | ||
// if env[data] is undefined, the config validation will occur an error. | ||
const env = { | ||
...process.env, | ||
// override | ||
...extraEnv, | ||
} | ||
return env[data]; | ||
}, | ||
}); | ||
|
||
const envYamlType = new yaml.Type('!env', { | ||
kind: 'scalar', | ||
resolve(data) { | ||
return typeof data === "string"; | ||
}, | ||
construct(data) { | ||
return process.env[data]; | ||
}, | ||
}); | ||
const jsonDecodeYamlType = new yaml.Type('!json_decode', { | ||
kind: 'scalar', | ||
resolve(data) { | ||
return typeof data === "string"; | ||
}, | ||
construct(data) { | ||
return JSON.parse(data); | ||
}, | ||
}); | ||
|
||
const jsonDecodeYamlType = new yaml.Type('!json_decode', { | ||
kind: 'scalar', | ||
resolve(data) { | ||
return typeof data === "string"; | ||
}, | ||
construct(data) { | ||
return JSON.parse(data); | ||
}, | ||
}); | ||
const unrecommendedJsYamlType = new yaml.Type('!unrecommended_js', { | ||
kind: 'scalar', | ||
resolve(data) { | ||
return typeof data === "string"; | ||
}, | ||
construct(data) { | ||
return new Function("require", data)(require); | ||
}, | ||
}); | ||
|
||
const unrecommendedJsYamlType = new yaml.Type('!unrecommended_js', { | ||
kind: 'scalar', | ||
resolve(data) { | ||
return typeof data === "string"; | ||
}, | ||
construct(data) { | ||
return new Function("require", data)(require); | ||
}, | ||
}); | ||
const customYamlSchema = yaml.DEFAULT_SCHEMA.extend([ | ||
concatYamlType, | ||
envYamlType, | ||
jsonDecodeYamlType, | ||
unrecommendedJsYamlType, | ||
]); | ||
|
||
const customYamlSchema = yaml.DEFAULT_SCHEMA.extend([ | ||
concatYamlType, | ||
envYamlType, | ||
jsonDecodeYamlType, | ||
unrecommendedJsYamlType, | ||
]); | ||
return yaml.load(yamlString, { schema: customYamlSchema }); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters