diff --git a/manifest/chrome.json b/manifest/chrome.json index 12815b26..50243437 100644 --- a/manifest/chrome.json +++ b/manifest/chrome.json @@ -18,6 +18,6 @@ "128": "icons/128x128.png" }, "background": { - "service_worker": "background-chrome.js" + "service_worker": "background.js" } } diff --git a/package.json b/package.json index 9689e7a6..27a021a2 100644 --- a/package.json +++ b/package.json @@ -37,6 +37,7 @@ "@commitlint/config-conventional": "^17.4.4", "@eartharoid/deep-merge": "^0.0.2", "@vitejs/plugin-react-swc": "^3.2.0", + "adm-zip": "^0.5.10", "eslint": "^8.36.0", "eslint-config-prettier": "^8.7.0", "eslint-config-react-app": "^7.0.1", @@ -56,8 +57,6 @@ "dev:host": "vite --host", "translations": "cd scripts && node updatetranslations.js", "build": "vite build", - "prepare:chrome": "cp manifest/chrome.json dist/manifest.json && cp -r manifest/_locales dist/_locales && cp manifest/background-chrome.js dist/background-chrome.js", - "prepare:firefox": "rm -rf dist/_locales && cp manifest/firefox.json dist/manifest.json", "pretty": "prettier --write \"./**/*.{js,jsx,json,scss,css}\"", "lint": "eslint --ext .js,.jsx src/** && stylelint \"**/*.scss\"", "lint:fix": "eslint --ext .js,.jsx src/** --fix && stylelint \"**/*.scss\" --fix", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 4fb6891b..7b2aa3a4 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -10,9 +10,10 @@ specifiers: '@floating-ui/react-dom': ^1.3.0 '@fontsource/lexend-deca': 4.5.14 '@fontsource/montserrat': 4.5.14 - '@mui/material': 5.11.12 + '@mui/material': 5.11.13 '@sentry/react': ^7.42.0 '@vitejs/plugin-react-swc': ^3.2.0 + adm-zip: ^0.5.10 embla-carousel-autoplay: ^7.1.0 embla-carousel-react: ^7.1.0 eslint: ^8.36.0 @@ -46,7 +47,7 @@ dependencies: '@floating-ui/react-dom': 1.3.0_biqbaboplfbrettd7655fr4n2y '@fontsource/lexend-deca': 4.5.14 '@fontsource/montserrat': 4.5.14 - '@mui/material': 5.11.12_fbxtuirhogpez7m7qjkm3itwca + '@mui/material': 5.11.13_fbxtuirhogpez7m7qjkm3itwca '@sentry/react': 7.43.0_react@18.2.0 embla-carousel-autoplay: 7.1.0 embla-carousel-react: 7.1.0_react@18.2.0 @@ -66,6 +67,7 @@ devDependencies: '@commitlint/config-conventional': 17.4.4 '@eartharoid/deep-merge': 0.0.2 '@vitejs/plugin-react-swc': 3.2.0_vite@4.1.4 + adm-zip: 0.5.10 eslint: 8.36.0 eslint-config-prettier: 8.7.0_eslint@8.36.0 eslint-config-react-app: 7.0.1_eslint@8.36.0 @@ -2157,8 +2159,8 @@ packages: '@jridgewell/sourcemap-codec': 1.4.14 dev: true - /@mui/base/5.0.0-alpha.119_biqbaboplfbrettd7655fr4n2y: - resolution: {integrity: sha512-XA5zhlYfXi67u613eIF0xRmktkatx6ERy3h+PwrMN5IcWFbgiL1guz8VpdXON+GWb8+G7B8t5oqTFIaCqaSAeA==} + /@mui/base/5.0.0-alpha.121_biqbaboplfbrettd7655fr4n2y: + resolution: {integrity: sha512-8nJRY76UqlJV+q/Yzo0tgGfPWEOa+4N9rjO81fMmcJqP0I6m54hLDXsjvMg4tvelY5eKHXUK6Tb7en+GHfTqZA==} engines: {node: '>=12.0.0'} peerDependencies: '@types/react': ^17.0.0 || ^18.0.0 @@ -2171,7 +2173,7 @@ packages: '@babel/runtime': 7.21.0 '@emotion/is-prop-valid': 1.2.0 '@mui/types': 7.2.3 - '@mui/utils': 5.11.12_react@18.2.0 + '@mui/utils': 5.11.13_react@18.2.0 '@popperjs/core': 2.11.6 clsx: 1.2.1 prop-types: 15.8.1 @@ -2180,12 +2182,12 @@ packages: react-is: 18.2.0 dev: false - /@mui/core-downloads-tracker/5.11.12: - resolution: {integrity: sha512-LHh8HZQ5nPVcW5QnyLwkAZ40txc/S2bzKMQ3bTO+5mjuwAJ2AzQrjZINLVy1geY7ei1pHXVqO1hcWHg/QdT44w==} + /@mui/core-downloads-tracker/5.11.13: + resolution: {integrity: sha512-lx+GXBR9h/ApZsEP728tl0pyZyuajto+VnBgsoAzw1d5+CbmOo8ZWieKwVUGxZlPT1wMYNUYS5NtKzCli0xYjw==} dev: false - /@mui/material/5.11.12_fbxtuirhogpez7m7qjkm3itwca: - resolution: {integrity: sha512-M6BiIeJjySeEzWeiFJQ9pIjJy6mx5mHPWeMT99wjQdAmA2GxCQhE9A0fh6jQP4jMmYzxhOIhjsGcp0vSdpseXg==} + /@mui/material/5.11.13_fbxtuirhogpez7m7qjkm3itwca: + resolution: {integrity: sha512-2CnSj43F+159LbGmTLLQs5xbGYMiYlpTByQhP7c7cMX6opbScctBFE1PuyElpAmwW8Ag9ysfZH1d1MFAmJQkjg==} engines: {node: '>=12.0.0'} peerDependencies: '@emotion/react': ^11.5.0 @@ -2204,11 +2206,11 @@ packages: '@babel/runtime': 7.21.0 '@emotion/react': 11.10.6_react@18.2.0 '@emotion/styled': 11.10.6_3og6jmu6wvzuytygvdoxepq3x4 - '@mui/base': 5.0.0-alpha.119_biqbaboplfbrettd7655fr4n2y - '@mui/core-downloads-tracker': 5.11.12 - '@mui/system': 5.11.12_xqp3pgpqjlfxxa3zxu4zoc4fba + '@mui/base': 5.0.0-alpha.121_biqbaboplfbrettd7655fr4n2y + '@mui/core-downloads-tracker': 5.11.13 + '@mui/system': 5.11.13_xqp3pgpqjlfxxa3zxu4zoc4fba '@mui/types': 7.2.3 - '@mui/utils': 5.11.12_react@18.2.0 + '@mui/utils': 5.11.13_react@18.2.0 '@types/react-transition-group': 4.4.5 clsx: 1.2.1 csstype: 3.1.1 @@ -2219,8 +2221,8 @@ packages: react-transition-group: 4.4.5_biqbaboplfbrettd7655fr4n2y dev: false - /@mui/private-theming/5.11.12_react@18.2.0: - resolution: {integrity: sha512-hnJ0svNI1TPeWZ18E6DvES8PB4NyMLwal6EyXf69rTrYqT6wZPLjB+HiCYfSOCqU/fwArhupSqIIkQpDs8CkAw==} + /@mui/private-theming/5.11.13_react@18.2.0: + resolution: {integrity: sha512-PJnYNKzW5LIx3R+Zsp6WZVPs6w5sEKJ7mgLNnUXuYB1zo5aX71FVLtV7geyPXRcaN2tsoRNK7h444ED0t7cIjA==} engines: {node: '>=12.0.0'} peerDependencies: '@types/react': ^17.0.0 || ^18.0.0 @@ -2230,7 +2232,7 @@ packages: optional: true dependencies: '@babel/runtime': 7.21.0 - '@mui/utils': 5.11.12_react@18.2.0 + '@mui/utils': 5.11.13_react@18.2.0 prop-types: 15.8.1 react: 18.2.0 dev: false @@ -2257,8 +2259,8 @@ packages: react: 18.2.0 dev: false - /@mui/system/5.11.12_xqp3pgpqjlfxxa3zxu4zoc4fba: - resolution: {integrity: sha512-sYjsXkiwKpZDC3aS6O/6KTjji0jGINLQcrD5EJ5NTkIDiLf19I4HJhnufgKqlTWNfoDBlRohuTf3TzfM06c4ug==} + /@mui/system/5.11.13_xqp3pgpqjlfxxa3zxu4zoc4fba: + resolution: {integrity: sha512-OWP0Alp6C8ufnGm9+CZcl3d+OoRXL2PnrRT5ohaMLxvGL9OfNcL2t4JOjMmA0k1UAGd6E/Ygbu5lEPrZSDlvCg==} engines: {node: '>=12.0.0'} peerDependencies: '@emotion/react': ^11.5.0 @@ -2276,10 +2278,10 @@ packages: '@babel/runtime': 7.21.0 '@emotion/react': 11.10.6_react@18.2.0 '@emotion/styled': 11.10.6_3og6jmu6wvzuytygvdoxepq3x4 - '@mui/private-theming': 5.11.12_react@18.2.0 + '@mui/private-theming': 5.11.13_react@18.2.0 '@mui/styled-engine': 5.11.11_xqp3pgpqjlfxxa3zxu4zoc4fba '@mui/types': 7.2.3 - '@mui/utils': 5.11.12_react@18.2.0 + '@mui/utils': 5.11.13_react@18.2.0 clsx: 1.2.1 csstype: 3.1.1 prop-types: 15.8.1 @@ -2295,8 +2297,8 @@ packages: optional: true dev: false - /@mui/utils/5.11.12_react@18.2.0: - resolution: {integrity: sha512-5vH9B/v8pzkpEPO2HvGM54ToXV6cFdAn8UrvdN8TMEEwpn/ycW0jLiyBcgUlPsQ+xha7hqXCPQYHaYFDIcwaiw==} + /@mui/utils/5.11.13_react@18.2.0: + resolution: {integrity: sha512-5ltA58MM9euOuUcnvwFJqpLdEugc9XFsRR8Gt4zZNb31XzMfSKJPR4eumulyhsOTK1rWf7K4D63NKFPfX0AxqA==} engines: {node: '>=12.0.0'} peerDependencies: react: ^17.0.0 || ^18.0.0 @@ -2767,6 +2769,11 @@ packages: hasBin: true dev: true + /adm-zip/0.5.10: + resolution: {integrity: sha512-x0HvcHqVJNTPk/Bw8JbLWlWoo6Wwnsug0fnYYro1HBrjxZ3G7/AZk7Ahv8JwDe1uIcz8eBqvu86FuF1POiG7vQ==} + engines: {node: '>=6.0'} + dev: true + /ajv/6.12.6: resolution: {integrity: sha512-j3fVLgvTo527anyYyJOGTYJbG+vnnQYvE0m5mmkc1TK+nxAppkCLMIL0aZ4dblVCNoGShhm+kzE4ZUykBoMg4g==} dependencies: diff --git a/vite.config.js b/vite.config.js index b7878e14..acd08036 100644 --- a/vite.config.js +++ b/vite.config.js @@ -1,11 +1,65 @@ import { defineConfig } from 'vite'; import react from '@vitejs/plugin-react-swc'; import path from 'path'; +import fs from 'fs'; +import ADMZip from 'adm-zip'; +import * as pkg from './package.json'; const isProd = process.env.NODE_ENV === 'production'; +const prepareBuilds = () => ({ + name: 'prepareBuilds', + buildEnd() { + if (isProd) { + // chrome + fs.mkdirSync(path.resolve(__dirname, './build/chrome'), { recursive: true }); + fs.copyFileSync( + path.resolve(__dirname, './manifest/chrome.json'), + path.resolve(__dirname, './build/chrome/manifest.json'), + ); + fs.copyFileSync( + path.resolve(__dirname, './manifest/background-chrome.js'), + path.resolve(__dirname, './build/chrome/background.js'), + ); + fs.cpSync( + path.resolve(__dirname, './manifest/_locales'), + path.resolve(__dirname, './build/chrome/_locales'), + { + recursive: true, + }, + ); + fs.cpSync(path.resolve(__dirname, './dist'), path.resolve(__dirname, './build/chrome/'), { + recursive: true, + }); + + // firefox + fs.mkdirSync(path.resolve(__dirname, './build/firefox'), { recursive: true }); + fs.copyFileSync( + path.resolve(__dirname, './manifest/firefox.json'), + path.resolve(__dirname, './build/firefox/manifest.json'), + ); + fs.copyFileSync( + path.resolve(__dirname, './manifest/background-firefox.js'), + path.resolve(__dirname, './build/firefox/background.js'), + ); + fs.cpSync(path.resolve(__dirname, './dist'), path.resolve(__dirname, './build/firefox/'), { + recursive: true, + }); + + // create zip + const zip = new ADMZip(); + zip.addLocalFolder(path.resolve(__dirname, './build/chrome')); + zip.writeZip(path.resolve(__dirname, `./build/chrome-${pkg.version}.zip`)); + + const zip2 = new ADMZip(); + zip2.addLocalFolder(path.resolve(__dirname, './build/firefox')); + zip2.writeZip(path.resolve(__dirname, `./build/firefox-${pkg.version}.zip`)); + } + }, +}); + export default defineConfig({ - plugins: [react()], + plugins: [react(), prepareBuilds()], server: { hmr: { protocol: 'ws',