neo-cmp-cli 1.8.7 → 1.8.9

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 (125) hide show
  1. package/bin/index.js +2 -2
  2. package/dist/_virtual/_commonjsHelpers.js +12 -0
  3. package/dist/_virtual/array-set.js +7 -0
  4. package/dist/_virtual/base64-vlq.js +7 -0
  5. package/dist/_virtual/base64.js +7 -0
  6. package/dist/_virtual/binary-search.js +7 -0
  7. package/dist/_virtual/mapping-list.js +7 -0
  8. package/dist/_virtual/quick-sort.js +7 -0
  9. package/dist/_virtual/source-map-consumer.js +7 -0
  10. package/dist/_virtual/source-map-generator.js +7 -0
  11. package/dist/_virtual/source-map-support.js +7 -0
  12. package/dist/_virtual/source-map.js +7 -0
  13. package/dist/_virtual/source-node.js +7 -0
  14. package/dist/_virtual/typescript.js +7 -0
  15. package/dist/_virtual/util.js +7 -0
  16. package/dist/config/auth.config.js +43 -0
  17. package/dist/config/default.config.js +192 -0
  18. package/dist/config/index.js +26 -0
  19. package/dist/main.js +9 -0
  20. package/dist/main2.js +259 -0
  21. package/dist/module/inspect.js +63 -0
  22. package/dist/module/neoInit.js +75 -0
  23. package/dist/module/neoInitByCopy.js +83 -0
  24. package/dist/neo/neoLogin.js +590 -0
  25. package/dist/neo/neoRequire.js +123 -0
  26. package/dist/neo/neoService.js +898 -0
  27. package/dist/node_modules/buffer-from/index.js +86 -0
  28. package/dist/node_modules/source-map/lib/array-set.js +138 -0
  29. package/dist/node_modules/source-map/lib/base64-vlq.js +157 -0
  30. package/dist/node_modules/source-map/lib/base64.js +83 -0
  31. package/dist/node_modules/source-map/lib/binary-search.js +129 -0
  32. package/dist/node_modules/source-map/lib/mapping-list.js +96 -0
  33. package/dist/node_modules/source-map/lib/quick-sort.js +130 -0
  34. package/dist/node_modules/source-map/lib/source-map-consumer.js +1166 -0
  35. package/dist/node_modules/source-map/lib/source-map-generator.js +445 -0
  36. package/dist/node_modules/source-map/lib/source-node.js +431 -0
  37. package/dist/node_modules/source-map/lib/util.js +506 -0
  38. package/dist/node_modules/source-map/source-map.js +27 -0
  39. package/dist/node_modules/source-map-support/source-map-support.js +646 -0
  40. package/dist/node_modules/typescript/lib/typescript.js +174130 -0
  41. package/dist/oss/publish2oss.js +331 -0
  42. package/dist/plugins/AddNeoRequirePlugin.js +195 -0
  43. package/dist/utils/autoEntryRootDir.js +103 -0
  44. package/dist/utils/cmpUtils/createCmpByTemplate.js +82 -0
  45. package/dist/utils/cmpUtils/createCmpByZip.js +433 -0
  46. package/dist/utils/cmpUtils/createCommonModulesCode.js +139 -0
  47. package/dist/utils/cmpUtils/deleteCmp.js +81 -0
  48. package/dist/utils/cmpUtils/getCmpModelRegisterCode.js +47 -0
  49. package/dist/utils/cmpUtils/getCmpPreviewCode.js +60 -0
  50. package/dist/utils/cmpUtils/getCmpRegisterCode.js +47 -0
  51. package/dist/utils/cmpUtils/getCmpTypeByDir.js +59 -0
  52. package/dist/utils/cmpUtils/hasCmpTypeByDir.js +27 -0
  53. package/dist/utils/cmpUtils/previewCmp.js +75 -0
  54. package/dist/utils/cmpUtils/pullCmp.js +126 -0
  55. package/dist/utils/cmpUtils/pushCmp.js +254 -0
  56. package/dist/utils/common.js +125 -0
  57. package/dist/utils/configureNeoBuild.js +129 -0
  58. package/dist/utils/generateEntries.js +80 -0
  59. package/dist/utils/neoConfigInit.js +30 -0
  60. package/dist/utils/neoParams.js +26 -0
  61. package/dist/utils/pathUtils.js +40 -0
  62. package/dist/utils/projectNameValidator.js +90 -0
  63. package/dist/utils/projectUtils/createCmpProjectByTemplate.js +81 -0
  64. package/dist/utils/projectUtils/createCmpProjectZip.js +141 -0
  65. package/dist/utils/projectUtils/getEntries.js +99 -0
  66. package/dist/utils/projectUtils/getEntriesWithAutoRegister.js +129 -0
  67. package/dist/utils/projectUtils/hasNeoProject.js +34 -0
  68. package/dist/utils/projectUtils/openProject.js +117 -0
  69. package/dist/utils/projectUtils/updatePublishLog.js +47 -0
  70. package/dist/utils/replaceInFilesByMap.js +71 -0
  71. package/dist/utils/replaceInPackage.js +151 -0
  72. package/dist/utils/resetPackageVersion.js +132 -0
  73. package/package.json +6 -8
  74. package/test/demo.js +0 -2
  75. package/test/deprecate-versions.js +1 -1
  76. package/src/config/auth.config.js +0 -27
  77. package/src/config/default.config.js +0 -176
  78. package/src/config/index.js +0 -9
  79. package/src/main.js +0 -221
  80. package/src/module/inspect.js +0 -41
  81. package/src/module/neoInit.js +0 -55
  82. package/src/module/neoInitByCopy.js +0 -61
  83. package/src/neo/NeoUMDContent.js +0 -30
  84. package/src/neo/neoLogin.js +0 -565
  85. package/src/neo/neoRequire.js +0 -125
  86. package/src/neo/neoService.js +0 -874
  87. package/src/neo/webpack.mf.js +0 -60
  88. package/src/neo/wrapperContent.js +0 -16
  89. package/src/oss/publish2oss.js +0 -348
  90. package/src/plugins/AddNeoRequirePlugin-v1.js +0 -47
  91. package/src/plugins/AddNeoRequirePlugin.js +0 -179
  92. package/src/plugins/README.md +0 -109
  93. package/src/utils/autoEntryRootDir.js +0 -85
  94. package/src/utils/cmpUtils/createCmpByTemplate.js +0 -60
  95. package/src/utils/cmpUtils/createCmpByZip.js +0 -408
  96. package/src/utils/cmpUtils/createCommonModulesCode.js +0 -121
  97. package/src/utils/cmpUtils/deleteCmp.js +0 -63
  98. package/src/utils/cmpUtils/getCmpModelRegisterCode.js +0 -31
  99. package/src/utils/cmpUtils/getCmpPreviewCode.js +0 -43
  100. package/src/utils/cmpUtils/getCmpRegisterCode.js +0 -31
  101. package/src/utils/cmpUtils/getCmpTypeByDir.js +0 -41
  102. package/src/utils/cmpUtils/hasCmpTypeByDir.js +0 -11
  103. package/src/utils/cmpUtils/previewCmp.js +0 -55
  104. package/src/utils/cmpUtils/pullCmp.js +0 -104
  105. package/src/utils/cmpUtils/pushCmp.js +0 -230
  106. package/src/utils/common.js +0 -107
  107. package/src/utils/configureNeoBuild.js +0 -109
  108. package/src/utils/generateEntries.js +0 -63
  109. package/src/utils/neoConfigInit.js +0 -13
  110. package/src/utils/neoParams.js +0 -12
  111. package/src/utils/pathUtils.js +0 -23
  112. package/src/utils/projectNameValidator.js +0 -76
  113. package/src/utils/projectUtils/createCmpProjectByTemplate.js +0 -59
  114. package/src/utils/projectUtils/createCmpProjectZip.js +0 -120
  115. package/src/utils/projectUtils/getEntries.js +0 -80
  116. package/src/utils/projectUtils/getEntriesWithAutoRegister.js +0 -108
  117. package/src/utils/projectUtils/hasNeoProject.js +0 -17
  118. package/src/utils/projectUtils/openProject.js +0 -96
  119. package/src/utils/projectUtils/updatePublishLog.js +0 -30
  120. package/src/utils/replaceInFiles.js +0 -47
  121. package/src/utils/replaceInFilesByMap.js +0 -54
  122. package/src/utils/replaceInPackage.js +0 -134
  123. package/src/utils/resetPackageVersion.js +0 -115
  124. /package/{src → template}/initData/defaultTemplate.html +0 -0
  125. /package/{src → template}/initData/neo.config.js +0 -0
@@ -1,230 +0,0 @@
1
- const fs = require('fs');
2
- const path = require('path');
3
- const _ = require('lodash');
4
- const { getConfigObj } = require('akfun');
5
- const { catchCurPackageJson } = require('../pathUtils');
6
- const ora = require('ora');
7
- const NeoService = require('../../neo/neoService');
8
- const { getFramework, errorLog, successLog } = require('../common');
9
- const createCmpProjectZip = require('../projectUtils/createCmpProjectZip');
10
-
11
- // 获取当前项目的package文件
12
- const currentPackageJsonDir = catchCurPackageJson();
13
- const currentPackageJson = getConfigObj(currentPackageJsonDir);
14
-
15
- // 获取属性 propsSchema 数据结构
16
- const getPropsSchema = (propsSchema = []) => {
17
- return propsSchema.map((item) => {
18
- return {
19
- label: item.label,
20
- description: item.description,
21
- propSchema: JSON.stringify(item)
22
- };
23
- });
24
- };
25
-
26
- /**
27
- * 构建组件数据映射
28
- * @param {string} assetsRoot 构建产物的目录
29
- * @param {object} cmpInfo 自定义组件信息
30
- * @returns {Promise<object|null>} 自定义组件数据(含自定义组件模型信息)
31
- */
32
- const buildComponentData = async (assetsRoot, cmpInfo) => {
33
- if (!cmpInfo || !cmpInfo.cmpType) {
34
- errorLog('自定义组件信息或组件名称不能为空');
35
- return null;
36
- }
37
-
38
- const { cmpType } = cmpInfo;
39
-
40
- if (!assetsRoot || !fs.existsSync(assetsRoot)) {
41
- errorLog(`未找到自定义组件目录: ${assetsRoot}`);
42
- return null;
43
- }
44
- const widgetName = _.camelCase(cmpType);
45
- const modelFile = path.join(assetsRoot, `${widgetName}Model.js`);
46
-
47
- // 为 Node.js 环境设置全局 window 对象(模型文件可能需要)
48
- // 使用 globalThis 以确保在 Node.js 和浏览器环境中都能工作
49
- const originalWindow = globalThis.window;
50
- if (!globalThis.window) {
51
- globalThis.window = {
52
- console: console,
53
- neoRequire: () => {},
54
- postMessage: () => {}
55
- // 可以添加其他常用的 window 属性
56
- };
57
- }
58
-
59
- try {
60
- // 加载自定义组件模型资源文件
61
- if (fs.existsSync(modelFile)) {
62
- // 加载自定义组件模型资源文件
63
- let modelModule = require(modelFile);
64
- // 获取导出的模型类(可能是 default 导出或命名导出)
65
- // const CatchCustomCmpModelClass = modelModule.default || modelModule;
66
- } else {
67
- errorLog(`未找到自定义组件模型文件,请检查以下路径是否存在:${modelFile}`);
68
- process.exit(1);
69
- }
70
- if (!globalThis.window || !globalThis.window.NEOEditorCustomModels) {
71
- errorLog(
72
- `模型文件未导出有效模型方法(CatchCustomCmpModelClass),模型文件地址: ${modelFile} `
73
- );
74
- process.exit(1);
75
- }
76
-
77
- const ModelClass = globalThis.window.NEOEditorCustomModels[cmpType];
78
- if (!ModelClass) {
79
- errorLog(`未找到自定义组件模型类(${cmpType}),模型文件地址: ${modelFile} `);
80
- process.exit(1);
81
- }
82
- // 实例化模型类
83
- const modelInstance = new ModelClass();
84
-
85
- if (!modelInstance) {
86
- errorLog(`未找到自定义组件模型信息(${cmpType}),模型文件地址: ${modelFile} `);
87
- process.exit(1);
88
- }
89
-
90
- // 构建组件数据,合并模型实例的信息
91
- const curCmpInfo = {
92
- ...cmpInfo,
93
- version: currentPackageJson.version || '1.0.0',
94
- // 技术栈标识: 从 package.json / framework 字段获取,没有则默认 为 react ts 技术栈
95
- framework: currentPackageJson.framework ? getFramework(currentPackageJson.framework) : 0, // 0: React, 1: vue2, 2: jQuery, 3: vue3
96
- // 从模型实例中提取并设置组件信息
97
- label: modelInstance.label || cmpType,
98
- description: modelInstance.description || '',
99
- componentCategory: (modelInstance.tags || ['自定义组件']).join(','),
100
- targetPage: modelInstance.targetPage || ['customPage'], // 支持的页面类型
101
- targetObject: modelInstance.targetObject || ['all'], // 支持的实体类型
102
- targetApplication: modelInstance.targetApplication || ['all'], // 支持的应用类型
103
- targetDevice: modelInstance.targetDevice || 'all', // 支持的设备类型。只有这个字段是字符串数值,其他都是数组
104
- iconUrl: modelInstance.iconSrc || modelInstance.iconUrl,
105
- defaultProps: JSON.stringify(modelInstance.defaultComProps || {}),
106
- previewProps: JSON.stringify(modelInstance.previewComProps || {}),
107
- props: getPropsSchema(modelInstance.propsSchema || []),
108
- events: modelInstance.events || [],
109
- functions: modelInstance.functions || modelInstance.actions || [],
110
- // 如果模型实例中有其他属性,也可以添加
111
- exposedToDesigner:
112
- modelInstance.exposedToDesigner !== undefined ? modelInstance.exposedToDesigner : true,
113
- namespace: modelInstance.namespace || 'neo-cmp-cli',
114
- enableDuplicate:
115
- modelInstance.enableDuplicate !== undefined ? modelInstance.enableDuplicate : true
116
- };
117
-
118
- console.log(
119
- `自定义组件模型信息(${cmpType}):`,
120
- _.omit(curCmpInfo, ['assetFile', 'modelAssetFile', 'cssAssetFile', 'codeLibFile'])
121
- );
122
- return curCmpInfo;
123
- } catch (error) {
124
- errorLog(`自定义组件模型文件解析失败 (${modelFile || '未知路径'}): ${error.message}`);
125
- errorLog(error.stack);
126
- return null;
127
- } finally {
128
- // 恢复原始的 window 对象(如果之前存在)
129
- if (originalWindow === undefined) {
130
- delete globalThis.window;
131
- } else {
132
- globalThis.window = originalWindow;
133
- }
134
- }
135
- };
136
-
137
- /**
138
- * 发布组件到 NeoCRM
139
- * @param {object} config 配置信息
140
- * @param {string} cmpType 自定义组件类型
141
- *
142
- * 发布流程说明
143
- * 1. 打包源码文件:将自定义组件源码打包成 zip 文件
144
- * 2. 上传构建产物到 OSS:将构建后的资源文件上传到 NeoCRM 平台提供的 CDN
145
- * 3. 构建组件数据:从组件模型文件中提取组件信息
146
- * 4. 保存组件信息到 NeoCRM 平台:将组件信息保存到平台数据库
147
- */
148
- const pushCmp = async (config, cmpType) => {
149
- const spinner = ora('正在发布组件...').start();
150
-
151
- try {
152
- // 步骤 1: 初始化 NeoService
153
- let neoService = new NeoService(config);
154
- // 获取 token
155
- await neoService.ensureValidToken();
156
-
157
- // 步骤 2: 打包源码文件(打包单个自定义组件源码)
158
- spinner.start(`[1/4] 打包源码文件(含单个自定义组件源码)...`);
159
- let zipPath;
160
- try {
161
- zipPath = createCmpProjectZip(cmpType, process.cwd(), config.assetsRoot);
162
- if (!zipPath) {
163
- errorLog('[1/4] 源码文件打包失败,未返回 zip 文件路径。', spinner);
164
- } else {
165
- successLog(`[1/4] 源码文件打包完成: ${path.basename(zipPath)}。`, spinner);
166
- }
167
- } catch (error) {
168
- errorLog(`[1/4] 源码文件打包失败。`, spinner);
169
- }
170
-
171
- /*
172
- // 步骤 3: 上传构建后资源文件(改放在保存时直接上传组件资源文件)
173
- spinner.start(`[2/4] 上传自定义组件构建产物到 OSS...`);
174
- let cmpInfo;
175
- try {
176
- cmpInfo = await neoService.publish2oss(cmpType);
177
- if (!cmpInfo || !cmpInfo.cmpType) {
178
- errorLog('[2/4] 上传构建产物失败,未获取到组件信息。', spinner);
179
- } else {
180
- successLog(`[2/4] 构建产物上传完成。`, spinner);
181
- }
182
- } catch (error) {
183
- errorLog(`[2/4] 构建产物上传失败。`, spinner);
184
- }
185
- */
186
- spinner.start(`[2/4] 获取自定义组件构建产物...`);
187
- const cmpInfo = await neoService.getCmpAssets(cmpType);
188
-
189
- // 步骤 4: 构建组件数据
190
- spinner.start(`[3/4] 构建组件数据...`);
191
- let componentInfo;
192
- try {
193
- componentInfo = await buildComponentData(config.assetsRoot, cmpInfo);
194
- if (!componentInfo) {
195
- errorLog(`[3/4] 未获取到自定义组件模型信息(${cmpType})。`, spinner);
196
- } else {
197
- successLog(`[3/4] 组件数据构建完成。`, spinner);
198
- }
199
- } catch (error) {
200
- errorLog(`[3/4] 组件数据构建失败: ${error.message}`, spinner);
201
- }
202
-
203
- // 步骤 5: 保存组件信息
204
- spinner.start(`[4/4] 保存组件信息到 NeoCRM 平台...`);
205
- try {
206
- await neoService.updateCustomComponent(componentInfo);
207
- successLog(`[4/4] 组件信息保存成功`, spinner);
208
- } catch (error) {
209
- errorLog(`[4/4] 组件信息保存失败`, spinner);
210
- }
211
-
212
- // 最终成功提示
213
- console.log('\n✅ 自定义组件发布成功!');
214
- } catch (error) {
215
- // 内层 catch 已经处理了步骤错误并显示了 spinner 失败状态
216
- // 这里处理未预期的错误(如果 spinner 还在运行)
217
- try {
218
- // ora 的 spinner 对象可能没有 isSpinning 属性,使用 try-catch 安全访问
219
- if (spinner && spinner.isSpinning) {
220
- errorLog(`❌ 自定义组件发布失败: ${error.message}`, spinner);
221
- }
222
- } catch {
223
- // 如果访问失败或 spinner 已停止,直接输出错误信息
224
- errorLog(`\n❌ 自定义组件发布失败: ${error.message}`);
225
- }
226
- throw error;
227
- }
228
- };
229
-
230
- module.exports = pushCmp;
@@ -1,107 +0,0 @@
1
- const chalk = require('chalk');
2
- const ts = require('typescript');
3
- const { consoleTag } = require('./neoParams');
4
-
5
- /**
6
- * 获取技术栈标识
7
- * 目的:兼容用户非标准写法
8
- * 0: React, 1: vue2, 2: jQuery, 3: vue3
9
- */
10
- function getFramework(_framework) {
11
- let defaultFramework = 0; // 默认 React 技术栈
12
- if (!_framework) {
13
- return defaultFramework;
14
- }
15
- let curFramework = _framework.toLowerCase().trim();
16
- switch (curFramework) {
17
- case 'jquery':
18
- case 'jq':
19
- curFramework = 2;
20
- break;
21
- case 'vue2':
22
- case 'vue 2':
23
- case 'vue2.0':
24
- case 'vue 2.0':
25
- curFramework = 1;
26
- break;
27
- case 'vue':
28
- case 'vue3':
29
- case 'vue 3':
30
- case 'vue3.0':
31
- case 'vue 3.0':
32
- curFramework = 3;
33
- errorLog('暂不支持 vue3.0 技术栈。');
34
- break;
35
- case 'react-js':
36
- errorLog('暂不支持 react-js 技术栈。');
37
- curFramework = 0;
38
- break;
39
- case 'react':
40
- case 'react-ts':
41
- curFramework = 0;
42
- break;
43
- default:
44
- curFramework = 0;
45
- }
46
- return curFramework;
47
- }
48
-
49
- // 输出红色字体的错误日志
50
- function errorLog(message, spinner) {
51
- const errorMessage = `${consoleTag} ${chalk.red(message)}`;
52
- if (spinner) {
53
- spinner.fail(errorMessage);
54
- } else {
55
- console.error(errorMessage);
56
- }
57
- }
58
-
59
- // 输出黄色字体的警告日志
60
- function warningLog(message, spinner) {
61
- const warningMessage = `${consoleTag} ${chalk.yellow(message)}`;
62
- if (spinner) {
63
- spinner.warn(warningMessage);
64
- } else {
65
- console.warn(warningMessage);
66
- }
67
- }
68
-
69
- // 输出绿色字体的成功日志
70
- function successLog(message, spinner) {
71
- const successMessage = `${consoleTag} ${chalk.green(message)}`;
72
- if (spinner) {
73
- spinner.succeed(successMessage);
74
- } else {
75
- console.log(successMessage);
76
- }
77
- }
78
-
79
- /**
80
- * 使用 TypeScript 官方 API 解析 tsconfig.json(推荐)
81
- * 需要安装: npm install typescript --save-dev
82
- * 优点: 官方支持,能正确处理 extends、注释等所有特性
83
- */
84
- function parseTsConfigWithTypeScript(configPath) {
85
- try {
86
- const configFile = ts.readConfigFile(configPath, ts.sys.readFile);
87
-
88
- if (configFile.error) {
89
- throw new Error(`解析 tsconfig.json 失败: ${configFile.error.messageText}`);
90
- }
91
-
92
- return configFile.config;
93
- } catch (error) {
94
- if (error.code === 'MODULE_NOT_FOUND') {
95
- throw new Error('请先安装 typescript: npm install typescript --save-dev');
96
- }
97
- throw error;
98
- }
99
- }
100
-
101
- module.exports = {
102
- getFramework,
103
- errorLog,
104
- warningLog,
105
- successLog,
106
- parseTsConfigWithTypeScript
107
- };
@@ -1,109 +0,0 @@
1
- const _ = require('lodash');
2
- const AddNeoRequirePlugin = require('../plugins/AddNeoRequirePlugin');
3
- const createCommonModulesCode = require('../utils/cmpUtils/createCommonModulesCode');
4
- const { getExternalsByNeoCommonModules } = require('../neo/neoRequire');
5
- const curConfig = require('../config/index'); // 获取当前项目根目录下的配置文件
6
-
7
- // neo.config.js 中的添加的 Neo 共享依赖模块配置
8
- const neoCommonModule = curConfig.neoCommonModule || {};
9
- // 自定义组件 需要剔除的依赖模块
10
- const cmpNeoExternals = neoCommonModule.externals || [];
11
-
12
- // 组件目录
13
- const componentsDir = curConfig.componentsDir || './src/components';
14
-
15
- /**
16
- * 添加 AddNeoRequirePlugin 到 webpack 配置
17
- * @param {object} webpackConfig webpack 配置对象
18
- * @param {object} [options] 选项
19
- * @param {boolean} [options.verbose] 是否启用详细日志,默认为 false
20
- */
21
- function addNeoRequirePlugin(webpackConfig, options = {}) {
22
- const { verbose = false } = options;
23
- const plugin = new AddNeoRequirePlugin({ verbose });
24
-
25
- if (webpackConfig && webpackConfig.plugins && Array.isArray(webpackConfig.plugins)) {
26
- webpackConfig.plugins.push(plugin);
27
- } else {
28
- webpackConfig.plugins = [plugin];
29
- }
30
- }
31
-
32
- /**
33
- * 添加 Neo externals 配置
34
- * @param {object} config 配置对象(dev 或 build2lib)
35
- * @param {object} externalsConfig 现有的 externals 配置
36
- */
37
- function addNeoExternals(config, externalsConfig) {
38
- const externals = getExternalsByNeoCommonModules(cmpNeoExternals);
39
- if (externalsConfig && _.isPlainObject(externalsConfig)) {
40
- config.externals = Object.assign(externalsConfig, externals);
41
- } else {
42
- config.externals = externals;
43
- }
44
- }
45
-
46
- /**
47
- * 创建并注入 commonModulesCode 到 entry
48
- * @param {object} config 配置对象(dev 或 build2lib)
49
- * @param {array} cmpTypes 组件类型列表
50
- * @param {object} [options] 选项
51
- * @param {boolean} [options.excludeModel] 是否排除 Model 结尾的 entry,默认为 false
52
- */
53
- function injectCommonModulesCode(config, options = {}) {
54
- const { cmpTypes, defaultExports, excludeModel = false } = options;
55
-
56
- // 添加默认导出
57
- if (defaultExports && _.isPlainObject(defaultExports)) {
58
- if (neoCommonModule.exports && _.isPlainObject(neoCommonModule.exports)) {
59
- neoCommonModule.exports = Object.assign(neoCommonModule.exports, defaultExports);
60
- } else if (neoCommonModule.exports && _.isArray(neoCommonModule.exports)) {
61
- // 先将数组格式改成对象格式
62
- neoCommonModule.exports.forEach((item) => {
63
- if (_.isString(item)) {
64
- neoCommonModule.exports[item] = item;
65
- }
66
- });
67
- neoCommonModule.exports = Object.assign(neoCommonModule.exports, defaultExports);
68
- } else {
69
- neoCommonModule.exports = defaultExports;
70
- }
71
- }
72
-
73
- const commonModulesFilePath = createCommonModulesCode(neoCommonModule, cmpTypes);
74
-
75
- if (commonModulesFilePath && config.entry) {
76
- Object.keys(config.entry).forEach((name) => {
77
- // 如果 excludeModel 为 true,排除 Model 结尾的文件
78
- if (!excludeModel || !name.endsWith('Model')) {
79
- config.entry[name] = [commonModulesFilePath].concat(config.entry[name]);
80
- }
81
- });
82
- }
83
- }
84
-
85
- /**
86
- * 配置 webpack 插件、externals 和 commonModulesCode(用于 linkDebug、publish2oss、pushCmp)
87
- * @param {object} config 配置对象(dev 或 build2lib)
88
- * @param {object} [options] 选项
89
- * @param {array} [options.cmpTypes] 组件类型列表
90
- * @param {object} [options.defaultExports] 默认导出
91
- * @param {boolean} [options.verbose] 是否启用详细日志,默认为 false
92
- * @param {boolean} [options.excludeModel] 是否排除 Model 结尾的 entry,默认为 false
93
- */
94
- function configureNeoBuild(config, options = {}) {
95
- const { cmpTypes, defaultExports, verbose = false, excludeModel = false } = options;
96
-
97
- // 添加自定义 webpack 插件
98
- addNeoRequirePlugin(curConfig.webpack, { verbose });
99
-
100
- // 添加内置 Neo 的 externals 配置
101
- addNeoExternals(config, config.externals);
102
-
103
- // 创建并注入 commonModulesCode
104
- injectCommonModulesCode(config, { cmpTypes, defaultExports, excludeModel });
105
- }
106
-
107
- module.exports = {
108
- configureNeoBuild
109
- };
@@ -1,63 +0,0 @@
1
- const getEntries = require('./projectUtils/getEntries');
2
- const getEntriesWithAutoRegister = require('./projectUtils/getEntriesWithAutoRegister');
3
-
4
- /**
5
- * 生成 entry 配置
6
- * @param {object} options 配置选项
7
- * @param {object} options.configEntry 当前配置中的 entry(如果已存在则直接返回)
8
- * @param {boolean} options.disableAutoRegister 是否禁用自动注册
9
- * @param {string} options.componentsDir 组件目录路径
10
- * @param {string} options.entryType entry 类型:'widget' | 'linkDebug',默认为 'widget'
11
- * @param {string} [options.cmpType] 可选的组件类型,如果指定则只生成该组件的 entry
12
- */
13
- function generateEntries({
14
- configEntry,
15
- disableAutoRegister,
16
- componentsDir,
17
- entryType = 'widget',
18
- cmpType
19
- }) {
20
- // 如果已配置 entry 且不需要强制获取 cmpTypes,直接返回
21
- if (configEntry && Object.keys(configEntry).length > 0) {
22
- return {
23
- entries: configEntry,
24
- cmpTypes: []
25
- };
26
- }
27
-
28
- // 根据 disableAutoRegister 选择不同的生成方法
29
- let entriesResult;
30
- if (disableAutoRegister) {
31
- // disableAutoRegister 为 true 时,仅自动生成入口文件(不自动注册)
32
- entriesResult = getEntries(componentsDir, cmpType);
33
- } else {
34
- // 自动生成入口文件(并自动创建对应的注册文件)
35
- entriesResult = getEntriesWithAutoRegister(componentsDir, cmpType);
36
- }
37
-
38
- // 根据 entryType 选择对应的 entries
39
- let entries;
40
- if (entryType === 'linkDebug') {
41
- entries = entriesResult.linkDebugEntries || {};
42
- } else {
43
- entries = entriesResult.widgetEntries || {};
44
- }
45
-
46
- const cmpTypes = entriesResult.cmpTypes || [];
47
-
48
- // 验证 entries 是否有效(仅在需要生成新 entry 时验证)
49
- if (!entries || Object.keys(entries).length === 0) {
50
- const defaultComponentsDir = componentsDir || './src/components';
51
- throw new Error(
52
- `未识别到自定义组件,请检查 ${defaultComponentsDir} 目录下是否存在自定义组件。`
53
- );
54
- }
55
-
56
- return {
57
- entries: entries || configEntry || {},
58
- cmpTypes,
59
- defaultExports: entriesResult.defaultExports || {}
60
- };
61
- }
62
-
63
- module.exports = generateEntries;
@@ -1,13 +0,0 @@
1
- const path = require('path');
2
- const { createFile } = require('akfun');
3
-
4
- // 将脚手架的默认配置文件拷贝到当前项目根目录
5
- const createDefaultConfig = function (_configProjectName) {
6
- const configProjectName = _configProjectName || 'neo.config.js';
7
- createFile(
8
- path.resolve(__dirname, `../initData/${configProjectName}`),
9
- path.resolve(process.cwd(), `./${configProjectName}`)
10
- );
11
- };
12
-
13
- module.exports = createDefaultConfig;
@@ -1,12 +0,0 @@
1
- let consoleTag = '[neo-cmp-cli]'; // 输出标记
2
-
3
- function setConsoleTag(newText) {
4
- consoleTag = newText;
5
- }
6
-
7
- module.exports = {
8
- get consoleTag() {
9
- return consoleTag;
10
- },
11
- setConsoleTag
12
- };
@@ -1,23 +0,0 @@
1
- const path = require('path');
2
- const fs = require('fs');
3
-
4
- // 当前命令执行的路径
5
- const currentRoot = () => fs.realpathSync(process.cwd());
6
- const resolveToCurrentRoot = (filePath) => path.resolve(currentRoot(), filePath);
7
- const resolveToCurrentDist = (filePath, outDir) =>
8
- path.resolve(currentRoot(), outDir || 'dist/', filePath);
9
- const currentSrc = () => resolveToCurrentRoot('src');
10
- const currentBuild = () => resolveToCurrentRoot('build');
11
-
12
- // 获取当前项目的package文件(从当前命令执行的路径下查找)
13
- const catchCurPackageJson = () => resolveToCurrentRoot('package.json');
14
-
15
- module.exports = {
16
- currentRoot,
17
- resolveToCurrentRoot,
18
- resolveToCurrentDist,
19
- resolve: resolveToCurrentRoot,
20
- currentSrc,
21
- currentBuild,
22
- catchCurPackageJson
23
- };
@@ -1,76 +0,0 @@
1
- /**
2
- * 文件名验证工具
3
- * 验证规则:
4
- * 1. 至少5个字符
5
- * 2. 必须以字母开头
6
- * 3. 只能包含字母、数字、连字符(-)
7
- */
8
-
9
- /**
10
- * 验证文件名是否符合规范
11
- * @param {string} ProjectName 文件名(不包含路径和扩展名)
12
- * @returns {Object} 验证结果对象
13
- */
14
- function validateProjectName(ProjectName) {
15
- const errors = [];
16
-
17
- // 检查文件名是否为空
18
- if (!ProjectName || ProjectName.trim().length === 0) {
19
- errors.push('文件名不能为空');
20
- return { isValid: false, errors };
21
- }
22
-
23
- // 检查长度是否至少5个字符
24
- if (ProjectName.length < 5) {
25
- errors.push(`文件名长度必须至少5个字符,当前长度: ${ProjectName.length}`);
26
- }
27
-
28
- // 检查是否以字母开头
29
- if (!/^[a-zA-Z]/.test(ProjectName)) {
30
- errors.push('文件名必须以字母开头');
31
- }
32
-
33
- // 检查是否只包含字母、数字、连字符
34
- if (!/^[a-zA-Z][a-zA-Z0-9-]*$/.test(ProjectName)) {
35
- errors.push('文件名只能包含字母、数字和连字符(-),且必须以字母开头');
36
- }
37
-
38
- // 检查是否包含连续连字符
39
- if (ProjectName.includes('--')) {
40
- errors.push('文件名不能包含连续连字符(--)');
41
- }
42
-
43
- // 检查是否以连字符结尾
44
- if (ProjectName.endsWith('-')) {
45
- errors.push('文件名不能以连字符结尾');
46
- }
47
-
48
- return {
49
- isValid: errors.length === 0,
50
- errors
51
- };
52
- }
53
-
54
- /**
55
- * 验证文件名并返回布尔值
56
- * @param {string} ProjectName 文件名
57
- * @returns {boolean} 是否有效
58
- */
59
- function isValidProjectName(ProjectName) {
60
- return validateProjectName(ProjectName).isValid;
61
- }
62
-
63
- /**
64
- * 获取文件名验证的错误信息
65
- * @param {string} ProjectName 文件名
66
- * @returns {Array} 错误信息数组
67
- */
68
- function getProjectNameErrors(ProjectName) {
69
- return validateProjectName(ProjectName).errors;
70
- }
71
-
72
- module.exports = {
73
- validateProjectName,
74
- isValidProjectName,
75
- getProjectNameErrors
76
- };