From 755ab1e3db3d70b67e48bafc25e1fd8629c91ed5 Mon Sep 17 00:00:00 2001 From: EnixCoda Date: Sat, 27 Apr 2024 22:40:55 +0800 Subject: [PATCH] release manifest v2 for firefox --- Makefile | 20 +++++++++++++++++++- scripts/patch-manifest-for-firefox.js | 15 +++++++++++++++ 2 files changed, 34 insertions(+), 1 deletion(-) create mode 100644 scripts/patch-manifest-for-firefox.js diff --git a/Makefile b/Makefile index 135f167..602c9f9 100755 --- a/Makefile +++ b/Makefile @@ -31,7 +31,13 @@ upload-for-analytics: yarn sentry-cli releases finalize "$(FULL_VERSION)" compress: - cd dist && zip -r Gitako-$(FULL_VERSION).zip * -x *.map -x *.DS_Store + cd dist && zip -r Gitako-$(FULL_VERSION).zip * -x *.map -x *.DS_Store -x*.zip + +patch-firefox-manifest: + node scripts/patch-manifest-for-firefox.js + +compress-firefox: + cd dist && zip -r Gitako-$(FULL_VERSION)-firefox.zip * -x *.map -x *.DS_Store -x*.zip compress-source: git archive -o dist/Gitako-$(FULL_VERSION)-source.zip HEAD @@ -48,5 +54,17 @@ release: $(MAKE) test $(MAKE) upload-for-analytics $(MAKE) compress + $(MAKE) patch-firefox-manifest + $(MAKE) compress-firefox + $(MAKE) compress-source + $(MAKE) copy-build-safari + +release-dry-run: + $(MAKE) clean + $(MAKE) build + $(MAKE) test + $(MAKE) compress + $(MAKE) patch-firefox-manifest + $(MAKE) compress-firefox $(MAKE) compress-source $(MAKE) copy-build-safari diff --git a/scripts/patch-manifest-for-firefox.js b/scripts/patch-manifest-for-firefox.js new file mode 100644 index 0000000..eaee144 --- /dev/null +++ b/scripts/patch-manifest-for-firefox.js @@ -0,0 +1,15 @@ +const path = require('path') +const fs = require('fs') + +const manifestPath = path.join(__dirname, '..', 'dist', 'manifest.json') +const manifest = require(manifestPath) +manifest.manifest_version = 2 +const serviceWorker = manifest.background?.['service_worker'] +if (serviceWorker) { + console.log('Patching background') + manifest.background.scripts = [serviceWorker] + Reflect.deleteProperty(manifest.background, 'service_worker') + fs.writeFileSync(manifestPath, JSON.stringify(manifest, null, 2)) +} else { + console.log('Service worker field not found, skipped patching') +}