Compare commits
No commits in common. "a92cf120353ecdeb171336ca89dacad9485ce622" and "153988c35a9815afa6a5f467d900d5dac40285a0" have entirely different histories.
a92cf12035
...
153988c35a
|
@ -2,13 +2,13 @@ name: 构建扩展程序
|
||||||
|
|
||||||
on:
|
on:
|
||||||
push:
|
push:
|
||||||
branches: [ main, dev ]
|
branches: [ main ]
|
||||||
pull_request:
|
pull_request:
|
||||||
branches: [ main, dev ]
|
branches: [ main ]
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
build-for-chrome:
|
build:
|
||||||
name: 构建 Chrome 扩展程序
|
name: 构建扩展程序
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
|
@ -24,64 +24,31 @@ jobs:
|
||||||
run: npm install
|
run: npm install
|
||||||
|
|
||||||
- name: 构建扩展程序
|
- name: 构建扩展程序
|
||||||
run: npm run build:chrome
|
run: npm run build
|
||||||
|
|
||||||
- name: 将构建结果压缩成 ZIP
|
- name: 将构建结果压缩成 ZIP
|
||||||
run: |-
|
run: |-
|
||||||
cd dist
|
cd dist
|
||||||
zip -r ../msrmod-chrome-${{ gitea.sha | slice(0, 8) }}.zip ./*
|
zip -r ../extension-${{ gitea.sha }}.zip ./*
|
||||||
cd ..
|
cd ..
|
||||||
|
|
||||||
- name: 上传构建工件
|
- name: 上传构建工件
|
||||||
uses: actions/upload-artifact@v3
|
uses: actions/upload-artifact@v3
|
||||||
with:
|
with:
|
||||||
name: chrome-extension
|
name: extension-${{ gitea.sha }}
|
||||||
path: msrmod-chrome-${{ gitea.sha | slice(0, 8) }}.zip
|
path: extension-${{ gitea.sha }}.zip
|
||||||
|
|
||||||
build-for-firefox:
|
|
||||||
name: 构建 Firefox 扩展程序
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
|
|
||||||
steps:
|
|
||||||
- uses: actions/checkout@v3
|
|
||||||
name: 检出代码
|
|
||||||
|
|
||||||
- name: 设置 Node.js
|
|
||||||
uses: actions/setup-node@v3
|
|
||||||
with:
|
|
||||||
node-version: '22'
|
|
||||||
|
|
||||||
- name: 安装依赖
|
|
||||||
run: npm install
|
|
||||||
|
|
||||||
- name: 构建扩展程序
|
|
||||||
run: npm run build:firefox
|
|
||||||
|
|
||||||
- name: 将构建结果压缩成 ZIP
|
|
||||||
run: |-
|
|
||||||
cd dist
|
|
||||||
zip -r ../msrmod-firefox-${{ gitea.sha | slice(0, 8) }}.zip ./*
|
|
||||||
cd ..
|
|
||||||
|
|
||||||
- name: 上传构建工件
|
|
||||||
uses: actions/upload-artifact@v3
|
|
||||||
with:
|
|
||||||
name: firefox-addon
|
|
||||||
path: msrmod-firefox-${{ gitea.sha | slice(0, 8) }}.zip
|
|
||||||
|
|
||||||
publish:
|
publish:
|
||||||
name: 发布至 Chrome 应用商店
|
name: 发布至 Chrome 应用商店
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
needs: build-for-chrome
|
needs: build
|
||||||
# 仅在 main 分支上执行发布
|
if: github.ref == 'refs/heads/main'
|
||||||
if: gitea.ref == 'refs/heads/main'
|
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- name: 下载构建工件
|
- name: 下载构建工件
|
||||||
uses: actions/download-artifact@v3
|
uses: actions/download-artifact@v3
|
||||||
with:
|
with:
|
||||||
name: chrome-extension
|
name: extension-${{ gitea.sha }}
|
||||||
path: ./
|
|
||||||
|
|
||||||
- name: 设置 Node.js
|
- name: 设置 Node.js
|
||||||
uses: actions/setup-node@v3
|
uses: actions/setup-node@v3
|
||||||
|
@ -95,7 +62,7 @@ jobs:
|
||||||
- name: 上传扩展程序到 Chrome Web Store
|
- name: 上传扩展程序到 Chrome Web Store
|
||||||
run: |-
|
run: |-
|
||||||
chrome-webstore-upload upload \
|
chrome-webstore-upload upload \
|
||||||
--source msrmod-chrome-${{ gitea.sha | slice(0, 8) }}.zip \
|
--source extension-${{ gitea.sha }}.zip \
|
||||||
--extension-id kphoaomopljjiofeaigjmbagmbdaamhh \
|
--extension-id kphoaomopljjiofeaigjmbagmbdaamhh \
|
||||||
--client-id ${{ secrets.CI_GOOGLE_CLIENT_ID }} \
|
--client-id ${{ secrets.CI_GOOGLE_CLIENT_ID }} \
|
||||||
--client-secret ${{ secrets.CI_GOOGLE_CLIENT_SECRET }} \
|
--client-secret ${{ secrets.CI_GOOGLE_CLIENT_SECRET }} \
|
||||||
|
|
|
@ -5,17 +5,14 @@
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"dev": "vite",
|
"dev": "vite",
|
||||||
"build": "echo 'No platform specified, will build for Chromium.' && npm run build-chrome",
|
"build": "npm run prebuild && vue-tsc -b && vite build && cp -r public/* dist/",
|
||||||
"build:chrome": "npm run prebuild:chrome && vue-tsc -b && vite build && cp -r public/* dist/",
|
|
||||||
"build:firefox": "npm run prebuild:firefox && vue-tsc -b && vite build && cp -r public/* dist/",
|
|
||||||
"dev:refresh": "vue-tsc -b && vite build && cp -r public/* dist/",
|
"dev:refresh": "vue-tsc -b && vite build && cp -r public/* dist/",
|
||||||
"build:watch": "vite build --watch",
|
"build:watch": "vite build --watch",
|
||||||
"preview": "vite preview",
|
"preview": "vite preview",
|
||||||
"lint": "biome format --write .",
|
"lint": "biome format --write .",
|
||||||
"quality-check": "biome ci",
|
"quality-check": "biome ci",
|
||||||
"qc": "npm run quality-check",
|
"qc": "npm run quality-check",
|
||||||
"prebuild:chrome": "node scripts/prebuild-chrome.js",
|
"prebuild": "node scripts/prebuild.js"
|
||||||
"prebuild:firefox": "node scripts/prebuild-firefox.js"
|
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@tailwindcss/vite": "^4.1.7",
|
"@tailwindcss/vite": "^4.1.7",
|
||||||
|
|
|
@ -1,80 +0,0 @@
|
||||||
import fs from 'fs';
|
|
||||||
import path from 'path';
|
|
||||||
import { fileURLToPath } from 'url';
|
|
||||||
|
|
||||||
const __filename = fileURLToPath(import.meta.url);
|
|
||||||
const __dirname = path.dirname(__filename);
|
|
||||||
|
|
||||||
// 处理 manifest.json
|
|
||||||
function processManifest() {
|
|
||||||
const manifestPath = path.join(__dirname, '../public/manifest.json');
|
|
||||||
const manifest = JSON.parse(fs.readFileSync(manifestPath, 'utf8'));
|
|
||||||
|
|
||||||
// 移除本地调试相关的配置
|
|
||||||
if (manifest.host_permissions) {
|
|
||||||
manifest.host_permissions = manifest.host_permissions.filter(
|
|
||||||
permission => !permission.includes('localhost')
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (manifest.content_security_policy && manifest.content_security_policy.extension_pages) {
|
|
||||||
// 移除 CSP 中的本地开发相关配置
|
|
||||||
manifest.content_security_policy.extension_pages = manifest.content_security_policy.extension_pages
|
|
||||||
.replace(/script-src 'self' http:\/\/localhost:5173;\s*/g, '')
|
|
||||||
.replace(/\s*http:\/\/localhost:5173\s*/g, ' ')
|
|
||||||
.replace(/\s*ws:\/\/localhost:5173\s*/g, ' ')
|
|
||||||
.replace(/;\s+/g, '; ') // 标准化分号后的空格
|
|
||||||
.replace(/\s+/g, ' ') // 合并多个空格为一个
|
|
||||||
.trim();
|
|
||||||
}
|
|
||||||
|
|
||||||
// 移除 CSP 中的 sandbox 配置(Firefox 不支持)
|
|
||||||
if (manifest.content_security_policy && manifest.content_security_policy.sandbox) {
|
|
||||||
delete manifest.content_security_policy.sandbox;
|
|
||||||
}
|
|
||||||
|
|
||||||
// 移除 background.service_worker,替换为 background.scripts
|
|
||||||
if (manifest.background && manifest.background.service_worker) {
|
|
||||||
manifest.background.scripts = [manifest.background.service_worker];
|
|
||||||
delete manifest.background.service_worker;
|
|
||||||
}
|
|
||||||
|
|
||||||
// 添加 firefox 特有配置
|
|
||||||
manifest.browser_specific_settings = {
|
|
||||||
gecko: {
|
|
||||||
id: 'msr-mod@firefox-addon.astrian.moe',
|
|
||||||
strict_min_version: '115.0',
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
fs.writeFileSync(manifestPath, JSON.stringify(manifest, null, 2));
|
|
||||||
console.log('✅ Manifest.json processed');
|
|
||||||
}
|
|
||||||
|
|
||||||
// 处理 index.html
|
|
||||||
function processIndexHtml() {
|
|
||||||
const indexPath = path.join(__dirname, '../index.html');
|
|
||||||
let content = fs.readFileSync(indexPath, 'utf8');
|
|
||||||
|
|
||||||
// 替换脚本地址
|
|
||||||
content = content.replace(
|
|
||||||
/src="[^"]*\/src\/main\.ts"/g,
|
|
||||||
'src="./src/main.ts"'
|
|
||||||
);
|
|
||||||
|
|
||||||
// 移除 crossorigin 属性
|
|
||||||
content = content.replace(/\s+crossorigin/g, '');
|
|
||||||
|
|
||||||
fs.writeFileSync(indexPath, content);
|
|
||||||
console.log('✅ Index.html processed');
|
|
||||||
}
|
|
||||||
|
|
||||||
// 执行处理
|
|
||||||
try {
|
|
||||||
processManifest();
|
|
||||||
processIndexHtml();
|
|
||||||
console.log('🎉 Build preparation completed!');
|
|
||||||
} catch (error) {
|
|
||||||
console.error('❌ Error during build preparation:', error);
|
|
||||||
process.exit(1);
|
|
||||||
}
|
|
Loading…
Reference in New Issue
Block a user