将更改的监视文件的名称作为参数传递给 shell 命令
Pass the name of watched file that changed as argument to a shell command
我有一组 .svg 文件。
当我修改其中一个时,我希望 g运行t 对每个已修改的 svg 文件重新运行 一个命令
inkscape --file=FILENAME.svg --export-pdf=FILENAME.pdf
到目前为止,我有这个 g运行t 脚本
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']);
};
但我不知道如何配置 g运行t 以便用每个已修改文件的名称替换 FILENAME
。
我在 shell:figs
运行
之前使用在 watch
事件上修改的配置变量解决了这个问题
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']);
};
唯一的缺点是shell:figs
不能手动调用,它只在运行 watch
任务时有效,或者只是grunt
。
我有一组 .svg 文件。 当我修改其中一个时,我希望 g运行t 对每个已修改的 svg 文件重新运行 一个命令
inkscape --file=FILENAME.svg --export-pdf=FILENAME.pdf
到目前为止,我有这个 g运行t 脚本
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']);
};
但我不知道如何配置 g运行t 以便用每个已修改文件的名称替换 FILENAME
。
我在 shell:figs
运行
watch
事件上修改的配置变量解决了这个问题
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']);
};
唯一的缺点是shell:figs
不能手动调用,它只在运行 watch
任务时有效,或者只是grunt
。