Skip to content

Commit

Permalink
add profile support (fix #30)
Browse files Browse the repository at this point in the history
  • Loading branch information
Armaldio committed Sep 4, 2019
1 parent 3c1e656 commit 5030d18
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 21 deletions.
33 changes: 19 additions & 14 deletions src/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand All @@ -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,
Expand All @@ -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);
}

/**
Expand All @@ -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]);

Expand Down
14 changes: 7 additions & 7 deletions src/new-project-template/config.js
Original file line number Diff line number Diff line change
@@ -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',
Expand All @@ -9,7 +9,7 @@ module.exports = isProd => ({
window: {
width: 800,
height: 600,
fullscreen: isProd,
fullscreen: false,
frame: true,
transparent: false,
toolbar: true,
Expand All @@ -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: {
Expand All @@ -32,4 +32,4 @@ module.exports = isProd => ({
version: '0.0.0',
},
switches: [],
});
};

0 comments on commit 5030d18

Please sign in to comment.