gulp-ng-config icon indicating copy to clipboard operation
gulp-ng-config copied to clipboard

Allow for no json file (and only inline values from gulp)

Open bdwain opened this issue 9 years ago • 8 comments

the use case i'm thinking of is pass a command line param to gulp and pass that directly to the plugin

gulpNgConfig('myApp.config', {
  constants: {
    apiUrl: argv.apiUrl
  }
});

this would be especially nice since it allows you to avoid putting the value of your constants in source control, which is what drew me to this in the first place.

my workaround for the time being will be to create a json file that is just {}

bdwain avatar Mar 10 '15 05:03 bdwain

Hi @ajwhite and @bdwain,

I'm thinking of contributing to this issue. Have one of you already started to think about it ?

ThamosIO avatar May 15 '15 10:05 ThamosIO

Nope, feel free

atticoos avatar May 15 '15 11:05 atticoos

i haven't either.

bdwain avatar May 15 '15 14:05 bdwain

You can achieve this using buffer-to-vinyl.

var b2v = require('buffer-to-vinyl');
var gulpNgConfig = require('gulp-ng-config');

gulp.task('make-config', function() {
  var json = JSON.stringify({
    // your config here
  });

  return b2v.stream(new Buffer(json), 'config.js')
    .pipe(gulpNgConfig('app.config'))
    .pipe(gulp.dest('build'));
});

Is this worth putting in the readme? I can whip up a PR.

psalaets avatar Jun 21 '15 13:06 psalaets

@psalaets great call, one of the beautiful things about streams is that we can & should be extremely modular and allow for single responsibility -- piping the result of that into gulpNgConfig would be ideal here. We can add an "Additional Usages" section that shows how this can be integrated with other preceding or proceeding streams. I think this is a great entry to start off a new "Additional Usages" section. Feel free to PR!

atticoos avatar Jun 21 '15 23:06 atticoos

that works, but it seems a little weird to me to require an extra module to read what you already have in code. It seems more logical to me to require something extra to read configs from a file (and default to only inline objects), though since it's already implemented this way, might not be worth changing.

bdwain avatar Jun 24 '15 05:06 bdwain

When it comes to the principles behind a stream build system, a gulp plugin only serves as a stage (pipe) of the stream. To build around edges where there might not be a source of a stream, it kind of defeats the purpose of how a gulp plugin is intended to work -- there needs to be a stream source. The source, in this case, should be responsible for taking your command line args, creating your JSON object, and beginning a new readable stream.

atticoos avatar Jun 26 '15 05:06 atticoos

Think I'm going to take a look at this for 1.4.0

atticoos avatar Nov 17 '15 00:11 atticoos