Tuesday, July 19, 2005

Extending in batch

Inspired by Andrew Beacock, with thanks to Brian Duff's post here and the cracking resource at XUL Planet, I've started to look at doing some Firefox extension development.

It all looks pretty straightforward. Produce a bit of XML in the guise of XUL and slap in some Javascript event handlers and you've got the idea. Early testing is easy since Firefox just lets you open XUL files as if they're HTML. It's all very easy to get going with.

The only issue I had at the start was the structuring of the source code tree and the packaging up of the .XPI file.
An .XPI file is a packages extension that Firefox can install. It's easy to run one, you can simply double click on it and firefox kicks of its extension manager. Packaging one up though, it a little trickier. Without wanting to get into the details of the how any why (again, Brian Duff's got the intro covered), I've found it's easist to develop within the directory structure that's ultimately required by the XPI package...


+YourExtentionName
|
|-- install.rdf
|
|-+ chrome
|
|---+ content
|-- contents.rdf + other .rdf files
|-- .xul files
|-- .js files
|-- .css files


Brian suggests dropping the chrome directory and having the content in the extension directory, but that's much of a muchness if you ask me. He also supplies an ANT task to package up the XPI file for you. I don't have ANT installed. I don't use it, because I've got no need for it at home (it's overkill for this, really). So in true Windows skript kiddi traditions, I've put together a batch file that'll do the same job.

It assumes the directory structure is the same as stated above, and it should be ran from the YourExtensionName directory.

Forgive me if it's not perfect, feel free to use and amend. It'd be nice if you posted a comment back here if you improve it.

Update:Just had my attention drawn here/ Shame I didn't spot that before I wrote my own Batch file based packager! Eerily similar they are too...



BUILD_XPI.BAT


@ECHO OFF

SETLOCAL

IF ""=="%1" GOTO :noparams

SET current_directory=%cd%
SET extension_name=%1

MKDIR build\chrome
DEL %extension_name%.xpi

CD chrome
CALL :createZipFile "%current_directory%\build\chrome\%extension_name%" *.*
MOVE "%current_directory%\build\chrome\%extension_name%.zip" "%current_directory%\build\chrome\%extension_name%.jar"

CD ..\build
COPY ..\install.rdf .
CALL :createZipFile "%current_directory%\%extension_name%" *.*
MOVE "%current_directory%\%extension_name%.zip" "%current_directory%\%extension_name%.xpi"

cd ..
RD build /q /s

GOTO:EOF


:createZipFile
SET zip_file=%~1
SET files=%~2

REM Change the following line to one that runs your particular CMD Zip executable
REM
REM It should create a ZIP file, adding files recursively, keeping
REM their directory structure

pkzipc -add -rec -dir=specify %zip_file% %files%

GOTO :EOF

:noparams
Must specify a name for the extension



Technorati Tags: , , , , , ,

No comments: