neo-cmp-cli 1.6.0-beta.1 → 1.6.0-beta.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/module/index.js +32 -26
- package/src/module/main.js +161 -267
- package/src/module/neoInit.js +1 -0
- package/src/neo/NeoUMDContent.js +5 -5
- package/src/neo/neoService.js +17 -18
- package/src/oss/publish2oss.js +174 -71
- package/src/template/antd-custom-cmp-template/README.md +26 -2
- package/src/template/antd-custom-cmp-template/neo.config.js +2 -2
- package/src/template/echarts-custom-cmp-template/README.md +26 -2
- package/src/template/echarts-custom-cmp-template/neo.config.js +4 -3
- package/src/template/empty-custom-cmp-template/README.md +26 -0
- package/src/template/empty-custom-cmp-template/neo.config.js +2 -2
- package/src/template/neo-custom-cmp-template/README.md +26 -2
- package/src/template/neo-custom-cmp-template/neo.config.js +1 -1
- package/src/template/react-custom-cmp-template/README.md +26 -2
- package/src/template/react-custom-cmp-template/neo.config.js +2 -2
- package/src/template/react-ts-custom-cmp-template/README.md +26 -2
- package/src/template/react-ts-custom-cmp-template/neo.config.js +2 -2
- package/src/template/vue2-custom-cmp-template/README.md +26 -2
- package/src/template/vue2-custom-cmp-template/neo.config.js +2 -2
- package/src/{cmpUtils → utils/cmpUtils}/createCmpByTemplate.js +7 -5
- package/src/{cmpUtils → utils/cmpUtils}/createCmpByZip.js +5 -2
- package/src/{cmpUtils → utils/cmpUtils}/createCommonModulesCode.js +2 -2
- package/src/{cmpUtils → utils/cmpUtils}/getCmpModelRegisterCode.js +1 -1
- package/src/{cmpUtils → utils/cmpUtils}/getCmpPreviewCode.js +1 -1
- package/src/{cmpUtils → utils/cmpUtils}/getCmpRegisterCode.js +1 -1
- package/src/{cmpUtils → utils/cmpUtils}/getCmpTypeByDir.js +2 -2
- package/src/{cmpUtils → utils/cmpUtils}/hasCmpTypeByDir.js +1 -1
- package/src/{cmpUtils → utils/cmpUtils}/previewCmp.js +3 -3
- package/src/{cmpUtils → utils/cmpUtils}/pullCmp.js +9 -9
- package/src/{cmpUtils → utils/cmpUtils}/pushCmp.js +7 -5
- package/src/utils/generateEntries.js +73 -0
- package/src/{projectUtils → utils/projectUtils}/createCmpProjectByTemplate.js +10 -6
- package/src/{projectUtils → utils/projectUtils}/createCmpProjectZip.js +1 -3
- package/src/{projectUtils → utils/projectUtils}/getEntries.js +2 -2
- package/src/{projectUtils → utils/projectUtils}/getEntriesWithAutoRegister.js +2 -2
- package/src/{projectUtils → utils/projectUtils}/updatePublishLog.js +1 -1
- package/src/template/neo-custom-cmp-template/pushCmp.js +0 -166
- /package/src/{projectUtils → utils/projectUtils}/hasNeoProject.js +0 -0
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
- src: 自定义组件源码;
|
|
3
3
|
- src/assets: 存放组件静态资源,比如 css、img等;
|
|
4
4
|
- src/components: 存放自定义组件代码,每个自定义组件以自身名称(cmpType 数值)作为目录进行存放;
|
|
5
|
-
- src/components/
|
|
6
|
-
- src/components/
|
|
5
|
+
- src/components/xxCmp/index: 自定义组件的内容文件;
|
|
6
|
+
- src/components/xxCmp/model: 自定义组件的模型文件,用于对接页面设计器;
|
|
7
7
|
- neo.config.js: neo-cmp-cli 配置文件。
|
|
8
8
|
|
|
9
9
|
### 组件开发规范
|
|
@@ -43,5 +43,29 @@ $ npm run linkDebug
|
|
|
43
43
|
$ npm run pushCmp
|
|
44
44
|
```
|
|
45
45
|
|
|
46
|
+
##### 需自行添加 NeoCRM 授权配置
|
|
47
|
+
```javascript
|
|
48
|
+
module.exports = {
|
|
49
|
+
neoConfig: {
|
|
50
|
+
neoBaseURL: 'https://crm-cd.xiaoshouyi.com', // 平台根地址(默认:https://crm.xiaoshouyi.com)
|
|
51
|
+
tokenAPI: 'https://login-cd.xiaoshouyi.com/auc/oauth2/token', // Token 获取接口地址(默认:https://login.xiaoshouyi.com/auc/oauth2/token)
|
|
52
|
+
// NeoCRM 授权配置
|
|
53
|
+
auth: {
|
|
54
|
+
client_id: 'xx', // 客户端 ID,从创建连接器的客户端信息中获取(Client_Id)
|
|
55
|
+
client_secret: 'xxx', // 客户端秘钥,从创建连接器的客户端信息中获取(Client_Secret)
|
|
56
|
+
username: 'xx', // 用户在销售易系统中的用户名
|
|
57
|
+
/**
|
|
58
|
+
* password 为 用户在销售易系统中的账号密码加上 8 位安全令牌。
|
|
59
|
+
* 例如,用户密码为 123456,安全令牌为 ABCDEFGH,则 password 的值应为 123456ABCDEFGH。
|
|
60
|
+
*/
|
|
61
|
+
password: 'xx xx' // 用户账户密码 + 8 位安全令牌
|
|
62
|
+
},
|
|
63
|
+
},
|
|
64
|
+
}
|
|
65
|
+
```
|
|
66
|
+
1、客户端 ID 和 客户端秘钥 需通过 创建连接器 获取,获取方式见:[https://doc.xiaoshouyi.com](https://doc.xiaoshouyi.com) / 创建连接器;
|
|
67
|
+
2、如何获取 安全令牌 见:[https://doc.xiaoshouyi.com](https://doc.xiaoshouyi.com) / OAuth安全认证 / 密码模式 / 获取令牌;
|
|
68
|
+
3、发布成功后即可在 NeoCRM 对应租户环境的页面设计器和表单设计器中使用此自定义组件。
|
|
69
|
+
|
|
46
70
|
### 配置项说明(neo-cmp-cli)
|
|
47
71
|
[请查看neo-cmp-cli](https://github.com/wibetter/neo-cmp-cli)
|
|
@@ -110,8 +110,8 @@ module.exports = {
|
|
|
110
110
|
* password 为 用户在销售易系统中的账号密码加上 8 位安全令牌。
|
|
111
111
|
* 例如,用户密码为 123456,安全令牌为 ABCDEFGH,则 password 的值应为 123456ABCDEFGH。
|
|
112
112
|
*/
|
|
113
|
-
password: 'xx xx' // 用户账户密码 + 8 位安全令牌
|
|
114
|
-
}
|
|
113
|
+
password: 'xx xx', // 用户账户密码 + 8 位安全令牌
|
|
114
|
+
},
|
|
115
115
|
},
|
|
116
116
|
pushCmp: {
|
|
117
117
|
// 用于构建并发布至 NeoCRM 的相关配置
|
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
- src: 自定义组件源码;
|
|
3
3
|
- src/assets: 存放组件静态资源,比如 css、img等;
|
|
4
4
|
- src/components: 存放自定义组件代码,每个自定义组件以自身名称(cmpType 数值)作为目录进行存放;
|
|
5
|
-
- src/components/
|
|
6
|
-
- src/components/
|
|
5
|
+
- src/components/xxCmp/index: 自定义组件的内容文件;
|
|
6
|
+
- src/components/xxCmp/model: 自定义组件的模型文件,用于对接页面设计器;
|
|
7
7
|
- neo.config.js: neo-cmp-cli 配置文件。
|
|
8
8
|
|
|
9
9
|
### 组件开发规范
|
|
@@ -43,5 +43,29 @@ $ npm run linkDebug
|
|
|
43
43
|
$ npm run pushCmp
|
|
44
44
|
```
|
|
45
45
|
|
|
46
|
+
##### 需自行添加 NeoCRM 授权配置
|
|
47
|
+
```javascript
|
|
48
|
+
module.exports = {
|
|
49
|
+
neoConfig: {
|
|
50
|
+
neoBaseURL: 'https://crm-cd.xiaoshouyi.com', // 平台根地址(默认:https://crm.xiaoshouyi.com)
|
|
51
|
+
tokenAPI: 'https://login-cd.xiaoshouyi.com/auc/oauth2/token', // Token 获取接口地址(默认:https://login.xiaoshouyi.com/auc/oauth2/token)
|
|
52
|
+
// NeoCRM 授权配置
|
|
53
|
+
auth: {
|
|
54
|
+
client_id: 'xx', // 客户端 ID,从创建连接器的客户端信息中获取(Client_Id)
|
|
55
|
+
client_secret: 'xxx', // 客户端秘钥,从创建连接器的客户端信息中获取(Client_Secret)
|
|
56
|
+
username: 'xx', // 用户在销售易系统中的用户名
|
|
57
|
+
/**
|
|
58
|
+
* password 为 用户在销售易系统中的账号密码加上 8 位安全令牌。
|
|
59
|
+
* 例如,用户密码为 123456,安全令牌为 ABCDEFGH,则 password 的值应为 123456ABCDEFGH。
|
|
60
|
+
*/
|
|
61
|
+
password: 'xx xx' // 用户账户密码 + 8 位安全令牌
|
|
62
|
+
},
|
|
63
|
+
},
|
|
64
|
+
}
|
|
65
|
+
```
|
|
66
|
+
1、客户端 ID 和 客户端秘钥 需通过 创建连接器 获取,获取方式见:[https://doc.xiaoshouyi.com](https://doc.xiaoshouyi.com) / 创建连接器;
|
|
67
|
+
2、如何获取 安全令牌 见:[https://doc.xiaoshouyi.com](https://doc.xiaoshouyi.com) / OAuth安全认证 / 密码模式 / 获取令牌;
|
|
68
|
+
3、发布成功后即可在 NeoCRM 对应租户环境的页面设计器和表单设计器中使用此自定义组件。
|
|
69
|
+
|
|
46
70
|
### 配置项说明(neo-cmp-cli)
|
|
47
71
|
[请查看neo-cmp-cli](https://github.com/wibetter/neo-cmp-cli)
|
|
@@ -118,8 +118,8 @@ module.exports = {
|
|
|
118
118
|
* password 为 用户在销售易系统中的账号密码加上 8 位安全令牌。
|
|
119
119
|
* 例如,用户密码为 123456,安全令牌为 ABCDEFGH,则 password 的值应为 123456ABCDEFGH。
|
|
120
120
|
*/
|
|
121
|
-
password: 'xx xx' // 用户账户密码 + 8 位安全令牌
|
|
122
|
-
}
|
|
121
|
+
password: 'xx xx', // 用户账户密码 + 8 位安全令牌
|
|
122
|
+
},
|
|
123
123
|
},
|
|
124
124
|
pushCmp: {
|
|
125
125
|
// 用于构建并发布至 NeoCRM 的相关配置
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
const fs = require('fs-extra');
|
|
2
2
|
const path = require('path');
|
|
3
3
|
const _ = require('lodash');
|
|
4
|
-
const { consoleTag } = require('../
|
|
5
|
-
const replaceInFilesByMap = require('../
|
|
4
|
+
const { consoleTag } = require('../neoParams'); // 输出标记
|
|
5
|
+
const replaceInFilesByMap = require('../replaceInFilesByMap');
|
|
6
6
|
const hasCmpTypeByDir = require('./hasCmpTypeByDir');
|
|
7
7
|
const hasNeoProject = require('../projectUtils/hasNeoProject');
|
|
8
8
|
|
|
@@ -14,7 +14,7 @@ const curCmpTemplate = {
|
|
|
14
14
|
modelName: 'CmpModel',
|
|
15
15
|
cmpClassName: 'custom-cmp-container',
|
|
16
16
|
cmpType: 'xx-custom-cmp',
|
|
17
|
-
cmpLabel: 'xx组件'
|
|
17
|
+
cmpLabel: 'xx组件'
|
|
18
18
|
},
|
|
19
19
|
dir: path.resolve(__dirname, '../template/empty-cmp')
|
|
20
20
|
};
|
|
@@ -29,7 +29,9 @@ module.exports = function (cmpName, componentBaseDir = './src/components') {
|
|
|
29
29
|
const finalCmpPath = path.resolve(process.cwd(), componentBaseDir, finalCmpName);
|
|
30
30
|
|
|
31
31
|
if (!hasNeoProject()) {
|
|
32
|
-
console.error(
|
|
32
|
+
console.error(
|
|
33
|
+
`${consoleTag}当前(${process.cwd()})还不是自定义组件项目,请先创建一个自定义组件项目(neo init / neo createProject)。`
|
|
34
|
+
);
|
|
33
35
|
process.exit(1);
|
|
34
36
|
}
|
|
35
37
|
|
|
@@ -49,7 +51,7 @@ module.exports = function (cmpName, componentBaseDir = './src/components') {
|
|
|
49
51
|
[curCmpTemplate.widgetInfo.cmpName]: curCmpName,
|
|
50
52
|
[curCmpTemplate.widgetInfo.cmpClassName]: `${cmpType}-container`,
|
|
51
53
|
[curCmpTemplate.widgetInfo.cmpType]: cmpType,
|
|
52
|
-
[curCmpTemplate.widgetInfo.cmpLabel]: `${cmpType}
|
|
54
|
+
[curCmpTemplate.widgetInfo.cmpLabel]: `${cmpType}组件`
|
|
53
55
|
});
|
|
54
56
|
|
|
55
57
|
console.log(`${consoleTag}已创建自定义组件(${finalCmpName})!`);
|
|
@@ -3,7 +3,7 @@ const path = require('path');
|
|
|
3
3
|
const axios = require('axios');
|
|
4
4
|
const ora = require('ora');
|
|
5
5
|
const AdmZip = require('adm-zip');
|
|
6
|
-
const { consoleTag } = require('../
|
|
6
|
+
const { consoleTag } = require('../neoParams'); // 输出标记
|
|
7
7
|
const hasCmpTypeByDir = require('./hasCmpTypeByDir');
|
|
8
8
|
const hasNeoProject = require('../projectUtils/hasNeoProject');
|
|
9
9
|
|
|
@@ -78,7 +78,10 @@ module.exports = async function (cmpZipUrl, cmpName, componentBaseDir = './src/c
|
|
|
78
78
|
|
|
79
79
|
return true;
|
|
80
80
|
} catch (error) {
|
|
81
|
-
spinner.stopAndFail(
|
|
81
|
+
spinner.stopAndFail(
|
|
82
|
+
`${consoleTag}从 zip 包创建自定义组件失败(${finalCmpName}):`,
|
|
83
|
+
error.message
|
|
84
|
+
);
|
|
82
85
|
// 清理临时目录
|
|
83
86
|
await fs.remove(tempDir);
|
|
84
87
|
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
const fs = require('fs');
|
|
2
|
-
const { resolveToCurrentRoot } = require('../
|
|
2
|
+
const { resolveToCurrentRoot } = require('../pathUtils');
|
|
3
3
|
const { isPlainObject } = require('lodash');
|
|
4
4
|
|
|
5
5
|
/**
|
|
@@ -9,7 +9,7 @@ const { isPlainObject } = require('lodash');
|
|
|
9
9
|
* @returns 组件预览代码
|
|
10
10
|
*/
|
|
11
11
|
const createCommonModulesCode = (neoCommonModule, cmpTypes) => {
|
|
12
|
-
const {neoExports, remoteDeps} = neoCommonModule;
|
|
12
|
+
const { neoExports, remoteDeps } = neoCommonModule;
|
|
13
13
|
|
|
14
14
|
if (!neoExports && !remoteDeps) {
|
|
15
15
|
return '';
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
const fs = require('fs');
|
|
2
2
|
const path = require('path');
|
|
3
|
-
const { resolveToCurrentRoot } = require('../
|
|
3
|
+
const { resolveToCurrentRoot } = require('../pathUtils');
|
|
4
4
|
/**
|
|
5
5
|
* 根据当前组件目录,获取所有组件类型
|
|
6
6
|
* @param {*} componentsBaseDir 自定义组件目录
|
|
@@ -23,7 +23,7 @@ const getCmpTypeByDir = (componentsBaseDir = './src/components') => {
|
|
|
23
23
|
dirs.forEach((dir) => {
|
|
24
24
|
const dirPath = path.join(componentsDir, dir);
|
|
25
25
|
const stat = fs.statSync(dirPath);
|
|
26
|
-
|
|
26
|
+
|
|
27
27
|
// 只处理目录,过滤掉隐藏目录和 node_modules
|
|
28
28
|
if (stat.isDirectory() && !dir.startsWith('.') && dir !== 'node_modules') {
|
|
29
29
|
cmpTypes.push(dir);
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
const fs = require('fs');
|
|
2
2
|
const akfun = require('akfun');
|
|
3
|
-
const { consoleTag } = require('../
|
|
4
|
-
const { resolveToCurrentRoot } = require('../
|
|
5
|
-
const getCmpPreviewCode = require('
|
|
3
|
+
const { consoleTag } = require('../neoParams'); // 输出标记
|
|
4
|
+
const { resolveToCurrentRoot } = require('../pathUtils');
|
|
5
|
+
const getCmpPreviewCode = require('./getCmpPreviewCode'); // 获取自定义组件预览代码
|
|
6
6
|
|
|
7
7
|
/**
|
|
8
8
|
* 用于预览指定自定义组件的脚本
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
const _ = require('lodash');
|
|
2
|
-
const { catchCurPackageJson } = require('../
|
|
3
|
-
const getConfigObj = require('../
|
|
2
|
+
const { catchCurPackageJson } = require('../pathUtils');
|
|
3
|
+
const getConfigObj = require('../getConfigObj');
|
|
4
4
|
const ora = require('ora');
|
|
5
5
|
const NeoService = require('../neo/neoService');
|
|
6
|
-
const { getFramework } = require('../
|
|
7
|
-
const getCmpTypeByDir = require('../
|
|
8
|
-
const createCmpByZip = require('../
|
|
6
|
+
const { getFramework } = require('../common');
|
|
7
|
+
const getCmpTypeByDir = require('../getCmpTypeByDir.js');
|
|
8
|
+
const createCmpByZip = require('../createCmpByZip.js');
|
|
9
9
|
|
|
10
10
|
// 获取当前项目的package文件
|
|
11
11
|
const currentPackageJsonDir = catchCurPackageJson();
|
|
@@ -18,7 +18,6 @@ const framework = getFramework(currentPackageJson.framework);
|
|
|
18
18
|
* @param {object} authConfig 授权配置
|
|
19
19
|
*/
|
|
20
20
|
const pullCmp = async (cmpType, authConfig, _neoService) => {
|
|
21
|
-
|
|
22
21
|
if (!authConfig) {
|
|
23
22
|
console.error('未找到 NeoCRM 平台授权配置(neo.config.js / authConfig)。');
|
|
24
23
|
return;
|
|
@@ -34,7 +33,8 @@ const pullCmp = async (cmpType, authConfig, _neoService) => {
|
|
|
34
33
|
|
|
35
34
|
try {
|
|
36
35
|
let neoService = _neoService;
|
|
37
|
-
let cmpList = [],
|
|
36
|
+
let cmpList = [],
|
|
37
|
+
cmpInfoMap = {};
|
|
38
38
|
let cmpInfo = null;
|
|
39
39
|
|
|
40
40
|
if (_neoService) {
|
|
@@ -44,7 +44,7 @@ const pullCmp = async (cmpType, authConfig, _neoService) => {
|
|
|
44
44
|
} else {
|
|
45
45
|
// 创建新的 neoService 实例
|
|
46
46
|
neoService = new NeoService(authConfig);
|
|
47
|
-
|
|
47
|
+
|
|
48
48
|
// 获取自定义组件列表
|
|
49
49
|
spinner.text('正在获取自定义组件列表...');
|
|
50
50
|
cmpList = await neoService.getCustomCmpList();
|
|
@@ -78,7 +78,7 @@ const pullCmp = async (cmpType, authConfig, _neoService) => {
|
|
|
78
78
|
|
|
79
79
|
// 下载源码文件并解析到 src/components 目录下
|
|
80
80
|
const codeLib = cmpInfo.codeLib; // 源码文件地址(zip包地址)
|
|
81
|
-
|
|
81
|
+
|
|
82
82
|
// 将zip 包里面的自定义组件源码解析到 src/components 目录下
|
|
83
83
|
const cmpResult = await createCmpByZip(codeLib, cmpType, './src/components');
|
|
84
84
|
if (!cmpResult) {
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
const fs = require('fs');
|
|
2
2
|
const path = require('path');
|
|
3
3
|
const _ = require('lodash');
|
|
4
|
-
const { catchCurPackageJson } = require('../
|
|
5
|
-
const getConfigObj = require('../
|
|
4
|
+
const { catchCurPackageJson } = require('../pathUtils');
|
|
5
|
+
const getConfigObj = require('../getConfigObj');
|
|
6
6
|
const ora = require('ora');
|
|
7
7
|
const NeoService = require('../neo/neoService');
|
|
8
|
-
const { getFramework } = require('../
|
|
8
|
+
const { getFramework } = require('../common');
|
|
9
9
|
const createCmpProjectZip = require('../projectUtils/createCmpProjectZip');
|
|
10
10
|
|
|
11
11
|
// 获取当前项目的package文件
|
|
@@ -56,14 +56,14 @@ const buildComponentData = async (assetsRoot, cmpInfo) => {
|
|
|
56
56
|
console.error(`未找到自定义组件模型文件,请检查以下路径是否存在:`, modelFile);
|
|
57
57
|
return null;
|
|
58
58
|
}
|
|
59
|
-
if (!window.NEOEditorCustomModels) {
|
|
59
|
+
if (!globalThis.window || !globalThis.window.NEOEditorCustomModels) {
|
|
60
60
|
console.error(
|
|
61
61
|
`模型文件未导出有效模型方法(CatchCustomCmpModelClass),模型文件地址: ${modelFile} `
|
|
62
62
|
);
|
|
63
63
|
return null;
|
|
64
64
|
}
|
|
65
65
|
|
|
66
|
-
const ModelClass = window.NEOEditorCustomModels[cmpType];
|
|
66
|
+
const ModelClass = globalThis.window.NEOEditorCustomModels[cmpType];
|
|
67
67
|
if (!ModelClass) {
|
|
68
68
|
console.error(`未找到自定义组件模型类(${cmpType}),模型文件地址: ${modelFile} `);
|
|
69
69
|
return null;
|
|
@@ -135,6 +135,8 @@ const pushCmp = async (config, cmpType) => {
|
|
|
135
135
|
try {
|
|
136
136
|
// 步骤 1: 初始化 NeoService
|
|
137
137
|
let neoService = new NeoService(config);
|
|
138
|
+
// 获取 token
|
|
139
|
+
await neoService.ensureValidToken();
|
|
138
140
|
|
|
139
141
|
// 步骤 2: 打包源码文件(打包单个自定义组件源码)
|
|
140
142
|
spinner.start(`[1/4] 打包源码文件(含单个自定义组件源码)...`);
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
const getEntries = require('./projectUtils/getEntries');
|
|
2
|
+
const getEntriesWithAutoRegister = require('./projectUtils/getEntriesWithAutoRegister');
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* 生成 entry 配置
|
|
6
|
+
* @param {object} options 配置选项
|
|
7
|
+
* @param {object} options.configEntry 当前配置中的 entry(如果已存在则直接返回)
|
|
8
|
+
* @param {boolean} options.disableAutoRegister 是否禁用自动注册
|
|
9
|
+
* @param {string} options.componentsDir 组件目录路径
|
|
10
|
+
* @param {string} options.entryType entry 类型:'widget' | 'linkDebug',默认为 'widget'
|
|
11
|
+
* @param {string} [options.cmpType] 可选的组件类型,如果指定则只生成该组件的 entry
|
|
12
|
+
* @param {boolean} [options.forceGetCmpTypes] 即使 entry 已存在,也强制获取 cmpTypes,默认为 false
|
|
13
|
+
* @returns {object} { entries: object, cmpTypes: array } 如果 configEntry 已存在且 forceGetCmpTypes 为 false,则返回 { entries: configEntry, cmpTypes: [] }
|
|
14
|
+
*/
|
|
15
|
+
function generateEntries({
|
|
16
|
+
configEntry,
|
|
17
|
+
disableAutoRegister,
|
|
18
|
+
componentsDir,
|
|
19
|
+
entryType = 'widget',
|
|
20
|
+
cmpType,
|
|
21
|
+
forceGetCmpTypes = false
|
|
22
|
+
}) {
|
|
23
|
+
// 如果已配置 entry 且不需要强制获取 cmpTypes,直接返回
|
|
24
|
+
if (configEntry && Object.keys(configEntry).length > 0 && !forceGetCmpTypes) {
|
|
25
|
+
return {
|
|
26
|
+
entries: configEntry,
|
|
27
|
+
cmpTypes: []
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
// 根据 disableAutoRegister 选择不同的生成方法
|
|
32
|
+
let entriesResult;
|
|
33
|
+
if (disableAutoRegister) {
|
|
34
|
+
// disableAutoRegister 为 true 时,仅自动生成入口文件(不自动注册)
|
|
35
|
+
entriesResult = getEntries(componentsDir, cmpType);
|
|
36
|
+
} else {
|
|
37
|
+
// 自动生成入口文件(并自动创建对应的注册文件)
|
|
38
|
+
entriesResult = getEntriesWithAutoRegister(componentsDir, cmpType);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
// 根据 entryType 选择对应的 entries
|
|
42
|
+
let entries;
|
|
43
|
+
if (entryType === 'linkDebug') {
|
|
44
|
+
entries = entriesResult.linkDebugEntries || {};
|
|
45
|
+
} else {
|
|
46
|
+
entries = entriesResult.widgetEntries || {};
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
const cmpTypes = entriesResult.cmpTypes || [];
|
|
50
|
+
|
|
51
|
+
// 如果 entry 已存在但需要获取 cmpTypes,使用已存在的 entry
|
|
52
|
+
if (configEntry && Object.keys(configEntry).length > 0 && forceGetCmpTypes) {
|
|
53
|
+
entries = configEntry;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
// 验证 entries 是否有效(仅在需要生成新 entry 时验证)
|
|
57
|
+
if (
|
|
58
|
+
(!configEntry || Object.keys(configEntry).length === 0) &&
|
|
59
|
+
(!entries || Object.keys(entries).length === 0)
|
|
60
|
+
) {
|
|
61
|
+
const defaultComponentsDir = componentsDir || './src/components';
|
|
62
|
+
throw new Error(
|
|
63
|
+
`未识别到自定义组件,请检查 ${defaultComponentsDir} 目录下是否存在自定义组件。`
|
|
64
|
+
);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
return {
|
|
68
|
+
entries: entries || configEntry || {},
|
|
69
|
+
cmpTypes
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
module.exports = generateEntries;
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
const fs = require('fs-extra');
|
|
2
2
|
const path = require('path');
|
|
3
|
-
const { consoleTag } = require('../
|
|
4
|
-
const { replaceInPackage } = require('../
|
|
5
|
-
const { resetPackageVersion } = require('../
|
|
6
|
-
const autoEntryRootDir = require('../
|
|
3
|
+
const { consoleTag } = require('../neoParams'); // 输出标记
|
|
4
|
+
const { replaceInPackage } = require('../replaceInPackage');
|
|
5
|
+
const { resetPackageVersion } = require('../resetPackageVersion');
|
|
6
|
+
const autoEntryRootDir = require('../autoEntryRootDir');
|
|
7
7
|
const hasNeoProject = require('./hasNeoProject');
|
|
8
8
|
|
|
9
9
|
const cmpTemplateList = {
|
|
@@ -22,12 +22,16 @@ module.exports = function (projectName, type = 'react-ts') {
|
|
|
22
22
|
const finalProjectPath = path.resolve(process.cwd(), projectName);
|
|
23
23
|
|
|
24
24
|
if (hasNeoProject()) {
|
|
25
|
-
console.error(
|
|
25
|
+
console.error(
|
|
26
|
+
`${consoleTag}创建自定义组件项目失败,当前目录(${process.cwd()})已经是一个自定义组件项目,请勿重复创建。`
|
|
27
|
+
);
|
|
26
28
|
process.exit(1);
|
|
27
29
|
}
|
|
28
30
|
|
|
29
31
|
if (fs.existsSync(finalProjectPath)) {
|
|
30
|
-
console.error(
|
|
32
|
+
console.error(
|
|
33
|
+
`${consoleTag}创建自定义组件项目失败,当前已存在(${projectName})项目,请勿创建重名项目。`
|
|
34
|
+
);
|
|
31
35
|
process.exit(1);
|
|
32
36
|
}
|
|
33
37
|
|
|
@@ -2,7 +2,7 @@ const fs = require('fs-extra');
|
|
|
2
2
|
const path = require('path');
|
|
3
3
|
const AdmZip = require('adm-zip');
|
|
4
4
|
const _ = require('lodash');
|
|
5
|
-
const { consoleTag } = require('../
|
|
5
|
+
const { consoleTag } = require('../neoParams'); // 输出标记
|
|
6
6
|
const hasNeoProject = require('./hasNeoProject');
|
|
7
7
|
|
|
8
8
|
/**
|
|
@@ -116,7 +116,5 @@ module.exports = function (cmpType, _projectPath, assetsRoot) {
|
|
|
116
116
|
// 写入 zip 文件
|
|
117
117
|
zip.writeZip(zipPath);
|
|
118
118
|
|
|
119
|
-
console.log(`${consoleTag}已创建自定义组件源码 zip 包: ${zipFileName}`);
|
|
120
|
-
|
|
121
119
|
return zipPath;
|
|
122
120
|
};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
const fs = require('fs');
|
|
2
2
|
const path = require('path');
|
|
3
3
|
const _ = require('lodash');
|
|
4
|
-
const { resolveToCurrentRoot } = require('../
|
|
4
|
+
const { resolveToCurrentRoot } = require('../pathUtils');
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
7
|
* 从指定目录获取组件入口文件
|
|
@@ -70,6 +70,6 @@ module.exports = (defaultComponentsDir = './src/components', cmpType) => {
|
|
|
70
70
|
return {
|
|
71
71
|
widgetEntries,
|
|
72
72
|
linkDebugEntries,
|
|
73
|
-
cmpTypes
|
|
73
|
+
cmpTypes
|
|
74
74
|
};
|
|
75
75
|
};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
const fs = require('fs');
|
|
2
2
|
const path = require('path');
|
|
3
3
|
const _ = require('lodash');
|
|
4
|
-
const { resolveToCurrentRoot } = require('../
|
|
4
|
+
const { resolveToCurrentRoot } = require('../pathUtils');
|
|
5
5
|
const getCmpRegisterCode = require('../cmpUtils/getCmpRegisterCode');
|
|
6
6
|
const getCmpModelRegisterCode = require('../cmpUtils/getCmpModelRegisterCode');
|
|
7
7
|
/**
|
|
@@ -100,6 +100,6 @@ module.exports = (defaultComponentsDir = './src/components', cmpType) => {
|
|
|
100
100
|
return {
|
|
101
101
|
widgetEntries,
|
|
102
102
|
linkDebugEntries,
|
|
103
|
-
cmpTypes
|
|
103
|
+
cmpTypes
|
|
104
104
|
};
|
|
105
105
|
};
|