Skip to content

Commit

Permalink
refactor(util): add global config file name
Browse files Browse the repository at this point in the history
  • Loading branch information
xuchaoying committed Jul 11, 2019
1 parent 5343710 commit ab29cc2
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions packages/svrx-util/lib/rc-file-read.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,28 +3,29 @@ const userHome = require('user-home');
const path = require('path');
const fs = require('fs');

const RC_FILES = ['.svrxrc.js', 'svrx.config.js'];
const readGlobal = () => {
const configRoot = process.env.SVRX_DIR;
if (!configRoot && !userHome) {
return {};
}

const root = configRoot || path.resolve(userHome, '.svrx');
const configPath = `${root}/config/.svrxrc.js`;
const fileName = RC_FILES.find(file => fs.existsSync(`${root}/config/${file}`));

if (fs.existsSync(configPath)) {
return require(configPath); // eslint-disable-line
if (fileName) {
return require(`${root}/config/${fileName}`); // eslint-disable-line
}

return {};
};

const readScope = () => {
const explorer = cosmiconfig('svrx', {
searchPlaces: ['.svrxrc.js', 'svrx.config.js'],
searchPlaces: RC_FILES,
});
const result = explorer.searchSync();
if (result && !result.isEmpty) {
this._rcFilePath = result.filepath;
return result.config;
}
return {};
Expand Down

0 comments on commit ab29cc2

Please sign in to comment.