Skip to content

Commit

Permalink
[config] clean up logic in config locator
Browse files Browse the repository at this point in the history
- exported simple field can't be changed (and it's not a good idea to
  export object)
- less return and no process.exit in non entry libraries
  • Loading branch information
at15 committed Sep 7, 2016
1 parent 0663369 commit cb6b63b
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 5 deletions.
Empty file added example/.about.yml
Empty file.
1 change: 1 addition & 0 deletions example/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
build
7 changes: 6 additions & 1 deletion lib/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@ module.exports = {
logger.debug('cli input', cli.input);
logger.debug('cli flags', cli.flags);

configLocator.detectConfigFile(cli.flags);
let configFilePath = configLocator.detectConfigFile(cli.flags);
if (configFilePath === '') {
process.exit(1);
}

logger.debug('keep moving!');
}
};
17 changes: 13 additions & 4 deletions lib/config/locator.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,26 @@
*/
const logger = require('../logger');
const fsUtil = require('../util/fs');
const DEFAULT_CONFIG_FILE = '.about.yml';

function detectConfigFile(flags) {
if (typeof flags.config === 'string') {
let configFile = flags.config;
logger.debug(`config file set as ${configFile}`);
// it must exist, if not we fallback to the default one and throw a warning
if (!fsUtil.fileExists(configFile)) {
logger.warn(`config file can't be found ${configFile}`);
if (fsUtil.fileExists(configFile)) {
return configFile;
}
logger.warn(`specified config file can't be found`, {file: configFile});
}
logger.debug('using default config file');
logger.debug('try to use default config file');
// TODO: may need to add cwd
if (fsUtil.fileExists(DEFAULT_CONFIG_FILE)) {
return DEFAULT_CONFIG_FILE;
} else {
logger.warn(`default config file can't be found`, {file: DEFAULT_CONFIG_FILE});
}
logger.error('no config file found');
return '';
}

module.exports = {
Expand Down

0 comments on commit cb6b63b

Please sign in to comment.