neo-cmp-cli 1.7.12 → 1.7.15-beta.1

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.
Files changed (33) hide show
  1. package/package.json +1 -1
  2. package/src/module/main.js +24 -94
  3. package/src/neo/neoRequire.js +10 -0
  4. package/src/neo/neoService.js +75 -7
  5. package/src/template/antd-custom-cmp-template/package.json +1 -1
  6. package/src/template/antd-custom-cmp-template/src/components/dataDashboard/model.ts +15 -1
  7. package/src/template/antd-custom-cmp-template/src/components/infoCard/model.ts +15 -1
  8. package/src/template/develop/neo-custom-cmp-template/src/components/contactCardList/model.ts +1 -1
  9. package/src/template/develop/neo-custom-cmp-template/src/components/contactForm/model.ts +1 -1
  10. package/src/template/develop/neo-custom-cmp-template/src/components/neoEntityGrid/model.ts +1 -1
  11. package/src/template/echarts-custom-cmp-template/package.json +2 -2
  12. package/src/template/echarts-custom-cmp-template/src/components/chartWidget/model.ts +15 -1
  13. package/src/template/echarts-custom-cmp-template/src/components/mapWidget/model.ts +15 -1
  14. package/src/template/empty-cmp/model.ts +15 -1
  15. package/src/template/empty-custom-cmp-template/package.json +1 -1
  16. package/src/template/neo-custom-cmp-template/package.json +3 -3
  17. package/src/template/neo-custom-cmp-template/src/components/entityCardList/model.ts +15 -1
  18. package/src/template/neo-custom-cmp-template/src/components/entityDetail/model.ts +15 -1
  19. package/src/template/neo-custom-cmp-template/src/components/entityForm/model.ts +15 -1
  20. package/src/template/neo-custom-cmp-template/src/components/entityTable/model.ts +15 -1
  21. package/src/template/react-custom-cmp-template/package.json +1 -1
  22. package/src/template/react-custom-cmp-template/src/components/infoCard/model.js +15 -1
  23. package/src/template/react-ts-custom-cmp-template/package.json +1 -1
  24. package/src/template/react-ts-custom-cmp-template/src/components/listWidget/model.ts +15 -1
  25. package/src/template/vue2-custom-cmp-template/package.json +1 -1
  26. package/src/template/vue2-custom-cmp-template/src/components/vueInfoCard/model.js +15 -1
  27. package/src/utils/cmpUtils/pushCmp.js +22 -5
  28. package/src/utils/configureNeoBuild.js +109 -0
  29. package/src/utils/generateEntries.js +5 -15
  30. package/src/utils/projectUtils/getEntries.js +7 -2
  31. package/src/utils/projectUtils/getEntriesWithAutoRegister.js +9 -6
  32. package/test/demo.js +3 -3
  33. package/test/deprecate-versions.js +1 -1
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "neo-cmp-cli",
3
- "version": "1.7.12",
3
+ "version": "1.7.15-beta.1",
4
4
  "description": "前端脚手架:自定义组件开发工具,支持react 和 vue2.0技术栈。",
5
5
  "keywords": [
6
6
  "neo-cli",
@@ -10,98 +10,39 @@ const publish2oss = require('../oss/publish2oss');
10
10
  const pushCmp = require('../utils/cmpUtils/pushCmp');
11
11
  const previewCmp = require('../utils/cmpUtils/previewCmp');
12
12
  const generateEntries = require('../utils/generateEntries');
13
- const AddNeoRequirePlugin = require('../plugins/AddNeoRequirePlugin');
14
- const { getExternalsByNeoCommonModules } = require('../neo/neoRequire');
15
13
  // const { MFPlugins } = require('../neo/webpack.mf');
16
- const createCommonModulesCode = require('../utils/cmpUtils/createCommonModulesCode');
17
14
  const createCmpByTemplate = require('../utils/cmpUtils/createCmpByTemplate');
18
15
  const createCmpProjectByTemplate = require('../utils/projectUtils/createCmpProjectByTemplate');
19
16
  const pullCmp = require('../utils/cmpUtils/pullCmp');
20
17
  const deleteCmp = require('../utils/cmpUtils/deleteCmp');
21
18
  const openProject = require('../utils/projectUtils/openProject');
19
+ const { configureNeoBuild } = require('../utils/configureNeoBuild');
22
20
  const { errorLog, successLog } = require('../utils/common');
23
21
 
24
22
  const getValue = (originValue, defaultValue) => {
25
23
  return originValue !== undefined ? originValue : defaultValue;
26
24
  };
27
25
 
28
- const neoCommonModule = curConfig.neoCommonModule || {};
29
- // 自定义组件 需要剔除的依赖模块
30
- const cmpNeoExternals = neoCommonModule.externals || [];
31
-
32
- /**
33
- * 添加 AddNeoRequirePlugin 到 webpack 配置
34
- * @param {object} webpackConfig webpack 配置对象
35
- * @param {object} [options] 选项
36
- * @param {boolean} [options.verbose] 是否启用详细日志,默认为 false
37
- */
38
- function addNeoRequirePlugin(webpackConfig, options = {}) {
39
- const { verbose = false } = options;
40
- const plugin = new AddNeoRequirePlugin({ verbose });
41
-
42
- if (webpackConfig && webpackConfig.plugins && Array.isArray(webpackConfig.plugins)) {
43
- webpackConfig.plugins.push(plugin);
44
- } else {
45
- webpackConfig.plugins = [plugin];
46
- }
47
- }
48
-
49
- /**
50
- * 添加 Neo externals 配置
51
- * @param {object} config 配置对象(dev 或 build2lib)
52
- * @param {object} externalsConfig 现有的 externals 配置
53
- */
54
- function addNeoExternals(config, externalsConfig) {
55
- const externals = getExternalsByNeoCommonModules(cmpNeoExternals);
56
- if (externalsConfig && _.isPlainObject(externalsConfig)) {
57
- config.externals = Object.assign(externalsConfig, externals);
58
- } else {
59
- config.externals = externals;
60
- }
61
- }
62
-
63
- /**
64
- * 创建并注入 commonModulesCode 到 entry
65
- * @param {object} config 配置对象(dev 或 build2lib)
66
- * @param {array} cmpTypes 组件类型列表
67
- * @param {object} [options] 选项
68
- * @param {boolean} [options.excludeModel] 是否排除 Model 结尾的 entry,默认为 false
69
- */
70
- function injectCommonModulesCode(config, cmpTypes, options = {}) {
71
- const { excludeModel = false } = options;
72
- const commonModulesFilePath = createCommonModulesCode(neoCommonModule, cmpTypes);
73
-
74
- if (commonModulesFilePath && config.entry) {
75
- Object.keys(config.entry).forEach((name) => {
76
- // 如果 excludeModel 为 true,排除 Model 结尾的文件
77
- if (!excludeModel || !name.endsWith('Model')) {
78
- config.entry[name] = [commonModulesFilePath].concat(config.entry[name]);
79
- }
80
- });
81
- }
82
- }
83
-
84
26
  /**
85
27
  * 生成并设置 entry 配置
86
28
  * @param {object} config 配置对象(dev 或 build2lib)
87
29
  * @param {object} options 生成选项
88
30
  * @param {string} options.entryType entry 类型:'widget' | 'linkDebug'
89
31
  * @param {string} [options.cmpType] 可选的组件类型
90
- * @param {boolean} [options.forceGetCmpTypes] 是否强制获取 cmpTypes
91
32
  * @returns {array} cmpTypes 组件类型列表
92
33
  */
93
34
  function setupEntries(config, options) {
94
- const { entryType, cmpType, forceGetCmpTypes = false } = options;
35
+ const { entryType, cmpType } = options;
95
36
 
96
37
  let cmpTypes = [];
38
+ let defaultExports = {};
97
39
  try {
98
- const { entries, cmpTypes: generatedCmpTypes } = generateEntries({
40
+ const { entries, cmpTypes: generatedCmpTypes, defaultExports: generatedDefaultExports } = generateEntries({
99
41
  configEntry: config.entry,
100
42
  disableAutoRegister: config.disableAutoRegister,
101
43
  componentsDir: curConfig.componentsDir,
102
44
  entryType,
103
- cmpType,
104
- forceGetCmpTypes
45
+ cmpType
105
46
  });
106
47
 
107
48
  if (entries && Object.keys(entries).length > 0) {
@@ -109,12 +50,17 @@ function setupEntries(config, options) {
109
50
  cmpTypes = generatedCmpTypes;
110
51
  console.info('已自动生成 entry 入口配置:', entries);
111
52
  }
53
+
54
+ defaultExports = generatedDefaultExports;
112
55
  } catch (error) {
113
56
  errorLog(error.message);
114
57
  process.exit(1);
115
58
  }
116
59
 
117
- return cmpTypes;
60
+ return {
61
+ cmpTypes,
62
+ defaultExports
63
+ };
118
64
  }
119
65
 
120
66
  /**
@@ -126,27 +72,6 @@ function prepareBuild2LibConfig(sourceConfig) {
126
72
  return Object.assign(curConfig.build2lib, sourceConfig);
127
73
  }
128
74
 
129
- /**
130
- * 配置 webpack 插件、externals 和 commonModulesCode(用于 linkDebug、publish2oss、pushCmp)
131
- * @param {object} config 配置对象(dev 或 build2lib)
132
- * @param {array} cmpTypes 组件类型列表
133
- * @param {object} [options] 选项
134
- * @param {boolean} [options.verbose] 是否启用详细日志,默认为 false
135
- * @param {boolean} [options.excludeModel] 是否排除 Model 结尾的 entry,默认为 false
136
- */
137
- function configureNeoBuild(config, cmpTypes, options = {}) {
138
- const { verbose = false, excludeModel = false } = options;
139
-
140
- // 添加自定义 webpack 插件
141
- addNeoRequirePlugin(curConfig.webpack, { verbose });
142
-
143
- // 添加内置 Neo 的 externals 配置
144
- addNeoExternals(config, config.externals);
145
-
146
- // 创建并注入 commonModulesCode
147
- injectCommonModulesCode(config, cmpTypes, { excludeModel });
148
- }
149
-
150
75
  module.exports = {
151
76
  neoInit,
152
77
  neoInitByCopy,
@@ -190,13 +115,14 @@ module.exports = {
190
115
  curConfig.webpack.ignoreNodeModules = false;
191
116
 
192
117
  // 生成并设置 entry 配置
193
- const curCmpTypes = setupEntries(curConfig.dev, {
194
- entryType: 'linkDebug',
195
- forceGetCmpTypes: true // linkDebug 需要 cmpTypes 来生成 commonModulesCode
118
+ const {cmpTypes: curCmpTypes, defaultExports} = setupEntries(curConfig.dev, {
119
+ entryType: 'linkDebug'
196
120
  });
197
121
 
198
122
  // 配置 webpack 插件、externals 和 commonModulesCode
199
- configureNeoBuild(curConfig.dev, curCmpTypes, {
123
+ configureNeoBuild(curConfig.dev, {
124
+ cmpTypes: curCmpTypes,
125
+ defaultExports,
200
126
  verbose: true,
201
127
  excludeModel: false // linkDebug 不排除 Model
202
128
  });
@@ -218,13 +144,15 @@ module.exports = {
218
144
  curConfig.build2lib = prepareBuild2LibConfig(publish2ossConfig);
219
145
 
220
146
  // 生成并设置 entry 配置
221
- const curCmpTypes = setupEntries(curConfig.build2lib, {
147
+ const {cmpTypes: curCmpTypes, defaultExports} = setupEntries(curConfig.build2lib, {
222
148
  entryType: 'widget',
223
149
  cmpType
224
150
  });
225
151
 
226
152
  // 配置 webpack 插件、externals 和 commonModulesCode
227
- configureNeoBuild(curConfig.build2lib, curCmpTypes, {
153
+ configureNeoBuild(curConfig.build2lib, {
154
+ cmpTypes: curCmpTypes,
155
+ defaultExports,
228
156
  verbose: true,
229
157
  excludeModel: true // publish2oss 排除 Model 结尾的文件
230
158
  });
@@ -246,13 +174,15 @@ module.exports = {
246
174
  curConfig.build2lib = prepareBuild2LibConfig(pushCmpConfig);
247
175
 
248
176
  // 生成并设置 entry 配置
249
- const curCmpTypes = setupEntries(curConfig.build2lib, {
177
+ const {cmpTypes: curCmpTypes, defaultExports} = setupEntries(curConfig.build2lib, {
250
178
  entryType: 'widget',
251
179
  cmpType
252
180
  });
253
181
 
254
182
  // 配置 webpack 插件、externals 和 commonModulesCode
255
- configureNeoBuild(curConfig.build2lib, curCmpTypes, {
183
+ configureNeoBuild(curConfig.build2lib, {
184
+ cmpTypes: curCmpTypes,
185
+ defaultExports,
256
186
  verbose: false,
257
187
  excludeModel: true // pushCmp 排除 Model 结尾的文件
258
188
  });
@@ -50,7 +50,17 @@ const addNeoCommonModules = (modules) => {
50
50
  const curModule = modules[moduleId];
51
51
  const curCommonModule = window.__NeoCommonModules[moduleId];
52
52
 
53
+ /**
54
+ * 如果 Neo 共享出来的依赖模块已经存在,则合并到 window.__NeoCommonModules 中
55
+ * 目的:解决依赖加载顺序问题,确保存在依赖的组件无论其加载顺序如何都能正常运行。
56
+ *
57
+ * 疑问1: 为什么 neoRequire 要返回一个 空的默认模块对象?
58
+ * 答:组件A 依赖 组件B 时,当 组件A 先加载(挂载对应的 asset 资源脚本)会报错,为了避免挂载时报错返回一个默认的空模块对象。
59
+ * 疑问2: 为什么不直接替换已有的模块,而是进行覆盖式合并(保持引用关联)?
60
+ * 答:为了避免依赖模块的引用关系被破坏,保持引用关联。确保动态注册进来的模块可以被提前挂载的组件所使用。
61
+ */
53
62
  if (curCommonModule && Object.keys(curCommonModule).length < 3) {
63
+ // 如果是默认模块对象,则覆盖式合并(保持引用关联)
54
64
  window.__NeoCommonModules[moduleId] = Object.assign(window.__NeoCommonModules[moduleId], curModule);
55
65
 
56
66
  // 处理模块中的特殊属性
@@ -14,11 +14,14 @@ const NeoCrmAPI = {
14
14
  neoBaseURL: 'https://crm.xiaoshouyi.com', // 平台根地址
15
15
  loginAPI: 'https://login-cd.xiaoshouyi.com/auc/oauth2/auth', // code 获取接口地址
16
16
  tokenAPI: 'https://login.xiaoshouyi.com/auc/oauth2/token', // Token 获取接口地址
17
- uploadAPI: '/rest/metadata/v3.0/ui/customComponents/actions/upload', // 文件上传接口地址
18
17
  delete: '/rest/metadata/v3.0/ui/customComponents',
19
- query: '/rest/metadata/v3.0/ui/customComponents/actions/queryCustomComponents', // 带分页
20
- queryAll: '/rest/metadata/v3.0/ui/customComponents/actions/queryAllCustomComponents', // 不带分页
21
- saveAPI: '/rest/metadata/v3.0/ui/customComponents/actions/saveOrUpdateComponent' // 创建或者保存接口地址
18
+ saveAPI: '/rest/metadata/v3.0/ui/customComponents/actions/saveOrUpdateComponent', // 创建或者保存接口地址
19
+ queryAll: '/rest/metadata/v3.0/ui/components/filter?custom=false', // 不带分页
20
+ getCodeLibAPI: (cmpType) => `rest/metadata/v3.0/ui/customComponents/${cmpType}/CodeLib`, // 组件源码下载
21
+
22
+ uploadAPI: '/rest/metadata/v3.0/ui/customComponents/actions/upload', // 文件上传接口地址(已废弃)
23
+ query: '/rest/metadata/v3.0/ui/customComponents/actions/queryCustomComponents' // 带分页(暂未使用)
24
+ // queryAll_v1: '/rest/metadata/v3.0/ui/customComponents/actions/queryAllCustomComponents', // 不带分页(已废弃)
22
25
  };
23
26
 
24
27
  const cmpFields = [
@@ -294,7 +297,8 @@ class NeoService {
294
297
  }
295
298
 
296
299
  /**
297
- * 上传文件到 Neo 平台
300
+ * 上传文件到 Neo 平台(已废弃)
301
+ * 备注:已废弃,改为 保存时直接上传组件资源文件
298
302
  * @param {string} filePath 文件路径
299
303
  * @param {object} options 可选配置
300
304
  * @param {string} options.fieldName 表单字段名,默认为 'customComponentCode'
@@ -323,7 +327,7 @@ class NeoService {
323
327
  }
324
328
 
325
329
  // 检查文件大小
326
- const maxSize = options.maxSize || 50 * 1024 * 1024; // 默认 50MB
330
+ const maxSize = options.maxSize || 5 * 1024 * 1024; // 默认 5MB
327
331
  if (fileStat.size > maxSize) {
328
332
  const sizeMB = (fileStat.size / 1024 / 1024).toFixed(2);
329
333
  const maxSizeMB = (maxSize / 1024 / 1024).toFixed(2);
@@ -454,7 +458,8 @@ class NeoService {
454
458
  }
455
459
 
456
460
  /**
457
- * 将构建产物上传到 NeoCRM 平台端
461
+ * 将构建产物上传到 NeoCRM 平台端(已废弃)
462
+ * 备注:已废弃,改为 保存时直接上传组件资源文件
458
463
  *
459
464
  * @param {object} cmpType 自定义组件名称
460
465
  * @param {array} fileExtensions 需要上传的文件类型,默认 ['.js', '.css', '.zip']
@@ -521,6 +526,69 @@ class NeoService {
521
526
  return curCmpInfo;
522
527
  }
523
528
 
529
+ /**
530
+ * 处理组件构建产物
531
+ *
532
+ * @param {object} cmpType 自定义组件名称
533
+ * @param {array} fileExtensions 需要处理的文件类型,默认 ['.js', '.css', '.zip']
534
+ */
535
+ async getCmpAssets(cmpType, fileExtensions = ['.js', '.css', '.zip']) {
536
+ if (!cmpType) {
537
+ errorLog(`自定义组件名称不能为空: ${cmpType}`);
538
+ return;
539
+ }
540
+ if (!fs.existsSync(this.assetsRoot)) {
541
+ errorLog(`未找到自定义组件资源目录: ${this.assetsRoot}`);
542
+ return;
543
+ }
544
+
545
+ // 当前组件信息
546
+ const curCmpInfo = {
547
+ cmpType
548
+ };
549
+
550
+ const files = fs.readdirSync(this.assetsRoot); // 读取构建目录下的所有文件
551
+
552
+ // 处理构建产物目录下所有指定类型的文件
553
+ files.forEach((file) => {
554
+ const filePath = path.join(this.assetsRoot, file);
555
+ // 获取文件状态
556
+ const fileStat = fs.statSync(filePath);
557
+ // 检查文件扩展名
558
+ // const fileExt = path.extname(file);
559
+ const fileInfo = path.parse(filePath);
560
+ if (fileStat.isFile() && fileExtensions.includes(fileInfo.ext)) {
561
+ let widgetName = _.camelCase(cmpType);
562
+
563
+ if (file.indexOf(widgetName) < 0) {
564
+ return;
565
+ }
566
+
567
+ // 检查文件大小
568
+ const maxSize = 5 * 1024 * 1024; // 默认 5MB
569
+ if (fileStat.size > maxSize) {
570
+ const sizeMB = (fileStat.size / 1024 / 1024).toFixed(2);
571
+ const maxSizeMB = (maxSize / 1024 / 1024).toFixed(2);
572
+ throw new Error(`${file} 文件大小超过限制: ${sizeMB}MB > ${maxSizeMB}MB`);
573
+ }
574
+
575
+ const fileContent = fs.createReadStream(filePath);
576
+ if (file.indexOf('Model') > -1) {
577
+ // 使用文件流而不是读取整个文件到内存(对大文件更友好)
578
+ curCmpInfo.modelAssetFile = fileContent;
579
+ } else if (file.endsWith('.css')) {
580
+ curCmpInfo.cssAssetFile = fileContent;
581
+ } else if (file.endsWith('.zip')) {
582
+ curCmpInfo.codeLibFile = fileContent;
583
+ } else {
584
+ curCmpInfo.assetFile = fileContent;
585
+ }
586
+ }
587
+ });
588
+
589
+ return curCmpInfo;
590
+ }
591
+
524
592
  /**
525
593
  * 更新自定义组件
526
594
  * @param {object} componentData 组件数据
@@ -38,7 +38,7 @@
38
38
  "url": "https://github.com/wibetter/antd-custom-cmp-template/issues"
39
39
  },
40
40
  "dependencies": {
41
- "neo-register": "^1.0.6",
41
+ "neo-register": "^1.0.7",
42
42
  "antd": "4.9.4",
43
43
  "react": "^16.9.0",
44
44
  "react-dom": "^16.9.0"
@@ -15,7 +15,21 @@ export class DataDashboardModel {
15
15
  description: string = '酷炫的数据展示仪表板,支持动态数据更新和动画效果';
16
16
 
17
17
  // 分类标签,用于设置在编辑器左侧组件面板哪个分类中展示(可设置多个分类标签)
18
- tags: string[] = ['仪表板'];
18
+ // tags: string[] = ['仪表板'];
19
+
20
+ /**
21
+ * 用于设置组件支持的页面类型
22
+ *
23
+ * 当前 NeoCRM 平台存在的页面类型:
24
+ * all: 1 全页面
25
+ * indexPage: 2 首页
26
+ * entityListPage: 3 实体列表页
27
+ * entityFormPage: 4 实体表单页
28
+ * entityDetailPage: 5 实体详情页
29
+ * customPage: 6 自定义页面
30
+ * bizPage: 7 业务页面
31
+ */
32
+ // targetPage: string[] = ['customPage'];
19
33
 
20
34
  // 组件图标,用于设置在编辑器左侧组件面板中展示的图标
21
35
  iconSrc: string = 'https://neo-widgets.bj.bcebos.com/custom-widget.svg';
@@ -15,7 +15,21 @@ export class InfoCardModel {
15
15
  description: string = '信息展示卡片';
16
16
 
17
17
  // 分类标签,用于设置在编辑器左侧组件面板哪个分类中展示(可设置多个分类标签)
18
- tags: string[] = ['自定义组件'];
18
+ // tags: string[] = ['自定义组件'];
19
+
20
+ /**
21
+ * 用于设置组件支持的页面类型
22
+ *
23
+ * 当前 NeoCRM 平台存在的页面类型:
24
+ * all: 1 全页面
25
+ * indexPage: 2 首页
26
+ * entityListPage: 3 实体列表页
27
+ * entityFormPage: 4 实体表单页
28
+ * entityDetailPage: 5 实体详情页
29
+ * customPage: 6 自定义页面
30
+ * bizPage: 7 业务页面
31
+ */
32
+ // targetPage: string[] = ['customPage'];
19
33
 
20
34
  // 组件图标,用于设置在编辑器左侧组件面板中展示的图标
21
35
  iconSrc: string = 'https://neo-widgets.bj.bcebos.com/custom-widget.svg';
@@ -15,7 +15,7 @@ export class ContactCardListModel {
15
15
  description: string = '展示联系人信息的卡片列表组件,支持姓名和手机号展示';
16
16
 
17
17
  // 分类标签,用于设置在编辑器左侧组件面板哪个分类中展示(可设置多个分类标签)
18
- tags: string[] = ['自定义组件'];
18
+ // tags: string[] = ['自定义组件'];
19
19
 
20
20
  // 组件图标,用于设置在编辑器左侧组件面板中展示的图标
21
21
  iconSrc: string = 'https://custom-widgets.bj.bcebos.com/card-list.svg';
@@ -16,7 +16,7 @@ export class ContactFormModel {
16
16
  '基于 Ant Design 的联系人表单组件,支持姓名、所有人、业务类型、所属部门、手机号等字段';
17
17
 
18
18
  // 分类标签,用于设置在编辑器左侧组件面板哪个分类中展示(可设置多个分类标签)
19
- tags: string[] = ['自定义组件'];
19
+ // tags: string[] = ['自定义组件'];
20
20
 
21
21
  // 组件图标,用于设置在编辑器左侧组件面板中展示的图标
22
22
  iconSrc: string = 'https://custom-widgets.bj.bcebos.com/contact-form.svg';
@@ -15,7 +15,7 @@ export class NeoEntityGridModel {
15
15
  description: string = 'Neo 实体表格组件';
16
16
 
17
17
  // 分类标签,用于设置在编辑器左侧组件面板哪个分类中展示(可设置多个分类标签)
18
- tags: string[] = ['自定义组件'];
18
+ // tags: string[] = ['自定义组件'];
19
19
 
20
20
  // 组件图标,用于设置在编辑器左侧组件面板中展示的图标
21
21
  iconSrc: string = 'https://custom-widgets.bj.bcebos.com/table.svg';
@@ -38,7 +38,7 @@
38
38
  "url": "https://github.com/wibetter/echarts-custom-cmp-template/issues"
39
39
  },
40
40
  "dependencies": {
41
- "neo-register": "^1.0.6",
41
+ "neo-register": "^1.0.7",
42
42
  "react": "^16.9.0",
43
43
  "react-dom": "^16.9.0",
44
44
  "echarts": "^5.5.1"
@@ -48,7 +48,7 @@
48
48
  "@commitlint/config-conventional": "^9.1.1",
49
49
  "@types/react": "^16.9.11",
50
50
  "@types/react-dom": "^16.9.15",
51
- "neo-cmp-cli": "^1.7.5",
51
+ "neo-cmp-cli": "^1.7.13",
52
52
  "husky": "^4.2.5",
53
53
  "lint-staged": "^10.2.9",
54
54
  "prettier": "^2.0.5",
@@ -16,7 +16,21 @@ export class ChartWidgetModel {
16
16
  '支持多种图表类型切换的专业图表组件,支持丰富的配置选项';
17
17
 
18
18
  // 分类标签,用于设置在编辑器左侧组件面板哪个分类中展示(可设置多个分类标签)
19
- tags: string[] = ['自定义组件'];
19
+ // tags: string[] = ['自定义组件'];
20
+
21
+ /**
22
+ * 用于设置组件支持的页面类型
23
+ *
24
+ * 当前 NeoCRM 平台存在的页面类型:
25
+ * all: 1 全页面
26
+ * indexPage: 2 首页
27
+ * entityListPage: 3 实体列表页
28
+ * entityFormPage: 4 实体表单页
29
+ * entityDetailPage: 5 实体详情页
30
+ * customPage: 6 自定义页面
31
+ * bizPage: 7 业务页面
32
+ */
33
+ // targetPage: string[] = ['customPage'];
20
34
 
21
35
  // 组件图标,用于设置在编辑器左侧组件面板中展示的图标
22
36
  iconSrc: string = 'https://custom-widgets.bj.bcebos.com/chart.svg';
@@ -15,7 +15,21 @@ export class MapWidgetModel {
15
15
  description: string = '地图展示组件,支持传入经纬度或地址名称';
16
16
 
17
17
  // 分类标签,用于设置在编辑器左侧组件面板哪个分类中展示(可设置多个分类标签)
18
- tags: string[] = ['自定义组件'];
18
+ // tags: string[] = ['自定义组件'];
19
+
20
+ /**
21
+ * 用于设置组件支持的页面类型
22
+ *
23
+ * 当前 NeoCRM 平台存在的页面类型:
24
+ * all: 1 全页面
25
+ * indexPage: 2 首页
26
+ * entityListPage: 3 实体列表页
27
+ * entityFormPage: 4 实体表单页
28
+ * entityDetailPage: 5 实体详情页
29
+ * customPage: 6 自定义页面
30
+ * bizPage: 7 业务页面
31
+ */
32
+ // targetPage: string[] = ['customPage'];
19
33
 
20
34
  // 组件图标,用于设置在编辑器左侧组件面板中展示的图标
21
35
  iconSrc: string = 'https://custom-widgets.bj.bcebos.com/map.svg';
@@ -15,7 +15,21 @@ export class CmpModel {
15
15
  description: string = 'xx组件详细描述';
16
16
 
17
17
  // 分类标签,用于设置在编辑器左侧组件面板哪个分类中展示(可设置多个分类标签)
18
- tags: string[] = ['自定义组件'];
18
+ // tags: string[] = ['自定义组件'];
19
+
20
+ /**
21
+ * 用于设置组件支持的页面类型
22
+ *
23
+ * 当前 NeoCRM 平台存在的页面类型:
24
+ * all: 1 全页面
25
+ * indexPage: 2 首页
26
+ * entityListPage: 3 实体列表页
27
+ * entityFormPage: 4 实体表单页
28
+ * entityDetailPage: 5 实体详情页
29
+ * customPage: 6 自定义页面
30
+ * bizPage: 7 业务页面
31
+ */
32
+ // targetPage: string[] = ['customPage'];
19
33
 
20
34
  // 组件图标,用于设置在编辑器左侧组件面板中展示的图标
21
35
  iconSrc: string = 'https://neo-widgets.bj.bcebos.com/custom-widget.svg';
@@ -37,7 +37,7 @@
37
37
  "url": "https://github.com/wibetter/empty-custom-cmp-template/issues"
38
38
  },
39
39
  "dependencies": {
40
- "neo-register": "^1.0.6",
40
+ "neo-register": "^1.0.7",
41
41
  "react": "^16.9.0",
42
42
  "react-dom": "^16.9.0"
43
43
  },
@@ -38,13 +38,13 @@
38
38
  "url": "https://github.com/wibetter/neo-custom-cmp-template/issues"
39
39
  },
40
40
  "dependencies": {
41
- "neo-register": "^1.0.6",
41
+ "neo-register": "^1.0.7",
42
42
  "react": "^16.9.0",
43
43
  "react-dom": "^16.9.0",
44
44
  "axios": "^0.27.2",
45
45
  "antd": "^4.9.4",
46
46
  "lodash": "^4.17.21",
47
- "neo-open-api": "^1.0.11"
47
+ "neo-open-api": "^1.1.0"
48
48
  },
49
49
  "devDependencies": {
50
50
  "@commitlint/cli": "^8.3.5",
@@ -52,7 +52,7 @@
52
52
  "@types/react": "^16.9.11",
53
53
  "@types/react-dom": "^16.9.15",
54
54
  "@types/axios": "^0.14.0",
55
- "neo-cmp-cli": "^1.7.5",
55
+ "neo-cmp-cli": "^1.7.15",
56
56
  "husky": "^4.2.5",
57
57
  "lint-staged": "^10.2.9",
58
58
  "prettier": "^2.0.5"
@@ -15,7 +15,21 @@ export class EntityCardListModel {
15
15
  description: string = '展示实体数据信息的卡片列表组件,支持姓名和手机号展示';
16
16
 
17
17
  // 分类标签,用于设置在编辑器左侧组件面板哪个分类中展示(可设置多个分类标签)
18
- tags: string[] = ['自定义组件'];
18
+ // tags: string[] = ['自定义组件'];
19
+
20
+ /**
21
+ * 用于设置组件支持的页面类型
22
+ *
23
+ * 当前 NeoCRM 平台存在的页面类型:
24
+ * all: 1 全页面
25
+ * indexPage: 2 首页
26
+ * entityListPage: 3 实体列表页
27
+ * entityFormPage: 4 实体表单页
28
+ * entityDetailPage: 5 实体详情页
29
+ * customPage: 6 自定义页面
30
+ * bizPage: 7 业务页面
31
+ */
32
+ // targetPage: string[] = ['customPage'];
19
33
 
20
34
  // 组件图标,用于设置在编辑器左侧组件面板中展示的图标
21
35
  iconSrc: string = 'https://custom-widgets.bj.bcebos.com/data-list.svg';
@@ -17,7 +17,21 @@ export class EntityDetailModel {
17
17
  description: string = '展示实体数据详情信息,支持多列布局和字段类型识别';
18
18
 
19
19
  /** 分类标签,用于设置在编辑器左侧组件面板哪个分类中展示(可设置多个分类标签) */
20
- tags: string[] = ['自定义组件'];
20
+ // tags: string[] = ['自定义组件'];
21
+
22
+ /**
23
+ * 用于设置组件支持的页面类型
24
+ *
25
+ * 当前 NeoCRM 平台存在的页面类型:
26
+ * all: 1 全页面
27
+ * indexPage: 2 首页
28
+ * entityListPage: 3 实体列表页
29
+ * entityFormPage: 4 实体表单页
30
+ * entityDetailPage: 5 实体详情页
31
+ * customPage: 6 自定义页面
32
+ * bizPage: 7 业务页面
33
+ */
34
+ // targetPage: string[] = ['customPage'];
21
35
 
22
36
  /** 组件图标,用于设置在编辑器左侧组件面板中展示的图标 */
23
37
  iconSrc: string = 'https://custom-widgets.bj.bcebos.com/detail.svg';
@@ -19,7 +19,21 @@ export class EntityFormModel {
19
19
  description: string = '基于 XObject 的对象表单组件,用于新增数据';
20
20
 
21
21
  /** 分类标签,用于设置在编辑器左侧组件面板哪个分类中展示(可设置多个分类标签) */
22
- tags: string[] = ['自定义组件'];
22
+ // tags: string[] = ['自定义组件'];
23
+
24
+ /**
25
+ * 用于设置组件支持的页面类型
26
+ *
27
+ * 当前 NeoCRM 平台存在的页面类型:
28
+ * all: 1 全页面
29
+ * indexPage: 2 首页
30
+ * entityListPage: 3 实体列表页
31
+ * entityFormPage: 4 实体表单页
32
+ * entityDetailPage: 5 实体详情页
33
+ * customPage: 6 自定义页面
34
+ * bizPage: 7 业务页面
35
+ */
36
+ // targetPage: string[] = ['customPage'];
23
37
 
24
38
  /** 组件图标,用于设置在编辑器左侧组件面板中展示的图标 */
25
39
  iconSrc: string = 'https://custom-widgets.bj.bcebos.com/custom-form.svg';
@@ -19,11 +19,25 @@ export class EntityTableModel {
19
19
  description: string = '基于 XObject 的数据表格组件,支持增删改查操作';
20
20
 
21
21
  /** 分类标签,用于设置在编辑器左侧组件面板哪个分类中展示(可设置多个分类标签) */
22
- tags: string[] = ['自定义组件'];
22
+ // tags: string[] = ['自定义组件'];
23
23
 
24
24
  /** 组件图标,用于设置在编辑器左侧组件面板中展示的图标 */
25
25
  iconSrc: string = 'https://custom-widgets.bj.bcebos.com/table.svg';
26
26
 
27
+ /**
28
+ * 用于设置组件支持的页面类型
29
+ *
30
+ * 当前 NeoCRM 平台存在的页面类型:
31
+ * all: 1 全页面
32
+ * indexPage: 2 首页
33
+ * entityListPage: 3 实体列表页
34
+ * entityFormPage: 4 实体表单页
35
+ * entityDetailPage: 5 实体详情页
36
+ * customPage: 6 自定义页面
37
+ * bizPage: 7 业务页面
38
+ */
39
+ // targetPage: string[] = ['customPage'];
40
+
27
41
  /** 初次插入页面的默认属性数据 */
28
42
  defaultComProps = {
29
43
  title: '实体数据表格',
@@ -38,7 +38,7 @@
38
38
  "url": "https://github.com/wibetter/react-custom-cmp-template/issues"
39
39
  },
40
40
  "dependencies": {
41
- "neo-register": "^1.0.6",
41
+ "neo-register": "^1.0.7",
42
42
  "react": "^16.9.0",
43
43
  "react-dom": "^16.9.0"
44
44
  },
@@ -15,7 +15,21 @@ export class InfoCardModel {
15
15
  description = '信息展示卡片';
16
16
 
17
17
  // 分类标签,用于设置在编辑器左侧组件面板哪个分类中展示(可设置多个分类标签)
18
- tags = ['自定义组件'];
18
+ // tags: string[] = ['自定义组件'];
19
+
20
+ /**
21
+ * 用于设置组件支持的页面类型
22
+ *
23
+ * 当前 NeoCRM 平台存在的页面类型:
24
+ * all: 1 全页面
25
+ * indexPage: 2 首页
26
+ * entityListPage: 3 实体列表页
27
+ * entityFormPage: 4 实体表单页
28
+ * entityDetailPage: 5 实体详情页
29
+ * customPage: 6 自定义页面
30
+ * bizPage: 7 业务页面
31
+ */
32
+ // targetPage: string[] = ['customPage'];
19
33
 
20
34
  // 组件图标,用于设置在编辑器左侧组件面板中展示的图标
21
35
  // iconSrc = 'https://neo-widgets.bj.bcebos.com/custom-widget.svg';
@@ -38,7 +38,7 @@
38
38
  "url": "https://github.com/wibetter/react-ts-custom-cmp-template/issues"
39
39
  },
40
40
  "dependencies": {
41
- "neo-register": "^1.0.6",
41
+ "neo-register": "^1.0.7",
42
42
  "react": "^16.9.0",
43
43
  "react-dom": "^16.9.0"
44
44
  },
@@ -15,7 +15,21 @@ export class ListWidgetModel {
15
15
  description: string = '支持配置的列表展示组件,内置模拟数据';
16
16
 
17
17
  // 分类标签,用于设置在编辑器左侧组件面板哪个分类中展示(可设置多个分类标签)
18
- tags: string[] = ['自定义组件'];
18
+ // tags: string[] = ['自定义组件'];
19
+
20
+ /**
21
+ * 用于设置组件支持的页面类型
22
+ *
23
+ * 当前 NeoCRM 平台存在的页面类型:
24
+ * all: 1 全页面
25
+ * indexPage: 2 首页
26
+ * entityListPage: 3 实体列表页
27
+ * entityFormPage: 4 实体表单页
28
+ * entityDetailPage: 5 实体详情页
29
+ * customPage: 6 自定义页面
30
+ * bizPage: 7 业务页面
31
+ */
32
+ // targetPage: string[] = ['customPage'];
19
33
 
20
34
  // 组件图标,用于设置在编辑器左侧组件面板中展示的图标
21
35
  iconSrc: string = 'https://neo-widgets.bj.bcebos.com/favicon.png';
@@ -38,7 +38,7 @@
38
38
  "url": "https://github.com/wibetter/vue2-custom-cmp-template/issues"
39
39
  },
40
40
  "dependencies": {
41
- "neo-register": "^1.0.6",
41
+ "neo-register": "^1.0.7",
42
42
  "vue": "^2.6.14",
43
43
  "element-ui": "^2.15.12"
44
44
  },
@@ -15,7 +15,21 @@ export class InfoCardModel {
15
15
  description = '信息展示卡片';
16
16
 
17
17
  // 分类标签,用于设置在编辑器左侧组件面板哪个分类中展示(可设置多个分类标签)
18
- tags = ['自定义组件'];
18
+ // tags: string[] = ['自定义组件'];
19
+
20
+ /**
21
+ * 用于设置组件支持的页面类型
22
+ *
23
+ * 当前 NeoCRM 平台存在的页面类型:
24
+ * all: 1 全页面
25
+ * indexPage: 2 首页
26
+ * entityListPage: 3 实体列表页
27
+ * entityFormPage: 4 实体表单页
28
+ * entityDetailPage: 5 实体详情页
29
+ * customPage: 6 自定义页面
30
+ * bizPage: 7 业务页面
31
+ */
32
+ // targetPage: string[] = ['customPage'];
19
33
 
20
34
  // 组件图标,用于设置在编辑器左侧组件面板中展示的图标
21
35
  iconSrc = 'https://neo-widgets.bj.bcebos.com/custom-widget.svg';
@@ -12,6 +12,18 @@ const createCmpProjectZip = require('../projectUtils/createCmpProjectZip');
12
12
  const currentPackageJsonDir = catchCurPackageJson();
13
13
  const currentPackageJson = getConfigObj(currentPackageJsonDir);
14
14
 
15
+
16
+ // 获取属性 propsSchema 数据结构
17
+ const getPropsSchema = (propsSchema = []) => {
18
+ return propsSchema.map((item) => {
19
+ return {
20
+ label: item.label,
21
+ description: item.description,
22
+ propSchema: item
23
+ };
24
+ });
25
+ };
26
+
15
27
  /**
16
28
  * 构建组件数据映射
17
29
  * @param {string} assetsRoot 构建产物的目录
@@ -86,13 +98,14 @@ const buildComponentData = async (assetsRoot, cmpInfo) => {
86
98
  // 从模型实例中提取并设置组件信息
87
99
  label: modelInstance.label || cmpType,
88
100
  description: modelInstance.description || '',
89
- componentCategory: (modelInstance.tags || []).join(','),
90
- icon: modelInstance.iconSrc,
101
+ componentCategory: (modelInstance.tags || ['自定义组件']).join(','),
102
+ targetPage: (modelInstance.targetPage || ['customPage']).join(','),
103
+ iconUrl: modelInstance.iconSrc,
91
104
  defaultProps: JSON.stringify(modelInstance.defaultComProps || {}),
92
105
  previewProps: JSON.stringify(modelInstance.previewComProps || {}),
93
- propsSchema: JSON.stringify(modelInstance.propsSchema || []),
106
+ props: JSON.stringify(getPropsSchema(modelInstance.propsSchema || [])),
94
107
  events: modelInstance.events || [],
95
- actions: modelInstance.actions || [],
108
+ functions: modelInstance.functions || modelInstance.actions || [],
96
109
  // 如果模型实例中有其他属性,也可以添加
97
110
  exposedToDesigner:
98
111
  modelInstance.exposedToDesigner !== undefined ? modelInstance.exposedToDesigner : true,
@@ -151,7 +164,8 @@ const pushCmp = async (config, cmpType) => {
151
164
  errorLog(`[1/4] 源码文件打包失败。`, spinner);
152
165
  }
153
166
 
154
- // 步骤 3: 上传构建后资源文件
167
+ /*
168
+ // 步骤 3: 上传构建后资源文件(改放在保存时直接上传组件资源文件)
155
169
  spinner.start(`[2/4] 上传自定义组件构建产物到 OSS...`);
156
170
  let cmpInfo;
157
171
  try {
@@ -164,6 +178,9 @@ const pushCmp = async (config, cmpType) => {
164
178
  } catch (error) {
165
179
  errorLog(`[2/4] 构建产物上传失败。`, spinner);
166
180
  }
181
+ */
182
+ spinner.start(`[2/4] 获取自定义组件构建产物...`);
183
+ const cmpInfo = await neoService.getCmpAssets(cmpType);
167
184
 
168
185
  // 步骤 4: 构建组件数据
169
186
  spinner.start(`[3/4] 构建组件数据...`);
@@ -0,0 +1,109 @@
1
+ const _ = require('lodash');
2
+ const AddNeoRequirePlugin = require('../plugins/AddNeoRequirePlugin');
3
+ const createCommonModulesCode = require('../utils/cmpUtils/createCommonModulesCode');
4
+ const { getExternalsByNeoCommonModules } = require('../neo/neoRequire');
5
+ const curConfig = require('../config/index'); // 获取当前项目根目录下的配置文件
6
+
7
+ // neo.config.js 中的添加的 Neo 共享依赖模块配置
8
+ const neoCommonModule = curConfig.neoCommonModule || {};
9
+ // 自定义组件 需要剔除的依赖模块
10
+ const cmpNeoExternals = neoCommonModule.externals || [];
11
+
12
+ // 组件目录
13
+ const componentsDir = curConfig.componentsDir || './src/components';
14
+
15
+ /**
16
+ * 添加 AddNeoRequirePlugin 到 webpack 配置
17
+ * @param {object} webpackConfig webpack 配置对象
18
+ * @param {object} [options] 选项
19
+ * @param {boolean} [options.verbose] 是否启用详细日志,默认为 false
20
+ */
21
+ function addNeoRequirePlugin(webpackConfig, options = {}) {
22
+ const { verbose = false } = options;
23
+ const plugin = new AddNeoRequirePlugin({ verbose });
24
+
25
+ if (webpackConfig && webpackConfig.plugins && Array.isArray(webpackConfig.plugins)) {
26
+ webpackConfig.plugins.push(plugin);
27
+ } else {
28
+ webpackConfig.plugins = [plugin];
29
+ }
30
+ }
31
+
32
+ /**
33
+ * 添加 Neo externals 配置
34
+ * @param {object} config 配置对象(dev 或 build2lib)
35
+ * @param {object} externalsConfig 现有的 externals 配置
36
+ */
37
+ function addNeoExternals(config, externalsConfig) {
38
+ const externals = getExternalsByNeoCommonModules(cmpNeoExternals);
39
+ if (externalsConfig && _.isPlainObject(externalsConfig)) {
40
+ config.externals = Object.assign(externalsConfig, externals);
41
+ } else {
42
+ config.externals = externals;
43
+ }
44
+ }
45
+
46
+ /**
47
+ * 创建并注入 commonModulesCode 到 entry
48
+ * @param {object} config 配置对象(dev 或 build2lib)
49
+ * @param {array} cmpTypes 组件类型列表
50
+ * @param {object} [options] 选项
51
+ * @param {boolean} [options.excludeModel] 是否排除 Model 结尾的 entry,默认为 false
52
+ */
53
+ function injectCommonModulesCode(config, options = {}) {
54
+ const { cmpTypes, defaultExports, excludeModel = false } = options;
55
+
56
+ // 添加默认导出
57
+ if (defaultExports && _.isPlainObject(defaultExports)) {
58
+ if (neoCommonModule.exports && _.isPlainObject(neoCommonModule.exports)) {
59
+ neoCommonModule.exports = Object.assign(neoCommonModule.exports, defaultExports);
60
+ } else if (neoCommonModule.exports && _.isArray(neoCommonModule.exports)) {
61
+ // 先将数组格式改成对象格式
62
+ neoCommonModule.exports.forEach((item) => {
63
+ if (_.isString(item)) {
64
+ neoCommonModule.exports[item] = item;
65
+ }
66
+ });
67
+ neoCommonModule.exports = Object.assign(neoCommonModule.exports, defaultExports);
68
+ } else {
69
+ neoCommonModule.exports = defaultExports;
70
+ }
71
+ }
72
+
73
+ const commonModulesFilePath = createCommonModulesCode(neoCommonModule, cmpTypes);
74
+
75
+ if (commonModulesFilePath && config.entry) {
76
+ Object.keys(config.entry).forEach((name) => {
77
+ // 如果 excludeModel 为 true,排除 Model 结尾的文件
78
+ if (!excludeModel || !name.endsWith('Model')) {
79
+ config.entry[name] = [commonModulesFilePath].concat(config.entry[name]);
80
+ }
81
+ });
82
+ }
83
+ }
84
+
85
+ /**
86
+ * 配置 webpack 插件、externals 和 commonModulesCode(用于 linkDebug、publish2oss、pushCmp)
87
+ * @param {object} config 配置对象(dev 或 build2lib)
88
+ * @param {object} [options] 选项
89
+ * @param {array} [options.cmpTypes] 组件类型列表
90
+ * @param {object} [options.defaultExports] 默认导出
91
+ * @param {boolean} [options.verbose] 是否启用详细日志,默认为 false
92
+ * @param {boolean} [options.excludeModel] 是否排除 Model 结尾的 entry,默认为 false
93
+ */
94
+ function configureNeoBuild(config, options = {}) {
95
+ const { cmpTypes, defaultExports, verbose = false, excludeModel = false } = options;
96
+
97
+ // 添加自定义 webpack 插件
98
+ addNeoRequirePlugin(curConfig.webpack, { verbose });
99
+
100
+ // 添加内置 Neo 的 externals 配置
101
+ addNeoExternals(config, config.externals);
102
+
103
+ // 创建并注入 commonModulesCode
104
+ injectCommonModulesCode(config, { cmpTypes, defaultExports, excludeModel });
105
+ }
106
+
107
+ module.exports = {
108
+ configureNeoBuild
109
+ };
@@ -9,19 +9,16 @@ const getEntriesWithAutoRegister = require('./projectUtils/getEntriesWithAutoReg
9
9
  * @param {string} options.componentsDir 组件目录路径
10
10
  * @param {string} options.entryType entry 类型:'widget' | 'linkDebug',默认为 'widget'
11
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
12
  */
15
13
  function generateEntries({
16
14
  configEntry,
17
15
  disableAutoRegister,
18
16
  componentsDir,
19
17
  entryType = 'widget',
20
- cmpType,
21
- forceGetCmpTypes = false
18
+ cmpType
22
19
  }) {
23
20
  // 如果已配置 entry 且不需要强制获取 cmpTypes,直接返回
24
- if (configEntry && Object.keys(configEntry).length > 0 && !forceGetCmpTypes) {
21
+ if (configEntry && Object.keys(configEntry).length > 0) {
25
22
  return {
26
23
  entries: configEntry,
27
24
  cmpTypes: []
@@ -48,16 +45,8 @@ function generateEntries({
48
45
 
49
46
  const cmpTypes = entriesResult.cmpTypes || [];
50
47
 
51
- // 如果 entry 已存在但需要获取 cmpTypes,使用已存在的 entry
52
- if (configEntry && Object.keys(configEntry).length > 0 && forceGetCmpTypes) {
53
- entries = configEntry;
54
- }
55
-
56
48
  // 验证 entries 是否有效(仅在需要生成新 entry 时验证)
57
- if (
58
- (!configEntry || Object.keys(configEntry).length === 0) &&
59
- (!entries || Object.keys(entries).length === 0)
60
- ) {
49
+ if (!entries || Object.keys(entries).length === 0) {
61
50
  const defaultComponentsDir = componentsDir || './src/components';
62
51
  throw new Error(
63
52
  `未识别到自定义组件,请检查 ${defaultComponentsDir} 目录下是否存在自定义组件。`
@@ -66,7 +55,8 @@ function generateEntries({
66
55
 
67
56
  return {
68
57
  entries: entries || configEntry || {},
69
- cmpTypes
58
+ cmpTypes,
59
+ defaultExports: entriesResult.defaultExports || {}
70
60
  };
71
61
  }
72
62
 
@@ -14,6 +14,7 @@ module.exports = (defaultComponentsDir = './src/components', cmpType) => {
14
14
  index: []
15
15
  };
16
16
  const cmpTypes = []; // 用于记录组件名称
17
+ const defaultExports = {}; // 用于记录默认导出
17
18
  const componentsBaseDir = resolveToCurrentRoot(defaultComponentsDir);
18
19
  if (!fs.existsSync(componentsBaseDir)) {
19
20
  console.error(`未找到组件目录,请检查 ${defaultComponentsDir} 目录是否存在`);
@@ -47,7 +48,7 @@ module.exports = (defaultComponentsDir = './src/components', cmpType) => {
47
48
  cmpTypes.push(curCmpName);
48
49
 
49
50
  fs.readdirSync(curCmpPath)
50
- .filter((file) => file.match(/[register|model]\.[tj]sx?$/))
51
+ .filter((file) => file.match(/[index|register|model]\.(tsx?|jsx?|vue)$/))
51
52
  .map((file) => path.join(defaultComponentsDir, curCmpName, file))
52
53
  .forEach((filePath) => {
53
54
  const curPath = `./${filePath}`;
@@ -55,6 +56,9 @@ module.exports = (defaultComponentsDir = './src/components', cmpType) => {
55
56
  widgetEntries[cmpNameKey] = curPath;
56
57
  } else if (filePath.match(/model\.[tj]sx?$/)) {
57
58
  widgetEntries[`${cmpNameKey}Model`] = curPath;
59
+ } else if (filePath.match(/index\.(tsx?|jsx?|vue)$/)) {
60
+ // 组件内容文件
61
+ defaultExports[cmpNameKey] = path.resolve(filePath); // 记录默认导出
58
62
  }
59
63
  linkDebugEntries.index.push(curPath);
60
64
  });
@@ -70,6 +74,7 @@ module.exports = (defaultComponentsDir = './src/components', cmpType) => {
70
74
  return {
71
75
  widgetEntries,
72
76
  linkDebugEntries,
73
- cmpTypes
77
+ cmpTypes,
78
+ defaultExports
74
79
  };
75
80
  };
@@ -15,6 +15,7 @@ module.exports = (defaultComponentsDir = './src/components', cmpType) => {
15
15
  index: []
16
16
  };
17
17
  const cmpTypes = []; // 用于记录组件名称
18
+ const defaultExports = {}; // 用于记录默认导出
18
19
  const componentsBaseDir = resolveToCurrentRoot(defaultComponentsDir);
19
20
  if (!fs.existsSync(componentsBaseDir)) {
20
21
  console.error(`未找到组件目录,请检查 ${defaultComponentsDir} 目录是否存在`);
@@ -41,14 +42,12 @@ module.exports = (defaultComponentsDir = './src/components', cmpType) => {
41
42
 
42
43
  // 遍历所有目录
43
44
  widgetDirs.forEach((dir) => {
44
- const filePath = path.join(componentsBaseDir, dir);
45
+ // 当前自定义组件目录
46
+ const widgetPath = path.join(componentsBaseDir, dir);
45
47
  // 获取文件状态
46
- const stat = fs.statSync(filePath);
48
+ const stat = fs.statSync(widgetPath);
47
49
  // 如果文件是目录,则递归处理子目录
48
50
  if (stat.isDirectory() && !dir.startsWith('.') && dir !== 'node_modules') {
49
- // 当前自定义组件目录
50
- const widgetPath = path.join(componentsBaseDir, dir);
51
-
52
51
  // 当前自定义组件名称
53
52
  const curCmpName = dir; // _.camelCase(dir);
54
53
  const cmpNameKey = _.camelCase(curCmpName);
@@ -67,6 +66,9 @@ module.exports = (defaultComponentsDir = './src/components', cmpType) => {
67
66
  .map((file) => path.join(defaultComponentsDir, curCmpName, file))
68
67
  .forEach((filePath) => {
69
68
  if (filePath.match(/index\.(tsx?|jsx?|vue)$/)) {
69
+ // 记录默认导出
70
+ defaultExports[cmpNameKey] = path.resolve(filePath);
71
+
70
72
  // 自动创建对应的注册文件
71
73
  const registerContent = getCmpRegisterCode(componentsBaseDir, curCmpName);
72
74
  const registerDir = `${cmpTempDir}/register.js`;
@@ -100,6 +102,7 @@ module.exports = (defaultComponentsDir = './src/components', cmpType) => {
100
102
  return {
101
103
  widgetEntries,
102
104
  linkDebugEntries,
103
- cmpTypes
105
+ cmpTypes,
106
+ defaultExports
104
107
  };
105
108
  };
package/test/demo.js CHANGED
@@ -1,6 +1,6 @@
1
- const {neoInit, neoConfigInit, inspect, preview, debug, build2lib, build2esm, neoInitByCopy, previewCmp, } = require('../src/module/main');
2
- const getEntries = require('../src/projectUtils/getEntries');
3
- const getEntriesWithAutoRegister = require('../src/projectUtils/getEntriesWithAutoRegister');
1
+ const {neoInit, neoConfigInit, inspect, preview, debug, build2lib, build2esm, neoInitByCopy, previewCmp } = require('../src/module/main');
2
+ const getEntries = require('../src/utils/projectUtils/getEntries');
3
+ const getEntriesWithAutoRegister = require('../src/utils/projectUtils/getEntriesWithAutoRegister');
4
4
  // inspect('dev');
5
5
  // neoInitByCopy('react-ts', 'test123');
6
6
 
@@ -1,7 +1,7 @@
1
1
  const { execSync } = require('child_process');
2
2
 
3
3
  // 所有需要废弃的版本(1.6.2 之前的所有版本)
4
- const versionsToDeprecate = ["1.7.5", "1.7.5-beta.1", "1.7.5-beta.2", "1.7.6", "1.7.7", "1.7.8", "1.7.9", "1.7.10"];
4
+ const versionsToDeprecate = ["1.7.10", "1.7.11", "1.7.12", "1.7.13"];
5
5
 
6
6
  const packageName = 'neo-cmp-cli';
7
7
  const deprecateMessage = '此版本为开发中版本(存在 bug),请升级到最新版本。';