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,121 +0,0 @@
1
- const fs = require('fs');
2
- const { resolveToCurrentRoot } = require('../pathUtils');
3
- const { isPlainObject } = require('lodash');
4
-
5
- /**
6
- * 获取组件预览代码
7
- * @param {*} cmpsDir 自定义组件目录
8
- * @param {*} cmpName 自定义组件名称
9
- * @returns 组件预览代码
10
- */
11
- const createCommonModulesCode = (neoCommonModule, cmpTypes) => {
12
- const { exports, remoteDeps } = neoCommonModule;
13
-
14
- if (!exports && !remoteDeps) {
15
- return '';
16
- }
17
- // 记录当前自定义组件共享出去的模块
18
- const CustomCmpCommonModules = {};
19
- // 记录当前自定义组件需要的远程依赖组件
20
- const CustomCmpRemoteDeps = {};
21
-
22
- // 根据 exports 获取共享的依赖模块
23
- if (Array.isArray(exports) && exports.length > 0) {
24
- exports.forEach((module) => {
25
- CustomCmpCommonModules[module] = require(module);
26
- });
27
- } else if (isPlainObject(exports) && Object.keys(exports).length > 0) {
28
- Object.keys(exports).forEach((moduleId) => {
29
- CustomCmpCommonModules[moduleId] = `require('${exports[moduleId]}')`;
30
- });
31
- } else if (exports) {
32
- console.error(
33
- 'exports 格式不正确,请检查 neo.config.js 文件中的 neoCommonModule / exports 配置'
34
- );
35
- process.exit(1);
36
- }
37
-
38
- // 根据 cmpTypes 和 remoteDeps 设置远程依赖组件信息
39
- if (Array.isArray(remoteDeps) && remoteDeps.length > 0) {
40
- cmpTypes.forEach((cmpType) => {
41
- CustomCmpRemoteDeps[cmpType] = remoteDeps;
42
- });
43
- }
44
-
45
- // 构建 CustomCmpCommonModules 对象的代码字符串
46
- let customCmpCommonModulesCode = '{\n';
47
- const moduleEntries = Object.entries(CustomCmpCommonModules);
48
- moduleEntries.forEach(([moduleId, moduleValue], index) => {
49
- const isLast = index === moduleEntries.length - 1;
50
- customCmpCommonModulesCode += ` "${moduleId}": ${moduleValue}${isLast ? '' : ','}\n`;
51
- });
52
- customCmpCommonModulesCode += '}';
53
-
54
- const commonModulesCode = `
55
- /**
56
- * 自定义组件 共享出来的依赖模块
57
- * 备注:可在其他模块中通过 neoRequire 中使用
58
- */
59
- import { isPlainObject } from 'lodash';
60
- const CustomCmpCommonModules = ${customCmpCommonModulesCode};
61
- const CustomCmpRemoteDeps = ${JSON.stringify(CustomCmpRemoteDeps)};
62
-
63
- // 用于添加共享的依赖模块
64
- const addNeoCommonModules = (modules) => {
65
- if (!window.__NeoCommonModules) {
66
- window.__NeoCommonModules = {}
67
- }
68
- if (isPlainObject(modules)) {
69
- const moduleIds = Object.keys(modules)
70
- moduleIds.forEach((moduleId) => {
71
- const curModule = modules[moduleId];
72
- const curCommonModule = window.__NeoCommonModules[moduleId];
73
-
74
- if (curCommonModule && Object.keys(curCommonModule).length < 3) {
75
- window.__NeoCommonModules[moduleId] = Object.assign(window.__NeoCommonModules[moduleId], curModule);
76
-
77
- // 处理模块中的特殊属性
78
- if (curModule.__esModule !== undefined) {
79
- window.__NeoCommonModules[moduleId].__esModule = curModule.__esModule;
80
- }
81
- if (curModule.default !== undefined) {
82
- window.__NeoCommonModules[moduleId].default = curModule.default;
83
- }
84
- } else {
85
- window.__NeoCommonModules[moduleId] = curModule;
86
- }
87
- })
88
- }
89
- }
90
-
91
- // 用于添加自定义组件的远程依赖组件(关联使用)
92
- const addNeoRemoteDeps = (remoteDeps) => {
93
- if (!window.__NeoCommonModules) {
94
- window.__NeoCommonModules = {}
95
- }
96
- if (!window.__NeoCommonModules.__neoRemoteDeps) {
97
- window.__NeoCommonModules.__neoRemoteDeps = {}
98
- }
99
- if (isPlainObject(remoteDeps)) {
100
- window.__NeoCommonModules.__neoRemoteDeps = Object.assign(window.__NeoCommonModules.__neoRemoteDeps, remoteDeps)
101
- }
102
- }
103
-
104
- addNeoCommonModules(CustomCmpCommonModules);
105
- addNeoRemoteDeps(CustomCmpRemoteDeps);
106
- `;
107
-
108
- // 创建存放 cli 的临时目录
109
- const cliTempDir = resolveToCurrentRoot('./.neo-cli');
110
- if (!fs.existsSync(cliTempDir)) {
111
- fs.mkdirSync(cliTempDir);
112
- }
113
-
114
- // 将 commonModulesCode 写入到临时目录中
115
- const commonModulesFilePath = `${cliTempDir}/commonModules.js`;
116
- fs.writeFileSync(commonModulesFilePath, commonModulesCode);
117
-
118
- return commonModulesFilePath;
119
- };
120
-
121
- module.exports = createCommonModulesCode;
@@ -1,63 +0,0 @@
1
- const ora = require('ora');
2
- const NeoService = require('../../neo/neoService');
3
- const { errorLog, successLog } = require('../common');
4
-
5
- /**
6
- * 从 NeoCRM 删除自定义组件
7
- * @param {string} cmpType 自定义组件类型
8
- * @param {object} authConfig 授权配置
9
- * @param {object} _neoService 可选的 NeoService 实例(用于复用已获取的组件列表)
10
- *
11
- * 删除流程说明
12
- * 1. 获取当前租户下的自定义组件列表
13
- * 2. 验证组件是否存在
14
- * 3. 调用删除 API 删除组件
15
- */
16
- const deleteCmp = async (cmpType, authConfig, _neoService) => {
17
- if (!authConfig) {
18
- errorLog('未找到 NeoCRM 平台授权配置(neo.config.js / authConfig)。');
19
- return;
20
- }
21
-
22
- const spinner = ora('正在删除组件...').start();
23
-
24
- try {
25
- let neoService = _neoService;
26
- let cmpList = [];
27
- let cmpInfo = null;
28
-
29
- if (_neoService) {
30
- // 使用传入的 neoService 实例
31
- cmpList = _neoService.cmpList || [];
32
- } else {
33
- // 创建新的 neoService 实例
34
- neoService = new NeoService(authConfig);
35
-
36
- // 获取自定义组件列表
37
- spinner.info('正在获取自定义组件列表...');
38
- cmpList = await neoService.getCustomCmpList();
39
- }
40
-
41
- if (cmpList.length === 0) {
42
- errorLog('删除失败,当前租户暂无任何自定义组件。', spinner);
43
- process.exit(1);
44
- }
45
-
46
- // 获取自定义组件信息
47
- cmpInfo = neoService.getCmpInfoByCmpType(cmpType);
48
- if (!cmpInfo) {
49
- errorLog(`删除失败,当前租户不存在${cmpType}自定义组件。`, spinner);
50
- process.exit(1);
51
- }
52
-
53
- // 调用删除 API
54
- spinner.info(`正在删除${cmpType}自定义组件...`);
55
- await neoService.deleteCmp(cmpType);
56
- successLog(`已成功删除${cmpType}自定义组件!\n`, spinner);
57
- } catch (error) {
58
- errorLog(`删除自定义组件失败: ${error.message}`, spinner);
59
- process.exit(1);
60
- }
61
- };
62
-
63
- module.exports = deleteCmp;
@@ -1,31 +0,0 @@
1
- const fs = require('fs');
2
- const { resolveToCurrentRoot } = require('../pathUtils');
3
-
4
- /**
5
- * 获取组件注册文件内容
6
- * @param {*} cmpsDir 自定义组件目录
7
- * @param {*} cmpName 自定义组件名称
8
- * @returns 组件注册文件内容
9
- */
10
- const getCmpModelRegisterCode = (cmpsDir, cmpName) => {
11
- const cpmModelDir = resolveToCurrentRoot(`${cmpsDir}/${cmpName}/model`);
12
-
13
- /*
14
- if (!fs.existsSync(cpmModelDir)) {
15
- console.error(`未找到 ${cmpName} 组件模型文件,请检查 ${cpmModelDir} 是否存在。`);
16
-
17
- // 退出进程
18
- process.exit(1);
19
- }
20
- */
21
-
22
- return `
23
- // @ts-ignore
24
- import { registerNeoEditorModel } from 'neo-register';
25
- import CustomCmpModel from '${cpmModelDir}';
26
-
27
- registerNeoEditorModel(CustomCmpModel, '${cmpName}');
28
- `;
29
- };
30
-
31
- module.exports = getCmpModelRegisterCode;
@@ -1,43 +0,0 @@
1
- const fs = require('fs');
2
- const { resolveToCurrentRoot } = require('../pathUtils');
3
-
4
- /**
5
- * 获取组件预览代码
6
- * @param {*} cmpsDir 自定义组件目录
7
- * @param {*} cmpName 自定义组件名称
8
- * @returns 组件预览代码
9
- */
10
- const getCmpPreviewCode = (cmpsDir, cmpName) => {
11
- const cpmDir = resolveToCurrentRoot(`${cmpsDir}/${cmpName}`);
12
- const cpmModelDir = resolveToCurrentRoot(`${cmpsDir}/${cmpName}/model`);
13
-
14
- if (!fs.existsSync(cpmDir)) {
15
- console.error(`未找到 ${cmpName} 组件入口文件,请检查 ${cpmDir} 是否存在。`);
16
-
17
- // 退出进程
18
- process.exit(1);
19
- }
20
-
21
- return `
22
- import * as React from 'react';
23
- import ReactDOM from 'react-dom';
24
- import { autoConvertVueComponent } from 'neo-register';
25
- import CustomCmp from '${cpmDir}';
26
- import CustomCmpModel from '${cpmModelDir}';
27
-
28
- // 获取组件模型中的默认属性
29
- const curDefaultComProps = new CustomCmpModel().defaultComProps;
30
- const previewComProps = new CustomCmpModel().previewComProps;
31
- const curPreviewComProps = Object.assign(curDefaultComProps, previewComProps);
32
-
33
- const NewCustomCmp = autoConvertVueComponent(CustomCmp);
34
-
35
- // 预览 自定义组件
36
- ReactDOM.render(
37
- <NewCustomCmp {...curPreviewComProps} />,
38
- document.getElementById('root'),
39
- );
40
- `;
41
- };
42
-
43
- module.exports = getCmpPreviewCode;
@@ -1,31 +0,0 @@
1
- const fs = require('fs');
2
- const { resolveToCurrentRoot } = require('../pathUtils');
3
-
4
- /**
5
- * 获取组件注册文件内容
6
- * @param {*} cmpsDir 自定义组件目录
7
- * @param {*} cmpName 自定义组件名称
8
- * @returns 组件注册文件内容
9
- */
10
- const getCmpRegisterCode = (cmpsDir, cmpName) => {
11
- const cpmIndexDir = resolveToCurrentRoot(`${cmpsDir}/${cmpName}/index`);
12
-
13
- /*
14
- if (!fs.existsSync(cpmIndexDir)) {
15
- console.error(`未找到 ${cmpName} 组件入口文件,请检查 ${cpmIndexDir} 是否存在。`);
16
-
17
- // 退出进程
18
- process.exit(1);
19
- }
20
- */
21
-
22
- return `
23
- // @ts-ignore
24
- import { registerNeoCmp } from 'neo-register';
25
- import CustomCmp from '${cpmIndexDir}';
26
-
27
- registerNeoCmp(CustomCmp, '${cmpName}');
28
- `;
29
- };
30
-
31
- module.exports = getCmpRegisterCode;
@@ -1,41 +0,0 @@
1
- const fs = require('fs');
2
- const path = require('path');
3
- const { resolveToCurrentRoot } = require('../pathUtils');
4
- /**
5
- * 根据当前组件目录,获取所有组件类型
6
- * @param {*} componentsBaseDir 自定义组件目录
7
- * @returns 组件类型列表
8
- */
9
- const getCmpTypeByDir = (componentsBaseDir = './src/components') => {
10
- const componentsDir = resolveToCurrentRoot(componentsBaseDir);
11
- if (!fs.existsSync(componentsDir)) {
12
- console.error(`未找到自定义组件目录,请检查 ${componentsDir} 目录是否存在。`);
13
- // 退出进程
14
- process.exit(1);
15
- }
16
-
17
- try {
18
- // 读取组件目录下的所有子目录
19
- const dirs = fs.readdirSync(componentsDir);
20
- const cmpTypes = [];
21
-
22
- // 遍历所有目录,过滤出有效的组件类型
23
- dirs.forEach((dir) => {
24
- const dirPath = path.join(componentsDir, dir);
25
- const stat = fs.statSync(dirPath);
26
-
27
- // 只处理目录,过滤掉隐藏目录和 node_modules
28
- if (stat.isDirectory() && !dir.startsWith('.') && dir !== 'node_modules') {
29
- cmpTypes.push(dir);
30
- }
31
- });
32
-
33
- return cmpTypes;
34
- } catch (error) {
35
- console.error('获取组件类型失败(getCmpTypeByDir):', error);
36
- // 退出进程
37
- process.exit(1);
38
- }
39
- };
40
-
41
- module.exports = getCmpTypeByDir;
@@ -1,11 +0,0 @@
1
- const getCmpTypeByDir = require('./getCmpTypeByDir');
2
- /**
3
- * 判断当前组件目录是否已经存在该组件类型
4
- * @param {*} componentsBaseDir 自定义组件目录
5
- * @param {*} cmpType 组件类型
6
- * @returns Boolean
7
- */
8
- module.exports = (cmpType) => {
9
- const cmpTypes = getCmpTypeByDir();
10
- return cmpTypes.includes(cmpType);
11
- };
@@ -1,55 +0,0 @@
1
- const fs = require('fs');
2
- const akfun = require('akfun');
3
- const { consoleTag } = require('../neoParams'); // 输出标记
4
- const { resolveToCurrentRoot } = require('../pathUtils');
5
- const getCmpPreviewCode = require('./getCmpPreviewCode'); // 获取自定义组件预览代码
6
-
7
- /**
8
- * 用于预览指定自定义组件的脚本
9
- */
10
- module.exports = (config, cmpName, defaultComponentsDir = './src/components') => {
11
- const cmpsDir = config.componentsDir || defaultComponentsDir;
12
- const curCmpsDir = resolveToCurrentRoot(cmpsDir);
13
-
14
- if (!fs.existsSync(curCmpsDir)) {
15
- console.error(`未找到组件目录,请检查 ${cmpsDir} 目录是否存在`);
16
- process.exit(1);
17
- }
18
-
19
- // 判断当前自定义组件是否存在
20
- const cpmDir = `${curCmpsDir}/${cmpName}`;
21
- if (!fs.existsSync(cpmDir)) {
22
- console.error(`${consoleTag}自定义组件 ${cmpName} 不存在。`);
23
- process.exit(1);
24
- }
25
-
26
- // 创建 cli 的临时目录
27
- const cliTempDir = resolveToCurrentRoot('./.neo-cli');
28
- if (!fs.existsSync(cliTempDir)) {
29
- fs.mkdirSync(cliTempDir);
30
- }
31
-
32
- // 当前自定义组件临时目录
33
- const cmpTempDir = `${cliTempDir}/${cmpName}`;
34
- if (!fs.existsSync(cmpTempDir)) {
35
- fs.mkdirSync(cmpTempDir);
36
- }
37
-
38
- const cmpPreviewContent = getCmpPreviewCode(cmpsDir, cmpName);
39
- fs.writeFileSync(`${cmpTempDir}/preview.jsx`, cmpPreviewContent);
40
-
41
- // 将临时预览文件添加到预览配置中
42
- if (!config.dev.entry) {
43
- config.dev.entry = {};
44
- }
45
- // 添加预览入口文件
46
- config.dev.entry.index = `${cmpTempDir}/preview.jsx`;
47
-
48
- if (config.webpack.projectDir) {
49
- config.webpack.projectDir.push(cmpTempDir);
50
- } else {
51
- config.webpack.projectDir = [cmpTempDir];
52
- }
53
-
54
- akfun.dev(config, consoleTag);
55
- };
@@ -1,104 +0,0 @@
1
- const _ = require('lodash');
2
- const { getConfigObj } = require('akfun');
3
- const { catchCurPackageJson } = require('../pathUtils');
4
- const ora = require('ora');
5
- const NeoService = require('../../neo/neoService');
6
- const { getFramework, errorLog, successLog } = require('../common');
7
- const getCmpTypeByDir = require('./getCmpTypeByDir.js');
8
- const createCmpByZip = require('./createCmpByZip.js');
9
-
10
- // 获取当前项目的package文件
11
- const currentPackageJsonDir = catchCurPackageJson();
12
- const currentPackageJson = getConfigObj(currentPackageJsonDir);
13
- const framework = getFramework(currentPackageJson.framework);
14
-
15
- /**
16
- * 从 NeoCRM 拉取自定义组件
17
- * @param {string} cmpType 自定义组件类型
18
- * @param {object} authConfig 授权配置
19
- *
20
- * 拉取流程说明
21
- * 1. 获取当前租户下的自定义组件列表
22
- * 2. 验证组件是否存在、是否已存在本地、技术栈是否一致
23
- * 3. 下载组件源码 zip 包到临时目录(`.neo-cli/zip-source`)
24
- * 4. 解压并解析组件源码到 `src/components` 目录
25
- * 5. 合并 `package.json` 中的依赖配置(如有新增依赖会提示安装)
26
- * 6. 清理解压目录,保留 zip 源文件(便于后续问题排查)
27
- */
28
- const pullCmp = async (cmpType, authConfig, _neoService) => {
29
- if (!authConfig) {
30
- errorLog('未找到 NeoCRM 平台授权配置(neo.config.js / authConfig)。');
31
- return;
32
- }
33
-
34
- const cmpTypes = getCmpTypeByDir(); // 获取当前项目目录中已存在的自定义组件类型
35
- if (cmpTypes.indexOf(cmpType) > -1) {
36
- errorLog(`当前项目目录中已存在${cmpType}自定义组件。(./src/components 目录下)`);
37
- process.exit(1);
38
- }
39
-
40
- const spinner = ora('正在拉取组件...').start();
41
-
42
- try {
43
- let neoService = _neoService;
44
- let cmpList = [],
45
- cmpInfoMap = {};
46
- let cmpInfo = null;
47
-
48
- if (_neoService) {
49
- // 使用传入的 neoService 实例
50
- cmpList = _neoService.cmpList || [];
51
- cmpInfoMap = _neoService.cmpInfoMap || {};
52
- } else {
53
- // 创建新的 neoService 实例
54
- neoService = new NeoService(authConfig);
55
-
56
- // 获取自定义组件列表
57
- spinner.info('正在获取自定义组件列表...');
58
- cmpList = await neoService.getCustomCmpList();
59
- cmpInfoMap = neoService.cmpInfoMap || {};
60
- }
61
-
62
- if (cmpList.length === 0) {
63
- errorLog('拉取失败,当前租户暂无任何自定义组件。', spinner);
64
- process.exit(1);
65
- }
66
-
67
- // 获取自定义组件信息
68
- cmpInfo = neoService.getCmpInfoByCmpType(cmpType);
69
- if (!cmpInfo) {
70
- errorLog(`拉取失败,当前租户不存在${cmpType}自定义组件。`, spinner);
71
- process.exit(1);
72
- }
73
-
74
- // 判断拉取的组件和当前项目是否为同一技术栈
75
- if (cmpInfo.framework && cmpInfo.framework !== framework) {
76
- errorLog(`拉取失败,${cmpType}自定义组件与当前项目技术栈不一致。`, spinner);
77
- process.exit(1);
78
- }
79
-
80
- // 下载源码文件并解析到 src/components 目录下
81
- const codeLib = neoService.getCodeLibByCmpType(cmpType); // 源码文件地址(zip包地址)
82
-
83
- // 确保 token 有效
84
- const token = await neoService.ensureValidToken();
85
-
86
- // 将zip 包里面的自定义组件源码解析到 src/components 目录下
87
- const cmpResult = await createCmpByZip(codeLib, {
88
- token,
89
- cmpName: cmpType,
90
- componentBaseDir: './src/components'
91
- });
92
- if (!cmpResult) {
93
- errorLog(`拉取失败,${cmpType}自定义组件源码解析失败,请检查源码文件是否正确。`, spinner);
94
- process.exit(1);
95
- }
96
-
97
- successLog(`已成功拉取${cmpType}自定义组件!\n`, spinner);
98
- } catch (error) {
99
- errorLog(`拉取自定义组件失败: ${error.message}`, spinner);
100
- throw error;
101
- }
102
- };
103
-
104
- module.exports = pullCmp;