2

I'm trying to convert a CodeKit project to use Grunt (so we can support our Windows friends).

In CodeKit, you can concatenate JS files by including concat instructions as comments in the files you want concatenated. For example, to prepend jquery.validate.js to your scripts.js file, you would add the following comment to scripts.js:

 /* @codekit-prepend "jquery.validate.js" */

How can I configure grunt-concat (or a similar plugin) to concatenate JS files based on instructions within the files themselves? I'd prefer to have concat instructions in the files so it's more clear what's going on (as opposed to referring to Gruntfile.js).

elstgav
  • 1,001
  • 7
  • 20

2 Answers2

5

I do not know about codekit syntax, but if all you need is the prepend feature, then take a look at https://github.com/miensol/grunt-concat-in-order, and specifically the filebased approach. You could customize the syntax to extract your codekit prepend syntax or replace that to something like @depend used in the example.

(for a cross platform example check out my fork, it has a windows safe example, using path.normalize)

Martin Hansen
  • 5,154
  • 3
  • 32
  • 53
  • Would you know if the same plugin could handle the codekit-append directives as well? – oligofren Feb 22 '14 at 04:12
  • I don't think it can. I only has a concept of having dependencies, not dependants. (which is what append logically seems to mean to me) – Martin Hansen Feb 22 '14 at 17:59
  • I added support for codekit-prepend and codekit-append to grunt-codekit. https://www.npmjs.org/package/grunt-codekit – oligofren Jun 10 '14 at 08:11
  • @oligofren It looks like you've since removed that support from your plugin and haven't moved it to a plugin of it's own. – Gidgidonihah Jun 08 '15 at 22:37
  • @Gidgidonihah I am embarrassed to say you are right ... I am handing in my master thesis in two weeks, so I haven't had time for that stuff atm. But it should not stop you anyway. Just download version 0.4. If you are using nom, just do `npm install grunt-codekit@0.4.0`. I'll update these answers then. – oligofren Jun 15 '15 at 22:08
1

I made a plugin for Grunt that understands the Kit language of CodeKit, as well as its @codekit-append and @codekit-prepend instructions. You can then build your projects both using Grunt and CodeKit interchangably without changing any code.

EDIT This functionality is still available through grunt-codekit version 0.4.x, but was removed in version 1.0.0 due to a general lack of interest. I am intending to split the functionality into a module of its own, but need some time to do it (or you can fork the code and create it yourself). Anyway, to simply use the 0.4 version you can do this npm install grunt-codekit@0.4.0 --save

oligofren
  • 20,744
  • 16
  • 93
  • 180