atticoos / gulp-ng-config

:wrench: Create AngularJS constants from a JSON config file
MIT License
173 stars 35 forks source link

Nested Environment with npm #52

Closed marcosjaojr closed 7 years ago

marcosjaojr commented 8 years ago

The package gulp-ng-config in npm doesn't accept environment configuration like "env.production", for example. I think that this happen because npm's package may not be up to date.

the 1.2.1 version contains this:

// select the environment in the configuration
if (configuration.environment && jsonObj.hasOwnProperty(configuration.environment)) {
    jsonObj = jsonObj[configuration.environment];
}
atticoos commented 8 years ago

Good observation -- this currently only allows a single keyspace. It could be easily achievable using something like _.get

Would really only need to update these lines to

if (configuration.environment) {
  jsonObj = _.get(jsonObj, configuration.environment, jsonObj)
}

(Third parameter would be the fallback)

Might even be good to emit an error if the property doesn't exist, rather than skipping as it does now.

vcardins commented 8 years ago

Hello, thanks for this cool package. Any updates on this?

atticoos commented 8 years ago

Not at the moment @vcardins, PR's are welcome. Otherwise I'll need to wait for a free weekend when I can poke around.

erperejildo commented 7 years ago

Is this correct @ajwhite ?

.pipe(gulpNgConfig('bb.configVars'), {
  // we should detect here the environmet
  environment: 'env.production'
})

I doesn't throw an error but the generated file has everything, not just env.production (I'm using the one in the example btw)

atticoos commented 7 years ago

@erperejildo would you mind uploading your issue into a gist of the relevant files (the JSON, gulpfile, and generated output).

I have a unit test that indicates this should work:

However, one test I notice that I don't have is when a nested key doesn't exist.. And I wonder if there's anything your setup where the keyspace might not be accurate.

In any case -- if you can share those files, that would be very helpful in narrowing down your issue.

erperejildo commented 7 years ago

After say you that I removed the whole example and I started from scratch. Everything looks great now. Probably I had something badly configured.

Anyway, thanks for your support! 👍

atticoos commented 7 years ago

Terrific :100: