From 5030d18860372083fc569d5172bfc6c16fee5cdd Mon Sep 17 00:00:00 2001 From: Quentin Goinaud Date: Wed, 4 Sep 2019 22:52:42 +0200 Subject: [PATCH] add profile support (fix #30) --- src/app.js | 33 +++++++++++++++++------------- src/new-project-template/config.js | 14 ++++++------- 2 files changed, 26 insertions(+), 21 deletions(-) diff --git a/src/app.js b/src/app.js index 372fc91..417a78c 100644 --- a/src/app.js +++ b/src/app.js @@ -7,7 +7,8 @@ const rollbar = require('./ErrorReport'); const USER_CONFIG = path.join(process.cwd(), 'config.js'); const PluginManager = require('./PluginManager'); -const logger = require('./utils/console').normal('system'); +const logger = require('./utils/console') + .normal('system'); const isDev = process.env.EFC_ENV === 'development'; @@ -18,9 +19,9 @@ let errorReporting = false; const alias = { h: 'help', - p: 'production', + p: 'profile', }; -const boolean = ['help', 'production']; +const boolean = ['help']; let args = mri(process.argv.slice(2), { alias, @@ -33,18 +34,21 @@ let config = { module.exports = async () => { try { - // check if production or dev mode - if (args.production) { - config.env = 'production'; - } else { - config.env = 'development'; - } + const profile = args.profile || 'development'; + + config.profile = profile; let userConfig = {}; if (fs.existsSync(USER_CONFIG)) { - const usrConfig = require(USER_CONFIG); config.isProject = true; - userConfig = usrConfig(config.env === 'production'); + userConfig = require(USER_CONFIG); + } + + // todo support json + const profileConfigPath = path.join(process.cwd(), `config.${profile}.js`); + if (fs.existsSync(profileConfigPath)) { + const profileConfig = require(profileConfigPath); + userConfig = deepmerge(userConfig, profileConfig); } /** @@ -60,9 +64,10 @@ module.exports = async () => { await pm.loadCommands(); let pluginsConfig = {}; - pm.getCommands().forEach((command) => { - pluginsConfig = deepmerge(pluginsConfig, { [command.name]: command.config || {} }); - }); + pm.getCommands() + .forEach((command) => { + pluginsConfig = deepmerge(pluginsConfig, { [command.name]: command.config || {} }); + }); config = deepmerge.all([config, pluginsConfig, userConfig]); diff --git a/src/new-project-template/config.js b/src/new-project-template/config.js index e0cc6f1..8b5a79e 100644 --- a/src/new-project-template/config.js +++ b/src/new-project-template/config.js @@ -1,6 +1,6 @@ // Happy with ElectronForConstruct ? ► Donate: https://armaldio.xyz/donations ♥ -module.exports = isProd => ({ +module.exports = { // add your own configuration electron: '6.0.1', @@ -9,7 +9,7 @@ module.exports = isProd => ({ window: { width: 800, height: 600, - fullscreen: isProd, + fullscreen: false, frame: true, transparent: false, toolbar: true, @@ -19,10 +19,10 @@ module.exports = isProd => ({ showConfig: false, }, developer: { - showConstructDevTools: !isProd, - autoClose: !isProd, - autoReload: !isProd, - showChromeDevTools: !isProd, + showConstructDevTools: true, + autoClose: true, + autoReload: true, + showChromeDevTools: true, overlay: null, }, project: { @@ -32,4 +32,4 @@ module.exports = isProd => ({ version: '0.0.0', }, switches: [], -}); +};