{"id":5375,"date":"2014-03-30T21:11:07","date_gmt":"2014-03-30T21:11:07","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2014\/03\/30\/how-to-create-grunt-multitask-to-process-my-templates-collection-of-common-programming-errors\/"},"modified":"2014-03-30T21:11:07","modified_gmt":"2014-03-30T21:11:07","slug":"how-to-create-grunt-multitask-to-process-my-templates-collection-of-common-programming-errors","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2014\/03\/30\/how-to-create-grunt-multitask-to-process-my-templates-collection-of-common-programming-errors\/","title":{"rendered":"How to create Grunt Multitask to process my templates-Collection of common programming errors"},"content":{"rendered":"<p>I am using Gruntjs to process templates for my Joomla! extensions.<\/p>\n<p>I have 3 directories and a Grunt file inside my main directory: <code>component<\/code>, <code>tmpl<\/code>, <code>tasks<\/code> and <code>Gruntfile.js<\/code>.<\/p>\n<p>Inside the <code>tasks<\/code> directory I have a file named <code>compile.js<\/code>:<\/p>\n<pre><code>module.exports = function( grunt ) {\n    grunt.registerMultiTask('compile', 'Compiles Joomla! extension templates', function() {\n\n        \/\/ Iterate over all specified file groups.\n        this.files.forEach(function(file) {\n\n            var template, phpcode;\n\n            var src = file.src;\n            var dest = file.dest;\n\n            if (!grunt.file.exists(src)) {\n                grunt.log.warn('Source file \"' + src + '\" not found.');\n                return false;\n            }\n\n            template = grunt.file.read(src);\n            phpcode = grunt.template.process(template);\n\n            \/\/ Write the destination file.\n            grunt.file.write(dest, phpcode);\n\n            \/\/ Print a success message.\n            grunt.log.writeln('File \"' + dest + '\" created.');\n        });\n    });\n};\n<\/code><\/pre>\n<p>My Gruntfile has the following code:<\/p>\n<pre><code>module.exports = function(grunt) {\n  grunt.initConfig({\n    compile: {\n        model: {          \n            files: [\n                {src: 'tmpl\/model.tmpl', dest: 'component\/models\/user.php'},\n                {src: 'tmpl\/model.tmpl', dest: 'component\/models\/company.php'}\n            ]\n        }\n    }\n  });\n\n  \/\/ Actually load this plugin's task.\n  grunt.loadTasks('tasks');\n\n  grunt.registerTask('compile', ['compile']);\n};\n<\/code><\/pre>\n<p>When I run the command <code>grunt compile<\/code><\/p>\n<pre><code>node.js:893\n    var fn = runInThisContext(source, this.filename, true);\n             ^\nTypeError: undefined is not a function\n    at createWritableStdioStream (node.js:555:18)\n    at process.stdout (node.js:612:16)\n    at write (\/home\/qawe\/Desktop\/code\/compile\/node_modules\/grunt\/lib\/grunt\/log.js:78:12)\n    at writeln (\/home\/qawe\/Desktop\/code\/compile\/node_modules\/grunt\/lib\/grunt\/log.js:85:3)\n    at Object.log.writeln (\/home\/qawe\/Desktop\/code\/compile\/node_modules\/grunt\/lib\/grunt\/log.js:96:3)\n    at writeln (\/home\/qawe\/Desktop\/code\/compile\/node_modules\/grunt\/lib\/grunt\/fail.js:39:13)\n    at Object.fail.fatal (\/home\/qawe\/Desktop\/code\/compile\/node_modules\/grunt\/lib\/grunt\/fail.js:55:3)\n    at process.uncaughtHandler (\/home\/qawe\/Desktop\/code\/compile\/node_modules\/grunt\/lib\/grunt.js:123:10)\n    at process.EventEmitter.emit (events.js:95:17)\n    at process._fatalException (node.js:272:26)\n<\/code><\/pre>\n<p>Is there something that I&#8217;m doing wrong? Please help, I&#8217;m still a newbie in Grunt.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I am using Gruntjs to process templates for my Joomla! extensions. I have 3 directories and a Grunt file inside my main directory: component, tmpl, tasks and Gruntfile.js. Inside the tasks directory I have a file named compile.js: module.exports = function( grunt ) { grunt.registerMultiTask(&#8216;compile&#8217;, &#8216;Compiles Joomla! extension templates&#8217;, function() { \/\/ Iterate over all [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-5375","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/5375","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/comments?post=5375"}],"version-history":[{"count":0,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/5375\/revisions"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=5375"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=5375"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=5375"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}