Skip to content

Commit

Permalink
Merge pull request #23 from adambullmer/config-overrides
Browse files Browse the repository at this point in the history
Added config override ability
  • Loading branch information
adambullmer authored Mar 14, 2017
2 parents 57b8eaf + 66a6920 commit cbf3f22
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 5 deletions.
31 changes: 27 additions & 4 deletions lib/angular-app.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,11 +92,34 @@ AngularApp.prototype.initOptions = function (options) {
};

AngularApp.prototype.configTree = function () {
var config = this.appConfig,
header = 'export default JSON.parse(\'',
footer = '\');';
var config,
file = `
const jsonConfig = JSON.parse('${this.appConfig}');
let config = jsonConfig;
if (jsonConfig.overrideConfig) {
config = new Proxy(jsonConfig, {
get: getterProxy.bind(this, window['angularConfig'], jsonConfig)
});
}
function getterProxy (override, original, target, name, receiver) {
let overrideValue = override && override[name],
value = overrideValue || original[name];
if (typeof value !== "object") {
return value;
}
return new Proxy(value, {
get: getterProxy.bind(this, overrideValue, original[name])
});
}
export default config;
`;

config = writeFile('/config/environment.js', header + config + footer);
config = writeFile('/config/environment.js', file);
config = new Babel(config, {
moduleIds : true,
modules : 'amdStrict',
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "angular-bro-app",
"version": "0.8.6",
"version": "0.9.0",
"description": "Angular broccoli plugin and compilation routine",
"main": "lib/angular-app.js",
"scripts": {
Expand Down

0 comments on commit cbf3f22

Please sign in to comment.