atticoos/gulp-ng-config

Nested Environment with npm

Closed this issue · 7 comments

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];
}

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.

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

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

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)

@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.

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! 👍

Terrific 💯