2016-05-25 9 views
-1

.svgファイルのコレクションがあります。 私はそれらのいずれかを変更すると、私はこれまでのところ引数として変更された監視対象ファイルの名前をシェルコマンドに渡します。

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

を変更された各SVGファイルの再実行コマンドにうなり声をしたいと思い、私はこのうなり声スクリプト

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

を持っている。しかし、私は持っていますFILENAMEを、変更された各ファイルの名前で置き換えるために、不快感をどのように設定するかは考えられません。

+0

なぜdownvoteが正確に? – Overdrivr

答えて

1

私が唯一の欠点は、shell:figsを手動で呼び出すことはできませんということですwatchタスクを実行するときに、それだけで動作しますshell:figs実行

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

watchイベントに変更された設定変数を使用して問題を解決し、または単純にgruntです。

関連する問題