Sunday, June 28, 2009

JSBuild

I finally did it. I broken down and cracked open my <jsmin> Ant task. It worked fine when crunching down file-for-file. When compiling multiple files into one, however, things got a bit problematic. The reason is probably obvious: the constituent files cannot be concatenated together in just any old order if you want to produce a usable result.

For the longest time I have lived with that problem by adding a set of specific files and then dragging in the rest wildcard style. Some reordering is not a problem after all. What was called for was an Ant task that understood how to navigate module dependencies and produce a file that would always work. The groundwork was already in place with the $requires functionality. This approach is already being used by $import.

So, here's what the new <jsbuild> task looks like in action:


<jsbuild out="${build.dir}/debug/src/zjs/zjs-all.js"
level="1" verbosity="quiet"
packages="zjs=${src.dir}/zjs" modules="zjs.**">
<comment>${jscomment}</comment>
</jsbuild>


I'll document this more fully on the ZJS wiki, but the basic idea is that jsbuild will compile a list of modules from one or more packages. The list of modules can use wildcards like “*” for every module in a package or “**” for every module in a package or any of its subpackages. There can also be a list of excluded modules.

While ZJS has been growing, it remains small by any objective measure. If the maintenance of this kind of thing was a frustration on the small scale, one can only imagine how bad things would get on a large scale! So while build process improvements aren't exactly the focus of ZJS, it is something we all have to grapple with. The jsmin and now jsbuild Ant tasks help elevate JavaScript in this area just like the high level OO mechanics of ZJS do for coding. And it doesn't hurt that the build process can leverage things defined by ZJS (like $requires) to eliminate redundant dependency information.

Enjoy!

No comments:

Post a Comment