I’ve been working on building some extensions for Firefox, including my prawn doohickey and, starting today, something for work. When you build an extension, you have to follow a given directory hierarchy that’s pretty well documented here. You also have to zip up a couple of sets of files and rename them appropriately, move them around, etc. I’ve got a code directory set up that’s forked into a “src” (source) and an “xpi” (the file extension given to completed Firefox extensions) directory. I change files in the src directory and then build the xpi file and save it in the xpi directory. Initially, this was a pain because you have to edit the files, zip some of them, move some of them, zip something else, etc. And every time you make changes to an extension, you have to do this routine. After about three iterations of it, I wrote a quick little shell script that does the build for me. I just execute “./build” from the command line and it assembles the xpi for me. Here’s the build script:
echo “- Removing old r2.jar.”
echo “- Zipping new r2.jar from content.”
zip -r r2.jar content skin locale
mv r2.jar chrome/
echo “- Creating xpi.”
zip -r r2.xpi install.rdf chrome/
echo “- Moving xpi to output directory.”
mv r2.xpi ../../xpi/
If I weren’t lazy, I’d make this portable so that I didn’t have to change the script for each extension, but for now, I can just do a regular expression and, in this case, replace “r2” throughout the script with whatever the directory name for the current script is. I think you can actually use ant and an xml config file to build extensions, and for more complicated extensions, that might be in order. This seems to fit the bill pretty well for small ones, though.
The script assumes that the current directory contains an install.rdf file, a directory named “chrome,” and directories named “content,” “skin,” and “locale.” It zips the latter three directories into a file named (in this case) r2.jar, shoves that jar file into the “chrome” directory, and then creates a zip of install.rdf and “chrome” with the xpi extension. It copies this up into the xpi directory from which I open xpis to install them.