Skip to content
This repository has been archived by the owner on Feb 7, 2022. It is now read-only.

support config as export function v2 #48

Merged
merged 5 commits into from
Jul 28, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions src/loadConfigurationFile.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,16 @@ function getMatchingLoader(configPath) {
return null;
}

function callConfigFunction(fn) {
return fn(require('minimist')(process.argv, { '--': true }).env || {});
}

function getConfig(configPath) {
var configModule = require(configPath);
var configDefault = configModule && configModule.__esModule ? configModule.default : configModule;
return typeof configDefault === 'function' ? callConfigFunction(configDefault) : configDefault;
}

module.exports = function(configPath) {
var mod = getMatchingLoader(configPath);
if(mod) {
Expand Down Expand Up @@ -60,5 +70,5 @@ module.exports = function(configPath) {
throw new Error('Could not load required module loading for ' + chalk.underline(configPath));
}
}
return require(configPath);
}
return getConfig(configPath);
}