Skip to content

Commit

Permalink
add patch-manifest ugly for Firefox
Browse files Browse the repository at this point in the history
  • Loading branch information
m1m1s1ku committed May 17, 2023
1 parent 3d77f6e commit 6aaecdd
Show file tree
Hide file tree
Showing 4 changed files with 120 additions and 3 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ lerna-debug.log*
node_modules
dist
dist-ssr
dist-firefox
*.local

# Editor directories and files
Expand Down
5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,13 @@
"type": "module",
"scripts": {
"build": "tsc && vite build",
"bundle": "npx web-ext build --source-dir ./dist/"
"bundle-chrome": "npx web-ext build --source-dir ./dist/",
"prepare-firefox": "ts-node --esm ./scripts/firefox-manifest.ts",
"bundle-firefox": "npx web-ext build --source-dir ./dist-firefox/"
},
"devDependencies": {
"@crxjs/vite-plugin": "2.0.0-beta.17",
"ts-node": "^10.9.1",
"typescript": "^5.0.4",
"vite": "^4.3.7"
},
Expand Down
95 changes: 93 additions & 2 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 22 additions & 0 deletions scripts/firefox-manifest.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { readFile, cp, writeFile } from 'fs/promises';
import { join } from 'path';

async function patchManifest(source: string) {
const buffer = await readFile(source);
const manifestV3 = JSON.parse(buffer.toString('utf-8'));
const manifestV2 = JSON.parse((await readFile(join(process.cwd(), 'manifest-v2.json'))).toString('utf-8'));

const distFirefox = join(process.cwd(), 'dist-firefox');
const distChrome = join(process.cwd(), 'dist');

await cp(distChrome, distFirefox, { recursive: true });

await writeFile(join(distFirefox, 'manifest.json'), JSON.stringify({
...manifestV2,
content_scripts: manifestV3.content_scripts
}));
}

patchManifest(join(process.cwd(), 'dist/manifest.json')).catch((err) => {
console.error(err);
});

0 comments on commit 6aaecdd

Please sign in to comment.