Skip to content

Commit

Permalink
feat: config support js file(eg: feflow.js or feflow.json)
Browse files Browse the repository at this point in the history
  • Loading branch information
cpselvis committed Jul 4, 2018
1 parent 1e63a49 commit 4c7dfd8
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 10 deletions.
28 changes: 19 additions & 9 deletions lib/internal/build/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,15 @@ class Config {
* @function getPath
* @desc Find feflow.json file
*/
static getPath() {
static getPath(filename) {
let currDir = process.cwd();

while (!fs.existsSync(path.join(currDir, 'feflow.json'))) {
while (!fs.existsSync(path.join(currDir, filename))) {
currDir = path.join(currDir, '../');

// unix跟目录为/, win32系统根目录为 C:\\格式的
if (currDir === '/' || /^[a-zA-Z]:\\$/.test(currDir)) {
console.error('未找到 feflow.json');
process.exit(1);
return false;
}
}

Expand All @@ -30,12 +29,10 @@ class Config {
*/
static getBuilderType() {
let builderType;
const configFile = path.join(Config.getPath(), './feflow.json');

if (!fs.existsSync(configFile)) {
console.error('未找到 feflow.json');
} else {
const fileContent = fs.readFileSync(configFile, 'utf-8');
if (Config.getPath('feflow.json')) {
const jsonConfigFile = path.join(Config.getPath('feflow.json'), './feflow.json');
const fileContent = fs.readFileSync(jsonConfigFile, 'utf-8');

let feflowCfg;

Expand All @@ -51,6 +48,19 @@ class Config {
console.error('请确保feflow.json配置是一个Object类型,并且含有builderType字段内容不为空')
}
return builderType;
} else if (Config.getPath('feflow.js')) {
const jsConfigFile = path.join(Config.getPath('feflow.js'), './feflow.js');

let feflowCfg = require(jsConfigFile);

builderType = feflowCfg.builderType;

if (!builderType) {
console.error('请确保feflow.js配置包含builderType字段,且内容不为空')
}
return builderType;
} else {
console.error('未找到 feflow 配置文件 feflow.json 或者 feflow.js');
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "feflow-cli",
"version": "0.13.4",
"version": "0.13.5",
"description": "A command line tool aims to improve front-end engineer workflow.",
"main": "lib/index.js",
"scripts": {
Expand Down

0 comments on commit 4c7dfd8

Please sign in to comment.