neo-cmp-cli 1.8.6 → 1.8.8

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 (127) hide show
  1. package/{src → bin}/index.js +18 -13
  2. package/bin/neo.js +1 -1
  3. package/dist/_virtual/_commonjsHelpers.js +12 -0
  4. package/dist/_virtual/array-set.js +7 -0
  5. package/dist/_virtual/base64-vlq.js +7 -0
  6. package/dist/_virtual/base64.js +7 -0
  7. package/dist/_virtual/binary-search.js +7 -0
  8. package/dist/_virtual/mapping-list.js +7 -0
  9. package/dist/_virtual/quick-sort.js +7 -0
  10. package/dist/_virtual/source-map-consumer.js +7 -0
  11. package/dist/_virtual/source-map-generator.js +7 -0
  12. package/dist/_virtual/source-map-support.js +7 -0
  13. package/dist/_virtual/source-map.js +7 -0
  14. package/dist/_virtual/source-node.js +7 -0
  15. package/dist/_virtual/typescript.js +7 -0
  16. package/dist/_virtual/util.js +7 -0
  17. package/dist/config/auth.config.js +43 -0
  18. package/dist/config/default.config.js +192 -0
  19. package/dist/config/index.js +26 -0
  20. package/dist/main.js +9 -0
  21. package/dist/main2.js +259 -0
  22. package/dist/module/inspect.js +63 -0
  23. package/dist/module/neoInit.js +75 -0
  24. package/dist/module/neoInitByCopy.js +83 -0
  25. package/dist/neo/neoLogin.js +590 -0
  26. package/dist/neo/neoRequire.js +123 -0
  27. package/dist/neo/neoService.js +898 -0
  28. package/dist/node_modules/buffer-from/index.js +86 -0
  29. package/dist/node_modules/source-map/lib/array-set.js +138 -0
  30. package/dist/node_modules/source-map/lib/base64-vlq.js +157 -0
  31. package/dist/node_modules/source-map/lib/base64.js +83 -0
  32. package/dist/node_modules/source-map/lib/binary-search.js +129 -0
  33. package/dist/node_modules/source-map/lib/mapping-list.js +96 -0
  34. package/dist/node_modules/source-map/lib/quick-sort.js +130 -0
  35. package/dist/node_modules/source-map/lib/source-map-consumer.js +1166 -0
  36. package/dist/node_modules/source-map/lib/source-map-generator.js +445 -0
  37. package/dist/node_modules/source-map/lib/source-node.js +431 -0
  38. package/dist/node_modules/source-map/lib/util.js +506 -0
  39. package/dist/node_modules/source-map/source-map.js +27 -0
  40. package/dist/node_modules/source-map-support/source-map-support.js +646 -0
  41. package/dist/node_modules/typescript/lib/typescript.js +174130 -0
  42. package/dist/oss/publish2oss.js +331 -0
  43. package/dist/plugins/AddNeoRequirePlugin.js +195 -0
  44. package/dist/utils/autoEntryRootDir.js +103 -0
  45. package/dist/utils/cmpUtils/createCmpByTemplate.js +82 -0
  46. package/dist/utils/cmpUtils/createCmpByZip.js +433 -0
  47. package/dist/utils/cmpUtils/createCommonModulesCode.js +139 -0
  48. package/dist/utils/cmpUtils/deleteCmp.js +81 -0
  49. package/dist/utils/cmpUtils/getCmpModelRegisterCode.js +47 -0
  50. package/dist/utils/cmpUtils/getCmpPreviewCode.js +60 -0
  51. package/dist/utils/cmpUtils/getCmpRegisterCode.js +47 -0
  52. package/dist/utils/cmpUtils/getCmpTypeByDir.js +59 -0
  53. package/dist/utils/cmpUtils/hasCmpTypeByDir.js +27 -0
  54. package/dist/utils/cmpUtils/previewCmp.js +75 -0
  55. package/dist/utils/cmpUtils/pullCmp.js +126 -0
  56. package/dist/utils/cmpUtils/pushCmp.js +254 -0
  57. package/dist/utils/common.js +125 -0
  58. package/dist/utils/configureNeoBuild.js +129 -0
  59. package/dist/utils/generateEntries.js +80 -0
  60. package/dist/utils/neoConfigInit.js +30 -0
  61. package/dist/utils/neoParams.js +26 -0
  62. package/dist/utils/pathUtils.js +40 -0
  63. package/dist/utils/projectNameValidator.js +90 -0
  64. package/dist/utils/projectUtils/createCmpProjectByTemplate.js +81 -0
  65. package/dist/utils/projectUtils/createCmpProjectZip.js +141 -0
  66. package/dist/utils/projectUtils/getEntries.js +99 -0
  67. package/dist/utils/projectUtils/getEntriesWithAutoRegister.js +129 -0
  68. package/dist/utils/projectUtils/hasNeoProject.js +34 -0
  69. package/dist/utils/projectUtils/openProject.js +117 -0
  70. package/dist/utils/projectUtils/updatePublishLog.js +47 -0
  71. package/dist/utils/replaceInFilesByMap.js +71 -0
  72. package/dist/utils/replaceInPackage.js +151 -0
  73. package/dist/utils/resetPackageVersion.js +132 -0
  74. package/package.json +5 -5
  75. package/test/demo.js +2 -4
  76. package/test/deprecate-versions.js +1 -1
  77. package/test/neo.config.js +1 -25
  78. package/src/config/auth.config.js +0 -27
  79. package/src/config/default.config.js +0 -176
  80. package/src/config/index.js +0 -9
  81. package/src/initData/defaultTemplate.html +0 -13
  82. package/src/initData/neo.config.js +0 -138
  83. package/src/main.js +0 -206
  84. package/src/module/inspect.js +0 -41
  85. package/src/module/neoInit.js +0 -55
  86. package/src/module/neoInitByCopy.js +0 -61
  87. package/src/neo/NeoUMDContent.js +0 -30
  88. package/src/neo/neoLogin.js +0 -565
  89. package/src/neo/neoRequire.js +0 -125
  90. package/src/neo/neoService.js +0 -874
  91. package/src/neo/webpack.mf.js +0 -60
  92. package/src/neo/wrapperContent.js +0 -16
  93. package/src/oss/publish2oss.js +0 -348
  94. package/src/plugins/AddNeoRequirePlugin-v1.js +0 -47
  95. package/src/plugins/AddNeoRequirePlugin.js +0 -179
  96. package/src/plugins/README.md +0 -109
  97. package/src/utils/autoEntryRootDir.js +0 -85
  98. package/src/utils/cmpUtils/createCmpByTemplate.js +0 -60
  99. package/src/utils/cmpUtils/createCmpByZip.js +0 -408
  100. package/src/utils/cmpUtils/createCommonModulesCode.js +0 -121
  101. package/src/utils/cmpUtils/deleteCmp.js +0 -63
  102. package/src/utils/cmpUtils/getCmpModelRegisterCode.js +0 -31
  103. package/src/utils/cmpUtils/getCmpPreviewCode.js +0 -43
  104. package/src/utils/cmpUtils/getCmpRegisterCode.js +0 -31
  105. package/src/utils/cmpUtils/getCmpTypeByDir.js +0 -41
  106. package/src/utils/cmpUtils/hasCmpTypeByDir.js +0 -11
  107. package/src/utils/cmpUtils/previewCmp.js +0 -55
  108. package/src/utils/cmpUtils/pullCmp.js +0 -104
  109. package/src/utils/cmpUtils/pushCmp.js +0 -230
  110. package/src/utils/common.js +0 -107
  111. package/src/utils/configureNeoBuild.js +0 -109
  112. package/src/utils/generateEntries.js +0 -63
  113. package/src/utils/neoConfigInit.js +0 -13
  114. package/src/utils/neoParams.js +0 -12
  115. package/src/utils/pathUtils.js +0 -23
  116. package/src/utils/projectNameValidator.js +0 -76
  117. package/src/utils/projectUtils/createCmpProjectByTemplate.js +0 -59
  118. package/src/utils/projectUtils/createCmpProjectZip.js +0 -120
  119. package/src/utils/projectUtils/getEntries.js +0 -80
  120. package/src/utils/projectUtils/getEntriesWithAutoRegister.js +0 -108
  121. package/src/utils/projectUtils/hasNeoProject.js +0 -17
  122. package/src/utils/projectUtils/openProject.js +0 -94
  123. package/src/utils/projectUtils/updatePublishLog.js +0 -30
  124. package/src/utils/replaceInFiles.js +0 -47
  125. package/src/utils/replaceInFilesByMap.js +0 -54
  126. package/src/utils/replaceInPackage.js +0 -134
  127. package/src/utils/resetPackageVersion.js +0 -115
@@ -1,60 +0,0 @@
1
- // 模块联邦插件
2
- const webpack = require('webpack');
3
- const { ModuleFederationPlugin } = require('webpack').container;
4
- const { getConfigObj } = require('akfun');
5
-
6
- // 解析 webpack 模块联邦 remotes 中的变量
7
- const ExternalTemplateRemotesPlugin = require('external-remotes-plugin');
8
-
9
- const { catchCurPackageJson } = require('../utils/pathUtils');
10
-
11
- // 获取当前项目的package文件
12
- const currentPackageJsonDir = catchCurPackageJson();
13
- const currentPackageJson = getConfigObj(currentPackageJsonDir);
14
-
15
- /**
16
- * Neo 提供的可共享依赖
17
- * 说明:用于剔除掉自定义组件中的重复依赖,避免重复打包,减少包体积
18
- */
19
- const neoSharedDeps = {
20
- antd: '4.9.4',
21
- 'antd-mobile': '2.3.4',
22
- '@ant-design/icons': '^4.8.0',
23
- axios: '^0.27.2',
24
- 'angular-expressions': '^1.1.4',
25
- echarts: '5.4.2',
26
- mobx: '^6.3.0',
27
- 'mobx-react': '^7.0.0',
28
- 'mobx-state-tree': '^5.4.0',
29
- moment: '^2.25.3',
30
- lodash: '^4.17.21',
31
- 'react-dnd': '^11.1.3',
32
- classnames: '^2.3.2',
33
- 'neo-open-api': '^1.0.11'
34
- };
35
-
36
- const MFPlugins = [
37
- new webpack.NormalModuleReplacementPlugin(/(.*)/, (resource) => {
38
- if (resource.request === 'react' || resource.request === 'react-dom') {
39
- // 使用 Neo 提供的 react 和 react-dom
40
- resource.request = `neoreact/${resource.request}`;
41
- } else if (neoSharedDeps[resource.request]) {
42
- // 使用 Neo 提供的其他依赖
43
- const mfKey = resource.request.replace(/(\/|\.)/gi, '_'); // 换成 neo-ui-mf-base exposes 的 key
44
- resource.request = `neobase/${mfKey}`;
45
- }
46
- }),
47
- new ModuleFederationPlugin({
48
- name: currentPackageJson.name,
49
- remotes: {
50
- // 通过 external-remotes-plugin 支持变量写法
51
- neobase: 'neobase@[window.neoEntrys.neobase]',
52
- neoreact: 'neoreact@[window.neoEntrys.neoreact]'
53
- }
54
- }),
55
- new ExternalTemplateRemotesPlugin()
56
- ];
57
-
58
- module.exports = {
59
- MFPlugins
60
- };
@@ -1,16 +0,0 @@
1
- /**
2
- * 注入 neoRequire 函数
3
- * 备注:用于实现和 Neo 平台共享依赖
4
- * 特别说明:这个文件只是用于说明 AddNeoRequirePlugin 中会插入的代码内容,实际内容内置在 AddNeoRequirePlugin 方法中。
5
- */
6
- (function(NeoCustomCmpFileFactory) {
7
- if (!window.neoRequire) {
8
- throw new Error('neoRequire 不存在,请在 NeoCRM 平台中加载此脚本。');
9
- }
10
- NeoCustomCmpFileFactory(window.neoRequire);
11
- })(function(require) {
12
- /**
13
- * 这里放自定义组件相关内容代码
14
- * 备注: 自定义组件代码中的 require 函数 已被替换成 neoRequire 函数(require === neoRequire)。
15
- */
16
- });
@@ -1,348 +0,0 @@
1
- const { aliBOS, baiduBOS } = require('akfun');
2
- const fs = require('fs');
3
- const path = require('path');
4
- const _ = require('lodash');
5
- const ora = require('ora');
6
- const { getConfigObj } = require('akfun');
7
- const { catchCurPackageJson } = require('../utils/pathUtils');
8
- const updatePublishLog = require('../utils/projectUtils/updatePublishLog');
9
- const { errorLog, warningLog, successLog } = require('../utils/common');
10
-
11
- // 获取当前项目的package文件
12
- const currentPackageJsonDir = catchCurPackageJson();
13
- const currentPackageJson = getConfigObj(currentPackageJsonDir);
14
-
15
- // 根据 ossType 获取对应的 BosClient
16
- const getBosClient = (ossType, ossConfig) => {
17
- if (ossType === 'baidu') {
18
- return new baiduBOS(
19
- ossConfig.endpoint,
20
- ossConfig.bucket,
21
- ossConfig.AccessKeyId ||
22
- ossConfig.AccessKeyID ||
23
- ossConfig.accessKeyId ||
24
- ossConfig.accessKeyID,
25
- ossConfig.AccessKeySecret
26
- );
27
- } else if (ossType === 'ali') {
28
- return new aliBOS(
29
- ossConfig.endpoint,
30
- ossConfig.bucket,
31
- ossConfig.AccessKeyId ||
32
- ossConfig.AccessKeyID ||
33
- ossConfig.accessKeyId ||
34
- ossConfig.accessKeyID,
35
- ossConfig.AccessKeySecret
36
- );
37
- }
38
- };
39
-
40
- const getFilePath = (ossType, bucket, objectKey) => {
41
- const regions = {
42
- baidu: 'bj.bcebos.com',
43
- ali: 'oss-cn-beijing.aliyuncs.com'
44
- };
45
- const region = regions[ossType];
46
- if (!region) {
47
- throw new Error(`不支持的oss类型: ${ossType}`);
48
- }
49
- return `https://${bucket}.${region}/${objectKey}`;
50
- };
51
-
52
- // 获取上传成功和失败的文件信息
53
- const getResultFiles = (files) => {
54
- const succeedFiles = [];
55
- const errorFiles = [];
56
- files.forEach((file) => {
57
- if (file && file.success) {
58
- succeedFiles.push({
59
- fileName: file.fileName,
60
- ossPath: file.ossPath
61
- });
62
- } else if (file && !file.success) {
63
- errorFiles.push({
64
- fileName: file.fileName,
65
- error: file.error,
66
- ossPath: file.ossPath
67
- });
68
- }
69
- });
70
- return {
71
- succeedFiles,
72
- errorFiles
73
- };
74
- };
75
-
76
- // 获取上传文件关键信息(文件名、oss路径)
77
- const getResultFile = (file) => {
78
- if (file && file.success) {
79
- return {
80
- fileName: file.fileName,
81
- ossPath: file.ossPath
82
- };
83
- } else if (file && !file.success) {
84
- return {
85
- error: file.error,
86
- fileName: file.fileName,
87
- ossPath: file.ossPath
88
- };
89
- }
90
- };
91
-
92
- // 按组件名称进行分类
93
- const getResultFilesByWidgetName = (files) => {
94
- const widgetFilesMap = {};
95
- files.forEach((file) => {
96
- if (!file || !file.widgetName) {
97
- return;
98
- }
99
- let widgetName = file.widgetName;
100
- const curCmpInfo = {
101
- cmpType: _.kebabCase(widgetName)
102
- };
103
-
104
- if (widgetName.includes('Model')) {
105
- widgetName = widgetName.replace('Model', '');
106
- curCmpInfo.cmpType = _.kebabCase(widgetName);
107
- curCmpInfo.modelAsset = !file.success ? `${file.error}[${file.ossPath}]` : file.ossPath;
108
- } else if (file.fileName.endsWith('.css')) {
109
- curCmpInfo.cssAsset = !file.success ? `${file.error}[${file.ossPath}]` : file.ossPath;
110
- } else {
111
- curCmpInfo.asset = !file.success ? `${file.error}[${file.ossPath}]` : file.ossPath;
112
- }
113
-
114
- if (widgetFilesMap[widgetName]) {
115
- widgetFilesMap[widgetName] = Object.assign(widgetFilesMap[widgetName], curCmpInfo);
116
- } else {
117
- // widgetFilesMap[widgetName] = [getResultFile(file)];
118
- widgetFilesMap[widgetName] = curCmpInfo;
119
- }
120
- });
121
-
122
- return widgetFilesMap;
123
- };
124
-
125
- // 文件名中添加当前项目版本号
126
- function addVersionToFilename(
127
- filename,
128
- version = currentPackageJson.version,
129
- projectName = currentPackageJson.name
130
- ) {
131
- // 找到最后一个点的位置,用于分离文件名和扩展名
132
- let lastDotIndex = filename.lastIndexOf('.umd');
133
- if (lastDotIndex === -1) {
134
- lastDotIndex = filename.lastIndexOf('.esm');
135
- }
136
- if (lastDotIndex === -1) {
137
- lastDotIndex = filename.lastIndexOf('.lib');
138
- }
139
- if (lastDotIndex === -1) {
140
- lastDotIndex = filename.lastIndexOf('.');
141
- }
142
- // 如果没有扩展名(没有点),直接在文件名后添加版本号
143
- if (lastDotIndex === -1) {
144
- return `${projectName}/${filename}-${version}`;
145
- }
146
-
147
- // 分离文件名的基础部分和扩展名
148
- const baseName = filename.substring(0, lastDotIndex);
149
- const extension = filename.substring(lastDotIndex);
150
-
151
- // 组合新的文件名:基础名-版本号.扩展名
152
- return `${projectName}/${baseName}-${version}${extension}`;
153
- }
154
-
155
- /**
156
- * 上传单个文件到 OSS
157
- * @param {object} bosClient OSS 客户端实例
158
- * @param {string} filePath 文件路径
159
- * @param {string} objectKey OSS 对象键
160
- * @param {string} ossType OSS 类型
161
- * @param {object} ossConfig OSS 配置
162
- * @param {object} fileInfo 文件信息
163
- * @returns {Promise<object>} 上传结果
164
- */
165
- async function uploadSingleFile(bosClient, filePath, objectKey, ossType, ossConfig, fileInfo) {
166
- const fileName = path.basename(filePath);
167
- const fileSizeKB = (fs.statSync(filePath).size / 1024).toFixed(2);
168
- const spinner = ora(`正在上传文件: ${fileName} (${fileSizeKB}KB)...`).start();
169
-
170
- try {
171
- // 判断线上是否存在重名文件,避免被覆盖
172
- const historyResult = await bosClient.get(objectKey);
173
- if (historyResult && historyResult.url) {
174
- spinner.warn(`文件已存在,跳过上传: ${fileName}`);
175
- return {
176
- success: false,
177
- status: '文件上传失败',
178
- widgetName: fileInfo.name,
179
- fileName: fileName,
180
- filepath: filePath,
181
- ossPath: historyResult.url,
182
- error: '线上存在重名文件。'
183
- };
184
- }
185
-
186
- // 上传文件
187
- const result = await bosClient.upload(objectKey, filePath);
188
- const ossPath = getFilePath(ossType, ossConfig.bucket, objectKey);
189
- successLog(`文件上传成功: ${fileName} -> ${ossPath}`, spinner);
190
-
191
- return {
192
- success: true,
193
- status: '文件上传成功',
194
- fileName: fileName,
195
- widgetName: fileInfo.name,
196
- filepath: filePath,
197
- ossPath: ossPath,
198
- resultMsg: result
199
- };
200
- } catch (error) {
201
- errorLog(`文件上传失败: ${fileName}`, spinner);
202
-
203
- // 输出详细的错误信息
204
- errorLog(`\n========== 上传文件详情 ==========`);
205
- errorLog(`文件路径: ${filePath}`);
206
- errorLog(`OSS 对象键: ${objectKey}`);
207
- errorLog(`错误信息: ${error.message}`);
208
- if (error.stack) {
209
- errorLog(`错误堆栈: ${error.stack}`);
210
- }
211
- errorLog(`==================================\n`);
212
-
213
- return {
214
- success: false,
215
- status: '文件上传失败',
216
- widgetName: fileInfo.name,
217
- fileName: fileName,
218
- filepath: filePath,
219
- error: error.message
220
- };
221
- }
222
- }
223
-
224
- /**
225
- * 将构建产物上传到指定 oss 存储桶
226
- *
227
- * @param {string} ossType oss 类型:baidu、ali
228
- * @param {object} ossConfig oss 配置
229
- * @param {string} assetsRoot 构建产物的目录
230
- * @param {array} fileExtensions 需要上传的文件类型,默认 ['.js', '.css']
231
- */
232
- const publish2oss = async (ossType, ossConfig, assetsRoot, fileExtensions = ['.js', '.css']) => {
233
- // 参数验证
234
- if (ossType !== 'baidu' && ossType !== 'ali') {
235
- errorLog(`不支持的oss类型: ${ossType}`);
236
- return;
237
- }
238
-
239
- if (!ossConfig) {
240
- errorLog('ossConfig 不能为空');
241
- return;
242
- }
243
-
244
- if (!assetsRoot) {
245
- errorLog('assetsRoot 不能为空');
246
- return;
247
- }
248
-
249
- // 检查目录是否存在
250
- if (!fs.existsSync(assetsRoot)) {
251
- errorLog(`assetsRoot 不存在: ${assetsRoot}`);
252
- return;
253
- }
254
-
255
- // 检查目录是否为目录
256
- const assetsRootStat = fs.statSync(assetsRoot);
257
- if (!assetsRootStat.isDirectory()) {
258
- errorLog(`assetsRoot 不是目录: ${assetsRoot}`);
259
- return;
260
- }
261
-
262
- // 创建 OSS 客户端
263
- const bosClient = getBosClient(ossType, ossConfig);
264
- if (!bosClient) {
265
- errorLog(`无法创建 OSS 客户端,请检查 ossType 和 ossConfig 配置`);
266
- return;
267
- }
268
-
269
- // 读取构建目录下的所有文件
270
- const files = fs.readdirSync(assetsRoot);
271
- if (files.length === 0) {
272
- warningLog(`构建目录为空: ${assetsRoot}`);
273
- return;
274
- }
275
-
276
- const spinner = ora('正在准备上传文件...').start();
277
-
278
- try {
279
- // 过滤出需要上传的文件
280
- const filesToUpload = files.filter((file) => {
281
- const filePath = path.join(assetsRoot, file);
282
- try {
283
- const fileStat = fs.statSync(filePath);
284
- if (!fileStat.isFile()) {
285
- return false;
286
- }
287
- const fileInfo = path.parse(filePath);
288
- return fileExtensions.includes(fileInfo.ext);
289
- } catch (error) {
290
- warningLog(`无法读取文件状态: ${filePath} - ${error.message}`);
291
- return false;
292
- }
293
- });
294
-
295
- if (filesToUpload.length === 0) {
296
- spinner.warn('未找到需要上传的文件');
297
- return;
298
- }
299
-
300
- successLog(`找到 ${filesToUpload.length} 个文件需要上传`, spinner);
301
-
302
- // 并行上传所有指定类型的文件
303
- const uploadPromises = filesToUpload.map(async (file) => {
304
- const filePath = path.join(assetsRoot, file);
305
- const fileInfo = path.parse(filePath);
306
- const objectKey = addVersionToFilename(file);
307
-
308
- return await uploadSingleFile(bosClient, filePath, objectKey, ossType, ossConfig, fileInfo);
309
- });
310
-
311
- // 等待所有文件上传完成
312
- const results = await Promise.all(uploadPromises);
313
-
314
- // 过滤掉 undefined 结果(不符合条件的文件)
315
- const validResults = results.filter((result) => result !== undefined);
316
-
317
- // 处理上传结果
318
- const widgetFilesMap = getResultFilesByWidgetName(validResults);
319
- if (widgetFilesMap && Object.keys(widgetFilesMap).length > 0) {
320
- console.info('\n上传至 OSS 的文件信息:\n', widgetFilesMap);
321
- // 更新发布日志
322
- updatePublishLog(widgetFilesMap);
323
- } else {
324
- warningLog('未生成有效的文件上传结果');
325
- }
326
-
327
- // 统计上传结果
328
- const succeedCount = validResults.filter((r) => r && r.success).length;
329
- const failCount = validResults.filter((r) => r && !r.success).length;
330
-
331
- if (failCount > 0) {
332
- warningLog(`\n上传完成:成功 ${succeedCount} 个,失败 ${failCount} 个`);
333
- } else {
334
- console.info(`\n✅ 所有文件上传成功!共 ${succeedCount} 个文件`);
335
- }
336
- } catch (error) {
337
- errorLog('批量上传文件异常', spinner);
338
- errorLog('\n========== 批量上传异常 ==========');
339
- errorLog(`错误信息: ${error.message}`);
340
- if (error.stack) {
341
- errorLog(`错误堆栈: ${error.stack}`);
342
- }
343
- errorLog('==================================\n');
344
- throw error;
345
- }
346
- };
347
-
348
- module.exports = publish2oss;
@@ -1,47 +0,0 @@
1
- const { ConcatSource } = require('webpack-sources');
2
-
3
- /**
4
- * 注入 neoRequire 函数
5
- * 备注:用于实现和 Neo 平台共享依赖
6
- */
7
- class AddNeoRequirePlugin {
8
- apply(compiler) {
9
- compiler.hooks.compilation.tap('AddNeoRequirePlugin', (compilation) => {
10
- compilation.hooks.processAssets.tap(
11
- {
12
- name: 'AddNeoRequirePlugin',
13
- stage: -100
14
- },
15
- () => {
16
- for (const chunk of compilation.chunks) {
17
- if (!chunk.canBeInitial() || !chunk.rendered) {
18
- continue;
19
- }
20
-
21
- for (const file of chunk.files) {
22
- if (/.css$/.test(file)) {
23
- // 不处理 css 文件
24
- continue;
25
- }
26
-
27
- const Header = `
28
- (function(cmpFileFactory) {
29
- if (!window.neoRequire) {
30
- throw new Error('neoRequire 不存在,请在 NeoCRM 平台中加载此脚本。');
31
- }
32
- cmpFileFactory(window.neoRequire);
33
- })(function(require) {
34
- `;
35
-
36
- const Footer = `})`;
37
-
38
- compilation.updateAsset(file, (oldFileContent) => new ConcatSource(Header, oldFileContent, Footer));
39
- }
40
- }
41
- }
42
- );
43
- });
44
- }
45
- }
46
-
47
- module.exports = AddNeoRequirePlugin;
@@ -1,179 +0,0 @@
1
- const { ConcatSource } = require('webpack-sources');
2
- const fs = require('fs');
3
- const path = require('path');
4
- /**
5
- * 注入 neoRequire 函数
6
- * 备注:用于实现和 Neo 平台共享依赖
7
- */
8
- class AddNeoRequirePlugin {
9
- key = 'AddNeoRequirePlugin';
10
-
11
- constructor(options = {}) {
12
- this.options = {
13
- // 是否启用详细日志
14
- verbose: options.verbose || false,
15
- // 是否跳过已注入的文件
16
- skipInjected: options.skipInjected !== false,
17
- // 需要跳过的文件扩展名
18
- skipExtensions: options.skipExtensions || ['.css', '.map', '.txt', '.html'],
19
- // 需要跳过的文件名模式
20
- skipPatterns: options.skipPatterns || [/\.map$/, /\.LICENSE\.txt$/, /\.html$/],
21
- ...options
22
- };
23
- }
24
-
25
- /**
26
- * 检查文件是否应该被跳过
27
- */
28
- shouldSkipFile(filename) {
29
- // 检查扩展名
30
- for (const ext of this.options.skipExtensions) {
31
- if (filename.endsWith(ext)) {
32
- return true;
33
- }
34
- }
35
-
36
- // 检查文件名模式
37
- for (const pattern of this.options.skipPatterns) {
38
- if (pattern.test(filename)) {
39
- return true;
40
- }
41
- }
42
-
43
- return false;
44
- }
45
-
46
- /**
47
- * 检查文件是否已经被注入过
48
- */
49
- isAlreadyInjected(content) {
50
- if (!content || typeof content !== 'string') {
51
- return false;
52
- }
53
-
54
- // 检查是否包含注入的标识
55
- return (
56
- content.includes('NeoCustomCmpFileFactory(window.neoRequire)') &&
57
- content.includes('if (!window.neoRequire)')
58
- );
59
- }
60
-
61
- /**
62
- * 验证文件内容是否有效
63
- */
64
- isValidFile(content) {
65
- if (!content || typeof content !== 'string') {
66
- return false;
67
- }
68
-
69
- // 检查文件是否为空或只包含空白字符
70
- if (content.trim().length === 0) {
71
- return false;
72
- }
73
-
74
- return true;
75
- }
76
-
77
- /**
78
- * 记录日志
79
- */
80
- log(message, level = 'info') {
81
- if (this.options.verbose || level === 'error') {
82
- const prefix = `[AddNeoRequirePlugin]`;
83
- console[level](`${prefix} ${message}`);
84
- }
85
- }
86
-
87
- apply(compiler) {
88
- compiler.hooks.compilation.tap('AddNeoRequirePlugin', (compilation) => {
89
- compilation.hooks.processAssets.tap(
90
- {
91
- name: 'AddNeoRequirePlugin',
92
- stage: -100
93
- },
94
- (assets) => {
95
- this.log('开始处理资源文件...');
96
-
97
- let processedCount = 0;
98
- let skippedCount = 0;
99
- let errorCount = 0;
100
-
101
- // 遍历所有资源文件
102
- for (const [filename, asset] of Object.entries(assets)) {
103
- try {
104
- // 检查是否应该跳过此文件
105
- if (this.shouldSkipFile(filename)) {
106
- this.log(`跳过文件: ${filename} (匹配跳过规则)`);
107
- skippedCount++;
108
- continue;
109
- }
110
-
111
- // 获取文件内容
112
- const source = asset.source();
113
- const content = typeof source === 'string' ? source : source.toString();
114
-
115
- // 验证文件内容
116
- if (!this.isValidFile(content)) {
117
- this.log(`跳过文件: ${filename} (内容无效)`, 'warn');
118
- skippedCount++;
119
- continue;
120
- }
121
-
122
- // 检查是否已经注入过
123
- if (this.options.skipInjected && this.isAlreadyInjected(content)) {
124
- this.log(`跳过文件: ${filename} (已注入过)`);
125
- skippedCount++;
126
- continue;
127
- }
128
-
129
- // 执行注入
130
- this.injectNeoRequire(compilation, filename, content);
131
- processedCount++;
132
-
133
- this.log(`成功处理文件: ${filename}`);
134
- } catch (error) {
135
- errorCount++;
136
- this.log(`处理文件失败: ${filename}, 错误: ${error.message}`, 'error');
137
- console.error(`[AddNeoRequirePlugin] 详细错误:`, error);
138
- }
139
- }
140
-
141
- // 输出处理统计
142
- this.log(
143
- `处理完成 - 成功: ${processedCount}, 跳过: ${skippedCount}, 错误: ${errorCount}`
144
- );
145
-
146
- if (errorCount > 0) {
147
- this.log(`警告: 有 ${errorCount} 个文件处理失败`, 'warn');
148
- }
149
- }
150
- );
151
- });
152
- }
153
-
154
- /**
155
- * 执行 neoRequire 注入
156
- */
157
- injectNeoRequire(compilation, filename, content) {
158
- const Header = `
159
- (function(NeoCustomCmpFileFactory) {
160
- if (!window.neoRequire) {
161
- throw new Error('neoRequire 不存在,请在 NeoCRM 平台中加载此脚本。');
162
- }
163
- NeoCustomCmpFileFactory(window.neoRequire);
164
- })(function(require) {
165
- `;
166
-
167
- // const NeoUMDContent = fs.readFileSync(path.join(__dirname, '../neo/NeoUMDContent.js'), 'utf8');
168
- // const Footer = `}); \n${NeoUMDContent}`;
169
- const Footer = `});`;
170
-
171
- // 创建新的资源
172
- const newSource = new ConcatSource(Header, content, Footer);
173
-
174
- // 更新资源
175
- compilation.updateAsset(filename, newSource);
176
- }
177
- }
178
-
179
- module.exports = AddNeoRequirePlugin;