1 | var toml = require('toml');
|
2 | var fs = require('fs');
|
3 | var path = require('path');
|
4 |
|
5 | exports.load = function() {
|
6 | var configPath = path.join(process.cwd(), 'netlify.toml');
|
7 | if (!fs.existsSync(configPath)) {
|
8 | console.error(
|
9 | 'No netlify.toml found. This is needed to configure the function settings. For more info: https://github.com/netlify/netlify-lambda#installation'
|
10 | );
|
11 | process.exit(1);
|
12 | }
|
13 |
|
14 | return toml.parse(fs.readFileSync(configPath));
|
15 | };
|
16 |
|
17 | exports.loadContext = function(config) {
|
18 | var buildConfig = config.build;
|
19 | var contextConfig =
|
20 | (process.env.CONTEXT &&
|
21 | config.context &&
|
22 | config.context[process.env.CONTEXT]) ||
|
23 | {};
|
24 | var branchConfig =
|
25 | (process.env.BRANCH &&
|
26 | config.context &&
|
27 | config.context[process.env.BRANCH]) ||
|
28 | {};
|
29 | var buildEnv = buildConfig.environment || buildConfig.Environment || {};
|
30 | var contextEnv = contextConfig.environment || contextConfig.Environment || {};
|
31 | var branchEnv = branchConfig.environment || branchConfig.Environment || {};
|
32 | return {
|
33 | ...buildConfig,
|
34 | ...contextConfig,
|
35 | ...branchConfig,
|
36 | environment: {
|
37 | ...buildEnv,
|
38 | ...contextEnv,
|
39 | ...branchEnv
|
40 | }
|
41 | };
|
42 | };
|