neo-cmp-cli 1.8.6-beta.2 → 1.8.6-beta.5

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 (156) hide show
  1. package/dist/_virtual/AddNeoRequirePlugin.js +8 -0
  2. package/dist/_virtual/OverloadYield.js +5 -0
  3. package/dist/_virtual/_commonjsHelpers.js +40 -0
  4. package/dist/_virtual/array-set.js +5 -0
  5. package/dist/_virtual/base64-vlq.js +5 -0
  6. package/dist/_virtual/base64.js +5 -0
  7. package/dist/_virtual/binary-search.js +5 -0
  8. package/dist/_virtual/createCmpByZip.js +8 -0
  9. package/dist/_virtual/deleteCmp.js +8 -0
  10. package/dist/_virtual/index.js +9 -0
  11. package/dist/_virtual/mapping-list.js +5 -0
  12. package/dist/_virtual/neoLogin.js +8 -0
  13. package/dist/_virtual/neoService.js +8 -0
  14. package/dist/_virtual/openProject.js +8 -0
  15. package/dist/_virtual/publish2oss.js +8 -0
  16. package/dist/_virtual/pullCmp.js +8 -0
  17. package/dist/_virtual/pushCmp.js +8 -0
  18. package/dist/_virtual/quick-sort.js +5 -0
  19. package/dist/_virtual/regenerator.js +5 -0
  20. package/dist/_virtual/regeneratorAsync.js +5 -0
  21. package/dist/_virtual/regeneratorAsyncGen.js +5 -0
  22. package/dist/_virtual/regeneratorAsyncIterator.js +5 -0
  23. package/dist/_virtual/regeneratorDefine.js +5 -0
  24. package/dist/_virtual/regeneratorKeys.js +5 -0
  25. package/dist/_virtual/regeneratorRuntime.js +5 -0
  26. package/dist/_virtual/regeneratorValues.js +5 -0
  27. package/dist/_virtual/source-map-consumer.js +5 -0
  28. package/dist/_virtual/source-map-generator.js +5 -0
  29. package/dist/_virtual/source-map-support.js +5 -0
  30. package/dist/_virtual/source-map.js +5 -0
  31. package/dist/_virtual/source-node.js +5 -0
  32. package/dist/_virtual/typeof.js +5 -0
  33. package/dist/_virtual/typescript.js +5 -0
  34. package/dist/_virtual/util.js +5 -0
  35. package/dist/config/auth.config.js +50 -0
  36. package/dist/config/default.config.js +225 -0
  37. package/dist/config/index.js +27 -0
  38. package/dist/main.js +9 -0
  39. package/dist/main2.js +261 -0
  40. package/dist/module/inspect.js +64 -0
  41. package/dist/module/neoInit.js +69 -0
  42. package/dist/module/neoInitByCopy.js +81 -0
  43. package/dist/neo/neoLogin.js +663 -0
  44. package/dist/neo/neoRequire.js +118 -0
  45. package/dist/neo/neoService.js +1246 -0
  46. package/dist/node_modules/@babel/runtime/helpers/OverloadYield.js +19 -0
  47. package/dist/node_modules/@babel/runtime/helpers/esm/asyncToGenerator.js +29 -0
  48. package/dist/node_modules/@babel/runtime/helpers/esm/extends.js +13 -0
  49. package/dist/node_modules/@babel/runtime/helpers/regenerator.js +105 -0
  50. package/dist/node_modules/@babel/runtime/helpers/regeneratorAsync.js +24 -0
  51. package/dist/node_modules/@babel/runtime/helpers/regeneratorAsyncGen.js +23 -0
  52. package/dist/node_modules/@babel/runtime/helpers/regeneratorAsyncIterator.js +50 -0
  53. package/dist/node_modules/@babel/runtime/helpers/regeneratorDefine.js +37 -0
  54. package/dist/node_modules/@babel/runtime/helpers/regeneratorKeys.js +25 -0
  55. package/dist/node_modules/@babel/runtime/helpers/regeneratorRuntime.js +98 -0
  56. package/dist/node_modules/@babel/runtime/helpers/regeneratorValues.js +35 -0
  57. package/dist/node_modules/@babel/runtime/helpers/typeof.js +25 -0
  58. package/dist/node_modules/@babel/runtime/regenerator/index.js +29 -0
  59. package/dist/node_modules/buffer-from/index.js +57 -0
  60. package/dist/node_modules/source-map/lib/array-set.js +134 -0
  61. package/dist/node_modules/source-map/lib/base64-vlq.js +144 -0
  62. package/dist/node_modules/source-map/lib/base64.js +81 -0
  63. package/dist/node_modules/source-map/lib/binary-search.js +122 -0
  64. package/dist/node_modules/source-map/lib/mapping-list.js +94 -0
  65. package/dist/node_modules/source-map/lib/quick-sort.js +126 -0
  66. package/dist/node_modules/source-map/lib/source-map-consumer.js +1018 -0
  67. package/dist/node_modules/source-map/lib/source-map-generator.js +385 -0
  68. package/dist/node_modules/source-map/lib/source-node.js +400 -0
  69. package/dist/node_modules/source-map/lib/util.js +449 -0
  70. package/dist/node_modules/source-map/source-map.js +25 -0
  71. package/dist/node_modules/source-map-support/source-map-support.js +610 -0
  72. package/dist/node_modules/typescript/lib/typescript.js +22376 -0
  73. package/dist/oss/publish2oss.js +378 -0
  74. package/dist/plugins/AddNeoRequirePlugin.js +178 -0
  75. package/dist/utils/autoEntryRootDir.js +98 -0
  76. package/dist/utils/cmpUtils/createCmpByTemplate.js +73 -0
  77. package/dist/utils/cmpUtils/createCmpByZip.js +530 -0
  78. package/dist/utils/cmpUtils/createCommonModulesCode.js +84 -0
  79. package/dist/utils/cmpUtils/deleteCmp.js +98 -0
  80. package/dist/utils/cmpUtils/getCmpModelRegisterCode.js +38 -0
  81. package/dist/utils/cmpUtils/getCmpPreviewCode.js +37 -0
  82. package/dist/utils/cmpUtils/getCmpRegisterCode.js +38 -0
  83. package/dist/utils/cmpUtils/getCmpTypeByDir.js +58 -0
  84. package/dist/utils/cmpUtils/hasCmpTypeByDir.js +25 -0
  85. package/dist/utils/cmpUtils/previewCmp.js +74 -0
  86. package/dist/utils/cmpUtils/pullCmp.js +144 -0
  87. package/dist/utils/cmpUtils/pushCmp.js +290 -0
  88. package/dist/utils/common.js +121 -0
  89. package/dist/utils/configureNeoBuild.js +153 -0
  90. package/dist/utils/generateEntries.js +73 -0
  91. package/dist/utils/neoConfigInit.js +25 -0
  92. package/dist/utils/neoParams.js +23 -0
  93. package/dist/utils/pathUtils.js +48 -0
  94. package/dist/utils/projectNameValidator.js +89 -0
  95. package/dist/utils/projectUtils/createCmpProjectByTemplate.js +74 -0
  96. package/dist/utils/projectUtils/createCmpProjectZip.js +135 -0
  97. package/dist/utils/projectUtils/getEntries.js +99 -0
  98. package/dist/utils/projectUtils/getEntriesWithAutoRegister.js +127 -0
  99. package/dist/utils/projectUtils/hasNeoProject.js +31 -0
  100. package/dist/utils/projectUtils/openProject.js +168 -0
  101. package/dist/utils/projectUtils/updatePublishLog.js +45 -0
  102. package/dist/utils/replaceInFilesByMap.js +70 -0
  103. package/dist/utils/replaceInPackage.js +151 -0
  104. package/dist/utils/resetPackageVersion.js +134 -0
  105. package/package.json +3 -3
  106. package/test/deprecate-versions.js +1 -1
  107. package/src/config/auth.config.js +0 -27
  108. package/src/config/default.config.js +0 -176
  109. package/src/config/index.js +0 -9
  110. package/src/initData/defaultTemplate.html +0 -13
  111. package/src/initData/neo.config.js +0 -138
  112. package/src/main.js +0 -221
  113. package/src/module/inspect.js +0 -41
  114. package/src/module/neoInit.js +0 -55
  115. package/src/module/neoInitByCopy.js +0 -61
  116. package/src/neo/NeoUMDContent.js +0 -30
  117. package/src/neo/neoLogin.js +0 -565
  118. package/src/neo/neoRequire.js +0 -125
  119. package/src/neo/neoService.js +0 -874
  120. package/src/neo/webpack.mf.js +0 -60
  121. package/src/neo/wrapperContent.js +0 -16
  122. package/src/oss/publish2oss.js +0 -348
  123. package/src/plugins/AddNeoRequirePlugin-v1.js +0 -47
  124. package/src/plugins/AddNeoRequirePlugin.js +0 -179
  125. package/src/plugins/README.md +0 -109
  126. package/src/utils/autoEntryRootDir.js +0 -85
  127. package/src/utils/cmpUtils/createCmpByTemplate.js +0 -60
  128. package/src/utils/cmpUtils/createCmpByZip.js +0 -408
  129. package/src/utils/cmpUtils/createCommonModulesCode.js +0 -121
  130. package/src/utils/cmpUtils/deleteCmp.js +0 -63
  131. package/src/utils/cmpUtils/getCmpModelRegisterCode.js +0 -31
  132. package/src/utils/cmpUtils/getCmpPreviewCode.js +0 -43
  133. package/src/utils/cmpUtils/getCmpRegisterCode.js +0 -31
  134. package/src/utils/cmpUtils/getCmpTypeByDir.js +0 -41
  135. package/src/utils/cmpUtils/hasCmpTypeByDir.js +0 -11
  136. package/src/utils/cmpUtils/previewCmp.js +0 -55
  137. package/src/utils/cmpUtils/pullCmp.js +0 -104
  138. package/src/utils/cmpUtils/pushCmp.js +0 -230
  139. package/src/utils/common.js +0 -107
  140. package/src/utils/configureNeoBuild.js +0 -109
  141. package/src/utils/generateEntries.js +0 -63
  142. package/src/utils/neoConfigInit.js +0 -13
  143. package/src/utils/neoParams.js +0 -12
  144. package/src/utils/pathUtils.js +0 -23
  145. package/src/utils/projectNameValidator.js +0 -76
  146. package/src/utils/projectUtils/createCmpProjectByTemplate.js +0 -59
  147. package/src/utils/projectUtils/createCmpProjectZip.js +0 -120
  148. package/src/utils/projectUtils/getEntries.js +0 -80
  149. package/src/utils/projectUtils/getEntriesWithAutoRegister.js +0 -108
  150. package/src/utils/projectUtils/hasNeoProject.js +0 -17
  151. package/src/utils/projectUtils/openProject.js +0 -94
  152. package/src/utils/projectUtils/updatePublishLog.js +0 -30
  153. package/src/utils/replaceInFiles.js +0 -47
  154. package/src/utils/replaceInFilesByMap.js +0 -54
  155. package/src/utils/replaceInPackage.js +0 -134
  156. package/src/utils/resetPackageVersion.js +0 -115
@@ -0,0 +1,1246 @@
1
+ 'use strict';
2
+
3
+ var require$$0$1 = require('axios');
4
+ var require$$1$1 = require('form-data');
5
+ var require$$0$2 = require('node:fs');
6
+ var require$$1 = require('node:path');
7
+ var require$$3 = require('ora');
8
+ var require$$2 = require('lodash');
9
+ var require$$0 = require('akfun');
10
+ var neoLogin = require('../_virtual/neoLogin.js');
11
+ var updatePublishLog$1 = require('../utils/projectUtils/updatePublishLog.js');
12
+ var common = require('../utils/common.js');
13
+ var _extends = require('../node_modules/@babel/runtime/helpers/esm/extends.js');
14
+ var asyncToGenerator = require('../node_modules/@babel/runtime/helpers/esm/asyncToGenerator.js');
15
+ var index = require('../_virtual/index.js');
16
+
17
+ var axios = require$$0$1;
18
+ var FormData = require$$1$1;
19
+ var fs = require$$0$2;
20
+ var path = require$$1;
21
+ var ora = require$$3;
22
+ var _ = require$$2;
23
+ var _require = require$$0,
24
+ resolve = _require.resolve;
25
+ var NeoLoginService = neoLogin;
26
+ var updatePublishLog = updatePublishLog$1.__require();
27
+ var _require2 = common.__require(),
28
+ getFramework = _require2.getFramework,
29
+ errorLog = _require2.errorLog,
30
+ successLog = _require2.successLog;
31
+
32
+ // NeoCRM 平台默认 API 配置
33
+ var NeoCrmAPI = {
34
+ neoBaseURL: 'https://crm.xiaoshouyi.com',
35
+ // 平台根地址
36
+ loginAPI: 'https://login-cd.xiaoshouyi.com/auc/oauth2/auth',
37
+ // code 获取接口地址
38
+ tokenAPI: 'https://login.xiaoshouyi.com/auc/oauth2/token',
39
+ // Token 获取接口地址
40
+ delete: '/rest/metadata/v3.0/ui/customComponents',
41
+ saveAPI: '/rest/metadata/v3.0/ui/customComponents/actions/saveOrUpdateComponent',
42
+ // 创建或者保存接口地址
43
+ queryAll: '/rest/metadata/v3.0/ui/components/filter?custom=true',
44
+ // 不带分页
45
+ getCodeLibAPI: function getCodeLibAPI(cmpType) {
46
+ return "/rest/metadata/v3.0/ui/customComponents/" + cmpType + "/codeLib";
47
+ },
48
+ // 组件源码下载
49
+
50
+ uploadAPI: '/rest/metadata/v3.0/ui/customComponents/actions/upload',
51
+ // 文件上传接口地址(已废弃)
52
+ query: '/rest/metadata/v3.0/ui/customComponents/actions/queryCustomComponents' // 带分页(暂未使用)
53
+ // queryAll_v1: '/rest/metadata/v3.0/ui/customComponents/actions/queryAllCustomComponents', // 不带分页(已废弃)
54
+ };
55
+ var cmpFields = ['cmpType', 'label', 'componentCategory', 'description', 'framework', 'icon', 'iconUrl', 'orderNo', 'version', 'propsSchema', 'defaultProps', 'previewProps', 'events', 'functions', 'asset', 'modelAsset', 'cssAsset', 'codeLib'];
56
+
57
+ /**
58
+ * Neo 平台服务类
59
+ * 提供 token 管理、文件上传、组件更新等功能
60
+ */
61
+ var NeoService = /*#__PURE__*/function () {
62
+ /**
63
+ * 初始化 Neo 服务
64
+ * @param {object} config 配置信息
65
+ * @param {string} config.authType 授权类型,可选值:oauth2(默认)、password
66
+ * @param {string} config.neoBaseURL Neo 平台根地址
67
+ * @param {string} config.tokenAPI Token 获取接口地址
68
+ * @param {string} config.loginURL OAuth2 登录授权 URL(OAuth2 模式需要)
69
+ * @param {object} config.auth 授权信息
70
+ * @param {string} config.auth.client_id 客户端 ID
71
+ * @param {string} config.auth.client_secret 客户端密钥
72
+ * @param {string} config.auth.username 用户名(password 模式需要)
73
+ * @param {string} config.auth.password 密码(password 模式需要)
74
+ */
75
+ function NeoService(config) {
76
+ if (config === void 0) {
77
+ config = {};
78
+ }
79
+ var _ref = config || {},
80
+ assetsRoot = _ref.assetsRoot,
81
+ neoBaseURL = _ref.neoBaseURL,
82
+ tokenAPI = _ref.tokenAPI,
83
+ loginURL = _ref.loginURL,
84
+ auth = _ref.auth,
85
+ authType = _ref.authType;
86
+
87
+ // 设置授权类型,默认为 oauth2
88
+ this.authType = authType || 'oauth2';
89
+ if (this.authType === 'password' && !auth) {
90
+ errorLog('密码授权模式时,neo.config.js / neoConfig / auth 配置不能为空');
91
+ process.exit(1);
92
+ }
93
+
94
+ // 根据授权类型验证必需的配置项
95
+ if (this.authType === 'password') {
96
+ if (!auth.client_id || !auth.client_secret || !auth.username || !auth.password) {
97
+ errorLog('neo.config.js / neoConfig / auth 配置不完整(password 模式),需要包含 client_id、client_secret、username、password');
98
+ process.exit(1);
99
+ }
100
+ } else if (this.authType === 'oauth2') {
101
+ if (!loginURL || !tokenAPI) {
102
+ errorLog('neo.config.js / neoConfig 配置不完整(oauth2 模式),需要包含 loginURL、tokenAPI 配置。');
103
+ process.exit(1);
104
+ }
105
+ } else {
106
+ errorLog("\u4E0D\u652F\u6301\u7684\u6388\u6743\u7C7B\u578B: " + this.authType + "\uFF0C\u53EF\u9009\u503C\uFF1Aoauth2\u3001password");
107
+ process.exit(1);
108
+ }
109
+ this.assetsRoot = assetsRoot || resolve('dist');
110
+ this.neoBaseURL = neoBaseURL || NeoCrmAPI.neoBaseURL;
111
+ this.tokenAPI = tokenAPI || NeoCrmAPI.tokenAPI;
112
+ this.loginURL = loginURL || NeoCrmAPI.loginAPI;
113
+ this.auth = auth;
114
+ this.cmpList = [];
115
+ this.cmpInfoMap = {};
116
+
117
+ // Token 缓存
118
+ this.tokenCache = {
119
+ token: null,
120
+ expiresAt: null
121
+ };
122
+ }
123
+
124
+ /**
125
+ * 构建完整的 API URL
126
+ * @param {string} url 相对或绝对 URL
127
+ * @returns {string} 完整的 URL
128
+ */
129
+ var _proto = NeoService.prototype;
130
+ _proto.buildFullUrl = function buildFullUrl(url) {
131
+ if (url.startsWith('http://') || url.startsWith('https://')) {
132
+ return url;
133
+ }
134
+ return "" + this.neoBaseURL + url;
135
+ }
136
+
137
+ // 获取文件上传接口地址
138
+ ;
139
+ _proto.uploadAPI = function uploadAPI() {
140
+ return this.buildFullUrl(NeoCrmAPI.uploadAPI);
141
+ }
142
+
143
+ // 获取组件信息保存接口地址
144
+ ;
145
+ _proto.saveAPI = function saveAPI() {
146
+ return this.buildFullUrl(NeoCrmAPI.saveAPI);
147
+ }
148
+
149
+ /**
150
+ * 检查 token 是否过期
151
+ * @returns {boolean} true 表示已过期,false 表示未过期
152
+ */;
153
+ _proto.isTokenExpired = function isTokenExpired() {
154
+ if (!this.tokenCache.token || !this.tokenCache.expiresAt) {
155
+ return true;
156
+ }
157
+ // 提前 60 秒判断为过期,避免边缘情况
158
+ return Date.now() >= this.tokenCache.expiresAt;
159
+ }
160
+
161
+ /**
162
+ * 获取 token(含授权信息、租户信息)
163
+ * 根据 authType 自动选择授权模式:oauth2 或 password
164
+ * @returns {Promise<string>} token
165
+ */;
166
+ _proto.getToken =
167
+ /*#__PURE__*/
168
+ function () {
169
+ var _getToken = asyncToGenerator(/*#__PURE__*/index.mark(function _callee() {
170
+ return index.wrap(function (_context) {
171
+ while (1) switch (_context.prev = _context.next) {
172
+ case 0:
173
+ if (this.isTokenExpired()) {
174
+ _context.next = 1;
175
+ break;
176
+ }
177
+ return _context.abrupt("return", this.tokenCache.token);
178
+ case 1:
179
+ if (!(this.authType === 'oauth2')) {
180
+ _context.next = 3;
181
+ break;
182
+ }
183
+ _context.next = 2;
184
+ return this.getTokenByOAuth2();
185
+ case 2:
186
+ return _context.abrupt("return", _context.sent);
187
+ case 3:
188
+ _context.next = 4;
189
+ return this.getTokenByPassword();
190
+ case 4:
191
+ return _context.abrupt("return", _context.sent);
192
+ case 5:
193
+ case "end":
194
+ return _context.stop();
195
+ }
196
+ }, _callee, this);
197
+ }));
198
+ function getToken() {
199
+ return _getToken.apply(this, arguments);
200
+ }
201
+ return getToken;
202
+ }()
203
+ /**
204
+ * 使用密码模式获取 token
205
+ * @returns {Promise<string>} token
206
+ */
207
+ ;
208
+ _proto.getTokenByPassword =
209
+ /*#__PURE__*/
210
+ function () {
211
+ var _getTokenByPassword = asyncToGenerator(/*#__PURE__*/index.mark(function _callee2() {
212
+ var spinner, formData, tokenUrl, response, _ref2, access_token, expires_in, expiresIn, _t;
213
+ return index.wrap(function (_context2) {
214
+ while (1) switch (_context2.prev = _context2.next) {
215
+ case 0:
216
+ spinner = ora('获取 token(密码模式)...').start(); // 检查缓存是否有效
217
+ if (this.isTokenExpired()) {
218
+ _context2.next = 1;
219
+ break;
220
+ }
221
+ successLog('使用缓存的 token。', spinner);
222
+ return _context2.abrupt("return", this.tokenCache.token);
223
+ case 1:
224
+ // 构建表单数据格式的请求参数
225
+ formData = new URLSearchParams();
226
+ formData.append('grant_type', 'password');
227
+ formData.append('client_id', this.auth.client_id);
228
+ formData.append('client_secret', this.auth.client_secret);
229
+ formData.append('username', this.auth.username);
230
+ formData.append('password', this.auth.password);
231
+ tokenUrl = this.buildFullUrl(this.tokenAPI);
232
+ _context2.prev = 2;
233
+ _context2.next = 3;
234
+ return axios.post(tokenUrl, formData.toString(), {
235
+ headers: {
236
+ 'Content-Type': 'application/x-www-form-urlencoded'
237
+ }
238
+ });
239
+ case 3:
240
+ response = _context2.sent;
241
+ _ref2 = response.data || {}, access_token = _ref2.access_token, expires_in = _ref2.expires_in;
242
+ if (!access_token) {
243
+ errorLog('获取 token 失败(授权配置错误):响应中未包含 access_token,' + JSON.stringify(response.data), spinner);
244
+ process.exit(1);
245
+ }
246
+
247
+ // 缓存 token(提前 60 秒过期,避免边缘情况)
248
+ expiresIn = parseInt(expires_in) || 3600; // 默认 1 小时
249
+ this.tokenCache = {
250
+ token: access_token,
251
+ expiresAt: Date.now() + (expiresIn - 60) * 1000
252
+ };
253
+ spinner.clear();
254
+ spinner.stop();
255
+ return _context2.abrupt("return", access_token);
256
+ case 4:
257
+ _context2.prev = 4;
258
+ _t = _context2["catch"](2);
259
+ errorLog('获取 token 失败', spinner);
260
+ errorLog("\n\u83B7\u53D6 token \u5931\u8D25: " + _t.message);
261
+ errorLog("\ntoken \u6388\u6743\u5730\u5740: " + tokenUrl);
262
+ errorLog("\ntoken \u8BF7\u6C42\u53C2\u6570: " + formData);
263
+ if (_t.response) {
264
+ errorLog("\u54CD\u5E94\u6570\u636E: " + JSON.stringify(_t.response.data));
265
+ }
266
+ process.exit(1);
267
+ case 5:
268
+ case "end":
269
+ return _context2.stop();
270
+ }
271
+ }, _callee2, this, [[2, 4]]);
272
+ }));
273
+ function getTokenByPassword() {
274
+ return _getTokenByPassword.apply(this, arguments);
275
+ }
276
+ return getTokenByPassword;
277
+ }()
278
+ /**
279
+ * 获取 OAuth2 授权码模式的 token
280
+ * @returns {Promise<string>} token
281
+ */
282
+ ;
283
+ _proto.getTokenByOAuth2 =
284
+ /*#__PURE__*/
285
+ function () {
286
+ var _getTokenByOAuth = asyncToGenerator(/*#__PURE__*/index.mark(function _callee3() {
287
+ var spinner, oauth2Config, loginService, accessToken, _t2;
288
+ return index.wrap(function (_context3) {
289
+ while (1) switch (_context3.prev = _context3.next) {
290
+ case 0:
291
+ spinner = ora('获取 token(OAuth2 模式)...').start();
292
+ _context3.prev = 1;
293
+ // 构建 OAuth2 配置
294
+ oauth2Config = {
295
+ loginURL: this.loginURL,
296
+ tokenAPI: this.tokenAPI
297
+ };
298
+ loginService = new NeoLoginService(oauth2Config);
299
+ _context3.next = 2;
300
+ return loginService.getAccessToken();
301
+ case 2:
302
+ accessToken = _context3.sent;
303
+ // 缓存 token(OAuth2 模式下的 token 有效期由 NeoLoginService 管理)
304
+ // 这里我们设置一个较长的过期时间,实际过期检查由 NeoLoginService 内部处理
305
+ this.tokenCache = {
306
+ token: accessToken,
307
+ expiresAt: Date.now() + 7200 * 1000 // 默认 2 小时,实际由 NeoLoginService 管理
308
+ };
309
+ spinner.clear();
310
+ spinner.stop();
311
+ return _context3.abrupt("return", accessToken);
312
+ case 3:
313
+ _context3.prev = 3;
314
+ _t2 = _context3["catch"](1);
315
+ errorLog('获取 token 失败(OAuth2 模式)', spinner);
316
+ errorLog("\n\u83B7\u53D6 token \u5931\u8D25: " + _t2.message);
317
+ if (_t2.response) {
318
+ errorLog("\u54CD\u5E94\u6570\u636E: " + JSON.stringify(_t2.response.data));
319
+ }
320
+ process.exit(1);
321
+ case 4:
322
+ case "end":
323
+ return _context3.stop();
324
+ }
325
+ }, _callee3, this, [[1, 3]]);
326
+ }));
327
+ function getTokenByOAuth2() {
328
+ return _getTokenByOAuth.apply(this, arguments);
329
+ }
330
+ return getTokenByOAuth2;
331
+ }()
332
+ /**
333
+ * 刷新 token
334
+ * @returns {Promise<string>} 新的 token
335
+ */
336
+ ;
337
+ _proto.refreshToken =
338
+ /*#__PURE__*/
339
+ function () {
340
+ var _refreshToken = asyncToGenerator(/*#__PURE__*/index.mark(function _callee4() {
341
+ return index.wrap(function (_context4) {
342
+ while (1) switch (_context4.prev = _context4.next) {
343
+ case 0:
344
+ // 清除缓存,强制获取新 token
345
+ this.tokenCache = {
346
+ token: null,
347
+ expiresAt: null
348
+ };
349
+ _context4.next = 1;
350
+ return this.getToken();
351
+ case 1:
352
+ return _context4.abrupt("return", _context4.sent);
353
+ case 2:
354
+ case "end":
355
+ return _context4.stop();
356
+ }
357
+ }, _callee4, this);
358
+ }));
359
+ function refreshToken() {
360
+ return _refreshToken.apply(this, arguments);
361
+ }
362
+ return refreshToken;
363
+ }()
364
+ /**
365
+ * 确保 token 有效,如果过期则自动刷新
366
+ * @returns {Promise<string>} 有效的 token
367
+ */
368
+ ;
369
+ _proto.ensureValidToken =
370
+ /*#__PURE__*/
371
+ function () {
372
+ var _ensureValidToken = asyncToGenerator(/*#__PURE__*/index.mark(function _callee5() {
373
+ var spinner, token, _t3;
374
+ return index.wrap(function (_context5) {
375
+ while (1) switch (_context5.prev = _context5.next) {
376
+ case 0:
377
+ if (this.tokenCache.token) {
378
+ _context5.next = 2;
379
+ break;
380
+ }
381
+ _context5.next = 1;
382
+ return this.getToken();
383
+ case 1:
384
+ return _context5.abrupt("return", _context5.sent);
385
+ case 2:
386
+ if (!this.isTokenExpired()) {
387
+ _context5.next = 6;
388
+ break;
389
+ }
390
+ spinner = ora('token 已过期,正在刷新...').start();
391
+ _context5.prev = 3;
392
+ _context5.next = 4;
393
+ return this.refreshToken();
394
+ case 4:
395
+ token = _context5.sent;
396
+ successLog('token 刷新成功。', spinner);
397
+ return _context5.abrupt("return", token);
398
+ case 5:
399
+ _context5.prev = 5;
400
+ _t3 = _context5["catch"](3);
401
+ errorLog('token 刷新失败。', spinner);
402
+ throw _t3;
403
+ case 6:
404
+ return _context5.abrupt("return", this.tokenCache.token);
405
+ case 7:
406
+ case "end":
407
+ return _context5.stop();
408
+ }
409
+ }, _callee5, this, [[3, 5]]);
410
+ }));
411
+ function ensureValidToken() {
412
+ return _ensureValidToken.apply(this, arguments);
413
+ }
414
+ return ensureValidToken;
415
+ }()
416
+ /**
417
+ * 上传文件到 Neo 平台(已废弃)
418
+ * 备注:已废弃,改为 保存时直接上传组件资源文件
419
+ * @param {string} filePath 文件路径
420
+ * @param {object} options 可选配置
421
+ * @param {string} options.fieldName 表单字段名,默认为 'customComponentCode'
422
+ * @param {number} options.maxSize 最大文件大小(字节),默认 50MB
423
+ * @param {number} options.timeout 超时时间(毫秒),默认 60000
424
+ * @returns {Promise<string>} CDN 地址或文件 URL
425
+ */
426
+ ;
427
+ _proto.uploadFile =
428
+ /*#__PURE__*/
429
+ function () {
430
+ var _uploadFile = asyncToGenerator(/*#__PURE__*/index.mark(function _callee6(filePath, options) {
431
+ var token, fileStat, maxSize, sizeMB, maxSizeMB, fileName, fileSizeKB, spinner, formData, fieldName, fileContent, fullUploadAPI, timeout, requestConfig, response, resultData, responseData, errorMsg, fileUrl, _error$config, status, statusText, _responseData, requestUrl, _t4;
432
+ return index.wrap(function (_context6) {
433
+ while (1) switch (_context6.prev = _context6.next) {
434
+ case 0:
435
+ if (options === void 0) {
436
+ options = {};
437
+ }
438
+ _context6.next = 1;
439
+ return this.ensureValidToken();
440
+ case 1:
441
+ token = _context6.sent;
442
+ if (!(!filePath || typeof filePath !== 'string')) {
443
+ _context6.next = 2;
444
+ break;
445
+ }
446
+ throw new Error("\u6587\u4EF6\u8DEF\u5F84\u65E0\u6548: " + filePath);
447
+ case 2:
448
+ if (fs.existsSync(filePath)) {
449
+ _context6.next = 3;
450
+ break;
451
+ }
452
+ throw new Error("\u6587\u4EF6\u4E0D\u5B58\u5728: " + filePath);
453
+ case 3:
454
+ // 检查文件状态
455
+ fileStat = fs.statSync(filePath);
456
+ if (fileStat.isFile()) {
457
+ _context6.next = 4;
458
+ break;
459
+ }
460
+ throw new Error("\u8DEF\u5F84\u4E0D\u662F\u6587\u4EF6: " + filePath);
461
+ case 4:
462
+ // 检查文件大小
463
+ maxSize = options.maxSize || 5 * 1024 * 1024; // 默认 5MB
464
+ if (!(fileStat.size > maxSize)) {
465
+ _context6.next = 5;
466
+ break;
467
+ }
468
+ sizeMB = (fileStat.size / 1024 / 1024).toFixed(2);
469
+ maxSizeMB = (maxSize / 1024 / 1024).toFixed(2);
470
+ throw new Error("\u6587\u4EF6\u5927\u5C0F\u8D85\u8FC7\u9650\u5236: " + sizeMB + "MB > " + maxSizeMB + "MB");
471
+ case 5:
472
+ if (!(fileStat.size === 0)) {
473
+ _context6.next = 6;
474
+ break;
475
+ }
476
+ throw new Error("\u6587\u4EF6\u4E3A\u7A7A: " + filePath);
477
+ case 6:
478
+ fileName = path.basename(filePath);
479
+ fileSizeKB = (fileStat.size / 1024).toFixed(2);
480
+ spinner = ora("\u6B63\u5728\u4E0A\u4F20\u6587\u4EF6: " + fileName + " (" + fileSizeKB + "KB)...").start();
481
+ _context6.prev = 7;
482
+ // 创建 FormData
483
+ formData = new FormData();
484
+ fieldName = options.fieldName || 'customComponentCode'; // 使用文件流而不是读取整个文件到内存(对大文件更友好)
485
+ fileContent = fs.createReadStream(filePath); // 追加文件到 FormData,第三个参数指定文件名
486
+ formData.append(fieldName, fileContent, fileName);
487
+
488
+ // 构建完整的上传 API 地址
489
+ fullUploadAPI = this.uploadAPI(); // 配置请求选项
490
+ timeout = options.timeout || 60000; // 默认 60 秒
491
+ requestConfig = {
492
+ headers: _extends({
493
+ Authorization: "Bearer " + token,
494
+ 'xsy-inner-source': 'bff'
495
+ }, formData.getHeaders()),
496
+ timeout: timeout,
497
+ // 确保 axios 正确处理大文件和流
498
+ maxContentLength: Infinity,
499
+ // 不限制响应内容长度
500
+ maxBodyLength: Infinity // 不限制请求体长度(适用于文件上传)
501
+ }; // 发送上传请求
502
+ _context6.next = 8;
503
+ return axios.post(fullUploadAPI, formData, requestConfig);
504
+ case 8:
505
+ response = _context6.sent;
506
+ responseData = response.data; // 检查响应状态码
507
+ if (!(response.status !== 200 && response.status !== 201)) {
508
+ _context6.next = 9;
509
+ break;
510
+ }
511
+ throw new Error("\u4E0A\u4F20\u5931\u8D25: HTTP " + response.status);
512
+ case 9:
513
+ if (!(typeof responseData === 'string')) {
514
+ _context6.next = 10;
515
+ break;
516
+ }
517
+ // 如果响应是字符串,直接使用
518
+ resultData = responseData.trim();
519
+ _context6.next = 13;
520
+ break;
521
+ case 10:
522
+ if (!(responseData && typeof responseData === 'object')) {
523
+ _context6.next = 12;
524
+ break;
525
+ }
526
+ if (!(responseData.code !== undefined && responseData.code !== 200 && responseData.code !== 0)) {
527
+ _context6.next = 11;
528
+ break;
529
+ }
530
+ errorMsg = responseData.message || responseData.msg || '未知错误';
531
+ throw new Error("\u4E0A\u4F20\u5931\u8D25: " + errorMsg + " (code: " + responseData.code + ")");
532
+ case 11:
533
+ // 提取数据
534
+ if (responseData.data !== undefined) {
535
+ resultData = responseData.data;
536
+ } else if (responseData.url !== undefined) {
537
+ resultData = responseData.url;
538
+ } else if (responseData.fileUrl !== undefined) {
539
+ resultData = responseData.fileUrl;
540
+ } else {
541
+ resultData = responseData;
542
+ }
543
+ _context6.next = 13;
544
+ break;
545
+ case 12:
546
+ throw new Error("\u54CD\u5E94\u6570\u636E\u683C\u5F0F\u4E0D\u6B63\u786E: " + typeof responseData);
547
+ case 13:
548
+ if (resultData) {
549
+ _context6.next = 14;
550
+ break;
551
+ }
552
+ throw new Error("\u8FD4\u56DE\u7684\u6587\u4EF6\u5730\u5740\u4E3A\u7A7A");
553
+ case 14:
554
+ if (typeof resultData === 'string') {
555
+ fileUrl = resultData;
556
+ } else if (resultData && typeof resultData === 'object' && resultData.url) {
557
+ fileUrl = resultData.url;
558
+ }
559
+ successLog("\u6587\u4EF6\u4E0A\u4F20\u6210\u529F: " + fileName + " -> " + fileUrl, spinner);
560
+ return _context6.abrupt("return", fileUrl);
561
+ case 15:
562
+ _context6.prev = 15;
563
+ _t4 = _context6["catch"](7);
564
+ errorLog("\u4E0A\u4F20\u6587\u4EF6\u5931\u8D25: " + _t4.message + ", \u6587\u4EF6\u8DEF\u5F84: " + filePath, spinner);
565
+
566
+ // 输出详细的错误信息
567
+ if (!_t4.response) {
568
+ _context6.next = 17;
569
+ break;
570
+ }
571
+ status = _t4.response.status;
572
+ statusText = _t4.response.statusText;
573
+ _responseData = _t4.response.data;
574
+ requestUrl = ((_error$config = _t4.config) == null ? void 0 : _error$config.url) || this.uploadAPI();
575
+ errorLog("\n========== \u4E0A\u4F20\u8BF7\u6C42\u8BE6\u60C5 ==========");
576
+ errorLog("\u8BF7\u6C42 URL: " + requestUrl);
577
+ errorLog("HTTP \u72B6\u6001\u7801: " + status + " " + statusText);
578
+ errorLog("\u54CD\u5E94\u6570\u636E: " + JSON.stringify(_responseData));
579
+ errorLog("==================================\n");
580
+ if (!(status === 404)) {
581
+ _context6.next = 16;
582
+ break;
583
+ }
584
+ throw new Error("\u4E0A\u4F20 API \u4E0D\u5B58\u5728 (404): " + requestUrl + "\n" + "\u8BF7\u68C0\u67E5 neo.config.js \u4E2D\u7684 neoBaseURL \u914D\u7F6E\u662F\u5426\u6B63\u786E\uFF0C\u6216\u8005 API \u8DEF\u5F84\u662F\u5426\u5B58\u5728\u3002\n" + ("\u5F53\u524D\u914D\u7F6E\u7684 API \u8DEF\u5F84: " + NeoCrmAPI.uploadAPI));
585
+ case 16:
586
+ _context6.next = 18;
587
+ break;
588
+ case 17:
589
+ if (_t4.request) {
590
+ errorLog('请求已发送但未收到响应,请检查网络连接或代理配置。');
591
+ }
592
+ case 18:
593
+ throw _t4;
594
+ case 19:
595
+ case "end":
596
+ return _context6.stop();
597
+ }
598
+ }, _callee6, this, [[7, 15]]);
599
+ }));
600
+ function uploadFile(_x, _x2) {
601
+ return _uploadFile.apply(this, arguments);
602
+ }
603
+ return uploadFile;
604
+ }()
605
+ /**
606
+ * 将构建产物上传到 NeoCRM 平台端(已废弃)
607
+ * 备注:已废弃,改为 保存时直接上传组件资源文件
608
+ *
609
+ * @param {object} cmpType 自定义组件名称
610
+ * @param {array} fileExtensions 需要上传的文件类型,默认 ['.js', '.css', '.zip']
611
+ */
612
+ ;
613
+ _proto.publish2oss =
614
+ /*#__PURE__*/
615
+ function () {
616
+ var _publish2oss = asyncToGenerator(/*#__PURE__*/index.mark(function _callee8(cmpType, fileExtensions) {
617
+ var _this = this;
618
+ var curCmpInfo, files, uploadPromises;
619
+ return index.wrap(function (_context8) {
620
+ while (1) switch (_context8.prev = _context8.next) {
621
+ case 0:
622
+ if (fileExtensions === void 0) {
623
+ fileExtensions = ['.js', '.css', '.zip'];
624
+ }
625
+ if (cmpType) {
626
+ _context8.next = 1;
627
+ break;
628
+ }
629
+ errorLog("\u81EA\u5B9A\u4E49\u7EC4\u4EF6\u540D\u79F0\u4E0D\u80FD\u4E3A\u7A7A: " + cmpType);
630
+ return _context8.abrupt("return");
631
+ case 1:
632
+ if (fs.existsSync(this.assetsRoot)) {
633
+ _context8.next = 2;
634
+ break;
635
+ }
636
+ errorLog("\u672A\u627E\u5230\u81EA\u5B9A\u4E49\u7EC4\u4EF6\u8D44\u6E90\u76EE\u5F55: " + this.assetsRoot);
637
+ return _context8.abrupt("return");
638
+ case 2:
639
+ // 当前组件信息
640
+ curCmpInfo = {
641
+ cmpType: cmpType
642
+ };
643
+ files = fs.readdirSync(this.assetsRoot); // 读取构建目录下的所有文件
644
+ // 并行上传所有指定类型的文件
645
+ uploadPromises = files.map(/*#__PURE__*/function () {
646
+ var _ref3 = asyncToGenerator(/*#__PURE__*/index.mark(function _callee7(file) {
647
+ var filePath, fileStat, fileInfo, widgetName, fileUrl;
648
+ return index.wrap(function (_context7) {
649
+ while (1) switch (_context7.prev = _context7.next) {
650
+ case 0:
651
+ filePath = path.join(_this.assetsRoot, file); // 获取文件状态
652
+ fileStat = fs.statSync(filePath); // 检查文件扩展名
653
+ // const fileExt = path.extname(file);
654
+ fileInfo = path.parse(filePath);
655
+ if (!(fileStat.isFile() && fileExtensions.includes(fileInfo.ext))) {
656
+ _context7.next = 4;
657
+ break;
658
+ }
659
+ widgetName = _.camelCase(cmpType);
660
+ if (!(file.indexOf(widgetName) < 0)) {
661
+ _context7.next = 1;
662
+ break;
663
+ }
664
+ return _context7.abrupt("return");
665
+ case 1:
666
+ _context7.prev = 1;
667
+ _context7.next = 2;
668
+ return _this.uploadFile(filePath);
669
+ case 2:
670
+ fileUrl = _context7.sent;
671
+ if (file.indexOf('Model') > -1) {
672
+ curCmpInfo.modelAsset = fileUrl;
673
+ } else if (file.endsWith('.css')) {
674
+ curCmpInfo.cssAsset = fileUrl;
675
+ } else if (file.endsWith('.zip')) {
676
+ curCmpInfo.codeLib = fileUrl;
677
+ } else {
678
+ curCmpInfo.asset = fileUrl;
679
+ }
680
+ _context7.next = 4;
681
+ break;
682
+ case 3:
683
+ _context7.prev = 3;
684
+ _context7["catch"](1);
685
+ errorLog("\u6587\u4EF6\u4E0A\u4F20\u5931\u8D25\uFF08" + file + "\uFF09\uFF1A\n");
686
+ process.exit(1);
687
+ case 4:
688
+ case "end":
689
+ return _context7.stop();
690
+ }
691
+ }, _callee7, null, [[1, 3]]);
692
+ }));
693
+ return function (_x5) {
694
+ return _ref3.apply(this, arguments);
695
+ };
696
+ }());
697
+ _context8.next = 3;
698
+ return Promise.all(uploadPromises);
699
+ case 3:
700
+ if (curCmpInfo && curCmpInfo.cmpType) {
701
+ console.info('上传至 OSS 的文件信息:\n', curCmpInfo);
702
+ // 更新发布日志
703
+ updatePublishLog(curCmpInfo);
704
+ }
705
+ return _context8.abrupt("return", curCmpInfo);
706
+ case 4:
707
+ case "end":
708
+ return _context8.stop();
709
+ }
710
+ }, _callee8, this);
711
+ }));
712
+ function publish2oss(_x3, _x4) {
713
+ return _publish2oss.apply(this, arguments);
714
+ }
715
+ return publish2oss;
716
+ }()
717
+ /**
718
+ * 处理组件构建产物
719
+ *
720
+ * @param {object} cmpType 自定义组件名称
721
+ * @param {array} fileExtensions 需要处理的文件类型,默认 ['.js', '.css', '.zip']
722
+ */
723
+ ;
724
+ _proto.getCmpAssets =
725
+ /*#__PURE__*/
726
+ function () {
727
+ var _getCmpAssets = asyncToGenerator(/*#__PURE__*/index.mark(function _callee9(cmpType, fileExtensions) {
728
+ var _this2 = this;
729
+ var curCmpInfo, files;
730
+ return index.wrap(function (_context9) {
731
+ while (1) switch (_context9.prev = _context9.next) {
732
+ case 0:
733
+ if (fileExtensions === void 0) {
734
+ fileExtensions = ['.js', '.css', '.zip'];
735
+ }
736
+ if (cmpType) {
737
+ _context9.next = 1;
738
+ break;
739
+ }
740
+ errorLog("\u81EA\u5B9A\u4E49\u7EC4\u4EF6\u540D\u79F0\u4E0D\u80FD\u4E3A\u7A7A: " + cmpType);
741
+ return _context9.abrupt("return");
742
+ case 1:
743
+ if (fs.existsSync(this.assetsRoot)) {
744
+ _context9.next = 2;
745
+ break;
746
+ }
747
+ errorLog("\u672A\u627E\u5230\u81EA\u5B9A\u4E49\u7EC4\u4EF6\u8D44\u6E90\u76EE\u5F55: " + this.assetsRoot);
748
+ return _context9.abrupt("return");
749
+ case 2:
750
+ // 当前组件信息
751
+ curCmpInfo = {
752
+ cmpType: cmpType
753
+ };
754
+ files = fs.readdirSync(this.assetsRoot); // 读取构建目录下的所有文件
755
+ // 处理构建产物目录下所有指定类型的文件
756
+ files.forEach(function (file) {
757
+ var filePath = path.join(_this2.assetsRoot, file);
758
+ // 获取文件状态
759
+ var fileStat = fs.statSync(filePath);
760
+ // 检查文件扩展名
761
+ // const fileExt = path.extname(file);
762
+ var fileInfo = path.parse(filePath);
763
+ if (fileStat.isFile() && fileExtensions.includes(fileInfo.ext)) {
764
+ var widgetName = _.camelCase(cmpType);
765
+ if (file.indexOf(widgetName) < 0) {
766
+ return;
767
+ }
768
+
769
+ // 检查文件大小
770
+ var maxSize = 5 * 1024 * 1024; // 默认 5MB
771
+ if (fileStat.size > maxSize) {
772
+ var sizeMB = (fileStat.size / 1024 / 1024).toFixed(2);
773
+ var maxSizeMB = (maxSize / 1024 / 1024).toFixed(2);
774
+ throw new Error(file + " \u6587\u4EF6\u5927\u5C0F\u8D85\u8FC7\u9650\u5236: " + sizeMB + "MB > " + maxSizeMB + "MB");
775
+ }
776
+ var fileContent = fs.createReadStream(filePath);
777
+ var _fileInfo = {
778
+ fileContent: fileContent,
779
+ fileName: file,
780
+ fileSize: fileStat.size
781
+ };
782
+ if (file.indexOf('Model') > -1) {
783
+ // 使用文件流而不是读取整个文件到内存(对大文件更友好)
784
+ curCmpInfo.modelAssetFile = _fileInfo;
785
+ } else if (file.endsWith('.css')) {
786
+ curCmpInfo.cssAssetFile = _fileInfo;
787
+ } else if (file.endsWith('.zip')) {
788
+ curCmpInfo.codeLibFile = _fileInfo;
789
+ } else {
790
+ curCmpInfo.assetFile = _fileInfo;
791
+ }
792
+ }
793
+ });
794
+ return _context9.abrupt("return", curCmpInfo);
795
+ case 3:
796
+ case "end":
797
+ return _context9.stop();
798
+ }
799
+ }, _callee9, this);
800
+ }));
801
+ function getCmpAssets(_x6, _x7) {
802
+ return _getCmpAssets.apply(this, arguments);
803
+ }
804
+ return getCmpAssets;
805
+ }()
806
+ /**
807
+ * 更新自定义组件
808
+ * @param {object} componentData 组件数据
809
+ * @returns {Promise<object>} 更新结果
810
+ */
811
+ ;
812
+ _proto.updateCustomComponent =
813
+ /*#__PURE__*/
814
+ function () {
815
+ var _updateCustomComponent = asyncToGenerator(/*#__PURE__*/index.mark(function _callee0(componentData) {
816
+ var token, spinner, fullUpdateAPI, formData, response, _ref4, code, _t6;
817
+ return index.wrap(function (_context0) {
818
+ while (1) switch (_context0.prev = _context0.next) {
819
+ case 0:
820
+ _context0.next = 1;
821
+ return this.ensureValidToken();
822
+ case 1:
823
+ token = _context0.sent;
824
+ if (componentData) {
825
+ _context0.next = 2;
826
+ break;
827
+ }
828
+ throw new Error('componentData 不能为空');
829
+ case 2:
830
+ spinner = ora('正在保存自定义组件信息...').start();
831
+ _context0.prev = 3;
832
+ fullUpdateAPI = this.saveAPI(); // 创建 FormData
833
+ formData = new FormData(); // 处理 componentData 中的 fileInfo 文件
834
+ if (componentData.assetFile) {
835
+ formData.append('assetFile', componentData.assetFile.fileContent, componentData.assetFile.fileName);
836
+ }
837
+ if (componentData.modelAssetFile) {
838
+ formData.append('modelAssetFile', componentData.modelAssetFile.fileContent, componentData.modelAssetFile.fileName);
839
+ }
840
+ if (componentData.cssAssetFile) {
841
+ formData.append('cssAssetFile', componentData.cssAssetFile.fileContent, componentData.cssAssetFile.fileName);
842
+ }
843
+ if (componentData.codeLibFile) {
844
+ formData.append('codeLibFile', componentData.codeLibFile.fileContent, componentData.codeLibFile.fileName);
845
+ }
846
+
847
+ // 将 componentData 中组件基本信息
848
+ formData.append('component', JSON.stringify(_.omit(componentData, ['assetFile', 'modelAssetFile', 'cssAssetFile', 'codeLibFile'])));
849
+ _context0.next = 4;
850
+ return axios.post(fullUpdateAPI, formData, {
851
+ headers: _extends({
852
+ Authorization: "Bearer " + token,
853
+ 'xsy-inner-source': 'bff'
854
+ }, formData.getHeaders()),
855
+ timeout: 120000,
856
+ // 默认 60 秒
857
+ // 确保 axios 正确处理大文件和流
858
+ maxContentLength: Infinity,
859
+ // 不限制响应内容长度
860
+ maxBodyLength: Infinity // 不限制请求体长度(适用于文件上传)
861
+ });
862
+ case 4:
863
+ response = _context0.sent;
864
+ _ref4 = response.data || {}, code = _ref4.code, _ref4.message;
865
+ if (code && code !== 200) {
866
+ errorLog("\u4FDD\u5B58\u81EA\u5B9A\u4E49\u7EC4\u4EF6\u4FE1\u606F\u5931\u8D25: " + (response.data.message || '未知错误'));
867
+ process.exit(1);
868
+ }
869
+ spinner.clear();
870
+ spinner.stop();
871
+ _context0.next = 6;
872
+ break;
873
+ case 5:
874
+ _context0.prev = 5;
875
+ _t6 = _context0["catch"](3);
876
+ if (_t6.message) {
877
+ errorLog("\u4FDD\u5B58\u81EA\u5B9A\u4E49\u7EC4\u4EF6\u4FE1\u606F\u5931\u8D25: " + _t6.message, spinner);
878
+ } else {
879
+ errorLog("\u4FDD\u5B58\u81EA\u5B9A\u4E49\u7EC4\u4EF6\u4FE1\u606F\u5931\u8D25: " + JSON.stringify(_t6), spinner);
880
+ }
881
+ process.exit(1);
882
+ case 6:
883
+ case "end":
884
+ return _context0.stop();
885
+ }
886
+ }, _callee0, this, [[3, 5]]);
887
+ }));
888
+ function updateCustomComponent(_x8) {
889
+ return _updateCustomComponent.apply(this, arguments);
890
+ }
891
+ return updateCustomComponent;
892
+ }()
893
+ /**
894
+ * 获取线上自定义组件列表
895
+ * @returns {Promise<array>} 自定义组件列表
896
+ */
897
+ ;
898
+ _proto.getCustomCmpList =
899
+ /*#__PURE__*/
900
+ function () {
901
+ var _getCustomCmpList = asyncToGenerator(/*#__PURE__*/index.mark(function _callee1() {
902
+ var token, queryAllAPI, response, _ref5, code, message, _t7;
903
+ return index.wrap(function (_context1) {
904
+ while (1) switch (_context1.prev = _context1.next) {
905
+ case 0:
906
+ _context1.next = 1;
907
+ return this.ensureValidToken();
908
+ case 1:
909
+ token = _context1.sent;
910
+ _context1.prev = 2;
911
+ queryAllAPI = this.buildFullUrl(NeoCrmAPI.queryAll);
912
+ queryAllAPI += "&fields=" + cmpFields.join(',');
913
+ _context1.next = 3;
914
+ return axios.get(queryAllAPI, {
915
+ headers: {
916
+ Authorization: "Bearer " + token,
917
+ 'xsy-inner-source': 'bff',
918
+ 'Content-Type': 'application/json'
919
+ }
920
+ });
921
+ case 3:
922
+ response = _context1.sent;
923
+ _ref5 = response.data || {}, code = _ref5.code, message = _ref5.message;
924
+ if (code && code !== 200) {
925
+ errorLog("\u83B7\u53D6\u81EA\u5B9A\u4E49\u7EC4\u4EF6\u5217\u8868\u5931\u8D25: " + (message || '未知错误'));
926
+ process.exit(1);
927
+ }
928
+ this.updateCustomCmpList(response.data.data || []);
929
+ _context1.next = 5;
930
+ break;
931
+ case 4:
932
+ _context1.prev = 4;
933
+ _t7 = _context1["catch"](2);
934
+ if (_t7.message) {
935
+ errorLog("\u83B7\u53D6\u81EA\u5B9A\u4E49\u7EC4\u4EF6\u5217\u8868\u5931\u8D25: " + _t7.message);
936
+ } else {
937
+ errorLog("\u54CD\u5E94\u6570\u636E: " + JSON.stringify(_t7));
938
+ }
939
+ process.exit(1);
940
+ case 5:
941
+ return _context1.abrupt("return", this.cmpList || []);
942
+ case 6:
943
+ case "end":
944
+ return _context1.stop();
945
+ }
946
+ }, _callee1, this, [[2, 4]]);
947
+ }));
948
+ function getCustomCmpList() {
949
+ return _getCustomCmpList.apply(this, arguments);
950
+ }
951
+ return getCustomCmpList;
952
+ }()
953
+ /**
954
+ * 获取自定义组件源码文件地址
955
+ * @param {string} cmpType 自定义组件名称
956
+ * @returns {string} 源码文件地址
957
+ */
958
+ ;
959
+ _proto.getCodeLibByCmpType = function getCodeLibByCmpType(cmpType) {
960
+ if (!cmpType) {
961
+ return null;
962
+ }
963
+ return this.buildFullUrl(NeoCrmAPI.getCodeLibAPI(cmpType));
964
+ }
965
+
966
+ /**
967
+ * 删除自定义组件
968
+ * @param {*} cmpType 自定义组件类型
969
+ * @returns {Promise<object>} 删除结果
970
+ */;
971
+ _proto.deleteCmp =
972
+ /*#__PURE__*/
973
+ function () {
974
+ var _deleteCmp = asyncToGenerator(/*#__PURE__*/index.mark(function _callee10(cmpType) {
975
+ var token, fullDeleteAPI, response, _ref6, code, message;
976
+ return index.wrap(function (_context10) {
977
+ while (1) switch (_context10.prev = _context10.next) {
978
+ case 0:
979
+ _context10.next = 1;
980
+ return this.ensureValidToken();
981
+ case 1:
982
+ token = _context10.sent;
983
+ if (!cmpType) {
984
+ errorLog('自定义组件名称不能为空。');
985
+ process.exit(1);
986
+ }
987
+ fullDeleteAPI = this.buildFullUrl(NeoCrmAPI.delete);
988
+ fullDeleteAPI += "/" + cmpType;
989
+ _context10.next = 2;
990
+ return axios.delete(fullDeleteAPI, {
991
+ headers: {
992
+ Authorization: "Bearer " + token,
993
+ 'xsy-inner-source': 'bff',
994
+ 'Content-Type': 'application/json'
995
+ }
996
+ });
997
+ case 2:
998
+ response = _context10.sent;
999
+ _ref6 = response.data || {}, code = _ref6.code, message = _ref6.message;
1000
+ if (code && code !== 200) {
1001
+ errorLog("\u5220\u9664\u81EA\u5B9A\u4E49\u7EC4\u4EF6\u5931\u8D25: " + (message || '未知错误'));
1002
+ process.exit(1);
1003
+ }
1004
+ return _context10.abrupt("return", response.data);
1005
+ case 3:
1006
+ case "end":
1007
+ return _context10.stop();
1008
+ }
1009
+ }, _callee10, this);
1010
+ }));
1011
+ function deleteCmp(_x9) {
1012
+ return _deleteCmp.apply(this, arguments);
1013
+ }
1014
+ return deleteCmp;
1015
+ }() // 获取指定框架的自定义组件列表
1016
+ ;
1017
+ _proto.getCmpListByFramework = function getCmpListByFramework(framework) {
1018
+ if (!framework) {
1019
+ return this.cmpList;
1020
+ }
1021
+ var curFramework = getFramework(framework);
1022
+ return this.cmpList.filter(function (cmp) {
1023
+ return cmp.framework === curFramework;
1024
+ });
1025
+ }
1026
+
1027
+ // 获取自定义组件信息
1028
+ ;
1029
+ _proto.getCmpInfoByCmpType = function getCmpInfoByCmpType(cmpType) {
1030
+ if (!cmpType) {
1031
+ return null;
1032
+ }
1033
+ return this.cmpInfoMap[cmpType] || null;
1034
+ }
1035
+
1036
+ // 更新自定义组件 Map
1037
+ ;
1038
+ _proto.updateCustomCmpList = function updateCustomCmpList(cmpList) {
1039
+ var _this3 = this;
1040
+ if (!cmpList || !Array.isArray(cmpList)) {
1041
+ return;
1042
+ }
1043
+ this.cmpList = cmpList;
1044
+ cmpList.forEach(function (cmp) {
1045
+ _this3.cmpInfoMap[cmp.cmpType] = cmp;
1046
+ });
1047
+ }
1048
+
1049
+ /**
1050
+ * 通用请求方法(确保 token 有效)
1051
+ * @param {string} method HTTP 方法
1052
+ * @param {string} api API 地址(相对或绝对路径)
1053
+ * @param {object} options 请求选项
1054
+ * @param {object} options.data 请求数据
1055
+ * @param {object} options.headers 额外的请求头
1056
+ * @param {object} options.params 查询参数
1057
+ * @returns {Promise<object>} 响应数据
1058
+ */;
1059
+ _proto.request =
1060
+ /*#__PURE__*/
1061
+ function () {
1062
+ var _request = asyncToGenerator(/*#__PURE__*/index.mark(function _callee11(method, api, options) {
1063
+ var token, _options, data, _options$headers, headers, params, fullAPI, response, _t8;
1064
+ return index.wrap(function (_context11) {
1065
+ while (1) switch (_context11.prev = _context11.next) {
1066
+ case 0:
1067
+ if (options === void 0) {
1068
+ options = {};
1069
+ }
1070
+ _context11.next = 1;
1071
+ return this.ensureValidToken();
1072
+ case 1:
1073
+ token = _context11.sent;
1074
+ _options = options, data = _options.data, _options$headers = _options.headers, headers = _options$headers === void 0 ? {} : _options$headers, params = _options.params;
1075
+ fullAPI = this.buildFullUrl(api);
1076
+ _context11.prev = 2;
1077
+ _context11.next = 3;
1078
+ return axios({
1079
+ method: method,
1080
+ url: fullAPI,
1081
+ data: data,
1082
+ params: params,
1083
+ headers: _extends({
1084
+ Authorization: "Bearer " + token,
1085
+ 'xsy-inner-source': 'bff'
1086
+ }, headers)
1087
+ });
1088
+ case 3:
1089
+ response = _context11.sent;
1090
+ if (!(response.data && response.data.code && response.data.code !== 200)) {
1091
+ _context11.next = 4;
1092
+ break;
1093
+ }
1094
+ throw new Error("\u8BF7\u6C42\u5931\u8D25: " + (response.data.message || '未知错误'));
1095
+ case 4:
1096
+ return _context11.abrupt("return", response.data);
1097
+ case 5:
1098
+ _context11.prev = 5;
1099
+ _t8 = _context11["catch"](2);
1100
+ errorLog("\u8BF7\u6C42\u5931\u8D25 [" + method + " " + api + "]: " + _t8.message);
1101
+ if (_t8.response) {
1102
+ errorLog("\u54CD\u5E94\u6570\u636E: " + JSON.stringify(_t8.response.data));
1103
+ }
1104
+ throw _t8;
1105
+ case 6:
1106
+ case "end":
1107
+ return _context11.stop();
1108
+ }
1109
+ }, _callee11, this, [[2, 5]]);
1110
+ }));
1111
+ function request(_x0, _x1, _x10) {
1112
+ return _request.apply(this, arguments);
1113
+ }
1114
+ return request;
1115
+ }()
1116
+ /**
1117
+ * GET 请求
1118
+ * @param {string} api API 地址
1119
+ * @param {object} options 请求选项
1120
+ * @returns {Promise<object>} 响应数据
1121
+ */
1122
+ ;
1123
+ _proto.get =
1124
+ /*#__PURE__*/
1125
+ function () {
1126
+ var _get = asyncToGenerator(/*#__PURE__*/index.mark(function _callee12(api, options) {
1127
+ return index.wrap(function (_context12) {
1128
+ while (1) switch (_context12.prev = _context12.next) {
1129
+ case 0:
1130
+ if (options === void 0) {
1131
+ options = {};
1132
+ }
1133
+ _context12.next = 1;
1134
+ return this.request('GET', api, options);
1135
+ case 1:
1136
+ return _context12.abrupt("return", _context12.sent);
1137
+ case 2:
1138
+ case "end":
1139
+ return _context12.stop();
1140
+ }
1141
+ }, _callee12, this);
1142
+ }));
1143
+ function get(_x11, _x12) {
1144
+ return _get.apply(this, arguments);
1145
+ }
1146
+ return get;
1147
+ }()
1148
+ /**
1149
+ * POST 请求
1150
+ * @param {string} api API 地址
1151
+ * @param {object} options 请求选项
1152
+ * @returns {Promise<object>} 响应数据
1153
+ */
1154
+ ;
1155
+ _proto.post =
1156
+ /*#__PURE__*/
1157
+ function () {
1158
+ var _post = asyncToGenerator(/*#__PURE__*/index.mark(function _callee13(api, options) {
1159
+ return index.wrap(function (_context13) {
1160
+ while (1) switch (_context13.prev = _context13.next) {
1161
+ case 0:
1162
+ if (options === void 0) {
1163
+ options = {};
1164
+ }
1165
+ _context13.next = 1;
1166
+ return this.request('POST', api, options);
1167
+ case 1:
1168
+ return _context13.abrupt("return", _context13.sent);
1169
+ case 2:
1170
+ case "end":
1171
+ return _context13.stop();
1172
+ }
1173
+ }, _callee13, this);
1174
+ }));
1175
+ function post(_x13, _x14) {
1176
+ return _post.apply(this, arguments);
1177
+ }
1178
+ return post;
1179
+ }()
1180
+ /**
1181
+ * PUT 请求
1182
+ * @param {string} api API 地址
1183
+ * @param {object} options 请求选项
1184
+ * @returns {Promise<object>} 响应数据
1185
+ */
1186
+ ;
1187
+ _proto.put =
1188
+ /*#__PURE__*/
1189
+ function () {
1190
+ var _put = asyncToGenerator(/*#__PURE__*/index.mark(function _callee14(api, options) {
1191
+ return index.wrap(function (_context14) {
1192
+ while (1) switch (_context14.prev = _context14.next) {
1193
+ case 0:
1194
+ if (options === void 0) {
1195
+ options = {};
1196
+ }
1197
+ _context14.next = 1;
1198
+ return this.request('PUT', api, options);
1199
+ case 1:
1200
+ return _context14.abrupt("return", _context14.sent);
1201
+ case 2:
1202
+ case "end":
1203
+ return _context14.stop();
1204
+ }
1205
+ }, _callee14, this);
1206
+ }));
1207
+ function put(_x15, _x16) {
1208
+ return _put.apply(this, arguments);
1209
+ }
1210
+ return put;
1211
+ }()
1212
+ /**
1213
+ * DELETE 请求
1214
+ * @param {string} api API 地址
1215
+ * @param {object} options 请求选项
1216
+ * @returns {Promise<object>} 响应数据
1217
+ */
1218
+ ;
1219
+ _proto.delete =
1220
+ /*#__PURE__*/
1221
+ function () {
1222
+ var _delete2 = asyncToGenerator(/*#__PURE__*/index.mark(function _callee15(api, options) {
1223
+ return index.wrap(function (_context15) {
1224
+ while (1) switch (_context15.prev = _context15.next) {
1225
+ case 0:
1226
+ if (options === void 0) {
1227
+ options = {};
1228
+ }
1229
+ _context15.next = 1;
1230
+ return this.request('DELETE', api, options);
1231
+ case 1:
1232
+ return _context15.abrupt("return", _context15.sent);
1233
+ case 2:
1234
+ case "end":
1235
+ return _context15.stop();
1236
+ }
1237
+ }, _callee15, this);
1238
+ }));
1239
+ function _delete(_x17, _x18) {
1240
+ return _delete2.apply(this, arguments);
1241
+ }
1242
+ return _delete;
1243
+ }();
1244
+ return NeoService;
1245
+ }();
1246
+ module.exports = NeoService;