3

I used grunt-contrib-concat alot and wondered why some files were not concatenated. I found out it was a small typo. Anyway, I've got a lot of different files with different destinations.

grunt.initConfig({
  concat: {
    js: {
      files: [
        {
          src: ["file1.js"],
          dest: "some/dir/fileXY.js"
        },
        {
          src: ["x/file2.js"],
          dest: "some/other/dir/fileAB.js"
        },

        // and so on, and on
      ]
    }
  }
}

Now as per the docs I have to set nonull: true in the object literal itself, to get some warnings if the file does not exist. Is there a way to set it by default so that I don't have to touch every single one of them?

I tried it with the options object, but no luck so far.

dan-lee
  • 14,365
  • 5
  • 52
  • 77

1 Answers1

4

Grunt allow you to get & set any configuration property.

Put it below grunt.initConfig:

  var files = grunt.config.get('concat.js.files').map(function(prop){ 
    prop.nonull = true;
    return prop;
  });

  grunt.config.set('concat.js.files',files);

Another way is to create the object and then pass it to initConfig:

files = [
  {
    src: ['a.js'],
    dest: 'b.js'
  }, {
    src: ['c.js'],
    dest: 'd.js'
  }
];

files = files.map(function(prop) { 
  prop.nonull = true;
  return prop;
});

grunt.initConfig({
  concat: {
    js: { files: files}
  }
});  
Ilan Frumer
  • 32,059
  • 8
  • 70
  • 84
  • Yeah cool! I hoped this would be more generic by the plugin itself, but this works for now, thanks :) – dan-lee Jan 15 '14 at 17:55
  • 1
    I think the return value of `grunt.config.get` is the same as the value input (grunt does no normalization), and so setting `prop.nonull = true` only works on [files-array format](http://gruntjs.com/configuring-tasks#files-array-format). (Or [compact format](http://gruntjs.com/configuring-tasks#compact-format) for a different property key.) – Carl G Apr 18 '14 at 01:57