From 98999519d8078873eab8f63e4b39a91b10f14d2c Mon Sep 17 00:00:00 2001 From: hz002 Date: Wed, 6 Nov 2024 23:09:39 +0800 Subject: [PATCH] feat: build for firefox --- .eslintignore | 1 + .github/workflows/autobuild.yml | 2 +- build/release.js | 16 +++++++++------- package.json | 2 +- scripts/autobuild.sh | 23 +++++++++++++++++++---- scripts/fns.js | 9 +++++---- 6 files changed, 36 insertions(+), 17 deletions(-) diff --git a/.eslintignore b/.eslintignore index 81beb53ec64..b6ef038c083 100644 --- a/.eslintignore +++ b/.eslintignore @@ -1,5 +1,6 @@ build/* dist/* +dist-mv2/* *.config.js _raw/* webpack.config.js diff --git a/.github/workflows/autobuild.yml b/.github/workflows/autobuild.yml index af8b1269111..2ae46533ad0 100644 --- a/.github/workflows/autobuild.yml +++ b/.github/workflows/autobuild.yml @@ -73,7 +73,7 @@ jobs: # for branch tmp/202*, force notify_lark=true echo "GIT_REF is $GIT_REF" if [[ $GIT_REF == refs/heads/tmp/202* ]]; then - export notify_lark=true; + export notify_lark=false; fi sh ./scripts/autobuild.sh; env: diff --git a/build/release.js b/build/release.js index 7d584e31ce9..33b40e06477 100644 --- a/build/release.js +++ b/build/release.js @@ -18,7 +18,7 @@ function updateManifestVersion(version, p) { fs.writeJSONSync(manifestPath, manifest, { spaces: 2 }); } -async function release([version, isDebug, isRelease]) { +async function release([version, isDebug, isRelease, isMV3]) { if (isRelease) { shell.exec(`npm version ${version} --force`); shell.exec('git add -A'); @@ -26,7 +26,7 @@ async function release([version, isDebug, isRelease]) { shell.exec(`git push origin refs/tags/v${version}`); shell.exec('git push origin master'); } - return [version, isDebug, isRelease]; + return [version, isDebug, isRelease, isMV3]; } async function bundle() { @@ -56,8 +56,9 @@ async function bundle() { const buildStr = isDebug ? 'build:debug' : 'build:pro'; - updateManifestVersion(version, 'mv3'); - updateManifestVersion(version, 'mv2'); + updateManifestVersion(version, 'chrome-mv3'); + updateManifestVersion(version, 'chrome-mv2'); + updateManifestVersion(version, 'firefox-mv2'); // shell.env['sourcemap'] = true; if (isMV3) { shell.exec(`cross-env VERSION=${version} yarn ${buildStr}`); @@ -65,12 +66,13 @@ async function bundle() { shell.exec(`cross-env VERSION=${version} yarn ${buildStr}:mv2`); } shell.rm('-rf', './dist/*.js.map'); - return [version, isDebug, isRelease]; + shell.rm('-rf', './dist-mv2/*.js.map'); + return [version, isDebug, isRelease, isMV3]; } -async function packed([version, isDebug]) { +async function packed([version, isDebug,, isMV3]) { import('./zip.mjs').then((re) => { re.createZipTask( - 'dist/**', + isMV3 ? 'dist/**' : 'dist-mv2/**', `Rabby_v${version}${isDebug ? '_debug' : ''}.zip` ); }); diff --git a/package.json b/package.json index 2944d6397b9..84d2550ac00 100644 --- a/package.json +++ b/package.json @@ -3,7 +3,7 @@ "version": "0.92.95", "description": "A browser plugin for DeFi users", "scripts": { - "clean": "mkdir -p dist && rm -rf dist/*", + "clean": "mkdir -p dist && rm -rf dist/* && mkdir -p dist-mv2 && rm -rf dist-mv2/*", "make-theme": "node ./scripts/make-theme.js", "build:dev:default": "npm run clean && npm run make-theme && cross-env TAILWIND_MODE=watch webpack --progress --env config=dev", "build:pro:default": "npm run clean && npm run make-theme && webpack --progress --env config=pro", diff --git a/scripts/autobuild.sh b/scripts/autobuild.sh index 73f9106ebd5..6160fc4fbc1 100755 --- a/scripts/autobuild.sh +++ b/scripts/autobuild.sh @@ -17,6 +17,7 @@ RABBY_GIT_HASH=$(git rev-parse --short HEAD); CURRENT_TIME=$(date +%Y%m%d%H%M%S); TARGET_FILE=$project_dir/tmp/RabbyDebug-v${VERSION}-${RABBY_GIT_HASH}.zip; +TARGET_FILE_MV2=$project_dir/tmp/RabbyDebugMV2-v${VERSION}-${RABBY_GIT_HASH}.zip; echo "[pack] VERSION is $VERSION"; @@ -25,22 +26,34 @@ if [ -z $NO_BUILD ]; then yarn; yarn build:${build_type}; fi -echo "[pack] built finished"; +echo "[pack] built mv3 finished"; + +if [ -z $NO_BUILD ]; then + yarn build:${build_type}:mv2; +fi +echo "[pack] built mv2 finished"; + cd $project_dir; rm -rf $project_dir/tmp/*.zip && mkdir -p $project_dir/tmp/; git_utc0_time_linux=$(TZ=UTC0 git show --quiet --date='format-local:%Y-%m-%dT%H:%M:%S+00:00' --format="%cd") -node $script_dir/fns.js $project_dir/dist $TARGET_FILE $git_utc0_time_linux; +node $script_dir/fns.js $project_dir/dist $TARGET_FILE $git_utc0_time_linux true; +node $script_dir/fns.js $project_dir/dist-mv2 $TARGET_FILE_MV2 $git_utc0_time_linux false; cd $project_dir; get_md5 $TARGET_FILE; target_md5_value=$last_md5_value; -echo "[pack] (md5: $TARGET_FILE) $target_md5_value"; +echo "[pack] mv3 (md5: $TARGET_FILE) $target_md5_value"; + +get_md5 $TARGET_FILE_MV2; +target_md5_value_mv2=$last_md5_value; +echo "[pack] mv2 (md5: $TARGET_FILE_MV2) $target_md5_value_mv2"; # upload to storage if [ -z $NO_UPLOAD ]; then DOWNLOAD_URL="https://download.rabby.io/autobuild/RabbyDebug-$CURRENT_TIME/RabbyDebug-v${VERSION}-${RABBY_GIT_HASH}.zip" + DOWNLOAD_URL_MV2="https://download.rabby.io/autobuild/RabbyDebug-$CURRENT_TIME/RabbyDebugMV2-v${VERSION}-${RABBY_GIT_HASH}.zip" if [ ! -z $CI ]; then QUIET_PARASM="--quiet" @@ -50,12 +63,14 @@ if [ -z $NO_UPLOAD ]; then echo "[pack] start upload..."; aws s3 cp $QUIET_PARASM $project_dir/tmp/ s3://$RABBY_BUILD_BUCKET/rabby/autobuild/RabbyDebug-$CURRENT_TIME --recursive --exclude="*" --include "*.zip" --acl public-read - echo "[pack] uploaded. DOWNLOAD_URL is $DOWNLOAD_URL"; + echo "[pack] uploaded. mv3 DOWNLOAD_URL is $DOWNLOAD_URL"; + echo "[pack] uploaded. mv2 DOWNLOAD_URL is $DOWNLOAD_URL_MV2"; if [ ! -z $notify_lark ]; then echo "[pack] update latest link..."; node ./scripts/notify-lark.js "$DOWNLOAD_URL" "$target_md5_value" + node ./scripts/notify-lark.js "$DOWNLOAD_URL_MV2" "$target_md5_value_mv2" else echo "[pack] skip notify."; fi diff --git a/scripts/fns.js b/scripts/fns.js index 8ae3969a341..3ac6ef5cd53 100644 --- a/scripts/fns.js +++ b/scripts/fns.js @@ -13,7 +13,8 @@ const chalk = require('chalk'); async function createConsistentZip( srcDir, destZip, - gitUTC0Time = new Date(1980, 0, 1) + gitUTC0Time = new Date(1980, 0, 1), + isMV3 = true ) { fs.mkdirSync(path.dirname(destZip), { recursive: true }); const output = fs.createWriteStream(destZip, { flags: 'w+' }); @@ -59,7 +60,7 @@ async function createConsistentZip( for (const item of allItems) { const itemPath = path.join(srcDir, item); - const itemZipPath = path.join('dist/', item); + const itemZipPath = path.join(isMV3 ? 'dist/' : 'dist-mv2/', item); const stat = fs.statSync(itemPath); @@ -86,7 +87,7 @@ async function createConsistentZip( return pReturn; } -const [, , srcDir, destZip, gitUTC0Time] = process.argv; +const [, , srcDir, destZip, gitUTC0Time, isMV3] = process.argv; console.log( `[fns] will pack ${srcDir} to ${destZip} with gitUTC0Time ${gitUTC0Time}` @@ -111,7 +112,7 @@ async function get_md5_file(filepath) { }); } -createConsistentZip(srcDir, destZip, gitUTC0Time) +createConsistentZip(srcDir, destZip, gitUTC0Time, isMV3) .then(async (result) => { const md5Value = await get_md5_file(destZip); console.log(`[fns] ZIP file created at ${destZip} (md5: ${chalk.yellow(md5Value)}, size: ${chalk.yellow(result.totalBytes)} bytes)`);