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.
Files changed (40) hide show
  1. package/package.json +1 -1
  2. package/src/module/index.js +32 -26
  3. package/src/module/main.js +161 -267
  4. package/src/module/neoInit.js +1 -0
  5. package/src/neo/NeoUMDContent.js +5 -5
  6. package/src/neo/neoService.js +17 -18
  7. package/src/oss/publish2oss.js +174 -71
  8. package/src/template/antd-custom-cmp-template/README.md +26 -2
  9. package/src/template/antd-custom-cmp-template/neo.config.js +2 -2
  10. package/src/template/echarts-custom-cmp-template/README.md +26 -2
  11. package/src/template/echarts-custom-cmp-template/neo.config.js +4 -3
  12. package/src/template/empty-custom-cmp-template/README.md +26 -0
  13. package/src/template/empty-custom-cmp-template/neo.config.js +2 -2
  14. package/src/template/neo-custom-cmp-template/README.md +26 -2
  15. package/src/template/neo-custom-cmp-template/neo.config.js +1 -1
  16. package/src/template/react-custom-cmp-template/README.md +26 -2
  17. package/src/template/react-custom-cmp-template/neo.config.js +2 -2
  18. package/src/template/react-ts-custom-cmp-template/README.md +26 -2
  19. package/src/template/react-ts-custom-cmp-template/neo.config.js +2 -2
  20. package/src/template/vue2-custom-cmp-template/README.md +26 -2
  21. package/src/template/vue2-custom-cmp-template/neo.config.js +2 -2
  22. package/src/{cmpUtils → utils/cmpUtils}/createCmpByTemplate.js +7 -5
  23. package/src/{cmpUtils → utils/cmpUtils}/createCmpByZip.js +5 -2
  24. package/src/{cmpUtils → utils/cmpUtils}/createCommonModulesCode.js +2 -2
  25. package/src/{cmpUtils → utils/cmpUtils}/getCmpModelRegisterCode.js +1 -1
  26. package/src/{cmpUtils → utils/cmpUtils}/getCmpPreviewCode.js +1 -1
  27. package/src/{cmpUtils → utils/cmpUtils}/getCmpRegisterCode.js +1 -1
  28. package/src/{cmpUtils → utils/cmpUtils}/getCmpTypeByDir.js +2 -2
  29. package/src/{cmpUtils → utils/cmpUtils}/hasCmpTypeByDir.js +1 -1
  30. package/src/{cmpUtils → utils/cmpUtils}/previewCmp.js +3 -3
  31. package/src/{cmpUtils → utils/cmpUtils}/pullCmp.js +9 -9
  32. package/src/{cmpUtils → utils/cmpUtils}/pushCmp.js +7 -5
  33. package/src/utils/generateEntries.js +73 -0
  34. package/src/{projectUtils → utils/projectUtils}/createCmpProjectByTemplate.js +10 -6
  35. package/src/{projectUtils → utils/projectUtils}/createCmpProjectZip.js +1 -3
  36. package/src/{projectUtils → utils/projectUtils}/getEntries.js +2 -2
  37. package/src/{projectUtils → utils/projectUtils}/getEntriesWithAutoRegister.js +2 -2
  38. package/src/{projectUtils → utils/projectUtils}/updatePublishLog.js +1 -1
  39. package/src/template/neo-custom-cmp-template/pushCmp.js +0 -166
  40. /package/src/{projectUtils → utils/projectUtils}/hasNeoProject.js +0 -0
@@ -1,166 +0,0 @@
1
- const fs = require('fs');
2
- const path = require('path');
3
- const _ = require('lodash');
4
- const { catchCurPackageJson } = require('../utils/pathUtils');
5
- const getConfigObj = require('../utils/getConfigObj');
6
- const ora = require('ora');
7
- const NeoService = require('../neo/neoService');
8
- const { getFramework } = require('../utils/common');
9
- const createCmpProjectZip = require('../projectUtils/createCmpProjectZip');
10
-
11
- // 获取当前项目的package文件
12
- const currentPackageJsonDir = catchCurPackageJson();
13
- const currentPackageJson = getConfigObj(currentPackageJsonDir);
14
-
15
- /**
16
- * 构建组件数据映射
17
- * @param {string} assetsRoot 构建产物的目录
18
- * @param {object} cmpInfo 自定义组件信息
19
- * @returns {Promise<object|null>} 自定义组件数据(含自定义组件模型信息)
20
- */
21
- const buildComponentData = async (assetsRoot, cmpInfo) => {
22
- if (!cmpInfo || !cmpInfo.cmpType) {
23
- console.error('自定义组件信息或组件名称不能为空');
24
- return null;
25
- }
26
-
27
- const { cmpType } = cmpInfo;
28
-
29
- if (!assetsRoot || !fs.existsSync(assetsRoot)) {
30
- console.error(`未找到自定义组件目录: ${assetsRoot}`);
31
- return null;
32
- }
33
- const widgetName = _.camelCase(cmpType);
34
- const modelFile = path.join(assetsRoot, `${widgetName}Model.js`);
35
-
36
- // 为 Node.js 环境设置全局 window 对象(模型文件可能需要)
37
- // 使用 globalThis 以确保在 Node.js 和浏览器环境中都能工作
38
- const originalWindow = globalThis.window;
39
- if (!globalThis.window) {
40
- globalThis.window = {
41
- console: console,
42
- neoRequire: () => {},
43
- postMessage: () => {}
44
- // 可以添加其他常用的 window 属性
45
- };
46
- }
47
-
48
- try {
49
- // 加载自定义组件模型资源文件
50
- if (fs.existsSync(modelFile)) {
51
- // 加载自定义组件模型资源文件
52
- let modelModule = require(modelFile);
53
- // 获取导出的模型类(可能是 default 导出或命名导出)
54
- // const CatchCustomCmpModelClass = modelModule.default || modelModule;
55
- } else {
56
- console.error(`未找到自定义组件模型文件,请检查以下路径是否存在:`, modelFile);
57
- return null;
58
- }
59
- if (!window.NEOEditorCustomModels) {
60
- console.error(
61
- `模型文件未导出有效模型方法(CatchCustomCmpModelClass),模型文件地址: ${modelFile} `
62
- );
63
- return null;
64
- }
65
-
66
- const ModelClass = window.NEOEditorCustomModels[cmpType];
67
- if (!ModelClass) {
68
- console.error(`未找到自定义组件模型类(${cmpType}),模型文件地址: ${modelFile} `);
69
- return null;
70
- }
71
- // 实例化模型类
72
- const modelInstance = new ModelClass();
73
-
74
- if (!modelInstance) {
75
- console.error(`未找到自定义组件模型信息(${cmpType}),模型文件地址: ${modelFile} `);
76
- return null;
77
- }
78
-
79
- // 构建组件数据,合并模型实例的信息
80
- const curCmpInfo = {
81
- ...cmpInfo,
82
- plugin: cmpInfo.modelAsset,
83
- version: currentPackageJson.version || '1.0.0',
84
- // 技术栈标识: 从 package.json / framework 字段获取,没有则默认 为 react ts 技术栈
85
- framework: currentPackageJson.framework ? getFramework(currentPackageJson.framework) : '0', // 0: React, 1: vue2, 2: jQuery, 3: vue3
86
- // 从模型实例中提取并设置组件信息
87
- label: modelInstance.label || cmpType,
88
- description: modelInstance.description || '',
89
- componentCategory: (modelInstance.tags || []).join(','),
90
- icon: modelInstance.iconSrc,
91
- defaultProps: JSON.stringify(modelInstance.defaultComProps || {}),
92
- previewProps: JSON.stringify(modelInstance.previewComProps || {}),
93
- propsSchema: JSON.stringify(modelInstance.propsSchema || []),
94
- events: modelInstance.events || [],
95
- actions: modelInstance.actions || [],
96
- // 如果模型实例中有其他属性,也可以添加
97
- exposedToDesigner:
98
- modelInstance.exposedToDesigner !== undefined ? modelInstance.exposedToDesigner : true,
99
- namespace: modelInstance.namespace || 'neo-cmp-cli',
100
- enableDuplicate:
101
- modelInstance.enableDuplicate !== undefined ? modelInstance.enableDuplicate : true
102
- };
103
-
104
- console.log(`自定义组件模型信息(${cmpType}):`, curCmpInfo);
105
- return curCmpInfo;
106
- } catch (error) {
107
- console.error(`自定义组件模型文件解析失败 (${modelFile || '未知路径'}):`, error.message);
108
- console.error(error.stack);
109
- return null;
110
- } finally {
111
- // 恢复原始的 window 对象(如果之前存在)
112
- if (originalWindow === undefined) {
113
- delete globalThis.window;
114
- } else {
115
- globalThis.window = originalWindow;
116
- }
117
- }
118
- };
119
-
120
- /**
121
- * 发布组件到 NeoCRM
122
- * @param {object} config 配置信息
123
- * @param {string} assetsRoot 构建产物的目录
124
- */
125
- const pushCmp = async (config, cmpType) => {
126
- const { auth: credentials } = config;
127
-
128
- if (!credentials) {
129
- console.error('未找到 NeoCRM 平台授权配置(neo.config.js / neoConfig');
130
- return;
131
- }
132
-
133
- const spinner = ora('正在发布组件...').start();
134
-
135
- try {
136
- // 步骤 1: 初始化 NeoService
137
- spinner.text = '发布自定义组件:初始化 NeoService...';
138
- const neoService = new NeoService(config);
139
-
140
- // 步骤 2: 打包源码文件(打包单个自定义组件源码)
141
- spinner.text = '发布自定义组件:打包源码文件(含单个自定义组件源码)...';
142
- createCmpProjectZip(cmpType, process.cwd(), config.assetsRoot);
143
-
144
- // 步骤 3: 上传构建后资源文件
145
- spinner.text = '发布自定义组件:上传自定义组件构建产物到 OSS...';
146
- const cmpInfo = await neoService.publish2oss(cmpType);
147
-
148
- // 步骤 5: 构建组件数据
149
- spinner.text = '发布自定义组件:构建组件数据...';
150
- const componentInfo = await buildComponentData(config.assetsRoot, cmpInfo);
151
- if (!componentInfo) {
152
- throw new Error(`构建组件数据失败,未获取到自定义组件模型信息。(${cmpType})`);
153
- }
154
-
155
- // 步骤 6: 保存组件信息
156
- spinner.text = '发布自定义组件:保存组件信息...';
157
- await neoService.updateCustomComponent(componentInfo);
158
-
159
- spinner.succeed('自定义组件发布成功!\n', componentInfo);
160
- } catch (error) {
161
- spinner.fail(`自定义组件发布失败: ${error.message}`);
162
- throw error;
163
- }
164
- };
165
-
166
- module.exports = pushCmp;