neo-cmp-cli 1.8.7 → 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 (124) 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/src/config/auth.config.js +0 -27
  76. package/src/config/default.config.js +0 -176
  77. package/src/config/index.js +0 -9
  78. package/src/initData/defaultTemplate.html +0 -13
  79. package/src/initData/neo.config.js +0 -138
  80. package/src/main.js +0 -221
  81. package/src/module/inspect.js +0 -41
  82. package/src/module/neoInit.js +0 -55
  83. package/src/module/neoInitByCopy.js +0 -61
  84. package/src/neo/NeoUMDContent.js +0 -30
  85. package/src/neo/neoLogin.js +0 -565
  86. package/src/neo/neoRequire.js +0 -125
  87. package/src/neo/neoService.js +0 -874
  88. package/src/neo/webpack.mf.js +0 -60
  89. package/src/neo/wrapperContent.js +0 -16
  90. package/src/oss/publish2oss.js +0 -348
  91. package/src/plugins/AddNeoRequirePlugin-v1.js +0 -47
  92. package/src/plugins/AddNeoRequirePlugin.js +0 -179
  93. package/src/plugins/README.md +0 -109
  94. package/src/utils/autoEntryRootDir.js +0 -85
  95. package/src/utils/cmpUtils/createCmpByTemplate.js +0 -60
  96. package/src/utils/cmpUtils/createCmpByZip.js +0 -408
  97. package/src/utils/cmpUtils/createCommonModulesCode.js +0 -121
  98. package/src/utils/cmpUtils/deleteCmp.js +0 -63
  99. package/src/utils/cmpUtils/getCmpModelRegisterCode.js +0 -31
  100. package/src/utils/cmpUtils/getCmpPreviewCode.js +0 -43
  101. package/src/utils/cmpUtils/getCmpRegisterCode.js +0 -31
  102. package/src/utils/cmpUtils/getCmpTypeByDir.js +0 -41
  103. package/src/utils/cmpUtils/hasCmpTypeByDir.js +0 -11
  104. package/src/utils/cmpUtils/previewCmp.js +0 -55
  105. package/src/utils/cmpUtils/pullCmp.js +0 -104
  106. package/src/utils/cmpUtils/pushCmp.js +0 -230
  107. package/src/utils/common.js +0 -107
  108. package/src/utils/configureNeoBuild.js +0 -109
  109. package/src/utils/generateEntries.js +0 -63
  110. package/src/utils/neoConfigInit.js +0 -13
  111. package/src/utils/neoParams.js +0 -12
  112. package/src/utils/pathUtils.js +0 -23
  113. package/src/utils/projectNameValidator.js +0 -76
  114. package/src/utils/projectUtils/createCmpProjectByTemplate.js +0 -59
  115. package/src/utils/projectUtils/createCmpProjectZip.js +0 -120
  116. package/src/utils/projectUtils/getEntries.js +0 -80
  117. package/src/utils/projectUtils/getEntriesWithAutoRegister.js +0 -108
  118. package/src/utils/projectUtils/hasNeoProject.js +0 -17
  119. package/src/utils/projectUtils/openProject.js +0 -96
  120. package/src/utils/projectUtils/updatePublishLog.js +0 -30
  121. package/src/utils/replaceInFiles.js +0 -47
  122. package/src/utils/replaceInFilesByMap.js +0 -54
  123. package/src/utils/replaceInPackage.js +0 -134
  124. package/src/utils/resetPackageVersion.js +0 -115
@@ -0,0 +1,47 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
4
+
5
+ require('node:fs');
6
+ const pathUtils = require('../pathUtils.js');
7
+
8
+ var getCmpModelRegisterCode_1;
9
+ var hasRequiredGetCmpModelRegisterCode;
10
+
11
+ function requireGetCmpModelRegisterCode () {
12
+ if (hasRequiredGetCmpModelRegisterCode) return getCmpModelRegisterCode_1;
13
+ hasRequiredGetCmpModelRegisterCode = 1;
14
+ const { resolveToCurrentRoot } = pathUtils.__require();
15
+
16
+ /**
17
+ * 获取组件注册文件内容
18
+ * @param {*} cmpsDir 自定义组件目录
19
+ * @param {*} cmpName 自定义组件名称
20
+ * @returns 组件注册文件内容
21
+ */
22
+ const getCmpModelRegisterCode = (cmpsDir, cmpName) => {
23
+ const cpmModelDir = resolveToCurrentRoot(`${cmpsDir}/${cmpName}/model`);
24
+
25
+ /*
26
+ if (!fs.existsSync(cpmModelDir)) {
27
+ console.error(`未找到 ${cmpName} 组件模型文件,请检查 ${cpmModelDir} 是否存在。`);
28
+
29
+ // 退出进程
30
+ process.exit(1);
31
+ }
32
+ */
33
+
34
+ return `
35
+ // @ts-ignore
36
+ import { registerNeoEditorModel } from 'neo-register';
37
+ import CustomCmpModel from '${cpmModelDir}';
38
+
39
+ registerNeoEditorModel(CustomCmpModel, '${cmpName}');
40
+ `;
41
+ };
42
+
43
+ getCmpModelRegisterCode_1 = getCmpModelRegisterCode;
44
+ return getCmpModelRegisterCode_1;
45
+ }
46
+
47
+ exports.__require = requireGetCmpModelRegisterCode;
@@ -0,0 +1,60 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
4
+
5
+ const require$$0 = require('node:fs');
6
+ const pathUtils = require('../pathUtils.js');
7
+
8
+ var getCmpPreviewCode_1;
9
+ var hasRequiredGetCmpPreviewCode;
10
+
11
+ function requireGetCmpPreviewCode () {
12
+ if (hasRequiredGetCmpPreviewCode) return getCmpPreviewCode_1;
13
+ hasRequiredGetCmpPreviewCode = 1;
14
+ const fs = require$$0;
15
+ const { resolveToCurrentRoot } = pathUtils.__require();
16
+
17
+ /**
18
+ * 获取组件预览代码
19
+ * @param {*} cmpsDir 自定义组件目录
20
+ * @param {*} cmpName 自定义组件名称
21
+ * @returns 组件预览代码
22
+ */
23
+ const getCmpPreviewCode = (cmpsDir, cmpName) => {
24
+ const cpmDir = resolveToCurrentRoot(`${cmpsDir}/${cmpName}`);
25
+ const cpmModelDir = resolveToCurrentRoot(`${cmpsDir}/${cmpName}/model`);
26
+
27
+ if (!fs.existsSync(cpmDir)) {
28
+ console.error(`未找到 ${cmpName} 组件入口文件,请检查 ${cpmDir} 是否存在。`);
29
+
30
+ // 退出进程
31
+ process.exit(1);
32
+ }
33
+
34
+ return `
35
+ import * as React from 'react';
36
+ import ReactDOM from 'react-dom';
37
+ import { autoConvertVueComponent } from 'neo-register';
38
+ import CustomCmp from '${cpmDir}';
39
+ import CustomCmpModel from '${cpmModelDir}';
40
+
41
+ // 获取组件模型中的默认属性
42
+ const curDefaultComProps = new CustomCmpModel().defaultComProps;
43
+ const previewComProps = new CustomCmpModel().previewComProps;
44
+ const curPreviewComProps = Object.assign(curDefaultComProps, previewComProps);
45
+
46
+ const NewCustomCmp = autoConvertVueComponent(CustomCmp);
47
+
48
+ // 预览 自定义组件
49
+ ReactDOM.render(
50
+ <NewCustomCmp {...curPreviewComProps} />,
51
+ document.getElementById('root'),
52
+ );
53
+ `;
54
+ };
55
+
56
+ getCmpPreviewCode_1 = getCmpPreviewCode;
57
+ return getCmpPreviewCode_1;
58
+ }
59
+
60
+ exports.__require = requireGetCmpPreviewCode;
@@ -0,0 +1,47 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
4
+
5
+ require('node:fs');
6
+ const pathUtils = require('../pathUtils.js');
7
+
8
+ var getCmpRegisterCode_1;
9
+ var hasRequiredGetCmpRegisterCode;
10
+
11
+ function requireGetCmpRegisterCode () {
12
+ if (hasRequiredGetCmpRegisterCode) return getCmpRegisterCode_1;
13
+ hasRequiredGetCmpRegisterCode = 1;
14
+ const { resolveToCurrentRoot } = pathUtils.__require();
15
+
16
+ /**
17
+ * 获取组件注册文件内容
18
+ * @param {*} cmpsDir 自定义组件目录
19
+ * @param {*} cmpName 自定义组件名称
20
+ * @returns 组件注册文件内容
21
+ */
22
+ const getCmpRegisterCode = (cmpsDir, cmpName) => {
23
+ const cpmIndexDir = resolveToCurrentRoot(`${cmpsDir}/${cmpName}/index`);
24
+
25
+ /*
26
+ if (!fs.existsSync(cpmIndexDir)) {
27
+ console.error(`未找到 ${cmpName} 组件入口文件,请检查 ${cpmIndexDir} 是否存在。`);
28
+
29
+ // 退出进程
30
+ process.exit(1);
31
+ }
32
+ */
33
+
34
+ return `
35
+ // @ts-ignore
36
+ import { registerNeoCmp } from 'neo-register';
37
+ import CustomCmp from '${cpmIndexDir}';
38
+
39
+ registerNeoCmp(CustomCmp, '${cmpName}');
40
+ `;
41
+ };
42
+
43
+ getCmpRegisterCode_1 = getCmpRegisterCode;
44
+ return getCmpRegisterCode_1;
45
+ }
46
+
47
+ exports.__require = requireGetCmpRegisterCode;
@@ -0,0 +1,59 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
4
+
5
+ const require$$0 = require('node:fs');
6
+ const require$$1 = require('node:path');
7
+ const pathUtils = require('../pathUtils.js');
8
+
9
+ var getCmpTypeByDir_1;
10
+ var hasRequiredGetCmpTypeByDir;
11
+
12
+ function requireGetCmpTypeByDir () {
13
+ if (hasRequiredGetCmpTypeByDir) return getCmpTypeByDir_1;
14
+ hasRequiredGetCmpTypeByDir = 1;
15
+ const fs = require$$0;
16
+ const path = require$$1;
17
+ const { resolveToCurrentRoot } = pathUtils.__require();
18
+ /**
19
+ * 根据当前组件目录,获取所有组件类型
20
+ * @param {*} componentsBaseDir 自定义组件目录
21
+ * @returns 组件类型列表
22
+ */
23
+ const getCmpTypeByDir = (componentsBaseDir = './src/components') => {
24
+ const componentsDir = resolveToCurrentRoot(componentsBaseDir);
25
+ if (!fs.existsSync(componentsDir)) {
26
+ console.error(`未找到自定义组件目录,请检查 ${componentsDir} 目录是否存在。`);
27
+ // 退出进程
28
+ process.exit(1);
29
+ }
30
+
31
+ try {
32
+ // 读取组件目录下的所有子目录
33
+ const dirs = fs.readdirSync(componentsDir);
34
+ const cmpTypes = [];
35
+
36
+ // 遍历所有目录,过滤出有效的组件类型
37
+ dirs.forEach((dir) => {
38
+ const dirPath = path.join(componentsDir, dir);
39
+ const stat = fs.statSync(dirPath);
40
+
41
+ // 只处理目录,过滤掉隐藏目录和 node_modules
42
+ if (stat.isDirectory() && !dir.startsWith('.') && dir !== 'node_modules') {
43
+ cmpTypes.push(dir);
44
+ }
45
+ });
46
+
47
+ return cmpTypes;
48
+ } catch (error) {
49
+ console.error('获取组件类型失败(getCmpTypeByDir):', error);
50
+ // 退出进程
51
+ process.exit(1);
52
+ }
53
+ };
54
+
55
+ getCmpTypeByDir_1 = getCmpTypeByDir;
56
+ return getCmpTypeByDir_1;
57
+ }
58
+
59
+ exports.__require = requireGetCmpTypeByDir;
@@ -0,0 +1,27 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
4
+
5
+ const getCmpTypeByDir = require('./getCmpTypeByDir.js');
6
+
7
+ var hasCmpTypeByDir;
8
+ var hasRequiredHasCmpTypeByDir;
9
+
10
+ function requireHasCmpTypeByDir () {
11
+ if (hasRequiredHasCmpTypeByDir) return hasCmpTypeByDir;
12
+ hasRequiredHasCmpTypeByDir = 1;
13
+ const getCmpTypeByDir$1 = getCmpTypeByDir.__require();
14
+ /**
15
+ * 判断当前组件目录是否已经存在该组件类型
16
+ * @param {*} componentsBaseDir 自定义组件目录
17
+ * @param {*} cmpType 组件类型
18
+ * @returns Boolean
19
+ */
20
+ hasCmpTypeByDir = (cmpType) => {
21
+ const cmpTypes = getCmpTypeByDir$1();
22
+ return cmpTypes.includes(cmpType);
23
+ };
24
+ return hasCmpTypeByDir;
25
+ }
26
+
27
+ exports.__require = requireHasCmpTypeByDir;
@@ -0,0 +1,75 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
4
+
5
+ const require$$0 = require('node:fs');
6
+ const require$$0$1 = require('akfun');
7
+ const neoParams = require('../neoParams.js');
8
+ const pathUtils = require('../pathUtils.js');
9
+ const getCmpPreviewCode = require('./getCmpPreviewCode.js');
10
+
11
+ var previewCmp;
12
+ var hasRequiredPreviewCmp;
13
+
14
+ function requirePreviewCmp () {
15
+ if (hasRequiredPreviewCmp) return previewCmp;
16
+ hasRequiredPreviewCmp = 1;
17
+ const fs = require$$0;
18
+ const akfun = require$$0$1;
19
+ const { consoleTag } = neoParams.__require(); // 输出标记
20
+ const { resolveToCurrentRoot } = pathUtils.__require();
21
+ const getCmpPreviewCode$1 = getCmpPreviewCode.__require(); // 获取自定义组件预览代码
22
+
23
+ /**
24
+ * 用于预览指定自定义组件的脚本
25
+ */
26
+ previewCmp = (config, cmpName, defaultComponentsDir = './src/components') => {
27
+ const cmpsDir = config.componentsDir || defaultComponentsDir;
28
+ const curCmpsDir = resolveToCurrentRoot(cmpsDir);
29
+
30
+ if (!fs.existsSync(curCmpsDir)) {
31
+ console.error(`未找到组件目录,请检查 ${cmpsDir} 目录是否存在`);
32
+ process.exit(1);
33
+ }
34
+
35
+ // 判断当前自定义组件是否存在
36
+ const cpmDir = `${curCmpsDir}/${cmpName}`;
37
+ if (!fs.existsSync(cpmDir)) {
38
+ console.error(`${consoleTag}自定义组件 ${cmpName} 不存在。`);
39
+ process.exit(1);
40
+ }
41
+
42
+ // 创建 cli 的临时目录
43
+ const cliTempDir = resolveToCurrentRoot('./.neo-cli');
44
+ if (!fs.existsSync(cliTempDir)) {
45
+ fs.mkdirSync(cliTempDir);
46
+ }
47
+
48
+ // 当前自定义组件临时目录
49
+ const cmpTempDir = `${cliTempDir}/${cmpName}`;
50
+ if (!fs.existsSync(cmpTempDir)) {
51
+ fs.mkdirSync(cmpTempDir);
52
+ }
53
+
54
+ const cmpPreviewContent = getCmpPreviewCode$1(cmpsDir, cmpName);
55
+ fs.writeFileSync(`${cmpTempDir}/preview.jsx`, cmpPreviewContent);
56
+
57
+ // 将临时预览文件添加到预览配置中
58
+ if (!config.dev.entry) {
59
+ config.dev.entry = {};
60
+ }
61
+ // 添加预览入口文件
62
+ config.dev.entry.index = `${cmpTempDir}/preview.jsx`;
63
+
64
+ if (config.webpack.projectDir) {
65
+ config.webpack.projectDir.push(cmpTempDir);
66
+ } else {
67
+ config.webpack.projectDir = [cmpTempDir];
68
+ }
69
+
70
+ akfun.dev(config, consoleTag);
71
+ };
72
+ return previewCmp;
73
+ }
74
+
75
+ exports.__require = requirePreviewCmp;
@@ -0,0 +1,126 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
4
+
5
+ require('lodash');
6
+ const require$$0 = require('akfun');
7
+ const pathUtils = require('../pathUtils.js');
8
+ const require$$3 = require('ora');
9
+ const neoService = require('../../neo/neoService.js');
10
+ const common = require('../common.js');
11
+ const getCmpTypeByDir = require('./getCmpTypeByDir.js');
12
+ const createCmpByZip = require('./createCmpByZip.js');
13
+
14
+ var pullCmp_1;
15
+ var hasRequiredPullCmp;
16
+
17
+ function requirePullCmp () {
18
+ if (hasRequiredPullCmp) return pullCmp_1;
19
+ hasRequiredPullCmp = 1;
20
+ const { getConfigObj } = require$$0;
21
+ const { catchCurPackageJson } = pathUtils.__require();
22
+ const ora = require$$3;
23
+ const NeoService = neoService.__require();
24
+ const { getFramework, errorLog, successLog } = common.__require();
25
+ const getCmpTypeByDir$1 = getCmpTypeByDir.__require();
26
+ const createCmpByZip$1 = createCmpByZip.__require();
27
+
28
+ // 获取当前项目的package文件
29
+ const currentPackageJsonDir = catchCurPackageJson();
30
+ const currentPackageJson = getConfigObj(currentPackageJsonDir);
31
+ const framework = getFramework(currentPackageJson.framework);
32
+
33
+ /**
34
+ * 从 NeoCRM 拉取自定义组件
35
+ * @param {string} cmpType 自定义组件类型
36
+ * @param {object} authConfig 授权配置
37
+ *
38
+ * 拉取流程说明
39
+ * 1. 获取当前租户下的自定义组件列表
40
+ * 2. 验证组件是否存在、是否已存在本地、技术栈是否一致
41
+ * 3. 下载组件源码 zip 包到临时目录(`.neo-cli/zip-source`)
42
+ * 4. 解压并解析组件源码到 `src/components` 目录
43
+ * 5. 合并 `package.json` 中的依赖配置(如有新增依赖会提示安装)
44
+ * 6. 清理解压目录,保留 zip 源文件(便于后续问题排查)
45
+ */
46
+ const pullCmp = async (cmpType, authConfig, _neoService) => {
47
+ if (!authConfig) {
48
+ errorLog('未找到 NeoCRM 平台授权配置(neo.config.js / authConfig)。');
49
+ return;
50
+ }
51
+
52
+ const cmpTypes = getCmpTypeByDir$1(); // 获取当前项目目录中已存在的自定义组件类型
53
+ if (cmpTypes.indexOf(cmpType) > -1) {
54
+ errorLog(`当前项目目录中已存在${cmpType}自定义组件。(./src/components 目录下)`);
55
+ process.exit(1);
56
+ }
57
+
58
+ const spinner = ora('正在拉取组件...').start();
59
+
60
+ try {
61
+ let neoService = _neoService;
62
+ let cmpList = [],
63
+ cmpInfoMap = {};
64
+ let cmpInfo = null;
65
+
66
+ if (_neoService) {
67
+ // 使用传入的 neoService 实例
68
+ cmpList = _neoService.cmpList || [];
69
+ cmpInfoMap = _neoService.cmpInfoMap || {};
70
+ } else {
71
+ // 创建新的 neoService 实例
72
+ neoService = new NeoService(authConfig);
73
+
74
+ // 获取自定义组件列表
75
+ spinner.info('正在获取自定义组件列表...');
76
+ cmpList = await neoService.getCustomCmpList();
77
+ cmpInfoMap = neoService.cmpInfoMap || {};
78
+ }
79
+
80
+ if (cmpList.length === 0) {
81
+ errorLog('拉取失败,当前租户暂无任何自定义组件。', spinner);
82
+ process.exit(1);
83
+ }
84
+
85
+ // 获取自定义组件信息
86
+ cmpInfo = neoService.getCmpInfoByCmpType(cmpType);
87
+ if (!cmpInfo) {
88
+ errorLog(`拉取失败,当前租户不存在${cmpType}自定义组件。`, spinner);
89
+ process.exit(1);
90
+ }
91
+
92
+ // 判断拉取的组件和当前项目是否为同一技术栈
93
+ if (cmpInfo.framework && cmpInfo.framework !== framework) {
94
+ errorLog(`拉取失败,${cmpType}自定义组件与当前项目技术栈不一致。`, spinner);
95
+ process.exit(1);
96
+ }
97
+
98
+ // 下载源码文件并解析到 src/components 目录下
99
+ const codeLib = neoService.getCodeLibByCmpType(cmpType); // 源码文件地址(zip包地址)
100
+
101
+ // 确保 token 有效
102
+ const token = await neoService.ensureValidToken();
103
+
104
+ // 将zip 包里面的自定义组件源码解析到 src/components 目录下
105
+ const cmpResult = await createCmpByZip$1(codeLib, {
106
+ token,
107
+ cmpName: cmpType,
108
+ componentBaseDir: './src/components'
109
+ });
110
+ if (!cmpResult) {
111
+ errorLog(`拉取失败,${cmpType}自定义组件源码解析失败,请检查源码文件是否正确。`, spinner);
112
+ process.exit(1);
113
+ }
114
+
115
+ successLog(`已成功拉取${cmpType}自定义组件!\n`, spinner);
116
+ } catch (error) {
117
+ errorLog(`拉取自定义组件失败: ${error.message}`, spinner);
118
+ throw error;
119
+ }
120
+ };
121
+
122
+ pullCmp_1 = pullCmp;
123
+ return pullCmp_1;
124
+ }
125
+
126
+ exports.__require = requirePullCmp;
@@ -0,0 +1,254 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
4
+
5
+ const require$$0$1 = require('node:fs');
6
+ const require$$1 = require('node:path');
7
+ const require$$2 = require('lodash');
8
+ const require$$0 = require('akfun');
9
+ const pathUtils = require('../pathUtils.js');
10
+ const require$$3 = require('ora');
11
+ const neoService = require('../../neo/neoService.js');
12
+ const common = require('../common.js');
13
+ const createCmpProjectZip = require('../projectUtils/createCmpProjectZip.js');
14
+
15
+ var pushCmp_1;
16
+ var hasRequiredPushCmp;
17
+
18
+ function requirePushCmp () {
19
+ if (hasRequiredPushCmp) return pushCmp_1;
20
+ hasRequiredPushCmp = 1;
21
+ const fs = require$$0$1;
22
+ const path = require$$1;
23
+ const _ = require$$2;
24
+ const { getConfigObj } = require$$0;
25
+ const { catchCurPackageJson } = pathUtils.__require();
26
+ const ora = require$$3;
27
+ const NeoService = neoService.__require();
28
+ const { getFramework, errorLog, successLog } = common.__require();
29
+ const createCmpProjectZip$1 = createCmpProjectZip.__require();
30
+
31
+ // 获取当前项目的package文件
32
+ const currentPackageJsonDir = catchCurPackageJson();
33
+ const currentPackageJson = getConfigObj(currentPackageJsonDir);
34
+
35
+ // 获取属性 propsSchema 数据结构
36
+ const getPropsSchema = (propsSchema = []) => {
37
+ return propsSchema.map((item) => {
38
+ return {
39
+ label: item.label,
40
+ description: item.description,
41
+ propSchema: JSON.stringify(item)
42
+ };
43
+ });
44
+ };
45
+
46
+ /**
47
+ * 构建组件数据映射
48
+ * @param {string} assetsRoot 构建产物的目录
49
+ * @param {object} cmpInfo 自定义组件信息
50
+ * @returns {Promise<object|null>} 自定义组件数据(含自定义组件模型信息)
51
+ */
52
+ const buildComponentData = async (assetsRoot, cmpInfo) => {
53
+ if (!cmpInfo || !cmpInfo.cmpType) {
54
+ errorLog('自定义组件信息或组件名称不能为空');
55
+ return null;
56
+ }
57
+
58
+ const { cmpType } = cmpInfo;
59
+
60
+ if (!assetsRoot || !fs.existsSync(assetsRoot)) {
61
+ errorLog(`未找到自定义组件目录: ${assetsRoot}`);
62
+ return null;
63
+ }
64
+ const widgetName = _.camelCase(cmpType);
65
+ const modelFile = path.join(assetsRoot, `${widgetName}Model.js`);
66
+
67
+ // 为 Node.js 环境设置全局 window 对象(模型文件可能需要)
68
+ // 使用 globalThis 以确保在 Node.js 和浏览器环境中都能工作
69
+ const originalWindow = globalThis.window;
70
+ if (!globalThis.window) {
71
+ globalThis.window = {
72
+ console: console,
73
+ neoRequire: () => {},
74
+ postMessage: () => {}
75
+ // 可以添加其他常用的 window 属性
76
+ };
77
+ }
78
+
79
+ try {
80
+ // 加载自定义组件模型资源文件
81
+ if (fs.existsSync(modelFile)) {
82
+ // 加载自定义组件模型资源文件
83
+ let modelModule = require(modelFile);
84
+ // 获取导出的模型类(可能是 default 导出或命名导出)
85
+ // const CatchCustomCmpModelClass = modelModule.default || modelModule;
86
+ } else {
87
+ errorLog(`未找到自定义组件模型文件,请检查以下路径是否存在:${modelFile}`);
88
+ process.exit(1);
89
+ }
90
+ if (!globalThis.window || !globalThis.window.NEOEditorCustomModels) {
91
+ errorLog(
92
+ `模型文件未导出有效模型方法(CatchCustomCmpModelClass),模型文件地址: ${modelFile} `
93
+ );
94
+ process.exit(1);
95
+ }
96
+
97
+ const ModelClass = globalThis.window.NEOEditorCustomModels[cmpType];
98
+ if (!ModelClass) {
99
+ errorLog(`未找到自定义组件模型类(${cmpType}),模型文件地址: ${modelFile} `);
100
+ process.exit(1);
101
+ }
102
+ // 实例化模型类
103
+ const modelInstance = new ModelClass();
104
+
105
+ if (!modelInstance) {
106
+ errorLog(`未找到自定义组件模型信息(${cmpType}),模型文件地址: ${modelFile} `);
107
+ process.exit(1);
108
+ }
109
+
110
+ // 构建组件数据,合并模型实例的信息
111
+ const curCmpInfo = {
112
+ ...cmpInfo,
113
+ version: currentPackageJson.version || '1.0.0',
114
+ // 技术栈标识: 从 package.json / framework 字段获取,没有则默认 为 react ts 技术栈
115
+ framework: currentPackageJson.framework ? getFramework(currentPackageJson.framework) : 0, // 0: React, 1: vue2, 2: jQuery, 3: vue3
116
+ // 从模型实例中提取并设置组件信息
117
+ label: modelInstance.label || cmpType,
118
+ description: modelInstance.description || '',
119
+ componentCategory: (modelInstance.tags || ['自定义组件']).join(','),
120
+ targetPage: modelInstance.targetPage || ['customPage'], // 支持的页面类型
121
+ targetObject: modelInstance.targetObject || ['all'], // 支持的实体类型
122
+ targetApplication: modelInstance.targetApplication || ['all'], // 支持的应用类型
123
+ targetDevice: modelInstance.targetDevice || 'all', // 支持的设备类型。只有这个字段是字符串数值,其他都是数组
124
+ iconUrl: modelInstance.iconSrc || modelInstance.iconUrl,
125
+ defaultProps: JSON.stringify(modelInstance.defaultComProps || {}),
126
+ previewProps: JSON.stringify(modelInstance.previewComProps || {}),
127
+ props: getPropsSchema(modelInstance.propsSchema || []),
128
+ events: modelInstance.events || [],
129
+ functions: modelInstance.functions || modelInstance.actions || [],
130
+ // 如果模型实例中有其他属性,也可以添加
131
+ exposedToDesigner:
132
+ modelInstance.exposedToDesigner !== undefined ? modelInstance.exposedToDesigner : true,
133
+ namespace: modelInstance.namespace || 'neo-cmp-cli',
134
+ enableDuplicate:
135
+ modelInstance.enableDuplicate !== undefined ? modelInstance.enableDuplicate : true
136
+ };
137
+
138
+ console.log(
139
+ `自定义组件模型信息(${cmpType}):`,
140
+ _.omit(curCmpInfo, ['assetFile', 'modelAssetFile', 'cssAssetFile', 'codeLibFile'])
141
+ );
142
+ return curCmpInfo;
143
+ } catch (error) {
144
+ errorLog(`自定义组件模型文件解析失败 (${modelFile || '未知路径'}): ${error.message}`);
145
+ errorLog(error.stack);
146
+ return null;
147
+ } finally {
148
+ // 恢复原始的 window 对象(如果之前存在)
149
+ if (originalWindow === undefined) {
150
+ delete globalThis.window;
151
+ } else {
152
+ globalThis.window = originalWindow;
153
+ }
154
+ }
155
+ };
156
+
157
+ /**
158
+ * 发布组件到 NeoCRM
159
+ * @param {object} config 配置信息
160
+ * @param {string} cmpType 自定义组件类型
161
+ *
162
+ * 发布流程说明
163
+ * 1. 打包源码文件:将自定义组件源码打包成 zip 文件
164
+ * 2. 上传构建产物到 OSS:将构建后的资源文件上传到 NeoCRM 平台提供的 CDN
165
+ * 3. 构建组件数据:从组件模型文件中提取组件信息
166
+ * 4. 保存组件信息到 NeoCRM 平台:将组件信息保存到平台数据库
167
+ */
168
+ const pushCmp = async (config, cmpType) => {
169
+ const spinner = ora('正在发布组件...').start();
170
+
171
+ try {
172
+ // 步骤 1: 初始化 NeoService
173
+ let neoService = new NeoService(config);
174
+ // 获取 token
175
+ await neoService.ensureValidToken();
176
+
177
+ // 步骤 2: 打包源码文件(打包单个自定义组件源码)
178
+ spinner.start(`[1/4] 打包源码文件(含单个自定义组件源码)...`);
179
+ let zipPath;
180
+ try {
181
+ zipPath = createCmpProjectZip$1(cmpType, process.cwd(), config.assetsRoot);
182
+ if (!zipPath) {
183
+ errorLog('[1/4] 源码文件打包失败,未返回 zip 文件路径。', spinner);
184
+ } else {
185
+ successLog(`[1/4] 源码文件打包完成: ${path.basename(zipPath)}。`, spinner);
186
+ }
187
+ } catch (error) {
188
+ errorLog(`[1/4] 源码文件打包失败。`, spinner);
189
+ }
190
+
191
+ /*
192
+ // 步骤 3: 上传构建后资源文件(改放在保存时直接上传组件资源文件)
193
+ spinner.start(`[2/4] 上传自定义组件构建产物到 OSS...`);
194
+ let cmpInfo;
195
+ try {
196
+ cmpInfo = await neoService.publish2oss(cmpType);
197
+ if (!cmpInfo || !cmpInfo.cmpType) {
198
+ errorLog('[2/4] 上传构建产物失败,未获取到组件信息。', spinner);
199
+ } else {
200
+ successLog(`[2/4] 构建产物上传完成。`, spinner);
201
+ }
202
+ } catch (error) {
203
+ errorLog(`[2/4] 构建产物上传失败。`, spinner);
204
+ }
205
+ */
206
+ spinner.start(`[2/4] 获取自定义组件构建产物...`);
207
+ const cmpInfo = await neoService.getCmpAssets(cmpType);
208
+
209
+ // 步骤 4: 构建组件数据
210
+ spinner.start(`[3/4] 构建组件数据...`);
211
+ let componentInfo;
212
+ try {
213
+ componentInfo = await buildComponentData(config.assetsRoot, cmpInfo);
214
+ if (!componentInfo) {
215
+ errorLog(`[3/4] 未获取到自定义组件模型信息(${cmpType})。`, spinner);
216
+ } else {
217
+ successLog(`[3/4] 组件数据构建完成。`, spinner);
218
+ }
219
+ } catch (error) {
220
+ errorLog(`[3/4] 组件数据构建失败: ${error.message}`, spinner);
221
+ }
222
+
223
+ // 步骤 5: 保存组件信息
224
+ spinner.start(`[4/4] 保存组件信息到 NeoCRM 平台...`);
225
+ try {
226
+ await neoService.updateCustomComponent(componentInfo);
227
+ successLog(`[4/4] 组件信息保存成功`, spinner);
228
+ } catch (error) {
229
+ errorLog(`[4/4] 组件信息保存失败`, spinner);
230
+ }
231
+
232
+ // 最终成功提示
233
+ console.log('\n✅ 自定义组件发布成功!');
234
+ } catch (error) {
235
+ // 内层 catch 已经处理了步骤错误并显示了 spinner 失败状态
236
+ // 这里处理未预期的错误(如果 spinner 还在运行)
237
+ try {
238
+ // ora 的 spinner 对象可能没有 isSpinning 属性,使用 try-catch 安全访问
239
+ if (spinner && spinner.isSpinning) {
240
+ errorLog(`❌ 自定义组件发布失败: ${error.message}`, spinner);
241
+ }
242
+ } catch {
243
+ // 如果访问失败或 spinner 已停止,直接输出错误信息
244
+ errorLog(`\n❌ 自定义组件发布失败: ${error.message}`);
245
+ }
246
+ throw error;
247
+ }
248
+ };
249
+
250
+ pushCmp_1 = pushCmp;
251
+ return pushCmp_1;
252
+ }
253
+
254
+ exports.__require = requirePushCmp;