gruntjs - Pass the name of watched file that changed as argument to a shell command -


i have collection of .svg files. when modify 1 of them, grunt re-run command on each svg file modified

inkscape --file=filename.svg --export-pdf=filename.pdf 

so far, have grunt script

module.exports = function (grunt) { 'use strict'; grunt.initconfig({   shell: {     figures: {       command: 'inkscape --file=filename.svg --export-pdf=filename.pdf'     }   },   watch: {     figs: {       files: '**/*.svg',       tasks: ['shell:figures']     }   } }); grunt.loadnpmtasks('grunt-contrib-watch'); grunt.loadnpmtasks('grunt-shell');  grunt.registertask('default', [watch']); }; 

but have no idea how configure grunt in order replace filename name of each file modified.

i solved issue using config variable modified on watch event before shell:figs runs

module.exports = function (grunt) {   'use strict';   // project configuration   grunt.initconfig({     shell: {       figs: {         command: function() {           return 'inkscape --file="' + grunt.config('shell.figs.src') + '" --export-pdf="' + grunt.config('shell.figs.src').replace('.svg', '.pdf') + '"';         },         src: '**/*.svg'       }     },     watch: {       svgs: {         files: '**/*.svg',         tasks: ['shell:figs'],         options: {         spawn: false,         }       }     }   });    grunt.event.on('watch', function(action, filepath) {     grunt.config('shell.figs.src', filepath);   });    // these plugins provide necessary tasks   grunt.loadnpmtasks('grunt-contrib-watch');   grunt.loadnpmtasks('grunt-shell');    // default task   grunt.registertask('default', ['connect', 'watch']); }; 

the downside shell:figs cannot called manually, works when running watch task, or grunt.


Comments

Popular posts from this blog

scala - 'wrong top statement declaration' when using slick in IntelliJ -

c# - DevExpress.Wpf.Grid.InfiniteGridSizeException was unhandled -

PySide and Qt Properties: Connecting signals from Python to QML -