Skip to content

Commit

Permalink
feat: build for firefox
Browse files Browse the repository at this point in the history
fix: clean dist

feat: revert lark notify
  • Loading branch information
hz002 committed Nov 11, 2024
1 parent 4432515 commit 0625c49
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 16 deletions.
1 change: 1 addition & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
build/*
dist/*
dist-mv2/*
*.config.js
_raw/*
webpack.config.js
Expand Down
17 changes: 17 additions & 0 deletions build/clean.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
const { exec } = require('child_process');

const MANIFEST_TYPE = process.env.MANIFEST_TYPE || 'chrome-mv3';

exec(
MANIFEST_TYPE.endsWith('-mv2')
?
'mkdir -p dist-mv2 && rm -rf dist-mv2/*'
:
'mkdir -p dist && rm -rf dist/*',
(error) => {
if (error) {
console.error(`exec error: ${error}`);
return;
}
}
);
16 changes: 9 additions & 7 deletions build/release.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,15 @@ 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');
shell.exec(`git commit -m "[release] ${version}"`);
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() {
Expand Down Expand Up @@ -56,21 +56,23 @@ 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}`);
} else {
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`
);
});
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"version": "0.92.97",
"description": "A browser plugin for DeFi users",
"scripts": {
"clean": "mkdir -p dist && rm -rf dist/*",
"clean": "node build/clean.js",
"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",
Expand Down
23 changes: 19 additions & 4 deletions scripts/autobuild.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand All @@ -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"
Expand All @@ -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
Expand Down
9 changes: 5 additions & 4 deletions scripts/fns.js
Original file line number Diff line number Diff line change
Expand Up @@ -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+' });
Expand Down Expand Up @@ -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);

Expand All @@ -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}`
Expand All @@ -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)`);
Expand Down

0 comments on commit 0625c49

Please sign in to comment.