Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Overriding Values? #41

Open
jsmarsch opened this issue Sep 28, 2016 · 2 comments
Open

Overriding Values? #41

jsmarsch opened this issue Sep 28, 2016 · 2 comments

Comments

@jsmarsch
Copy link

Hi:

I would like to have a base set of config values, and then override only certain values in an environment-specific config. I'm having hard time figuring out how to get gulp-ng-constant to do that. Can you give me a hint.

Example:
app.config.json would look like this:
{
"foo": "default",
"bar": "default"
}
app.dev.json might look like this:
{
"foo":"dev"
}

I want output to look like this
.constant("foo", "dev")
.constant("bar": "default")

I can't seem to make that work. (either app.dev.json completely overwrites app.config.json, so "bar" gets dropped, or app.config.json completely overwrites app.dev.json)

@guzart
Copy link
Owner

guzart commented Sep 29, 2016

Hi, currently you can't override the constants from multiple configuration files only using gulp-ng-constant.

However, one solution would be to do the overriding outside the plugin and then pass the properties to it, similar to the multiple environments example

var gulp = require('gulp');
var ngConstant = require('gulp-ng-constant');

gulp.task('constants', function () {
  var appConfig = require('./app.config.json');
  var devConfig = require('./app.dev.config.json');
  var finalConfig = Object.assign(appConfig, devConfig);
  return ngConstant({
      constants: finalConfig,
      stream: true
    })
    .pipe(gulp.dest('dist'));
});

Please note that instead of passing this plugin into a pipe, you use the stream option to create a stream from this plugin.

Let me know if this helps you

@jsmarsch
Copy link
Author

Thank you!

I actually ended up doing something very similar to what you described. I
used lodash's merge function to override / merge my base config with the
environment config.

On Thursday, September 29, 2016, Arturo Guzman notifications@github.com
wrote:

Hi, currently you can't override the constants from multiple configuration
files only using gulp-ng-constant.

However, one solution would be to do the overriding outside the plugin and
then pass the properties to it, similar to the multiple environments
example https://github.com/guzart/gulp-ng-constant#multiple-environments

var gulp = require('gulp');var ngConstant = require('gulp-ng-constant');
gulp.task('constants', function () {
var appConfig = require('./app.config.json');
var devConfig = require('./app.dev.config.json');
var finalConfig = Object.assign(appConfig, devConfig);
return ngConstant({
constants: finalConfig,
stream: true
})
.pipe(gulp.dest('dist'));
});

Please note that instead of passing this plugin into a pipe, you use the
stream option to create a stream from this plugin.

Let me know if this helps you


You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
#41 (comment),
or mute the thread
https://github.com/notifications/unsubscribe-auth/ADmuZ4ejC1UJYpyFJbWGxCfTIp_W63Qzks5qvB9tgaJpZM4KJPuo
.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants