Access file name in grunt task

73 Views Asked by At

I'm trying to edit quite a few svg files with Grunt.

I'm currently using svgmin and grunt-text-replace.

I need to add attribute to svg element, based on the name of the file.

I wonder if there is a kind of grunt template that lets you get the name of file being processed.

Here is what I want:

input: test.svg

<svg id="Layer_1"></svg>

output: test.svg 
<svg id="Layer_1" floor-map="test"></svg>

Here is the current script:

svgmin: {
      options: {
        plugins: [
          {
            removeViewBox: false
          },
          {
            cleanupIDs : false
          },
          {
            removeUselessStrokeAndFill: false
          },
          {
            removeAttrs: {
              attrs: ['fill','opacity',"font-family"]
            }
          },
          {
            addAttributesToSVGElement : {
              attributes:['floor-map="' + "<%= grunt.template.filename %>" + '"']
            }
          }
        ]
      },
      dist: {
        expand:true,
        cwd: 'img/floor-plans/maps-initial/',
        src: '*.svg',
        dest: 'img/floor-plans/svgmin-maps/',
        ext: '.svg'
      }
    },
0

There are 0 best solutions below