Skip to content

Commit 4c7dfd8

Browse files
committed
feat: config support js file(eg: feflow.js or feflow.json)
1 parent 1e63a49 commit 4c7dfd8

File tree

2 files changed

+20
-10
lines changed

2 files changed

+20
-10
lines changed

lib/internal/build/config.js

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,15 @@ class Config {
88
* @function getPath
99
* @desc Find feflow.json file
1010
*/
11-
static getPath() {
11+
static getPath(filename) {
1212
let currDir = process.cwd();
1313

14-
while (!fs.existsSync(path.join(currDir, 'feflow.json'))) {
14+
while (!fs.existsSync(path.join(currDir, filename))) {
1515
currDir = path.join(currDir, '../');
1616

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

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

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

4037
let feflowCfg;
4138

@@ -51,6 +48,19 @@ class Config {
5148
console.error('请确保feflow.json配置是一个Object类型,并且含有builderType字段内容不为空')
5249
}
5350
return builderType;
51+
} else if (Config.getPath('feflow.js')) {
52+
const jsConfigFile = path.join(Config.getPath('feflow.js'), './feflow.js');
53+
54+
let feflowCfg = require(jsConfigFile);
55+
56+
builderType = feflowCfg.builderType;
57+
58+
if (!builderType) {
59+
console.error('请确保feflow.js配置包含builderType字段,且内容不为空')
60+
}
61+
return builderType;
62+
} else {
63+
console.error('未找到 feflow 配置文件 feflow.json 或者 feflow.js');
5464
}
5565
}
5666
}

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "feflow-cli",
3-
"version": "0.13.4",
3+
"version": "0.13.5",
44
"description": "A command line tool aims to improve front-end engineer workflow.",
55
"main": "lib/index.js",
66
"scripts": {

0 commit comments

Comments
 (0)