2016-05-25 13 views
-1

Ich habe eine Sammlung von .svg-Dateien. Wenn ich einen von ihnen ändern, würde ich grunzen wie ein Befehl auf jeder svg-Datei erneut ausführen, dieÜbergeben Sie den Namen der überwachten Datei, die sich als Argument geändert hat, an einen Shell-Befehl.

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

Bisher geändert wurde, habe ich dieses Grunzen Skript

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']); 
}; 

Aber ich habe keine Ahnung, wie man grunt konfiguriert, um FILENAME durch den Namen jeder Datei zu ersetzen, die geändert wurde.

+0

Warum der Downvote genau? – Overdrivr

Antwort

1

Ich löste das Problem eine Konfigurationsvariable, die auf dem watch Ereignis vor shell:figs läuft

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']); 
}; 

Der einzige Nachteil ist nicht manuell aufgerufen werden kann, dass shell:figs geändert wird, es funktioniert nur, wenn die watch Aufgabe ausgeführt wird, oder einfach grunt.