11#! /bin/bash
2- # PixTab 一键打包脚本 (macOS/Linux)
2+ # PixTab Build Script (macOS/Linux)
3+ # Generates Chrome/Edge and Firefox extension packages
34set -e
45
5- cd " $( dirname " $0 " ) /.."
6+ SCRIPT_DIR=" $( dirname " $0 " ) "
7+ cd " $SCRIPT_DIR /.."
68
7- echo " 🔨 开始打包 PixTab..."
9+ echo " 🔨 [BUILD] Starting PixTab packaging ..."
810
9- # 读取版本号
11+ # Read version from manifest.json
1012VERSION=$( node -e " console.log(require('./manifest.json').version)" )
11- echo " 📋 版本号 : $VERSION "
13+ echo " 📋 [INFO] Version : $VERSION "
1214
1315rm -rf dist
1416mkdir -p dist
1517
16- # 打包 Chrome/Edge 版本
17- echo " 📦 打包 Chrome/Edge 版本 ..."
18+ # Chrome/Edge packaging
19+ echo " 📦 [PACK] Building Chrome/Edge version ..."
1820zip -r " dist/pixtab-${VERSION} -chrome.zip" manifest.json LICENSE index.html options.html style.css _locales icons src -x " *.git*" -x " *.DS_Store"
1921
20- # 打包 Firefox 版本(临时修改 manifest)
21- echo " 📦 打包 Firefox 版本 ..."
22+ # Firefox packaging (temporarily modify manifest)
23+ echo " 📦 [PACK] Building Firefox version ..."
2224cp manifest.json manifest.backup.json
2325
24- # 用 Node.js 处理 manifest 字段,兼容 Firefox
25- # Firefox 不支持 service_worker,需要转换为 scripts 数组格式
26- node -e "
27- const fs = require('fs');
28- const manifestPath = 'manifest.json';
29- const manifest = JSON.parse(fs.readFileSync(manifestPath, 'utf8'));
30- // Firefox 需要 scripts 数组而不是 service_worker
31- if (manifest.background && manifest.background.service_worker) {
32- const sw = manifest.background.service_worker;
33- const type = manifest.background.type;
34- manifest.background = { scripts: [sw] };
35- if (type) manifest.background.type = type;
36- }
37- if (manifest.action && manifest.action.default_icon && typeof manifest.action.default_icon === 'object') {
38- const sizes = ['48', '32', '16', '128'];
39- let selected = null;
40- for (const s of sizes) { if (manifest.action.default_icon[s]) { selected = manifest.action.default_icon[s]; break; } }
41- if (!selected) selected = 'icons/icon-48.png';
42- manifest.action.default_icon = selected;
43- }
44- if (!manifest.browser_specific_settings) manifest.browser_specific_settings = {};
45- if (!manifest.browser_specific_settings.gecko) manifest.browser_specific_settings.gecko = {};
46- manifest.browser_specific_settings.gecko.strict_min_version = '113.0';
47- if (!manifest.browser_specific_settings.gecko_android) manifest.browser_specific_settings.gecko_android = {};
48- manifest.browser_specific_settings.gecko_android.strict_min_version = '113.0';
49- manifest.browser_specific_settings.gecko.data_collection_permissions = manifest.browser_specific_settings.gecko.data_collection_permissions || { collects: false, required: ['none'], optional: [] };
50- fs.writeFileSync(manifestPath, JSON.stringify(manifest, null, 2));
51- "
26+ # Use external Node.js script for manifest conversion (more reliable)
27+ node " $SCRIPT_DIR /convert-manifest-firefox.js"
5228
5329zip -r " dist/pixtab-${VERSION} -firefox.xpi" manifest.json LICENSE index.html options.html style.css _locales icons src -x " *.git*" -x " *.DS_Store"
5430
31+ # Restore original manifest
5532mv manifest.backup.json manifest.json
5633
5734echo " "
58- echo " ✅ 打包完成 !"
59- echo " - dist/pixtab-${VERSION} -chrome.zip"
60- echo " - dist/pixtab-${VERSION} -firefox.xpi"
35+ echo " ✅ [DONE] Packaging complete !"
36+ echo " - dist/pixtab-${VERSION} -chrome.zip -> Chrome Web Store / Edge Add-ons "
37+ echo " - dist/pixtab-${VERSION} -firefox.xpi -> Firefox AMO "
0 commit comments