Chrome.exe本身就可以用来打包crx文件,但是用起来不是很方便,比如我将代码托管在Github上,在源代码目录下面会有许多目录不需要打包到crx文件中,例如.git目录,这个功能目前来说chrome.exe无法做到。幸运地是,网上有很多人写了各种版本的打包工具,有人还在一个网站上专门收集了这些打包脚本,传送门。
从中我选择了crxmake.sh作为打包的基础脚本,然后再此基本上做了些定制改进,除了最基本的打包功能外,它能够做到:
- 使用grep命令的扩展正则表达式ERE语法来排除文件;
- 查找manifest.json文件中的update和version信息,自动生成更新后的updates.xml
下载地址:dangoakachan/buildcrx · GitHub
使用
使用方法:
$ sh buildcrx.sh Usage: buildcrx.sh [OPTIONS] Options: -d specify the extension directory, required -p specify the pem file, optional -o specify the output directory, optional -n specify the build extension name, optional -e specify the exclude pattern like grep, optional -h show this help message
其中:
- -d:指定扩展的源代码目录,必选;
- -p:指定pem文件的路径,可选;
- -o:指定crx文件的输出目录,可选,默认为./output;
- -n:指定crx文件的名称,默认为扩展目录名;
- -e:指定排除文件的正则表达式,参考grep -E;
使用例子:
$ sh buildcrx.sh -d copybetter -p copybetter.pem -o copybetter/update -e 'update|\.git'