diff --git a/lib/internal/build/config.js b/lib/internal/build/config.js index c9012cc4..c1f2413b 100644 --- a/lib/internal/build/config.js +++ b/lib/internal/build/config.js @@ -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; } } @@ -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; @@ -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'); } } } diff --git a/package.json b/package.json index 99227ef8..c9ef8c8d 100644 --- a/package.json +++ b/package.json @@ -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": {