neo-cmp-cli 1.5.0-beta.3 → 1.5.0-beta.6
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/README.md +51 -14
- package/package.json +1 -1
- package/src/cmpUtils/createCmpByTemplate.js +50 -0
- package/src/cmpUtils/createCommonModulesCode.js +15 -15
- package/src/cmpUtils/{getCmpModelRegister.js → getCmpModelRegisterCode.js} +2 -2
- package/src/cmpUtils/{getCmpPreview.js → getCmpPreviewCode.js} +2 -2
- package/src/cmpUtils/{getCmpRegister.js → getCmpRegisterCode.js} +2 -2
- package/src/cmpUtils/getCmpTypeByDir.js +41 -0
- package/src/cmpUtils/hasCmpTypeByDir.js +11 -0
- package/src/{module → cmpUtils}/previewCmp.js +2 -2
- package/src/cmpUtils/publishCmp.js +18 -16
- package/src/config/default.config.js +1 -1
- package/src/module/index.js +144 -21
- package/src/module/main.js +15 -11
- package/src/module/neoInit.js +3 -0
- package/src/module/neoInitByCopy.js +3 -0
- package/src/neo/neoRequire.js +7 -7
- package/src/neo/neoService.js +32 -31
- package/src/oss/publish2oss.js +1 -1
- package/src/plugins/AddNeoRequirePlugin.js +5 -3
- package/src/projectUtils/createCmpProjectByTemplate.js +49 -0
- package/src/{cmpUtils → projectUtils}/getEntriesWithAutoRegister.js +4 -4
- package/src/template/antd-custom-cmp-template/README.md +2 -2
- package/src/template/antd-custom-cmp-template/neo.config.js +22 -14
- package/src/template/antd-custom-cmp-template/package.json +2 -2
- package/src/template/develop/neo-custom-cmp-template/neo.config.js +1 -1
- package/src/template/echarts-custom-cmp-template/README.md +2 -2
- package/src/template/echarts-custom-cmp-template/neo.config.js +19 -13
- package/src/template/echarts-custom-cmp-template/package.json +2 -2
- package/src/template/empty-cmp/index.tsx +51 -0
- package/src/template/empty-cmp/model.ts +77 -0
- package/src/template/empty-cmp/style.scss +72 -0
- package/src/template/empty-custom-cmp-template/.prettierrc.js +12 -0
- package/src/template/empty-custom-cmp-template/README.md +45 -0
- package/src/template/empty-custom-cmp-template/commitlint.config.js +59 -0
- package/src/template/empty-custom-cmp-template/neo.config.js +126 -0
- package/src/template/empty-custom-cmp-template/package.json +57 -0
- package/src/template/empty-custom-cmp-template/public/css/base.css +283 -0
- package/src/template/empty-custom-cmp-template/public/scripts/app/bluebird.js +6679 -0
- package/src/template/empty-custom-cmp-template/public/template.html +13 -0
- package/src/template/empty-custom-cmp-template/src/assets/css/common.scss +127 -0
- package/src/template/empty-custom-cmp-template/src/assets/css/mixin.scss +47 -0
- package/src/template/empty-custom-cmp-template/src/assets/img/NeoCRM.jpg +0 -0
- package/src/template/empty-custom-cmp-template/src/assets/img/custom-widget.svg +1 -0
- package/src/template/empty-custom-cmp-template/src/assets/img/favicon.png +0 -0
- package/src/template/empty-custom-cmp-template/src/assets/img/map.svg +1 -0
- package/src/template/empty-custom-cmp-template/src/components/README.md +3 -0
- package/src/template/empty-custom-cmp-template/tsconfig.json +68 -0
- package/src/template/neo-custom-cmp-template/README.md +2 -2
- package/src/template/neo-custom-cmp-template/neo.config.js +4 -26
- package/src/template/neo-custom-cmp-template/package.json +3 -5
- package/src/template/neo-custom-cmp-template/src/components/entity-detail/index.tsx +0 -2
- package/src/template/react-custom-cmp-template/README.md +2 -2
- package/src/template/react-custom-cmp-template/neo.config.js +20 -15
- package/src/template/react-custom-cmp-template/package.json +2 -2
- package/src/template/react-ts-custom-cmp-template/README.md +2 -2
- package/src/template/react-ts-custom-cmp-template/neo.config.js +19 -14
- package/src/template/react-ts-custom-cmp-template/package.json +2 -2
- package/src/template/vue2-custom-cmp-template/README.md +2 -2
- package/src/template/vue2-custom-cmp-template/neo.config.js +20 -15
- package/src/template/vue2-custom-cmp-template/package.json +2 -2
- package/src/utils/autoEntryRootDir.js +42 -0
- package/src/utils/replaceInFilesByMap.js +54 -0
- package/test/demo.js +2 -2
- /package/src/{cmpUtils → projectUtils}/getEntries.js +0 -0
- /package/src/{cmpUtils → projectUtils}/updatePublishLog.js +0 -0
package/README.md
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
## Neo 自定义组件开发工具
|
|
2
|
-
neo-cmp-cli 是 Neo 自定义组件开发工具,基于 [AKFun](https://github.com/wibetter/akfun) 的工程能力,提供
|
|
2
|
+
neo-cmp-cli 是 Neo 自定义组件开发工具,基于 [AKFun](https://github.com/wibetter/akfun) 的工程能力,提供 初始化、编译构建、预览调试、热更新、多技术栈支持和发布等功能。
|
|
3
3
|
|
|
4
4
|
### 主要特性
|
|
5
5
|
- **零配置**: 内置默认配置,开箱可用;
|
|
6
6
|
- **多技术栈**: 支持 Vue2、React、React+TypeScript 自定义组件的调试、构建与发布;
|
|
7
|
-
- **多构建场景**: 本地预览(含热更新/代理)、外链调试、库构建(UMD/ESM
|
|
7
|
+
- **多构建场景**: 本地预览(含热更新/代理)、外链调试、库构建(UMD/ESM)、部署&发布;
|
|
8
8
|
- **灵活可配**: 支持 构建入口、别名、代理、SASS 注入、ESLint/StyleLint、Babel/Loader/Plugin 扩展等配置;
|
|
9
9
|
- **样式与规范**: 内置 Autoprefixer、Sass、PostCSS、ESLint、StyleLint;
|
|
10
|
-
-
|
|
11
|
-
-
|
|
10
|
+
- **发布至 CDN**: 内置发布到对象存储(OSS)的能力,支持自定义对象存储配置;
|
|
11
|
+
- **发布至 NeoCRM 平台**: 支持一键发布到NeoCRM 平台的能力,需自行补充授权配置;
|
|
12
12
|
|
|
13
13
|
### 内置的自定义组件模板
|
|
14
14
|
创建自定义组件时(执行初始化命令 neo init)可选用。
|
|
@@ -40,8 +40,8 @@ neo preview
|
|
|
40
40
|
# 外链调试(在平台线上预览与调试)
|
|
41
41
|
neo linkDebug
|
|
42
42
|
|
|
43
|
-
# 构建并发布到
|
|
44
|
-
neo
|
|
43
|
+
# 构建并发布到 NeoCRM(需自行添加授权配置,并确保 package.json 的 name 唯一、version 不重复)
|
|
44
|
+
neo pushCmp
|
|
45
45
|
```
|
|
46
46
|
|
|
47
47
|
### 方法二:在现有业务项目中使用自定义组件开发工具
|
|
@@ -58,7 +58,7 @@ npm i neo-cmp-cli --save-dev
|
|
|
58
58
|
```bash
|
|
59
59
|
"preview": "neo preview",
|
|
60
60
|
"linkDebug": "neo linkDebug",
|
|
61
|
-
"
|
|
61
|
+
"pushCmp": "neo pushCmp"
|
|
62
62
|
```
|
|
63
63
|
##### 3) 初始化配置文件
|
|
64
64
|
```bash
|
|
@@ -76,10 +76,11 @@ npm run publish2oss
|
|
|
76
76
|
- **neo preview**: 本地预览自定义组件内容,默认支持热更新与接口代理。
|
|
77
77
|
- **neo linkDebug**: 外链调试模式,在平台端页面设计器中调试自定义组件。
|
|
78
78
|
- **neo publish2oss**: 构建并上传到对象存储(可自定义配置对象存储)。
|
|
79
|
+
- **neo pushCmp**: 构建并发布到NeoCRM平台(需自行添加授权配置)。
|
|
79
80
|
|
|
80
81
|
## 开发须知
|
|
81
82
|
#### 1)默认自动识别自定义组件
|
|
82
|
-
- **自动生成入口配置**: 当 `entry` 未配置时,自动从 `src/components` 目录下扫描并识别自定义组件,`src/components`
|
|
83
|
+
- **自动生成入口配置**: 当 `entry` 未配置时,自动从 `src/components` 目录下扫描并识别自定义组件,`src/components` 下的子目录名称作为自定义组件的名称,并以其目录下的 `index.ts/.tsx/.js/.jsx` 文件作为组件内容文件,model.[tj]s 作为模型内容文件;
|
|
83
84
|
- **自动注册自定义组件**: 当 `entry` 未配置时,自动生成自定义组件注册文件和模型注册文件,并注入到构建脚本中,无需用户手动编写注册文件([neo-register](https://www.npmjs.com/package/neo-register))。
|
|
84
85
|
|
|
85
86
|
#### 2)设置自定义组件属性配置项
|
|
@@ -128,16 +129,49 @@ neo linkDebug
|
|
|
128
129
|
##### 3. 页面设计器开启 debug 模式后,左侧会展示 外部链接 管理面板
|
|
129
130
|
将第 1 步生成的「外链脚本地址」添加进来,即可在此页面设计器 / 组件物料面板中看到对应自定义组件。
|
|
130
131
|
|
|
131
|
-
#### 6
|
|
132
|
-
执行 `neo
|
|
132
|
+
#### 6)发布自定义组件至 NeoCRM
|
|
133
|
+
执行 `neo pushCmp` 即可构建并发布自定义组件至 NeoCRM 平台,其构建后资源也会上传到 NeoCRM 平台端提供的 CDN 中。
|
|
133
134
|
|
|
134
135
|
##### 发布前请确保
|
|
135
136
|
- **package.json 的 name 唯一**
|
|
136
137
|
- **version 不重复**
|
|
137
|
-
|
|
138
|
+
|
|
139
|
+
##### 需自行添加授权配置
|
|
140
|
+
```javascript
|
|
141
|
+
module.exports = {
|
|
142
|
+
pushCmp: {
|
|
143
|
+
neoBaseURL: 'https://crm-cd.xiaoshouyi.com', // 平台根地址(默认:https://crm.xiaoshouyi.com)
|
|
144
|
+
tokenAPI: 'https://login-cd.xiaoshouyi.com/auc/oauth2/token', // Token 获取接口地址(默认:https://login.xiaoshouyi.com/auc/oauth2/token)
|
|
145
|
+
// NeoCRM 授权配置
|
|
146
|
+
authConfig: {
|
|
147
|
+
/**
|
|
148
|
+
* 客户端 ID 和 客户端秘钥 需通过 创建连接器 获取,
|
|
149
|
+
* 详细见:https://doc.xiaoshouyi.com / 创建连接器。
|
|
150
|
+
*/
|
|
151
|
+
client_id: 'xx', // 客户端 ID,从创建连接器的客户端信息中获取(Client_Id)
|
|
152
|
+
client_secret: 'xxx', // 客户端秘钥,从创建连接器的客户端信息中获取(Client_Secret)
|
|
153
|
+
username: 'xx', // 用户在销售易系统中的用户名
|
|
154
|
+
/**
|
|
155
|
+
* password 为 用户在销售易系统中的账号密码加上 8 位安全令牌。
|
|
156
|
+
* 例如,用户密码为 123456,安全令牌为 ABCDEFGH,则 password 的值应为 123456ABCDEFGH。
|
|
157
|
+
* 如何获取 安全令牌请见:https://doc.xiaoshouyi.com / OAuth安全认证 / 密码模式 / 获取令牌。
|
|
158
|
+
*/
|
|
159
|
+
password: 'xx xx' // 用户账户密码 + 8 位安全令牌
|
|
160
|
+
},
|
|
161
|
+
},
|
|
162
|
+
}
|
|
163
|
+
```
|
|
138
164
|
|
|
139
165
|
##### 支持发布指定自定义组件
|
|
140
|
-
执行 `neo
|
|
166
|
+
执行 `neo pushCmp --name=xxCmp`
|
|
167
|
+
|
|
168
|
+
#### 7)发布自定义组件至CDN
|
|
169
|
+
执行 `neo publish2oss` 即可构建对应自定义组件,并自动将构建后资源上传到对象存储(OSS)中。
|
|
170
|
+
|
|
171
|
+
##### 发布前请确保
|
|
172
|
+
- **package.json 的 name 唯一**
|
|
173
|
+
- **version 不重复**
|
|
174
|
+
- 可按需配置对象存储参数(支持自定义),默认使用内置对象存储配置。
|
|
141
175
|
|
|
142
176
|
##### 支持自定义对象存储配置
|
|
143
177
|
```javascript
|
|
@@ -159,6 +193,9 @@ module.exports = {
|
|
|
159
193
|
}
|
|
160
194
|
```
|
|
161
195
|
|
|
196
|
+
##### 支持发布指定自定义组件
|
|
197
|
+
执行 `neo publish2oss --name=xxCmp`
|
|
198
|
+
|
|
162
199
|
## 项目工程配置说明(neo.config.js)
|
|
163
200
|
neo-cmp-cli 默认提供完整配置;
|
|
164
201
|
如需自定义,使用 `neo config init` 生成 `neo.config.js` 并按需修改。
|
|
@@ -327,8 +364,8 @@ module.exports = {
|
|
|
327
364
|
```javascript
|
|
328
365
|
module.exports = {
|
|
329
366
|
neoCommonModule: {
|
|
330
|
-
|
|
331
|
-
neoExternals: ['xxModule_A'], // 自定义组件中需要剔除的模块(远程自定义组件中分享出来的模块),仅支持数组写法,需要和
|
|
367
|
+
remoteDeps: ['neo-custom-cmpA'], // 远程自定义组件,表示当前自定义组件 B 会用到的自定义组件
|
|
368
|
+
neoExternals: ['xxModule_A'], // 自定义组件中需要剔除的模块(远程自定义组件中分享出来的模块),仅支持数组写法,需要和 remoteDeps 配合使用
|
|
332
369
|
},
|
|
333
370
|
}
|
|
334
371
|
```
|
package/package.json
CHANGED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
const fs = require('fs-extra');
|
|
2
|
+
const path = require('path');
|
|
3
|
+
const _ = require('lodash');
|
|
4
|
+
const { consoleTag } = require('../utils/neoParams'); // 输出标记
|
|
5
|
+
const replaceInFilesByMap = require('../utils/replaceInFilesByMap');
|
|
6
|
+
const hasCmpTypeByDir = require('./hasCmpTypeByDir');
|
|
7
|
+
|
|
8
|
+
// 自定义组件内容模板信息
|
|
9
|
+
const curCmpTemplate = {
|
|
10
|
+
// 需要替换掉的字段信息(模板中的字段)
|
|
11
|
+
widgetInfo: {
|
|
12
|
+
cmpName: 'CustomCmp',
|
|
13
|
+
modelName: 'CustomCmpModel',
|
|
14
|
+
cmpClassName: 'custom-cmp-container',
|
|
15
|
+
cmpType: 'xx-custom-cmp',
|
|
16
|
+
cmpLabel: 'xx组件',
|
|
17
|
+
},
|
|
18
|
+
dir: path.resolve(__dirname, '../template/empty-cmp')
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* 创建自定义组件
|
|
23
|
+
* @param {*} cmpName 自定义组件名称
|
|
24
|
+
*/
|
|
25
|
+
module.exports = function (cmpName) {
|
|
26
|
+
const currentTemplateDir = curCmpTemplate.dir;
|
|
27
|
+
const finalCmpName = cmpName || 'neoCustomCmp';
|
|
28
|
+
const finalCmpPath = path.resolve(process.cwd(), finalCmpName);
|
|
29
|
+
|
|
30
|
+
if (hasCmpTypeByDir(cmpType)) {
|
|
31
|
+
console.error(`${consoleTag}创建自定义组件失败,当前已经存在${cmpType}自定义组件。`);
|
|
32
|
+
process.exit(1);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
fs.copy(currentTemplateDir, finalCmpPath)
|
|
36
|
+
.then(() => {
|
|
37
|
+
const curCmpName = _.camelCase(cmpName);
|
|
38
|
+
const cmpType = _.kebabCase(cmpName);
|
|
39
|
+
replaceInFilesByMap(finalCmpPath, {
|
|
40
|
+
[curCmpTemplate.widgetInfo.cmpName]: curCmpName,
|
|
41
|
+
[curCmpTemplate.widgetInfo.modelName]: `${curCmpName}Model`,
|
|
42
|
+
[curCmpTemplate.widgetInfo.cmpClassName]: `${cmpType}-container`,
|
|
43
|
+
[curCmpTemplate.widgetInfo.cmpType]: cmpType,
|
|
44
|
+
[curCmpTemplate.widgetInfo.cmpLabel]: `${cmpType}组件`,
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
console.log(`${consoleTag}已创建自定义组件(${finalCmpName})!`);
|
|
48
|
+
})
|
|
49
|
+
.catch((err) => console.error(`${consoleTag}自定义组件创建失败(${finalCmpName}):`, err));
|
|
50
|
+
};;
|
|
@@ -9,15 +9,15 @@ const { isPlainObject } = require('lodash');
|
|
|
9
9
|
* @returns 组件预览代码
|
|
10
10
|
*/
|
|
11
11
|
const createCommonModulesCode = (neoCommonModule, cmpTypes) => {
|
|
12
|
-
const {neoExports,
|
|
12
|
+
const {neoExports, remoteDeps} = neoCommonModule;
|
|
13
13
|
|
|
14
|
-
if (!neoExports && !
|
|
14
|
+
if (!neoExports && !remoteDeps) {
|
|
15
15
|
return '';
|
|
16
16
|
}
|
|
17
17
|
// 记录当前自定义组件共享出去的模块
|
|
18
18
|
const CustomCmpCommonModules = {};
|
|
19
|
-
//
|
|
20
|
-
const
|
|
19
|
+
// 记录当前自定义组件需要的远程依赖组件
|
|
20
|
+
const CustomCmpRemoteDeps = {};
|
|
21
21
|
|
|
22
22
|
// 根据 neoExports 获取共享的依赖模块
|
|
23
23
|
if (Array.isArray(neoExports) && neoExports.length > 0) {
|
|
@@ -35,10 +35,10 @@ const createCommonModulesCode = (neoCommonModule, cmpTypes) => {
|
|
|
35
35
|
process.exit(1);
|
|
36
36
|
}
|
|
37
37
|
|
|
38
|
-
// 根据 cmpTypes 和
|
|
39
|
-
if (Array.isArray(
|
|
38
|
+
// 根据 cmpTypes 和 remoteDeps 设置远程依赖组件信息
|
|
39
|
+
if (Array.isArray(remoteDeps) && remoteDeps.length > 0) {
|
|
40
40
|
cmpTypes.forEach((cmpType) => {
|
|
41
|
-
|
|
41
|
+
CustomCmpRemoteDeps[cmpType] = remoteDeps;
|
|
42
42
|
});
|
|
43
43
|
}
|
|
44
44
|
|
|
@@ -58,7 +58,7 @@ const createCommonModulesCode = (neoCommonModule, cmpTypes) => {
|
|
|
58
58
|
*/
|
|
59
59
|
import { isPlainObject } from 'lodash';
|
|
60
60
|
const CustomCmpCommonModules = ${customCmpCommonModulesCode};
|
|
61
|
-
const
|
|
61
|
+
const CustomCmpRemoteDeps = ${JSON.stringify(CustomCmpRemoteDeps)};
|
|
62
62
|
|
|
63
63
|
// 用于添加共享的依赖模块
|
|
64
64
|
const addNeoCommonModules = (modules) => {
|
|
@@ -88,21 +88,21 @@ const addNeoCommonModules = (modules) => {
|
|
|
88
88
|
}
|
|
89
89
|
}
|
|
90
90
|
|
|
91
|
-
//
|
|
92
|
-
const
|
|
91
|
+
// 用于添加自定义组件的远程依赖组件(关联使用)
|
|
92
|
+
const addNeoRemoteDeps = (remoteDeps) => {
|
|
93
93
|
if (!window.__NeoCommonModules) {
|
|
94
94
|
window.__NeoCommonModules = {}
|
|
95
95
|
}
|
|
96
|
-
if (!window.__NeoCommonModules.
|
|
97
|
-
window.__NeoCommonModules.
|
|
96
|
+
if (!window.__NeoCommonModules.__neoRemoteDeps) {
|
|
97
|
+
window.__NeoCommonModules.__neoRemoteDeps = {}
|
|
98
98
|
}
|
|
99
|
-
if (isPlainObject(
|
|
100
|
-
window.__NeoCommonModules.
|
|
99
|
+
if (isPlainObject(remoteDeps)) {
|
|
100
|
+
window.__NeoCommonModules.__neoRemoteDeps = Object.assign(window.__NeoCommonModules.__neoRemoteDeps, remoteDeps)
|
|
101
101
|
}
|
|
102
102
|
}
|
|
103
103
|
|
|
104
104
|
addNeoCommonModules(CustomCmpCommonModules);
|
|
105
|
-
|
|
105
|
+
addNeoRemoteDeps(CustomCmpRemoteDeps);
|
|
106
106
|
`;
|
|
107
107
|
|
|
108
108
|
// 创建存放 cli 的临时目录
|
|
@@ -7,7 +7,7 @@ const { resolveToCurrentRoot } = require('../utils/pathUtils');
|
|
|
7
7
|
* @param {*} cmpName 自定义组件名称
|
|
8
8
|
* @returns 组件注册文件内容
|
|
9
9
|
*/
|
|
10
|
-
const
|
|
10
|
+
const getCmpModelRegisterCode = (cmpsDir, cmpName) => {
|
|
11
11
|
const cpmModelDir = resolveToCurrentRoot(`${cmpsDir}/${cmpName}/model`);
|
|
12
12
|
|
|
13
13
|
/*
|
|
@@ -28,4 +28,4 @@ registerNeoEditorModel(CustomCmpModel, '${cmpName}');
|
|
|
28
28
|
`;
|
|
29
29
|
};
|
|
30
30
|
|
|
31
|
-
module.exports =
|
|
31
|
+
module.exports = getCmpModelRegisterCode;
|
|
@@ -7,7 +7,7 @@ const { resolveToCurrentRoot } = require('../utils/pathUtils');
|
|
|
7
7
|
* @param {*} cmpName 自定义组件名称
|
|
8
8
|
* @returns 组件预览代码
|
|
9
9
|
*/
|
|
10
|
-
const
|
|
10
|
+
const getCmpPreviewCode = (cmpsDir, cmpName) => {
|
|
11
11
|
const cpmDir = resolveToCurrentRoot(`${cmpsDir}/${cmpName}`);
|
|
12
12
|
const cpmModelDir = resolveToCurrentRoot(`${cmpsDir}/${cmpName}/model`);
|
|
13
13
|
|
|
@@ -37,4 +37,4 @@ ReactDOM.render(
|
|
|
37
37
|
`;
|
|
38
38
|
};
|
|
39
39
|
|
|
40
|
-
module.exports =
|
|
40
|
+
module.exports = getCmpPreviewCode;
|
|
@@ -7,7 +7,7 @@ const { resolveToCurrentRoot } = require('../utils/pathUtils');
|
|
|
7
7
|
* @param {*} cmpName 自定义组件名称
|
|
8
8
|
* @returns 组件注册文件内容
|
|
9
9
|
*/
|
|
10
|
-
const
|
|
10
|
+
const getCmpRegisterCode = (cmpsDir, cmpName) => {
|
|
11
11
|
const cpmIndexDir = resolveToCurrentRoot(`${cmpsDir}/${cmpName}/index`);
|
|
12
12
|
|
|
13
13
|
/*
|
|
@@ -28,4 +28,4 @@ registerNeoCmp(CustomCmp, '${cmpName}');
|
|
|
28
28
|
`;
|
|
29
29
|
};
|
|
30
30
|
|
|
31
|
-
module.exports =
|
|
31
|
+
module.exports = getCmpRegisterCode;
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
const fs = require('fs');
|
|
2
|
+
const path = require('path');
|
|
3
|
+
const { resolveToCurrentRoot } = require('../utils/pathUtils');
|
|
4
|
+
/**
|
|
5
|
+
* 根据当前组件目录,获取所有组件类型
|
|
6
|
+
* @param {*} componentsBaseDir 自定义组件目录
|
|
7
|
+
* @returns 组件类型列表
|
|
8
|
+
*/
|
|
9
|
+
const getCmpTypeByDir = (componentsBaseDir = './src/components') => {
|
|
10
|
+
const componentsDir = resolveToCurrentRoot(componentsBaseDir);
|
|
11
|
+
if (!fs.existsSync(componentsDir)) {
|
|
12
|
+
console.error(`未找到自定义组件目录,请检查 ${componentsDir} 目录是否存在。`);
|
|
13
|
+
// 退出进程
|
|
14
|
+
process.exit(1);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
try {
|
|
18
|
+
// 读取组件目录下的所有子目录
|
|
19
|
+
const dirs = fs.readdirSync(componentsDir);
|
|
20
|
+
const cmpTypes = [];
|
|
21
|
+
|
|
22
|
+
// 遍历所有目录,过滤出有效的组件类型
|
|
23
|
+
dirs.forEach((dir) => {
|
|
24
|
+
const dirPath = path.join(componentsDir, dir);
|
|
25
|
+
const stat = fs.statSync(dirPath);
|
|
26
|
+
|
|
27
|
+
// 只处理目录,过滤掉隐藏目录和 node_modules
|
|
28
|
+
if (stat.isDirectory() && !dir.startsWith('.') && dir !== 'node_modules') {
|
|
29
|
+
cmpTypes.push(dir);
|
|
30
|
+
}
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
return cmpTypes;
|
|
34
|
+
} catch (error) {
|
|
35
|
+
console.error('获取组件类型失败(getCmpTypeByDir):', error);
|
|
36
|
+
// 退出进程
|
|
37
|
+
process.exit(1);
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
module.exports = getCmpTypeByDir;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
const getCmpTypeByDir = require('./getCmpTypeByDir');
|
|
2
|
+
/**
|
|
3
|
+
* 判断当前组件目录是否已经存在该组件类型
|
|
4
|
+
* @param {*} componentsBaseDir 自定义组件目录
|
|
5
|
+
* @param {*} cmpType 组件类型
|
|
6
|
+
* @returns Boolean
|
|
7
|
+
*/
|
|
8
|
+
module.exports = (cmpType) => {
|
|
9
|
+
const cmpTypes = getCmpTypeByDir();
|
|
10
|
+
return cmpTypes.includes(cmpType);
|
|
11
|
+
};;
|
|
@@ -2,7 +2,7 @@ const fs = require('fs');
|
|
|
2
2
|
const akfun = require('akfun');
|
|
3
3
|
const { consoleTag } = require('../utils/neoParams'); // 输出标记
|
|
4
4
|
const { resolveToCurrentRoot } = require('../utils/pathUtils');
|
|
5
|
-
const
|
|
5
|
+
const getCmpPreviewCode = require('../cmpUtils/getCmpPreviewCode'); // 获取自定义组件预览代码
|
|
6
6
|
|
|
7
7
|
/**
|
|
8
8
|
* 用于预览指定自定义组件的脚本
|
|
@@ -35,7 +35,7 @@ module.exports = (config, cmpName, defaultComponentsDir = './src/components') =>
|
|
|
35
35
|
fs.mkdirSync(cmpTempDir);
|
|
36
36
|
}
|
|
37
37
|
|
|
38
|
-
const cmpPreviewContent =
|
|
38
|
+
const cmpPreviewContent = getCmpPreviewCode(cmpsDir, cmpName);
|
|
39
39
|
fs.writeFileSync(`${cmpTempDir}/preview.jsx`, cmpPreviewContent);
|
|
40
40
|
|
|
41
41
|
// 将临时预览文件添加到预览配置中
|
|
@@ -99,8 +99,6 @@ const buildComponentData = async (assetsRoot, cmpInfo) => {
|
|
|
99
99
|
}
|
|
100
100
|
const widgetName = _.camelCase(cmpType);
|
|
101
101
|
const modelFile = path.join(assetsRoot, `${widgetName}Model.js`);
|
|
102
|
-
|
|
103
|
-
let CatchCustomCmpModelClass = null;
|
|
104
102
|
|
|
105
103
|
// 为 Node.js 环境设置全局 window 对象(模型文件可能需要)
|
|
106
104
|
// 使用 globalThis 以确保在 Node.js 和浏览器环境中都能工作
|
|
@@ -109,6 +107,7 @@ const buildComponentData = async (assetsRoot, cmpInfo) => {
|
|
|
109
107
|
globalThis.window = {
|
|
110
108
|
console: console,
|
|
111
109
|
neoRequire: () => {},
|
|
110
|
+
postMessage: () => {},
|
|
112
111
|
// 可以添加其他常用的 window 属性
|
|
113
112
|
};
|
|
114
113
|
}
|
|
@@ -124,35 +123,38 @@ const buildComponentData = async (assetsRoot, cmpInfo) => {
|
|
|
124
123
|
console.error(`未找到自定义组件模型文件,请检查以下路径是否存在:`, modelFile);
|
|
125
124
|
return null;
|
|
126
125
|
}
|
|
127
|
-
|
|
128
|
-
if (!CatchCustomCmpModelClass || typeof CatchCustomCmpModelClass !== 'function') {
|
|
126
|
+
if (!window.NEOEditorCustomModels) {
|
|
129
127
|
console.error(`模型文件未导出有效模型方法(CatchCustomCmpModelClass),模型文件地址: ${modelFile} `);
|
|
130
128
|
return null;
|
|
131
129
|
}
|
|
132
130
|
|
|
133
|
-
|
|
134
|
-
|
|
131
|
+
const ModelClass = window.NEOEditorCustomModels[cmpType];
|
|
132
|
+
if (!ModelClass) {
|
|
133
|
+
console.error(`未找到自定义组件模型类(${cmpType}),模型文件地址: ${modelFile} `);
|
|
134
|
+
return null;
|
|
135
|
+
}
|
|
135
136
|
// 实例化模型类
|
|
136
137
|
const modelInstance = new ModelClass();
|
|
137
138
|
|
|
138
139
|
if (!modelInstance) {
|
|
139
|
-
console.error(
|
|
140
|
+
console.error(`未找到自定义组件模型信息(${cmpType}),模型文件地址: ${modelFile} `);
|
|
140
141
|
return null;
|
|
141
142
|
}
|
|
142
143
|
|
|
143
144
|
// 构建组件数据,合并模型实例的信息
|
|
144
145
|
const curCmpInfo = {
|
|
145
146
|
...cmpInfo,
|
|
147
|
+
plugin: cmpInfo.modelAsset,
|
|
146
148
|
version: currentPackageJson.version || '1.0.0',
|
|
147
149
|
framework: currentPackageJson.framework ? getFramework(currentPackageJson.framework) : '0', // 0: React, 1: vue2, 2: jQuery, 3: vue3
|
|
148
150
|
// 从模型实例中提取并设置组件信息
|
|
149
151
|
label: modelInstance.label || cmpType,
|
|
150
152
|
description: modelInstance.description || '',
|
|
151
|
-
componentCategory: modelInstance.tags || [],
|
|
153
|
+
componentCategory: (modelInstance.tags || []).join(','),
|
|
152
154
|
icon: modelInstance.iconSrc,
|
|
153
|
-
defaultProps: modelInstance.defaultComProps || {},
|
|
154
|
-
previewProps: modelInstance.previewComProps || {},
|
|
155
|
-
propsSchema: modelInstance.propsSchema || [],
|
|
155
|
+
defaultProps: JSON.stringify(modelInstance.defaultComProps || {}),
|
|
156
|
+
previewProps: JSON.stringify(modelInstance.previewComProps || {}),
|
|
157
|
+
propsSchema: JSON.stringify(modelInstance.propsSchema || []),
|
|
156
158
|
events: modelInstance.events || [],
|
|
157
159
|
actions: modelInstance.actions || [],
|
|
158
160
|
// 如果模型实例中有其他属性,也可以添加
|
|
@@ -161,7 +163,7 @@ const buildComponentData = async (assetsRoot, cmpInfo) => {
|
|
|
161
163
|
enableDuplicate: modelInstance.enableDuplicate !== undefined ? modelInstance.enableDuplicate : true
|
|
162
164
|
};
|
|
163
165
|
|
|
164
|
-
console.log(
|
|
166
|
+
console.log(`自定义组件模型信息(${cmpType}):`, curCmpInfo);
|
|
165
167
|
return curCmpInfo;
|
|
166
168
|
} catch (error) {
|
|
167
169
|
console.error(`自定义组件模型文件解析失败 (${modelFile || '未知路径'}):`, error.message);
|
|
@@ -182,13 +184,13 @@ const buildComponentData = async (assetsRoot, cmpInfo) => {
|
|
|
182
184
|
* @param {object} config 配置信息
|
|
183
185
|
* @param {string} assetsRoot 构建产物的目录
|
|
184
186
|
*/
|
|
185
|
-
const
|
|
187
|
+
const pushCmp = async (config, cmpType) => {
|
|
186
188
|
const {
|
|
187
|
-
|
|
189
|
+
authConfig: credentials
|
|
188
190
|
} = config;
|
|
189
191
|
|
|
190
192
|
if (!credentials) {
|
|
191
|
-
console.error('未找到 NeoCRM 平台授权配置(neo.config.js /
|
|
193
|
+
console.error('未找到 NeoCRM 平台授权配置(neo.config.js / pushCmp / authConfig)。');
|
|
192
194
|
return;
|
|
193
195
|
}
|
|
194
196
|
|
|
@@ -227,4 +229,4 @@ const publishCmp = async (config, cmpType) => {
|
|
|
227
229
|
}
|
|
228
230
|
};
|
|
229
231
|
|
|
230
|
-
module.exports =
|
|
232
|
+
module.exports = pushCmp;
|