Skip to content

Instantly share code, notes, and snippets.

@jeff-french
Created November 23, 2015 14:52
Show Gist options
  • Save jeff-french/688a40761c09b8a35616 to your computer and use it in GitHub Desktop.
Save jeff-french/688a40761c09b8a35616 to your computer and use it in GitHub Desktop.
var gulp    = require('gulp');  
var replace = require('gulp-replace-task');  
var args    = require('yargs').argv;  
var fs      = require('fs');

gulp.task('replace', function () {  
  // Get the environment from the command line
  var env = args.env || 'localdev';

  // Read the settings from the right file
  var filename = env + '.json';
  var settings = JSON.parse(fs.readFileSync('./config/' + filename, 'utf8'));

// Replace each placeholder with the correct value for the variable.  
gulp.src('js/coolapp-constants.js')  
  .pipe(replace({
    patterns: [
      {
        match: 'apiUrl',
        replacement: settings.apiUrl
      }
    ]
  }))
  .pipe(gulp.dest('build/js'));
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment