diff --git a/bin/prepare.sh b/bin/increment.sh similarity index 71% rename from bin/prepare.sh rename to bin/increment.sh index 5cc1784..5a72ae2 100755 --- a/bin/prepare.sh +++ b/bin/increment.sh @@ -8,9 +8,10 @@ function update_json() { } path='package.json' - update_json -path='src/manifest.json' +path='src/manifest-chrome.json' +update_json +path='src/manifest-firefox.json' update_json diff --git a/package.json b/package.json index 2decd1b..4dcbb09 100644 --- a/package.json +++ b/package.json @@ -9,25 +9,30 @@ "email": "hi@bamdad.fr" }, "scripts": { - "build": "pnpm clean && pnpm build:webpack && pnpm build:ext", + "build": "pnpm dev:clean && pnpm build:clean && pnpm build:chrome && pnpm build:firefox", "build:clean": "rimraf packages", - "build:ext": "web-ext build --source-dir dist", - "build:prepare": "./bin/prepare.sh", - "build:webpack": "NODE_ENV=production webpack", - "clean": "pnpm dev:clean && pnpm build:clean", - "dev": "pnpm dev:chrome", - "dev:chrome": "pnpm dev:clean && concurrently 'pnpm dev:webpack' 'wait-on dist/manifest.json && pnpm dev:ext:chrome'", + "build:increment": "build/increment.sh", + "build:chrome": "pnpm build:chrome:webpack && pnpm build:chrome:package", + "build:chrome:package": "web-ext build --source-dir dist/chrome --filename chrome.zip", + "build:chrome:webpack": "NODE_ENV=production pnpm webpack:chrome", + "build:firefox": "pnpm build:firefox:webpack && pnpm build:firefox:package", + "build:firefox:package": "web-ext build --source-dir dist/firefox --filename firefox.zip", + "build:firefox:webpack": "NODE_ENV=production pnpm webpack:firefox", "dev:clean": "rimraf dist", - "dev:ext:chrome": "web-ext run -t chromium", - "dev:ext:firefox": "web-ext run", - "dev:firefox": "pnpm dev:clean && concurrently 'pnpm dev:webpack' 'wait-on dist/manifest.json && pnpm dev:ext:firefox'", - "dev:webpack": "webpack", + "dev:chrome": "pnpm dev:clean && pnpm dev:chrome:watch", + "dev:chrome:run": "web-ext run --source-dir dist/chrome -t chromium", + "dev:chrome:watch": "concurrently 'pnpm webpack:chrome' 'wait-on dist/chrome/manifest.json && pnpm dev:chrome:run'", + "dev:firefox": "pnpm dev:clean && pnpm dev:firefox:watch", + "dev:firefox:run": "web-ext run --source-dir dist/firefox", + "dev:firefox:watch": "concurrently 'pnpm webpack:firefox' 'wait-on dist/firefox/manifest.json && pnpm dev:firefox:run'", "lint": "eslint src --ext .js --fix", "package:reinstall": "rimraf node_modules && pnpm", "package:sort": "npx sort-package-json", "test": "jest", "test:coverage": "jest --coverage", - "test:watch": "jest --watchAll" + "test:watch": "jest --watchAll", + "webpack:chrome": "webpack --env chrome", + "webpack:firefox": "webpack --env firefox" }, "dependencies": { "speed-to-percentage": "^1.2.1", diff --git a/release.config.js b/release.config.js index 9bf4f92..74d6363 100644 --- a/release.config.js +++ b/release.config.js @@ -1,38 +1,55 @@ /* eslint-disable no-template-curly-in-string */ module.exports = { - 'plugins': [ + plugins: [ ['@semantic-release/commit-analyzer'], ['@semantic-release/release-notes-generator'], - ['@semantic-release/changelog', { - changelogFile: 'CHANGELOG.md', - }], - ['@semantic-release/exec', { - prepareCmd: 'yarn build:prepare ${nextRelease.version} && yarn build', - }], - ['semantic-release-firefox-add-on', { - extensionId: '{891ed2be-6ca9-47d1-9466-1595afa33b80}', - targetXpi: 'bandcamp-plus--extension-${nextRelease.version}.xpi', - artifactsDir: 'packages', - channel: 'listed', - }], - ['semantic-release-chrome', { - extensionId: 'hggjmjobahhmbmnfndhdgidchhhhjkad', - asset: 'bandcamp-plus--extension-${nextRelease.version}.zip', - }], - ['@semantic-release/github', { - assets: [ - 'packages/bandcamp-plus--extension-${nextRelease.version}.xpi', - 'bandcamp-plus--extension-${nextRelease.version}.zip', - ], - }], - ['@semantic-release/git', { - assets: [ - 'CHANGELOG.md', - 'package.json', - 'src/manifest.json', - ], - message: 'chore(release): ${nextRelease.version} [skip ci]\n\n${nextRelease.notes}', - }], + [ + '@semantic-release/changelog', + { + changelogFile: 'CHANGELOG.md', + }, + ], + [ + '@semantic-release/exec', + { + prepareCmd: 'pnpm build:increment ${nextRelease.version} && pnpm build', + }, + ], + [ + 'semantic-release-firefox-add-on', + { + extensionId: '{891ed2be-6ca9-47d1-9466-1595afa33b80}', + targetXpi: 'bandcamp-plus--extension-${nextRelease.version}.xpi', + sourceDir: 'dist/firefox', + artifactsDir: 'packages', + channel: 'listed', + }, + ], + [ + 'semantic-release-chrome', + { + extensionId: 'hggjmjobahhmbmnfndhdgidchhhhjkad', + asset: 'bandcamp-plus--extension-${nextRelease.version}.zip', + distFolder: 'dist/chrome', + }, + ], + [ + '@semantic-release/github', + { + assets: [ + 'packages/bandcamp-plus--extension-${nextRelease.version}.xpi', + 'bandcamp-plus--extension-${nextRelease.version}.zip', + ], + }, + ], + [ + '@semantic-release/git', + { + assets: ['CHANGELOG.md', 'package.json', 'src/manifest-*.json'], + message: + 'chore(release): ${nextRelease.version} [skip ci]\n\n${nextRelease.notes}', + }, + ], ], }; diff --git a/src/manifest-chrome.json b/src/manifest-chrome.json new file mode 100644 index 0000000..75e4ce9 --- /dev/null +++ b/src/manifest-chrome.json @@ -0,0 +1,36 @@ +{ + "name": "Bandcamp+", + "short_name": "bandcamp-plus", + "description": "Add multiple features to bandcamp.com", + "version": "3.2.4", + "manifest_version": 2, + "icons": { + "512": "assets/bandcamp-plus-icon.png" + }, + "action": { + "default_title": "Bandcamp+", + "default_icon": { + "512": "assets/bandcamp-plus-icon.png" + } + }, + "content_scripts": [ + { + "matches": [ + "*://*.bandcamp.com/*" + ], + "js": [ + "scripts/content.js" + ], + "css": [ + "assets/content.css" + ], + "run_at": "document_start", + "all_frames": false + } + ], + "background": { + "scripts": [ + "scripts/background.js" + ] + } +} diff --git a/src/manifest.json b/src/manifest-firefox.json similarity index 100% rename from src/manifest.json rename to src/manifest-firefox.json diff --git a/webpack.config.js b/webpack.config.js index 7988aa6..08db863 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -1,50 +1,61 @@ const CopyPlugin = require('copy-webpack-plugin'); const isProduction = process.env.NODE_ENV === 'production'; +const path = require('path'); // eslint-disable-next-line no-console console.log('Production mode is: ', isProduction); -module.exports = { - watch: !isProduction, - mode: isProduction ? 'production' : 'development', - devtool: isProduction ? false : 'inline-source-map', - entry: { - 'scripts/content': './src/app/content.ts', - 'scripts/background': './src/app/background.ts', - }, - resolve: { - extensions: ['.ts', '.js'], - }, - output: { - 'publicPath': '', - }, - node: false, - plugins: [ - new CopyPlugin({ - patterns: [ +module.exports = (env) => { + const getBrowserFlavour = () => { + if (env.chrome === true) { + return 'chrome'; + } else if (env.firefox === true) { + return 'firefox'; + } + }; + + return { + watch: !isProduction, + mode: isProduction ? 'production' : 'development', + devtool: isProduction ? false : 'inline-source-map', + entry: { + 'scripts/content': './src/app/content.ts', + 'scripts/background': './src/app/background.ts', + }, + resolve: { + extensions: ['.ts', '.js'], + }, + output: { + path: path.resolve(__dirname, `dist/${getBrowserFlavour()}`), + }, + node: false, + plugins: [ + new CopyPlugin({ + patterns: [ + { + from: `./src/manifest-${getBrowserFlavour()}.json`, + to: 'manifest.json', + }, + { + from: './src/assets', + to: 'assets', + }, + ], + }), + ], + module: { + rules: [ { - from: './src/manifest.json', - to: 'manifest.json', + test: /\.js$/, + use: 'babel-loader', + exclude: /node_modules/, }, { - from: './src/assets', - to: 'assets', + test: /\.tsx?$/, + use: 'ts-loader', + exclude: /node_modules/, }, ], - }), - ], - module: { - rules: [ - { - test: /\.js$/, - use: 'babel-loader', - exclude: /node_modules/, - }, - { - test: /\.tsx?$/, - use: 'ts-loader', - exclude: /node_modules/, - }, - ], - }, + }, + }; };