Trouble using ‘this.files’ in GruntJS Tasks

Posted by whomba on Stack Overflow See other posts from Stack Overflow or by whomba
Published on 2013-11-11T02:44:40Z Indexed on 2013/11/11 3:53 UTC
Read the original article Hit count: 668

Filed under:
|
|

Background: So I’m new to writing grunt tasks, so hopefully this isn’t a stupid question.
Purpose of my grunt task: Given a file (html / jsp / php / etc) search all the link / script tags, compare the href / src to a key, and replace with the contents of the file. Proposed task configuration:

myTask:{
      index:{
          files:{src:"test/testcode/index.html", dest:"test/testcode/index.html"},

          css:[
              {
                  file: "/css/some/css/file.css",
                  fileToReplace:"/target/css/file.css"
              },
              {
                  file: "/css/some/css/file2.css",
                  fileToReplace:"/target/css/file2.css"
              }
          ],
          js:[
              {
                  file: "/css/some/css/file.css",
                  fileToReplace:”/target/css/file.css"
              },
              {
                  file: "/css/some/css/file2.css",
                  fileToReplace:"/target/css/file2.css"
              }
          ]
      }
  }

Problem: Now, per my understanding, when dealing with files, you should reference the ‘this.files’ object because it handles a bunch of nice things for you, correct? Using intelliJ and the debugger, I see the following when i watch the ‘this.files’ object: http://i.imgur.com/Gj6iANo.png What I would expect to see is src and dest to be the same, not dest ===‘src’ and src === undefined.

So, What is it that I am missing? Is there some documentation on ‘this.files’ I can read about? I’ve tried setting the files attribute in the target to a number of other formats per grunts spec, none seem to work (for this script, ideally the src / dest would be the same, so the user would just have to enter it once, but i’m not even getting in to that right now.)

Thanks for the help

© Stack Overflow or respective owner

Related posts about JavaScript

Related posts about node.js