neo-cmp-cli 1.2.9 → 1.2.10

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 CHANGED
@@ -13,7 +13,10 @@ neo-cmp-cli 是 Neo 自定义组件开发工具,基于 [AKFun](https://github.
13
13
  ### 模板类型(neo init 可选)
14
14
  - **React 模板**: [react-custom-cmp-template](https://github.com/wibetter/react-custom-cmp-template)
15
15
  - **React + TS 模板**: [react-ts-custom-cmp-template](https://github.com/wibetter/react-ts-custom-cmp-template)
16
- - **Vue2 模板**: [vue2-custom-cmp-template](https://github.com/wibetter/vue2-custom-cmp-template)
16
+ - **Antd 模板**: [antd-custom-cmp-template](https://github.com/wibetter/antd-custom-cmp-template) Antd 自定义组件
17
+ - **Neo 模板**: [neo-custom-cmp-template](https://github.com/wibetter/neo-custom-cmp-template) 支持使用 Neo 实体数据源(内置 Neo Open API 使用示例)
18
+ - **Echarts 模板**: [echarts-custom-cmp-template](https://github.com/wibetter/echarts-custom-cmp-template) Echarts 图表自定义组件
19
+ - **Vue2 模板**: [vue2-custom-cmp-template](https://github.com/wibetter/vue2-custom-cmp-template) Vue2.0 自定义组件
17
20
 
18
21
  ## 快速开始
19
22
 
@@ -68,11 +71,24 @@ npm run publish2oss
68
71
  ```
69
72
 
70
73
  ## 常用命令
71
- - **neo init**: 交互式创建项目(支持 -t、--name)。
74
+ - **neo init**: 交互式创建自定义组件(支持 -t、--name)。
72
75
  - **neo preview**: 本地预览自定义组件内容,默认支持热更新与接口代理。
73
- - **neo linkDebug**: 外链调试模式,在平台端页面设计器中联调组件。
76
+ - **neo linkDebug**: 外链调试模式,在平台端页面设计器中调试自定义组件。
74
77
  - **neo build2lib**: 产出 UMD/ESM 库文件(可配置)。
75
- - **neo publish2oss**: 构建并上传到对象存储(可自定义配置)。
78
+ - **neo publish2oss**: 构建并上传到对象存储(可自定义配置对象存储)。
79
+
80
+ ## 内置自动识别自定义组件
81
+ - **自动生成入口配置**: 当 `entry` 未配置时,会自动从 `src/components` 扫描并识别自定义组件,`src/components` 下的子目录名称作为自定义组件的 cmpType,并以其目录下的 `.ts/.tsx/.js/.jsx` 结尾的文件作为组件内容文件,model.[tj]s 作为模型内容文件;
82
+ - **自动生成相关注册文件并注入**: 自动生成自定义组件注册文件和模型注册文件,并注入到构建脚本中,无需用户关注 [neo-register](https://www.npmjs.com/package/neo-register)。
83
+
84
+ ## 发布到对象存储(OSS)
85
+ 执行 `npm run publish2oss` 即可构建并上传到对象存储。发布前请确保:
86
+ - **package.json 的 name 唯一**
87
+ - **version 不重复**
88
+ - 已按需配置对象存储参数(支持自定义)
89
+
90
+ 支持发布指定自定义组件:
91
+ 执行 `npm run publish2oss --cmpType=xxCmp`
76
92
 
77
93
  ## 配置说明(neo.config.js)
78
94
  neo-cmp-cli 默认提供完整配置;如需自定义,使用 `neo config init` 生成 `neo.config.js` 并按需修改。
@@ -222,15 +238,5 @@ module.exports = {
222
238
  }
223
239
  ```
224
240
 
225
- ## 多页面与模板
226
- - **多页面入口**: 当 `entry` 仅配置一个且对应文件不存在时,会自动从 `src/pages` 扫描以 `.ts/.tsx/.js/.jsx` 结尾的文件作为入口,匹配同名 HTML 作为模板。
227
- - **模板选择**: 优先使用 `./src/index.html`;不存在时使用内置默认模板。多页面时若存在同名 HTML,将其作为页面模板。
228
-
229
- ## 发布到对象存储(OSS)
230
- 执行 `npm run publish2oss` 即可构建并上传到对象存储。发布前请确保:
231
- - **package.json 的 name 唯一**
232
- - **version 不重复**
233
- - 已按需配置对象存储参数(支持自定义)
234
-
235
241
  ---
236
242
  如需更多细节与高级用法,请参考模板项目与源码注释。
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "neo-cmp-cli",
3
- "version": "1.2.9",
3
+ "version": "1.2.10",
4
4
  "description": "前端脚手架:自定义组件开发工具,支持react 和 vue2.0技术栈。",
5
5
  "keywords": [
6
6
  "neo-cli",
@@ -8,7 +8,7 @@ const { resolveToCurrentRoot } = require('../utils/pathUtils');
8
8
  * @param {*} defaultComponentsDir 默认组件目录
9
9
  * @returns 组件入口文件
10
10
  */
11
- module.exports = (defaultComponentsDir = './src/components') => {
11
+ module.exports = (defaultComponentsDir = './src/components', cmpType) => {
12
12
  const widgetEntries = {};
13
13
  const linkDebugEntries = {
14
14
  index: []
@@ -24,7 +24,13 @@ module.exports = (defaultComponentsDir = './src/components') => {
24
24
 
25
25
  try {
26
26
  // 读取指定目录下的所有文件
27
- const widgetDirs = fs.readdirSync(componentsBaseDir);
27
+ let widgetDirs = [];
28
+ if (cmpType) {
29
+ // 如果传入了 cmpType,则只读取指定组件目录
30
+ widgetDirs = [cmpType];
31
+ } else {
32
+ widgetDirs = fs.readdirSync(componentsBaseDir);
33
+ }
28
34
 
29
35
  // 遍历所有目录
30
36
  widgetDirs.forEach((dir) => {
@@ -9,7 +9,7 @@ const getCmpModelRegister = require('./getCmpModelRegister');
9
9
  * @param {*} defaultComponentsDir 默认组件目录
10
10
  * @returns 组件入口文件
11
11
  */
12
- module.exports = (defaultComponentsDir = './src/components') => {
12
+ module.exports = (defaultComponentsDir = './src/components', cmpType) => {
13
13
  const widgetEntries = {};
14
14
  const linkDebugEntries = {
15
15
  index: []
@@ -31,7 +31,13 @@ module.exports = (defaultComponentsDir = './src/components') => {
31
31
 
32
32
  try {
33
33
  // 读取指定目录下的所有文件
34
- const widgetDirs = fs.readdirSync(componentsBaseDir);
34
+ let widgetDirs = [];
35
+ if (cmpType) {
36
+ // 如果传入了 cmpType,则只读取指定组件目录
37
+ widgetDirs = [cmpType];
38
+ } else {
39
+ widgetDirs = fs.readdirSync(componentsBaseDir);
40
+ }
35
41
 
36
42
  // 遍历所有目录
37
43
  widgetDirs.forEach((dir) => {
@@ -0,0 +1,33 @@
1
+ const fs = require('fs');
2
+ const path = require('path');
3
+ const _ = require('lodash');
4
+ const { resolveToCurrentRoot } = require('../utils/pathUtils');
5
+ const getCmpRegister = require('./getCmpRegister');
6
+ const getCmpModelRegister = require('./getCmpModelRegister');
7
+ /**
8
+ * 更新发布日志
9
+ */
10
+ module.exports = (curHistoryData) => {
11
+ // 创建存放 cli 的临时目录
12
+ const cliTempDir = resolveToCurrentRoot('./.neo-cli');
13
+ if (!fs.existsSync(cliTempDir)) {
14
+ fs.mkdirSync(cliTempDir);
15
+ }
16
+
17
+ const historyFile = `${cliTempDir}/history.json`;
18
+ let historyData = {};
19
+ if (fs.existsSync(historyFile)) {
20
+ // 读取历史文件
21
+ try {
22
+ historyData = JSON.parse(fs.readFileSync(historyFile, 'utf8'));
23
+ } catch (error) {
24
+ console.error('读取历史文件失败:', error);
25
+ historyData = {};
26
+ }
27
+ }
28
+ const historyKey = new Date().toString();
29
+ historyData[historyKey] = curHistoryData;
30
+
31
+ // 更新历史文件
32
+ fs.writeFileSync(historyFile, JSON.stringify(historyData, null, 2));
33
+ };
@@ -232,16 +232,20 @@ yargs
232
232
  }
233
233
  )
234
234
  .command(
235
- 'publish2oss',
235
+ 'publish2oss [options]',
236
236
  '发布到oss',
237
237
  (yargs) => {
238
238
  yargs
239
239
  .reset()
240
- .usage(titleTip('Usage') + ': $0 build2lib')
240
+ .usage(titleTip('Usage') + ': $0 publish2oss [options]')
241
+ .option('cmpType', {
242
+ alias: 't',
243
+ describe: '自定义组件名称'
244
+ })
241
245
  .alias('h', 'help');
242
246
  },
243
247
  (argv) => {
244
- mainAction.publish2oss(); // 构建并发布脚本到oss
248
+ mainAction.publish2oss(argv.cmpType); // 构建并发布脚本到oss
245
249
  }
246
250
  )
247
251
  .command(
@@ -1,5 +1,4 @@
1
1
  const akfun = require('akfun');
2
- const path = require('path');
3
2
  const _ = require('lodash');
4
3
  const neoInit = require('./neoInit');
5
4
  const neoInitByCopy = require('./neoInitByCopy');
@@ -180,7 +179,7 @@ module.exports = {
180
179
 
181
180
  akfun.build('lib', curConfig, consoleTag);
182
181
  }, // 构建脚本:生产环境
183
- publish2oss: () => {
182
+ publish2oss: (cmpType) => {
184
183
  // 将 publish2oss 相关配置设置给 build2lib
185
184
  const publish2ossConfig = curConfig.publish2oss;
186
185
  curConfig.build2lib = Object.assign(curConfig.build2lib, publish2ossConfig);
@@ -193,12 +192,12 @@ module.exports = {
193
192
  let entries = {};
194
193
  if (curConfig.build2lib.disableAutoRegister) {
195
194
  // disableAutoRegister 为 true 时,仅自动生成入口文件(不自动注册)
196
- const { widgetEntries, cmpTypes } = getEntries(curConfig.componentsDir);
195
+ const { widgetEntries, cmpTypes } = getEntries(curConfig.componentsDir, cmpType);
197
196
  entries = widgetEntries;
198
197
  curCmpTypes = cmpTypes;
199
198
  } else {
200
199
  // 自动生成入口文件(并自动创建对应的注册文件)
201
- const { widgetEntries, cmpTypes } = getEntriesWithAutoRegister(curConfig.componentsDir);
200
+ const { widgetEntries, cmpTypes } = getEntriesWithAutoRegister(curConfig.componentsDir, cmpType);
202
201
  entries = widgetEntries;
203
202
  curCmpTypes = cmpTypes;
204
203
  }
@@ -3,6 +3,7 @@ const fs = require('fs');
3
3
  const path = require('path');
4
4
  const { catchCurPackageJson } = require('../utils/pathUtils');
5
5
  const getConfigObj = require('../utils/getConfigObj');
6
+ const updatePublishLog = require('../cmpUtils/updatePublishLog');
6
7
 
7
8
  // 获取当前项目的package文件
8
9
  const currentPackageJsonDir = catchCurPackageJson();
@@ -94,6 +95,8 @@ const publish2oss = (ossType, ossConfig, assetsRoot, fileExtensions = ['.js', '.
94
95
  const widgetFilesMap = getResultFilesByWidgetName(results);
95
96
  if (widgetFilesMap) {
96
97
  console.info('上传至 OSS 的文件信息:\n', widgetFilesMap);
98
+ // 更新发布日志
99
+ updatePublishLog(widgetFilesMap);
97
100
  }
98
101
  })
99
102
  .catch((error) => {
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "neo-custom-cmp-template",
3
- "version": "1.1.0",
3
+ "version": "1.1.1",
4
4
  "description": "neo自定义组件模板(react&ts技术栈)",
5
5
  "keywords": [
6
6
  "自定义组件模板",
@@ -1,6 +1,6 @@
1
1
  # 联系人表单组件
2
-
3
2
  基于 Ant Design 的联系人表单组件,支持姓名、所有人、业务类型、所属部门、手机号等字段的输入和提交。
3
+ 【备注】使用 cursor 生成的自定义组件。
4
4
 
5
5
  ## 功能特性
6
6
 
@@ -1,11 +1,6 @@
1
1
  # XObject 数据表格组件
2
2
  基于 XObject 的数据表格组件,支持增删改查操作,表格列根据 `getXObjectDesc` 返回的 fields 动态生成。
3
3
 
4
- - 对应的生成指令
5
- ```
6
- @utils/ 请根据这里提供的方法,参照 @contact-card-list/ 使用 antd 组件 写一个 表格组件,展示属性配置 xobject 对应的 业务数据列表,支持创建、编辑、删除操作。其中表格展示的列 根据 getXObjectDesc 返回的 fields 生成,表格的 Title 根据 其返回的 label 显示。另外 请使用 propsSchemaCreator 生成自定义组件的属性配置,支持 xobject 选择配置,其中 xobject 的选项 使用 getEntityList获取。
7
- ```
8
-
9
4
  ## 功能特性
10
5
 
11
6
  - 📊 **动态表格列**:根据 XObject 字段描述自动生成表格列
@@ -142,6 +142,14 @@ export default class XObjectTable extends React.PureComponent<
142
142
  entityTypeList: [],
143
143
  };
144
144
 
145
+ if (this.props.xObjectApiKey) {
146
+ // 初始化字段列表、加载数据和业务类型列表
147
+ this.loadFieldList().then(() => {
148
+ this.loadData();
149
+ });
150
+ this.getEntityTypeList();
151
+ }
152
+
145
153
  // 绑定方法上下文
146
154
  this.loadData = this.loadData.bind(this);
147
155
  this.loadFieldList = this.loadFieldList.bind(this);
@@ -153,18 +161,6 @@ export default class XObjectTable extends React.PureComponent<
153
161
  this.handleTableChange = this.handleTableChange.bind(this);
154
162
  }
155
163
 
156
- /**
157
- * 组件挂载后执行
158
- * 初始化字段列表、加载数据和业务类型列表
159
- */
160
- async componentDidMount() {
161
- if (this.props.xObjectApiKey) {
162
- await this.loadFieldList();
163
- this.loadData();
164
- this.getEntityTypeList();
165
- }
166
- }
167
-
168
164
  /**
169
165
  * 获取业务类型列表
170
166
  * 用于下拉选择框的选项数据
@@ -1,11 +1,6 @@
1
1
  # XObject 数据表格组件
2
2
  基于 XObject 的数据表格组件,支持增删改查操作,表格列根据 `getXObjectDesc` 返回的 fields 动态生成。
3
3
 
4
- - 对应的生成指令
5
- ```
6
- @utils/ 请根据这里提供的方法,参照 @contact-card-list/ 使用 antd 组件 写一个 表格组件,展示属性配置 xobject 对应的 业务数据列表,支持创建、编辑、删除操作。其中表格展示的列 根据 getXObjectDesc 返回的 fields 生成,表格的 Title 根据 其返回的 label 显示。另外 请使用 propsSchemaCreator 生成自定义组件的属性配置,支持 xobject 选择配置,其中 xobject 的选项 使用 getEntityList获取。
7
- ```
8
-
9
4
  ## 功能特性
10
5
 
11
6
  - 📊 **动态表格列**:根据 XObject 字段描述自动生成表格列
@@ -136,6 +136,14 @@ export default class XObjectTable extends React.PureComponent<
136
136
  entityTypeList: [],
137
137
  };
138
138
 
139
+ if (this.props.xObjectApiKey) {
140
+ // 初始化字段列表、加载数据和业务类型列表
141
+ this.loadFieldList().then(() => {
142
+ this.loadData();
143
+ });
144
+ this.getEntityTypeList();
145
+ }
146
+
139
147
  // 绑定方法上下文
140
148
  this.loadData = this.loadData.bind(this);
141
149
  this.loadFieldList = this.loadFieldList.bind(this);
@@ -147,18 +155,6 @@ export default class XObjectTable extends React.PureComponent<
147
155
  this.handleTableChange = this.handleTableChange.bind(this);
148
156
  }
149
157
 
150
- /**
151
- * 组件挂载后执行
152
- * 初始化字段列表、加载数据和业务类型列表
153
- */
154
- async componentDidMount() {
155
- if (this.props.xObjectApiKey) {
156
- await this.loadFieldList();
157
- this.loadData();
158
- await this.getEntityTypeList();
159
- }
160
- }
161
-
162
158
  /**
163
159
  * 获取业务类型列表
164
160
  * 用于下拉选择框的选项数据