初步学习了 Firefox 插件的编写,通过脚本来重新构建修改后的插件,这样将有效地提高开发效率。这里以插件的目录名称为 插件文件名称,将脚本放到插件的文件夹里执行就可以了。脚本的功能见源码吧。
#!/bin/bash
# check 7z
CHCKE_7Z=`which 7z`
if [ "uu$CHCKE_7Z" == "uu" ]
then
echo 7z is not found.
echo Please install 7z first.
exit 77
fi
#
BASE_DIR=`pwd`
PACKAGE=`basename $BASE_DIR`
# delete prior xpi
if [ -f "$BASE_DIR/$PACKAGE.xpi" ]
then
rm -v "$BASE_DIR/$PACKAGE.xpi"
fi
# clean up
BACKUPS=`find $BASE_DIR -name "*~"`
if [ "xx$BACKUPS" != "xx" ]
then
rm -v $BACKUPS
fi
#
mkdir -p $BASE_DIR/build/chrome
cd $BASE_DIR/build/chrome
7z a -tzip "$PACKAGE.jar" $BASE_DIR/chrome/* -r -mx=0
#
cd $BASE_DIR
cp install.* $BASE_DIR/build
#
cd $BASE_DIR/build
7z a -tzip "$BASE_DIR/$PACKAGE.xpi" * -r -mx=9
#
cd $BASE_DIR
rm -rvf $BASE_DIR/build
在 Windows 构建 Firefox Extension 的话,用批处理脚本比较合适。因为安装了 7z 和一些 Unix 命令工具,其实与Linux版本差别并不大。
@echo off
REM
Setlocal ENABLEDELAYEDEXPANSION
7z --help 2>NUL 1>NUL
if ERRORLEVEL 1 (
echo 7z is not found.
echo Please install 7z first.
goto END
)
set BaseDir=%~dp0
echo Current Directory : %BaseDir%
for %%i in (.) do set basename=%%~ni%%~xi
echo Extension Name : %basename%
if exist %basename%.xpi rm -vf %basename%.xpi
mkdir %BaseDir%build\chrome
cd %BaseDir%build\chrome
7z a -tzip "%basename%.jar" %BaseDir%chrome\* -r -mx=0
REM
cd %BaseDir%
cp -vf install.rdf chrome.manifest %BaseDir%build
if exist defaults cp -rvf defaults %BaseDir%build
if exist locale cp -rvf locale %BaseDir%build
if exist skin cp -rvf skin %BaseDir%build
REM
cd %BaseDir%build
7z a -tzip "%BaseDir%%basename%.xpi" * -r -mx=9
REM
cd %BaseDir%
rm -rvf %BaseDir%build
:END