Sunday, 15 January 2012

javascript - Unable to write "undefined" file in grunt plugin -



javascript - Unable to write "undefined" file in grunt plugin -

i'm new writing grunt plugins , i'm running problem when i'm trying run it:

running "inject_css:dev" (inject_css) task warning: unable write "undefined" file (error code: undefined). utilize --force continue.

my plugin looks like:

'use strict'; module.exports = function(grunt) { grunt.registermultitask('inject_css', 'allows inject css html files part of build process.', function() { var src = grunt.file.expand(this.data.src); var text = ''; if (src) { src.foreach(function (script) { text += grunt.file.read(script); }); } else { grunt.log.error('please specify file inject html.'); return; } this.files.foreach(function (file) { grunt.file.write(file.dest, grunt.file.read(file.src).replace('<!-- inject -->', '<style type="text/css">' + text + '</style>')); grunt.log.ok('file injected'.blue + ' ' + file.dest); }); }); };

and when trying phone call in gruntfile i'm using next config:

inject_css: { dev: { files:{ 'static/test/test.html': 'test.html' }, src: 'static/less/form.less' } }

any ideas i'm doing wrong?

looking @ warning, i'm guessing thrown there :

grunt.file.write(file.dest, grunt.file.read(file.src).replace('<!-- inject -->', '<style type="text/css">' + text + '</style>'));

which mean file.dest undefined.

and looking @ code, seems normal cause go foreach on this.files not contain dest property.

basically, think forgot expand this.dest , should trick :

var expandedfiles = grunt.file.expand(this.data.files); expandedfiles.foreach(function (file) { grunt.file.write(file.dest, grunt.file.read(file.src).replace('<!-- inject -->', '<style type="text/css">' + text + '</style>')); grunt.log.ok('file injected'.blue + ' ' + file.dest); });

as couldn't seek it, it's guess, allow me know if works fine.

javascript gruntjs npm

No comments:

Post a Comment