12

how to specify a separator in this scenario:
I'm concatenating my files with grunt-concat this way:

concat: {
  options: {
    banner: '<%= banner %>',
    separator: ""
  },
  dist: {
    files:{
      '<%= distdir %>/public/scripts/ieditor.js': [
        'public/scripts/ieditor/vars.js',
        'public/scripts/ieditor/controllers/*.js',
        'public/scripts/ieditor/directives/*.js',
        'public/scripts/ieditor/app.js',
        'public/scripts/ieditor/services/*.js',
        'public/scripts/ieditor/filters/*.js'
      ],
      '<%= distdir %>/public/scripts/dashboard.js': [
        'public/scripts/dashboard/vars.js',
        'public/scripts/dashboard/controllers/*.js',
        'public/scripts/dashboard/directives/*.js',
        'public/scripts/dashboard/app.js',
        'public/scripts/dashboard/services/*.js',
        'public/scripts/dashboard/filters/*.js'
      ]
    }
  }
}

what I want is to get a final result mapped to the original files like in compass when concatenating CSS files.
Example:

//####public/scripts/ieditor/vars.js###############
content of public/scripts/ieditor/vars.js
//####public/scripts/ieditor/controllers/a.js######
content of public/scripts/ieditor/controllers/a.js
//####public/scripts/ieditor/controllers/b.js######
content of public/scripts/ieditor/controllers/b.js
.....

So what's the name referring to the current file being concatenated so i can do something like this in the options area:

  options: {
    banner: '<%= banner %>',
    separator: "<%= current_file_name %>"
  },

Thanks in advance.

Yahya KACEM
  • 2,481
  • 7
  • 34
  • 61

1 Answers1

20

The process option, specified as a function, is your friend:

concat: {
  options: {
    process: function(src, filepath) {
      return '//####' + filepath + '\n' + src;
    }
  }
},
...
Misch
  • 10,350
  • 4
  • 35
  • 49
xverges
  • 4,608
  • 1
  • 39
  • 60
  • 1
    That didn't work for me, don't know why!? nothing is added by the process function. – Yahya KACEM Sep 12 '13 at 22:19
  • 1
    Maybe `console.log()` can help you to find out if the function is being called? I'm on `grunt` 0.4.1 and `grunt-contrib-concat` 0.3.0, and it does work for me – xverges Sep 13 '13 at 06:19
  • Actually the function is being called I used the example in the docs, where it replaces all the 'use restrict' with one at the top, that did work but the `filepath` was not added. – Yahya KACEM Sep 13 '13 at 14:16
  • Then, what are you getting as the value for the second parameter of the function? – xverges Sep 13 '13 at 16:46
  • Sorry, my grunt-contrib-concat was outdated I was using the v0.1.3 after updating it to v0.3.0 it worked. – Yahya KACEM Sep 14 '13 at 16:44