Skip to content
This repository has been archived by the owner on Jul 16, 2023. It is now read-only.

Commit

Permalink
feat(config): allow propagation of netlify env vars to config (#33)
Browse files Browse the repository at this point in the history
  • Loading branch information
filipowm committed Jun 4, 2020
1 parent 85128da commit 9f7c3df
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 2 deletions.
32 changes: 31 additions & 1 deletion config/config-reader.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,9 @@ const defaults = {
enabled: true,
arrowKeyNavigation: true
},
scrollTop: true
scrollTop: true,
showMetadata: true,
propagateNetlifyEnv: true
},
};

Expand Down Expand Up @@ -178,13 +180,41 @@ class EnvReader extends ConfigReader {
}
}

class NetlifyEnvReader extends ConfigReader {

constructor(allowNetlifyEnvPropagation) {
super();
this.allowNetlifyEnvPropagation = allowNetlifyEnvPropagation;
}

read() {
if (this.allowNetlifyEnvPropagation && readEnvOrDefault("NETLIFY", false)) {
const context = readEnvOrDefault("CONTEXT");
const repositoryUrl = readEnvOrDefault("REPOSITORY_URL");
const url = readEnvOrDefault("URL");
const deployUrl = context === "production" ? url : readEnvOrDefault("DEPLOY_PRIME_URL", url);
console.log("Setting up Netlify variables.", "URL:", deployUrl, "Docs Location:", repositoryUrl)
return {
metadata: {
url: deployUrl,
docsLocation: repositoryUrl,
}
}
}
return {};
}
}

const read = () => {
const fileConfig = new FileReader().read();
const envConfig = new EnvReader().read();
const def = _.cloneDeep(defaults);

let config = _.merge(def, fileConfig);
config = _.merge(config, envConfig);
const netlifyConfig = new NetlifyEnvReader(config.features.propagateNetlifyEnv).read();
config = _.merge(config, netlifyConfig)
console.log("meta", config.metadata)
postProcessConfig(config);
return config;
};
Expand Down
3 changes: 2 additions & 1 deletion config/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -72,4 +72,5 @@ features:
enabled: true
arrowKeyNavigation: true
scrollTop: true
showMetadata: true
showMetadata: true
propagateNetlifyEnv: true

0 comments on commit 9f7c3df

Please sign in to comment.