From b839ba7870c2872607ebf3ae41a8c08f17a7dde7 Mon Sep 17 00:00:00 2001 From: Henry Jameson Date: Tue, 11 Dec 2018 18:45:25 +0300 Subject: [PATCH 1/4] Quality of Frontend Developer's Life: here to stay --- README.md | 9 +++++++++ build/webpack.dev.conf.js | 4 +++- build/webpack.prod.conf.js | 12 +++++++++--- config/index.js | 19 +++++++++++++++---- src/boot/after_store.js | 11 ++++++++++- src/main.js | 6 ++++++ 6 files changed, 52 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index b6e5a58632..181b6a0d39 100644 --- a/README.md +++ b/README.md @@ -29,6 +29,15 @@ npm run build npm run unit ``` +# For Contributors: + +You can create file `/config/local.json` (see [example](https://git.pleroma.social/pleroma/pleroma-fe/blob/develop/config/local.example.json)) to enable some convenience dev options: + +* `target`: makes local dev server redirect to some existing instance's BE instead of local BE, useful for testing things in near-production environment and searching for real-life use-cases. +* `staticConfigPreference`: makes FE's `/static/config.json` take preference of BE-served `/api/statusnet/config.json`. Only works in dev mode. + +FE Build process also leaves current commit hash in global variable `___pleromafe_commit_hash` so that you can easily see which pleroma-fe commit instance is running, also helps pinpointing which commit was used when FE was bundled into BE. + # Configuration Edit config.json for configuration. scopeOptionsEnabled gives you input fields for CWs and the scope settings. diff --git a/build/webpack.dev.conf.js b/build/webpack.dev.conf.js index 7e1a104fe0..9f34619c88 100644 --- a/build/webpack.dev.conf.js +++ b/build/webpack.dev.conf.js @@ -18,7 +18,9 @@ module.exports = merge(baseWebpackConfig, { devtool: '#eval-source-map', plugins: [ new webpack.DefinePlugin({ - 'process.env': config.dev.env + 'process.env': config.dev.env, + 'COMMIT_HASH': JSON.stringify('DEV'), + 'DEV_OVERRIDES': JSON.stringify(config.dev.settings) }), // https://github.com/glenjamin/webpack-hot-middleware#installation--usage new webpack.optimize.OccurenceOrderPlugin(), diff --git a/build/webpack.prod.conf.js b/build/webpack.prod.conf.js index 6119f700f1..b2c87e6cca 100644 --- a/build/webpack.prod.conf.js +++ b/build/webpack.prod.conf.js @@ -7,8 +7,13 @@ var baseWebpackConfig = require('./webpack.base.conf') var ExtractTextPlugin = require('extract-text-webpack-plugin') var HtmlWebpackPlugin = require('html-webpack-plugin') var env = process.env.NODE_ENV === 'testing' - ? require('../config/test.env') - : config.build.env + ? require('../config/test.env') + : config.build.env + +let commitHash = require('child_process') + .execSync('git rev-parse --short HEAD') + .toString(); +console.log(commitHash) var webpackConfig = merge(baseWebpackConfig, { module: { @@ -29,7 +34,8 @@ var webpackConfig = merge(baseWebpackConfig, { plugins: [ // http://vuejs.github.io/vue-loader/workflow/production.html new webpack.DefinePlugin({ - 'process.env': env + 'process.env': env, + 'COMMIT_HASH': JSON.stringify(commitHash) }), new webpack.optimize.UglifyJsPlugin({ compress: { diff --git a/config/index.js b/config/index.js index 7b0ef26cf3..56fa594057 100644 --- a/config/index.js +++ b/config/index.js @@ -1,5 +1,15 @@ // see http://vuejs-templates.github.io/webpack for documentation. -var path = require('path') +const path = require('path') +let settings = {} +try { + settings = require('./local.json') + console.log('Using local dev server settings (/config/local.json):') + console.log(JSON.stringify(settings, null, 2)) +} catch (e) { + console.log('Local dev server settings not found (/config/local.json)') +} + +const target = settings.target || 'http://localhost:4000/' module.exports = { build: { @@ -19,21 +29,22 @@ module.exports = { dev: { env: require('./dev.env'), port: 8080, + settings, assetsSubDirectory: 'static', assetsPublicPath: '/', proxyTable: { '/api': { - target: 'http://localhost:4000/', + target, changeOrigin: true, cookieDomainRewrite: 'localhost' }, '/nodeinfo': { - target: 'http://localhost:4000/', + target, changeOrigin: true, cookieDomainRewrite: 'localhost' }, '/socket': { - target: 'http://localhost:4000/', + target, changeOrigin: true, cookieDomainRewrite: 'localhost', ws: true diff --git a/src/boot/after_store.js b/src/boot/after_store.js index a80baaf5e7..9ce2d7ed3b 100644 --- a/src/boot/after_store.js +++ b/src/boot/after_store.js @@ -38,8 +38,17 @@ const afterStoreSetup = ({store, i18n}) => { return {} }) .then((staticConfig) => { + const overrides = window.___pleromafe_dev_overrides || {} + const env = window.___pleromafe_mode.NODE_ENV + // This takes static config and overrides properties that are present in apiConfig - var config = Object.assign({}, staticConfig, apiConfig) + let config = {} + if (overrides.staticConfigPreference && env === 'DEV') { + console.warn('OVERRIDING API CONFIG WITH STATIC CONFIG') + config = Object.assign({}, apiConfig, staticConfig) + } else { + config = Object.assign({}, staticConfig, apiConfig) + } var theme = (config.theme) var background = (config.background) diff --git a/src/main.js b/src/main.js index 378fe95cb4..7f3746c818 100644 --- a/src/main.js +++ b/src/main.js @@ -69,3 +69,9 @@ createPersistedState(persistedStateOptions).then((persistedState) => { afterStoreSetup({store, i18n}) }) + +// These are inlined by webpack's DefinePlugin +/* eslint-disable */ +window.___pleromafe_mode = process.env +window.___pleromafe_commit_hash = COMMIT_HASH +window.___pleromafe_dev_overrides = DEV_OVERRIDES From b2d3b7e708236623ef25e27dd5e162849c756f1f Mon Sep 17 00:00:00 2001 From: Henry Jameson Date: Tue, 11 Dec 2018 18:54:17 +0300 Subject: [PATCH 2/4] fix --- build/webpack.prod.conf.js | 1 + 1 file changed, 1 insertion(+) diff --git a/build/webpack.prod.conf.js b/build/webpack.prod.conf.js index b2c87e6cca..f4038e7184 100644 --- a/build/webpack.prod.conf.js +++ b/build/webpack.prod.conf.js @@ -36,6 +36,7 @@ var webpackConfig = merge(baseWebpackConfig, { new webpack.DefinePlugin({ 'process.env': env, 'COMMIT_HASH': JSON.stringify(commitHash) + 'DEV_OVERRIDES': JSON.stringify(undefined) }), new webpack.optimize.UglifyJsPlugin({ compress: { From 4eb075fae75cf24d2fcc9083607fee3d64077b44 Mon Sep 17 00:00:00 2001 From: Henry Jameson Date: Tue, 11 Dec 2018 18:57:24 +0300 Subject: [PATCH 3/4] whoopsies --- .gitignore | 1 + build/webpack.prod.conf.js | 2 +- config/local.example.json | 4 ++++ 3 files changed, 6 insertions(+), 1 deletion(-) create mode 100644 config/local.example.json diff --git a/.gitignore b/.gitignore index faf3925230..479d57c408 100644 --- a/.gitignore +++ b/.gitignore @@ -6,3 +6,4 @@ test/unit/coverage test/e2e/reports selenium-debug.log .idea/ +config/local.json diff --git a/build/webpack.prod.conf.js b/build/webpack.prod.conf.js index f4038e7184..c02f8e8626 100644 --- a/build/webpack.prod.conf.js +++ b/build/webpack.prod.conf.js @@ -35,7 +35,7 @@ var webpackConfig = merge(baseWebpackConfig, { // http://vuejs.github.io/vue-loader/workflow/production.html new webpack.DefinePlugin({ 'process.env': env, - 'COMMIT_HASH': JSON.stringify(commitHash) + 'COMMIT_HASH': JSON.stringify(commitHash), 'DEV_OVERRIDES': JSON.stringify(undefined) }), new webpack.optimize.UglifyJsPlugin({ diff --git a/config/local.example.json b/config/local.example.json new file mode 100644 index 0000000000..2a3bd00da9 --- /dev/null +++ b/config/local.example.json @@ -0,0 +1,4 @@ +{ + "target": "https://pleroma.soykaf.com/", + "staticConfigPreference": false +} From c54eb1ecad33c4e45868ca35bcaa5404a1bfd0cd Mon Sep 17 00:00:00 2001 From: Henry Jameson Date: Tue, 11 Dec 2018 19:01:08 +0300 Subject: [PATCH 4/4] fix --- src/boot/after_store.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/boot/after_store.js b/src/boot/after_store.js index 9ce2d7ed3b..4374ce8e2c 100644 --- a/src/boot/after_store.js +++ b/src/boot/after_store.js @@ -43,7 +43,7 @@ const afterStoreSetup = ({store, i18n}) => { // This takes static config and overrides properties that are present in apiConfig let config = {} - if (overrides.staticConfigPreference && env === 'DEV') { + if (overrides.staticConfigPreference && env === 'development') { console.warn('OVERRIDING API CONFIG WITH STATIC CONFIG') config = Object.assign({}, apiConfig, staticConfig) } else {