[EC-473] Add feature flag config and environment loaders to Desktop (#3389)

This commit is contained in:
Thomas Rittson 2022-09-02 06:08:47 +10:00 committed by GitHub
parent 5c34e53280
commit e2cb0cf11a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 63 additions and 0 deletions

View File

@ -0,0 +1,4 @@
{
"dev_flags": {},
"flags": {}
}

View File

@ -0,0 +1,33 @@
function load(envName) {
return {
...loadConfig(envName),
...loadConfig("local"),
};
}
function log(configObj) {
const repeatNum = 50;
// eslint-disable-next-line
console.log(`${"=".repeat(repeatNum)}\nenvConfig`);
// eslint-disable-next-line
console.log(JSON.stringify(configObj, null, 2));
// eslint-disable-next-line
console.log(`${"=".repeat(repeatNum)}`);
}
function loadConfig(configName) {
try {
return require(`./${configName}.json`);
} catch (e) {
if (e instanceof Error && e.code === "MODULE_NOT_FOUND") {
return {};
} else {
throw e;
}
}
}
module.exports = {
load,
log,
};

View File

@ -0,0 +1,4 @@
{
"devFlags": {},
"flags": {}
}

View File

@ -0,0 +1,3 @@
{
"flags": {}
}

View File

@ -3,9 +3,15 @@ const { merge } = require("webpack-merge");
const CopyWebpackPlugin = require("copy-webpack-plugin");
const { CleanWebpackPlugin } = require("clean-webpack-plugin");
const TsconfigPathsPlugin = require("tsconfig-paths-webpack-plugin");
const configurator = require("./config/config");
const { EnvironmentPlugin } = require("webpack");
const NODE_ENV = process.env.NODE_ENV == null ? "development" : process.env.NODE_ENV;
console.log("Main process config");
const envConfig = configurator.load(NODE_ENV);
configurator.log(envConfig);
const common = {
module: {
rules: [
@ -69,6 +75,10 @@ const main = {
{ from: "./src/locales", to: "locales" },
],
}),
new EnvironmentPlugin({
FLAGS: envConfig.flags,
DEV_FLAGS: NODE_ENV === "development" ? envConfig.devFlags : {},
}),
],
externals: {
"electron-reload": "commonjs2 electron-reload",

View File

@ -5,9 +5,14 @@ const HtmlWebpackPlugin = require("html-webpack-plugin");
const MiniCssExtractPlugin = require("mini-css-extract-plugin");
const { AngularWebpackPlugin } = require("@ngtools/webpack");
const TerserPlugin = require("terser-webpack-plugin");
const configurator = require("./config/config");
const NODE_ENV = process.env.NODE_ENV == null ? "development" : process.env.NODE_ENV;
console.log("Renderer process config");
const envConfig = configurator.load(NODE_ENV);
configurator.log(envConfig);
const common = {
module: {
rules: [
@ -142,6 +147,10 @@ const renderer = {
filename: "[name].[contenthash].css",
chunkFilename: "[id].[contenthash].css",
}),
new webpack.EnvironmentPlugin({
FLAGS: envConfig.flags,
DEV_FLAGS: NODE_ENV === "development" ? envConfig.devFlags : {},
}),
],
};