From 76422d7343aa1d078d5c051ac49f59d82d298677 Mon Sep 17 00:00:00 2001 From: Manuel Bouza Date: Tue, 26 Mar 2019 16:09:58 +0100 Subject: [PATCH] Update configuration for local builds --- .env.example | 2 ++ .gitignore | 1 + package.json | 14 +++++++------ src/js/utils/notifier.js | 2 +- webpack.base.config.js | 42 ++++++++++++++++++++++++--------------- webpack.firefox.config.js | 5 ++++- yarn.lock | 5 +++++ 7 files changed, 47 insertions(+), 24 deletions(-) create mode 100644 .env.example diff --git a/.env.example b/.env.example new file mode 100644 index 00000000..5178bb6f --- /dev/null +++ b/.env.example @@ -0,0 +1,2 @@ +BUGSNAG_API_KEY= +APPLICATION_ID= diff --git a/.gitignore b/.gitignore index b38db2f2..17c578e0 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ node_modules/ build/ +.env diff --git a/package.json b/package.json index 17e9d4d5..f2524175 100644 --- a/package.json +++ b/package.json @@ -1,16 +1,16 @@ { "name": "moco-browser-extensions", "description": "Browser plugin for MOCO", - "version": "1.0.19", + "version": "1.0.20", "scripts": { "start": "yarn start:chrome", "start:chrome": "node_modules/.bin/webpack --config webpack.chrome.config.js --watch --env.browser chrome --env.NODE_ENV development", "start:firefox": "node_modules/.bin/webpack --config webpack.firefox.config.js --watch --env.browser firefox --env.NODE_ENV development", - "zip:chrome": "zip -r build/chrome/moco-bx-source.zip . -x .git/\\* build/\\* node_modules/\\* test/\\* .DS_Store", - "zip:firefox": "zip -r build/firefox/moco-bx-source.zip . -x .git/\\* build/\\* node_modules/\\* test/\\* .DS_Store", - "build:chrome": "node_modules/.bin/webpack -p --config webpack.chrome.config.js --env.browser chrome --env.NODE_ENV production && yarn zip:chrome", - "build:firefox": "node_modules/.bin/webpack -p --config webpack.firefox.config.js --env.browser firefox --env.NODE_ENV production && yarn zip:firefox", - "build": "yarn run build:firefox && yarn run build:chrome", + "zip:chrome": "zip -qr build/chrome/moco-bx-source.zip . -x .git/\\* build/\\* node_modules/\\* test/\\* .DS_Store", + "zip:firefox": "zip -qr build/firefox/moco-bx-source.zip . -x .git/\\* build/\\* node_modules/\\* test/\\* .DS_Store", + "build:chrome": "node_modules/.bin/webpack -p --config webpack.chrome.config.js --env.browser chrome --env.NODE_ENV production", + "build:firefox": "node_modules/.bin/webpack -p --config webpack.firefox.config.js --env.browser firefox --env.NODE_ENV production", + "build": "yarn build:firefox && yarn zip:firefox && yarn build:chrome && yarn zip:chrome", "test": "node_modules/.bin/jest", "test:watch": "node_modules/.bin/jest --watch" }, @@ -20,6 +20,7 @@ "axios": "^0.18.0", "classnames": "^2.2.6", "date-fns": "^1.30.1", + "dotenv": "^7.0.0", "lodash": "^4.17.11", "mobx": "^5.5.0", "mobx-react": "^5.2.8", @@ -56,6 +57,7 @@ "prettier": "^1.16.4", "sass-loader": "^7.1.0", "style-loader": "^0.23.1", + "uuid": "^3.3.2", "webpack": "^4.15.0", "webpack-bugsnag-plugins": "^1.3.0", "webpack-cli": "^3.0.8", diff --git a/src/js/utils/notifier.js b/src/js/utils/notifier.js index 88b21dc6..15a5d8c5 100644 --- a/src/js/utils/notifier.js +++ b/src/js/utils/notifier.js @@ -25,7 +25,7 @@ const filterReport = report => { } const bugsnagClient = bugsnag({ - apiKey: "da6caac4af70af3e4683454b40fe5ef5", + apiKey: process.env.BUGSNAG_API_KEY, appVersion: getAppVersion(), collectUserIp: false, beforeSend: filterReport, diff --git a/webpack.base.config.js b/webpack.base.config.js index 4f827443..9a6e1d92 100644 --- a/webpack.base.config.js +++ b/webpack.base.config.js @@ -1,3 +1,5 @@ +require("dotenv").config() + const path = require("path") const webpack = require("webpack") const CleanWebpackPlugin = require("clean-webpack-plugin") @@ -60,7 +62,10 @@ module.exports = env => { plugins: [ new CleanWebpackPlugin([`build/${env.browser}`]), new webpack.DefinePlugin({ - "process.env.NODE_ENV": JSON.stringify(env.NODE_ENV) + "process.env.NODE_ENV": JSON.stringify(env.NODE_ENV), + "process.env.BUGSNAG_API_KEY": JSON.stringify( + process.env.BUGSNAG_API_KEY + ) }), new MiniCssExtractPlugin({ filename: "[name].css", @@ -95,22 +100,27 @@ module.exports = env => { if (env.NODE_ENV === "production") { config.devtool = "source-maps" + if (process.env.BUGSNAG_API_KEY) { + config.plugins.push( + new BugsnagBuildReporterPlugin({ + apiKey: process.env.BUGSNAG_API_KEY, + appVersion: process.env.npm_package_version, + releaseStage: "production" + }), + // important: upload sourcemaps before removing source mapping url + new BugsnagSourceMapUploaderPlugin({ + apiKey: process.env.BUGSNAG_API_KEY, + appVersion: process.env.npm_package_version, + publicPath: + env.browser === "firefox" + ? "moz-extension*://*/" + : "chrome-extension*://*/", // extra asterisk after protocol needed + overwrite: true + }) + ) + } + config.plugins.push( - new BugsnagBuildReporterPlugin({ - apiKey: "da6caac4af70af3e4683454b40fe5ef5", - appVersion: process.env.npm_package_version, - releaseStage: "production" - }), - // important: upload sourcemaps before removing source mapping url - new BugsnagSourceMapUploaderPlugin({ - apiKey: "da6caac4af70af3e4683454b40fe5ef5", - appVersion: process.env.npm_package_version, - publicPath: - env.browser === "firefox" - ? "moz-extension*://*/" - : "chrome-extension*://*/", // extra asterisk after protocol needed - overwrite: true - }), new RemoveSourceMapPlugin(), new ZipPlugin({ filename: `moco-bx-${env.browser}-v${ diff --git a/webpack.firefox.config.js b/webpack.firefox.config.js index 8be86b71..ab486d3e 100644 --- a/webpack.firefox.config.js +++ b/webpack.firefox.config.js @@ -1,3 +1,4 @@ +const uuidv4 = require("uuid/v4") const CopyWebpackPlugin = require("copy-webpack-plugin") const { compact } = require("lodash/fp") @@ -30,7 +31,9 @@ module.exports = env => { browser_style: true }, browser_specific_settings: { - gecko: { id: "browser-extension@mocoapp.com" } + gecko: { + id: process.env.APPLICATION_ID || `{${uuidv4()}}` + } }, description: process.env.npm_package_description, version: process.env.npm_package_version diff --git a/yarn.lock b/yarn.lock index 9606a5a9..57058375 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2437,6 +2437,11 @@ domutils@1.5.1: dom-serializer "0" domelementtype "1" +dotenv@^7.0.0: + version "7.0.0" + resolved "https://registry.yarnpkg.com/dotenv/-/dotenv-7.0.0.tgz#a2be3cd52736673206e8a85fb5210eea29628e7c" + integrity sha512-M3NhsLbV1i6HuGzBUH8vXrtxOk+tWmzWKDMbAVSUp3Zsjm7ywFeuwrUXhmhQyRK1q5B5GGy7hcXPbj3bnfZg2g== + duplexify@^3.4.2, duplexify@^3.6.0: version "3.7.1" resolved "https://registry.yarnpkg.com/duplexify/-/duplexify-3.7.1.tgz#2a4df5317f6ccfd91f86d6fd25d8d8a103b88309"