@@ -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 - z A - 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}
0 commit comments