grunt-file-creator con un nombre de archivo variable
Frecuentes
Visto 544 veces
3
Estoy tratando de usar https://npmjs.org/package/grunt-file-creator to create a file, but I would like to have a variable filename...
grunt.initConfig({
file-creator: {
"test": {
grunt.config('meta.revision') + "-test.txt": function(fs, fd, done) {
fs.writeSync(fd, 'data');
done();
}
}
}
});
y
grunt.initConfig({
file-creator: {
"test": {
"<%= grunt.config('meta.revision') %>-test.txt": function(fs, fd, done) {
fs.writeSync(fd, 'data');
done();
}
}
}
});
don't seem to work. How can I have a variable filename? The idea is that I've set the git commit ID as the value of meta.revision
.
1 Respuestas
2
Es porque grunt-file-creator
implements their own API rather than utilizing the standard Grunt src/dest
API. I'd recommend that task be rewritten using this.files
más bien que this.data
but a simple fix the author doesn't want to use the standard API would be to change:
var filepath = item.key;
a
var filepath = grunt.template.process(item.key);
on line 34 of the task: https://github.com/travis-hilterbrand/grunt-file-creator/blob/master/tasks/file-creator.js#L34
Otherwise you would have to write a hacky workaround like this:
grunt.registerTask('fixed-file-creator', function() {
var taskName = 'file-creator';
var cfg = grunt.config(taskName);
Object.keys(cfg).forEach(function(target) {
var newcfg = {};
Object.keys(cfg[target]).forEach(function(dest) {
newcfg[grunt.template.process(dest)] = grunt.config([taskName, target, dest]);
});
grunt.config([taskName, target], newcfg);
});
grunt.task.run(taskName);
});
Y luego ejecutar grunt fixed-file-creator
.
respondido 29 nov., 13:21
No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas gruntjs or haz tu propia pregunta.