neo-cmp-cli 1.8.6-beta.6 → 1.8.7

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 (158) hide show
  1. package/bin/index.js +2 -2
  2. package/package.json +3 -3
  3. package/src/config/auth.config.js +27 -0
  4. package/src/config/default.config.js +176 -0
  5. package/src/config/index.js +9 -0
  6. package/src/initData/defaultTemplate.html +13 -0
  7. package/src/initData/neo.config.js +138 -0
  8. package/src/main.js +221 -0
  9. package/src/module/inspect.js +41 -0
  10. package/src/module/neoInit.js +55 -0
  11. package/src/module/neoInitByCopy.js +61 -0
  12. package/src/neo/NeoUMDContent.js +30 -0
  13. package/src/neo/neoLogin.js +565 -0
  14. package/src/neo/neoRequire.js +125 -0
  15. package/src/neo/neoService.js +874 -0
  16. package/src/neo/webpack.mf.js +60 -0
  17. package/src/neo/wrapperContent.js +16 -0
  18. package/src/oss/publish2oss.js +348 -0
  19. package/src/plugins/AddNeoRequirePlugin-v1.js +47 -0
  20. package/src/plugins/AddNeoRequirePlugin.js +179 -0
  21. package/src/plugins/README.md +109 -0
  22. package/src/utils/autoEntryRootDir.js +85 -0
  23. package/src/utils/cmpUtils/createCmpByTemplate.js +60 -0
  24. package/src/utils/cmpUtils/createCmpByZip.js +408 -0
  25. package/src/utils/cmpUtils/createCommonModulesCode.js +121 -0
  26. package/src/utils/cmpUtils/deleteCmp.js +63 -0
  27. package/src/utils/cmpUtils/getCmpModelRegisterCode.js +31 -0
  28. package/src/utils/cmpUtils/getCmpPreviewCode.js +43 -0
  29. package/src/utils/cmpUtils/getCmpRegisterCode.js +31 -0
  30. package/src/utils/cmpUtils/getCmpTypeByDir.js +41 -0
  31. package/src/utils/cmpUtils/hasCmpTypeByDir.js +11 -0
  32. package/src/utils/cmpUtils/previewCmp.js +55 -0
  33. package/src/utils/cmpUtils/pullCmp.js +104 -0
  34. package/src/utils/cmpUtils/pushCmp.js +230 -0
  35. package/src/utils/common.js +107 -0
  36. package/src/utils/configureNeoBuild.js +109 -0
  37. package/src/utils/generateEntries.js +63 -0
  38. package/src/utils/neoConfigInit.js +13 -0
  39. package/src/utils/neoParams.js +12 -0
  40. package/src/utils/pathUtils.js +23 -0
  41. package/src/utils/projectNameValidator.js +76 -0
  42. package/src/utils/projectUtils/createCmpProjectByTemplate.js +59 -0
  43. package/src/utils/projectUtils/createCmpProjectZip.js +120 -0
  44. package/src/utils/projectUtils/getEntries.js +80 -0
  45. package/src/utils/projectUtils/getEntriesWithAutoRegister.js +108 -0
  46. package/src/utils/projectUtils/hasNeoProject.js +17 -0
  47. package/src/utils/projectUtils/openProject.js +96 -0
  48. package/src/utils/projectUtils/updatePublishLog.js +30 -0
  49. package/src/utils/replaceInFiles.js +47 -0
  50. package/src/utils/replaceInFilesByMap.js +54 -0
  51. package/src/utils/replaceInPackage.js +134 -0
  52. package/src/utils/resetPackageVersion.js +115 -0
  53. package/test/deprecate-versions.js +1 -1
  54. package/test/neo.config.js +1 -25
  55. package/dist/_virtual/AddNeoRequirePlugin.js +0 -8
  56. package/dist/_virtual/OverloadYield.js +0 -5
  57. package/dist/_virtual/_commonjsHelpers.js +0 -40
  58. package/dist/_virtual/array-set.js +0 -5
  59. package/dist/_virtual/base64-vlq.js +0 -5
  60. package/dist/_virtual/base64.js +0 -5
  61. package/dist/_virtual/binary-search.js +0 -5
  62. package/dist/_virtual/createCmpByZip.js +0 -8
  63. package/dist/_virtual/deleteCmp.js +0 -8
  64. package/dist/_virtual/index.js +0 -9
  65. package/dist/_virtual/mapping-list.js +0 -5
  66. package/dist/_virtual/neoLogin.js +0 -8
  67. package/dist/_virtual/neoService.js +0 -8
  68. package/dist/_virtual/openProject.js +0 -8
  69. package/dist/_virtual/publish2oss.js +0 -8
  70. package/dist/_virtual/pullCmp.js +0 -8
  71. package/dist/_virtual/pushCmp.js +0 -8
  72. package/dist/_virtual/quick-sort.js +0 -5
  73. package/dist/_virtual/regenerator.js +0 -5
  74. package/dist/_virtual/regeneratorAsync.js +0 -5
  75. package/dist/_virtual/regeneratorAsyncGen.js +0 -5
  76. package/dist/_virtual/regeneratorAsyncIterator.js +0 -5
  77. package/dist/_virtual/regeneratorDefine.js +0 -5
  78. package/dist/_virtual/regeneratorKeys.js +0 -5
  79. package/dist/_virtual/regeneratorRuntime.js +0 -5
  80. package/dist/_virtual/regeneratorValues.js +0 -5
  81. package/dist/_virtual/source-map-consumer.js +0 -5
  82. package/dist/_virtual/source-map-generator.js +0 -5
  83. package/dist/_virtual/source-map-support.js +0 -5
  84. package/dist/_virtual/source-map.js +0 -5
  85. package/dist/_virtual/source-node.js +0 -5
  86. package/dist/_virtual/typeof.js +0 -5
  87. package/dist/_virtual/typescript.js +0 -5
  88. package/dist/_virtual/util.js +0 -5
  89. package/dist/config/auth.config.js +0 -50
  90. package/dist/config/default.config.js +0 -225
  91. package/dist/config/index.js +0 -27
  92. package/dist/main.js +0 -9
  93. package/dist/main2.js +0 -261
  94. package/dist/module/inspect.js +0 -64
  95. package/dist/module/neoInit.js +0 -69
  96. package/dist/module/neoInitByCopy.js +0 -81
  97. package/dist/neo/neoLogin.js +0 -663
  98. package/dist/neo/neoRequire.js +0 -118
  99. package/dist/neo/neoService.js +0 -1246
  100. package/dist/node_modules/@babel/runtime/helpers/OverloadYield.js +0 -19
  101. package/dist/node_modules/@babel/runtime/helpers/esm/asyncToGenerator.js +0 -29
  102. package/dist/node_modules/@babel/runtime/helpers/esm/extends.js +0 -13
  103. package/dist/node_modules/@babel/runtime/helpers/regenerator.js +0 -105
  104. package/dist/node_modules/@babel/runtime/helpers/regeneratorAsync.js +0 -24
  105. package/dist/node_modules/@babel/runtime/helpers/regeneratorAsyncGen.js +0 -23
  106. package/dist/node_modules/@babel/runtime/helpers/regeneratorAsyncIterator.js +0 -50
  107. package/dist/node_modules/@babel/runtime/helpers/regeneratorDefine.js +0 -37
  108. package/dist/node_modules/@babel/runtime/helpers/regeneratorKeys.js +0 -25
  109. package/dist/node_modules/@babel/runtime/helpers/regeneratorRuntime.js +0 -98
  110. package/dist/node_modules/@babel/runtime/helpers/regeneratorValues.js +0 -35
  111. package/dist/node_modules/@babel/runtime/helpers/typeof.js +0 -25
  112. package/dist/node_modules/@babel/runtime/regenerator/index.js +0 -29
  113. package/dist/node_modules/buffer-from/index.js +0 -57
  114. package/dist/node_modules/source-map/lib/array-set.js +0 -134
  115. package/dist/node_modules/source-map/lib/base64-vlq.js +0 -144
  116. package/dist/node_modules/source-map/lib/base64.js +0 -81
  117. package/dist/node_modules/source-map/lib/binary-search.js +0 -122
  118. package/dist/node_modules/source-map/lib/mapping-list.js +0 -94
  119. package/dist/node_modules/source-map/lib/quick-sort.js +0 -126
  120. package/dist/node_modules/source-map/lib/source-map-consumer.js +0 -1018
  121. package/dist/node_modules/source-map/lib/source-map-generator.js +0 -385
  122. package/dist/node_modules/source-map/lib/source-node.js +0 -400
  123. package/dist/node_modules/source-map/lib/util.js +0 -449
  124. package/dist/node_modules/source-map/source-map.js +0 -25
  125. package/dist/node_modules/source-map-support/source-map-support.js +0 -610
  126. package/dist/node_modules/typescript/lib/typescript.js +0 -22376
  127. package/dist/oss/publish2oss.js +0 -378
  128. package/dist/plugins/AddNeoRequirePlugin.js +0 -178
  129. package/dist/utils/autoEntryRootDir.js +0 -98
  130. package/dist/utils/cmpUtils/createCmpByTemplate.js +0 -73
  131. package/dist/utils/cmpUtils/createCmpByZip.js +0 -530
  132. package/dist/utils/cmpUtils/createCommonModulesCode.js +0 -84
  133. package/dist/utils/cmpUtils/deleteCmp.js +0 -98
  134. package/dist/utils/cmpUtils/getCmpModelRegisterCode.js +0 -38
  135. package/dist/utils/cmpUtils/getCmpPreviewCode.js +0 -37
  136. package/dist/utils/cmpUtils/getCmpRegisterCode.js +0 -38
  137. package/dist/utils/cmpUtils/getCmpTypeByDir.js +0 -58
  138. package/dist/utils/cmpUtils/hasCmpTypeByDir.js +0 -25
  139. package/dist/utils/cmpUtils/previewCmp.js +0 -74
  140. package/dist/utils/cmpUtils/pullCmp.js +0 -144
  141. package/dist/utils/cmpUtils/pushCmp.js +0 -290
  142. package/dist/utils/common.js +0 -121
  143. package/dist/utils/configureNeoBuild.js +0 -153
  144. package/dist/utils/generateEntries.js +0 -73
  145. package/dist/utils/neoConfigInit.js +0 -25
  146. package/dist/utils/neoParams.js +0 -23
  147. package/dist/utils/pathUtils.js +0 -48
  148. package/dist/utils/projectNameValidator.js +0 -89
  149. package/dist/utils/projectUtils/createCmpProjectByTemplate.js +0 -74
  150. package/dist/utils/projectUtils/createCmpProjectZip.js +0 -135
  151. package/dist/utils/projectUtils/getEntries.js +0 -99
  152. package/dist/utils/projectUtils/getEntriesWithAutoRegister.js +0 -127
  153. package/dist/utils/projectUtils/hasNeoProject.js +0 -31
  154. package/dist/utils/projectUtils/openProject.js +0 -169
  155. package/dist/utils/projectUtils/updatePublishLog.js +0 -45
  156. package/dist/utils/replaceInFilesByMap.js +0 -70
  157. package/dist/utils/replaceInPackage.js +0 -151
  158. package/dist/utils/resetPackageVersion.js +0 -134
@@ -1,73 +0,0 @@
1
- 'use strict';
2
-
3
- var require$$0 = require('fs-extra');
4
- var require$$1 = require('node:path');
5
- var require$$2 = require('lodash');
6
- var neoParams = require('../neoParams.js');
7
- var replaceInFilesByMap = require('../replaceInFilesByMap.js');
8
- var hasCmpTypeByDir = require('./hasCmpTypeByDir.js');
9
- var hasNeoProject = require('../projectUtils/hasNeoProject.js');
10
-
11
- var createCmpByTemplate;
12
- var hasRequiredCreateCmpByTemplate;
13
-
14
- function requireCreateCmpByTemplate () {
15
- if (hasRequiredCreateCmpByTemplate) return createCmpByTemplate;
16
- hasRequiredCreateCmpByTemplate = 1;
17
- var fs = require$$0;
18
- var path = require$$1;
19
- var _ = require$$2;
20
- var _require = neoParams.__require(),
21
- consoleTag = _require.consoleTag; // 输出标记
22
- var replaceInFilesByMap$1 = replaceInFilesByMap.__require();
23
- var hasCmpTypeByDir$1 = hasCmpTypeByDir.__require();
24
- var hasNeoProject$1 = hasNeoProject.__require();
25
-
26
- // 自定义组件内容模板信息
27
- var curCmpTemplate = {
28
- // 需要替换掉的字段信息(模板中的字段)
29
- widgetInfo: {
30
- cmpName: 'CustomCmp',
31
- modelName: 'CmpModel',
32
- cmpClassName: 'custom-cmp-container',
33
- cmpType: 'xx-custom-cmp',
34
- cmpLabel: 'xx组件'
35
- },
36
- dir: path.resolve(__dirname, '../../../template/empty-cmp')
37
- };
38
-
39
- /**
40
- * 创建自定义组件
41
- * @param {*} cmpName 自定义组件名称
42
- */
43
- createCmpByTemplate = function (cmpName, componentBaseDir) {
44
- if (componentBaseDir === void 0) {
45
- componentBaseDir = './src/components';
46
- }
47
- var currentTemplateDir = curCmpTemplate.dir;
48
- var finalCmpName = cmpName || 'neoCustomCmp';
49
- var finalCmpPath = path.resolve(process.cwd(), componentBaseDir, finalCmpName);
50
- if (!hasNeoProject$1()) {
51
- console.error(consoleTag + "\u5F53\u524D\uFF08" + process.cwd() + "\uFF09\u8FD8\u4E0D\u662F\u81EA\u5B9A\u4E49\u7EC4\u4EF6\u9879\u76EE\uFF0C\u8BF7\u5148\u521B\u5EFA\u4E00\u4E2A\u81EA\u5B9A\u4E49\u7EC4\u4EF6\u9879\u76EE\uFF08neo init / neo create project\uFF09\u3002");
52
- process.exit(1);
53
- }
54
- if (hasCmpTypeByDir$1(finalCmpName)) {
55
- console.error(consoleTag + "\u521B\u5EFA\u81EA\u5B9A\u4E49\u7EC4\u4EF6\u5931\u8D25\uFF0C\u5F53\u524D\u9879\u76EE\u5DF2\u7ECF\u5B58\u5728" + finalCmpName + "\u81EA\u5B9A\u4E49\u7EC4\u4EF6\u3002");
56
- process.exit(1);
57
- }
58
- fs.copy(currentTemplateDir, finalCmpPath).then(function () {
59
- var _replaceInFilesByMap;
60
- var curCmpName = _.camelCase(finalCmpName);
61
- var cmpType = _.kebabCase(finalCmpName);
62
-
63
- // 替换文件中的内容
64
- replaceInFilesByMap$1(finalCmpPath, (_replaceInFilesByMap = {}, _replaceInFilesByMap[curCmpTemplate.widgetInfo.modelName] = curCmpName + "Model", _replaceInFilesByMap[curCmpTemplate.widgetInfo.cmpName] = curCmpName, _replaceInFilesByMap[curCmpTemplate.widgetInfo.cmpClassName] = cmpType + "-container", _replaceInFilesByMap[curCmpTemplate.widgetInfo.cmpType] = cmpType, _replaceInFilesByMap[curCmpTemplate.widgetInfo.cmpLabel] = cmpType + "\u7EC4\u4EF6", _replaceInFilesByMap));
65
- console.log(consoleTag + "\u5DF2\u521B\u5EFA\u81EA\u5B9A\u4E49\u7EC4\u4EF6\uFF08" + finalCmpName + "\uFF09!");
66
- }).catch(function (err) {
67
- return console.error(consoleTag + "\u81EA\u5B9A\u4E49\u7EC4\u4EF6\u521B\u5EFA\u5931\u8D25\uFF08" + finalCmpName + "\uFF09\uFF1A", err);
68
- });
69
- };
70
- return createCmpByTemplate;
71
- }
72
-
73
- exports.__require = requireCreateCmpByTemplate;
@@ -1,530 +0,0 @@
1
- 'use strict';
2
-
3
- var require$$0 = require('fs-extra');
4
- var require$$1 = require('node:path');
5
- var require$$0$1 = require('axios');
6
- var require$$3 = require('ora');
7
- var require$$2 = require('adm-zip');
8
- var require$$2$1 = require('lodash');
9
- var neoParams = require('../neoParams.js');
10
- var hasCmpTypeByDir$1 = require('./hasCmpTypeByDir.js');
11
- var hasNeoProject$1 = require('../projectUtils/hasNeoProject.js');
12
- var common = require('../common.js');
13
- var asyncToGenerator = require('../../node_modules/@babel/runtime/helpers/esm/asyncToGenerator.js');
14
- var index = require('../../_virtual/index.js');
15
-
16
- function _createForOfIteratorHelperLoose(r, e) { var t = "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (t) return (t = t.call(r)).next.bind(t); if (Array.isArray(r) || (t = _unsupportedIterableToArray(r)) || e) { t && (r = t); var o = 0; return function () { return o >= r.length ? { done: true } : { done: false, value: r[o++] }; }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
17
- function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
18
- function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
19
- var fs = require$$0;
20
- var path = require$$1;
21
- var axios = require$$0$1;
22
- var ora = require$$3;
23
- var AdmZip = require$$2;
24
- var _ = require$$2$1;
25
- var _require = neoParams.__require(),
26
- consoleTag = _require.consoleTag; // 输出标记
27
- var hasCmpTypeByDir = hasCmpTypeByDir$1.__require();
28
- var hasNeoProject = hasNeoProject$1.__require();
29
- var _require2 = common.__require(),
30
- errorLog = _require2.errorLog,
31
- warningLog = _require2.warningLog,
32
- successLog = _require2.successLog,
33
- parseTsConfigWithTypeScript = _require2.parseTsConfigWithTypeScript;
34
-
35
- /**
36
- * 检查对象键名是否需要加引号
37
- * @param {string} key 键名
38
- * @returns {boolean} 是否需要加引号
39
- */
40
- function needsQuotes(key) {
41
- // 如果键名包含特殊字符(如 @、-、空格等)或不是有效的 JavaScript 标识符,需要加引号
42
- // 有效的 JavaScript 标识符:以字母、$、_ 开头,后续可以是字母、数字、$、_
43
- var validIdentifierRegex = /^[a-zA-Z_$][a-zA-Z0-9_$]*$/;
44
- return !validIdentifierRegex.test(key);
45
- }
46
-
47
- /**
48
- * 格式化对象键名,如果需要则加引号
49
- * @param {string} key 键名
50
- * @returns {string} 格式化后的键名
51
- */
52
- function formatKey(key) {
53
- if (needsQuotes(key)) {
54
- return JSON.stringify(key);
55
- }
56
- return key;
57
- }
58
-
59
- /**
60
- * 将配置对象格式化为 JavaScript 代码字符串
61
- * @param {*} obj 配置对象
62
- * @param {number} indent 缩进级别
63
- * @param {string} fileDir 配置文件所在目录路径,用于将绝对路径转换回相对路径(resolve() 基于 __dirname)
64
- * @returns {string} 格式化后的字符串
65
- */
66
- function formatConfigObject(obj, indent, fileDir) {
67
- if (indent === void 0) {
68
- indent = 0;
69
- }
70
- if (fileDir === void 0) {
71
- fileDir = '';
72
- }
73
- var indentStr = ' '.repeat(indent);
74
- var nextIndentStr = ' '.repeat(indent + 1);
75
- if (obj === null) {
76
- return 'null';
77
- }
78
- if (obj === undefined) {
79
- return 'undefined';
80
- }
81
- if (typeof obj === 'string') {
82
- // 尝试将绝对路径转换回 resolve() 调用
83
- if (fileDir && path.isAbsolute(obj)) {
84
- try {
85
- var relativePath = path.relative(fileDir, obj).replace(/\\/g, '/');
86
- // 如果路径看起来像是通过 resolve() 生成的,转换回 resolve() 调用
87
- // 排除包含 .. 的路径(这些可能是外部路径)
88
- if (relativePath && !relativePath.startsWith('..') && relativePath !== '') {
89
- // 确保路径使用正斜杠,并添加 ./ 前缀(如果需要)
90
- var normalizedPath = relativePath.startsWith('.') ? relativePath : './' + relativePath;
91
- return "resolve(" + JSON.stringify(normalizedPath) + ")";
92
- }
93
- } catch (e) {
94
- // 如果路径转换失败,继续使用原始字符串
95
- }
96
- }
97
- // 检查是否包含 resolve() 或 auth. 调用(从原始文件中提取的)
98
- if (obj.includes('resolve(') || obj.includes('auth.')) {
99
- return obj;
100
- }
101
- // 转义字符串中的特殊字符
102
- return JSON.stringify(obj);
103
- }
104
- if (typeof obj === 'number' || typeof obj === 'boolean') {
105
- return String(obj);
106
- }
107
- if (Array.isArray(obj)) {
108
- if (obj.length === 0) {
109
- return '[]';
110
- }
111
- var items = obj.map(function (item) {
112
- var formatted = formatConfigObject(item, indent + 1, fileDir);
113
- return nextIndentStr + formatted;
114
- });
115
- return '[\n' + items.join(',\n') + '\n' + indentStr + ']';
116
- }
117
- if (typeof obj === 'object') {
118
- var keys = Object.keys(obj);
119
- if (keys.length === 0) {
120
- return '{}';
121
- }
122
- var _items = keys.map(function (key) {
123
- var value = obj[key];
124
- var formattedValue = formatConfigObject(value, indent + 1, fileDir);
125
- return nextIndentStr + formatKey(key) + ': ' + formattedValue;
126
- });
127
- return '{\n' + _items.join(',\n') + '\n' + indentStr + '}';
128
- }
129
-
130
- // 对于函数或其他类型,尝试转换为字符串
131
- return String(obj);
132
- }
133
-
134
- /**
135
- * 从 zip 包中创建自定义组件
136
- * @param {*} cmpZipUrl 自定义组件源码文件地址(zip包地址)
137
- * @param {*} cmpName 自定义组件名称
138
- * @param {*} componentBaseDir 自定义组件目录
139
- *
140
- * 拉取线上自定义组件源码 规则:
141
- * 1、对于 组件源码中 src/components 中的所有文件 copy 至 当前项目 src/components,非覆盖式(copy 前判断是否存在);
142
- * 2、对于 组件源码中的 配置文件(neo.config.js)内容 和 当前项目配置 进行 非覆盖式 merge 处理;
143
- * 3、对于 组件源码中的 tsconfig.json 文件内容 和 当前项目 tsconfig  进行 非覆盖式 merge 处理;
144
- * 4、对于 组件源码中的 package.json 文件内容 和 当前项目 package.json  进行 非覆盖式 merge 处理,并识别新增 依赖,提示用户 重新安装依赖
145
- */
146
- function createCmpByZip(_x, _x2) {
147
- return _createCmpByZip.apply(this, arguments);
148
- }
149
- function _createCmpByZip() {
150
- _createCmpByZip = asyncToGenerator(/*#__PURE__*/index.mark(function _callee2(cmpZipUrl, option) {
151
- var _ref, token, cmpName, _ref$componentBaseDir, componentBaseDir, finalCmpName, tempDir, spinner, zipFilePath, response, errorMessage, buffer, zip, extractPath, cmpSourcePath, targetComponentsDir, normalizedComponentBaseDir, _copyOtherFiles, _extractPath, _t3, _t4, _t5, _t6, _t7;
152
- return index.wrap(function (_context2) {
153
- while (1) switch (_context2.prev = _context2.next) {
154
- case 0:
155
- if (option === void 0) {
156
- option = {};
157
- }
158
- _ref = option || {}, token = _ref.token, cmpName = _ref.cmpName, _ref$componentBaseDir = _ref.componentBaseDir, componentBaseDir = _ref$componentBaseDir === void 0 ? './src/components' : _ref$componentBaseDir;
159
- finalCmpName = cmpName;
160
- if (!hasNeoProject()) {
161
- errorLog("\u5F53\u524D\uFF08" + process.cwd() + "\uFF09\u8FD8\u4E0D\u662F\u81EA\u5B9A\u4E49\u7EC4\u4EF6\u9879\u76EE\uFF0C\u8BF7\u5148\u521B\u5EFA\u4E00\u4E2A\u81EA\u5B9A\u4E49\u7EC4\u4EF6\u9879\u76EE\uFF08neo init / neo create project\uFF09\u3002");
162
- process.exit(1);
163
- }
164
- if (hasCmpTypeByDir(finalCmpName)) {
165
- errorLog("\u5F53\u524D\u9879\u76EE\u5DF2\u7ECF\u5B58\u5728" + finalCmpName + "\u81EA\u5B9A\u4E49\u7EC4\u4EF6\u3002");
166
- process.exit(1);
167
- }
168
-
169
- // 创建临时目录
170
- tempDir = path.join(process.cwd(), '.neo-cli', 'zip-source');
171
- spinner = ora(consoleTag + "\u6B63\u5728\u4E0B\u8F7D\u7EC4\u4EF6\u6E90\u7801...").start(); // 下载源码文件并解析到 src/components 目录下
172
- _context2.prev = 1;
173
- _context2.next = 2;
174
- return fs.ensureDir(tempDir);
175
- case 2:
176
- // 如果目录不存在,会自动创建(包括所有必要的父目录)
177
- zipFilePath = path.join(tempDir, finalCmpName + ".zip"); // 检查是否存在同名 zip 包,如果存在则先删除
178
- _context2.next = 3;
179
- return fs.pathExists(zipFilePath);
180
- case 3:
181
- if (!_context2.sent) {
182
- _context2.next = 4;
183
- break;
184
- }
185
- _context2.next = 4;
186
- return fs.remove(zipFilePath);
187
- case 4:
188
- _context2.prev = 4;
189
- _context2.next = 5;
190
- return axios.get(cmpZipUrl, {
191
- headers: {
192
- Authorization: "Bearer " + token,
193
- 'xsy-inner-source': 'bff'
194
- },
195
- responseType: 'arraybuffer',
196
- timeout: 60000,
197
- // 60秒超时
198
- maxContentLength: Infinity,
199
- maxBodyLength: Infinity,
200
- maxRedirects: 5,
201
- // 支持重定向
202
- validateStatus: function validateStatus(status) {
203
- // 接受 2xx 和 3xx 状态码(重定向)
204
- return status >= 200 && status < 400;
205
- }
206
- });
207
- case 5:
208
- response = _context2.sent;
209
- _context2.next = 7;
210
- break;
211
- case 6:
212
- _context2.prev = 6;
213
- _t3 = _context2["catch"](4);
214
- errorMessage = _t3.response ? "\u4E0B\u8F7D\u6587\u4EF6\u5931\u8D25: HTTP " + _t3.response.status + " - " + _t3.message : "\u4E0B\u8F7D\u6587\u4EF6\u5931\u8D25: " + _t3.message;
215
- errorLog(errorMessage, spinner);
216
- throw _t3;
217
- case 7:
218
- _context2.prev = 7;
219
- // 处理不同的数据类型
220
- if (Buffer.isBuffer(response.data)) {
221
- // 如果已经是 Buffer,直接使用
222
- buffer = response.data;
223
- } else if (response.data instanceof ArrayBuffer) {
224
- // 如果是 ArrayBuffer,转换为 Buffer
225
- buffer = Buffer.from(response.data);
226
- } else if (response.data.buffer instanceof ArrayBuffer) {
227
- // 如果是 TypedArray (如 Uint8Array),使用其 buffer
228
- buffer = Buffer.from(response.data.buffer);
229
- } else {
230
- // 尝试直接转换
231
- buffer = Buffer.from(response.data);
232
- }
233
- _context2.next = 8;
234
- return fs.writeFile(zipFilePath, buffer);
235
- case 8:
236
- _context2.next = 10;
237
- break;
238
- case 9:
239
- _context2.prev = 9;
240
- _t4 = _context2["catch"](7);
241
- errorLog("\u8BFB\u53D6\u7EC4\u4EF6\u6E90\u7801\u6587\u4EF6\u5931\u8D25: " + _t4.message, spinner);
242
- throw _t4;
243
- case 10:
244
- // 解压 zip 文件
245
- spinner.info(consoleTag + "\u6B63\u5728\u89E3\u538B\u7EC4\u4EF6\u6E90\u7801...");
246
- zip = new AdmZip(zipFilePath); // 解压后的目录名称为组件名称:.neo-cli/zip-source/xxCmp
247
- extractPath = path.join(tempDir, finalCmpName);
248
- zip.extractAllTo(extractPath, true); // 解压到临时目录
249
-
250
- // 查找解压后的 src/components 目录
251
- cmpSourcePath = path.join(extractPath, componentBaseDir, finalCmpName);
252
- if (fs.existsSync(cmpSourcePath)) {
253
- _context2.next = 12;
254
- break;
255
- }
256
- errorLog("\u89E3\u538B\u540E\u7684 zip \u5305\u4E2D\u672A\u627E\u5230 " + finalCmpName + " \u7EC4\u4EF6\u6E90\u7801\u76EE\u5F55\u3002", spinner);
257
- // 只删除解压目录,保留 zip 源文件
258
- _context2.next = 11;
259
- return fs.remove(extractPath);
260
- case 11:
261
- return _context2.abrupt("return", false);
262
- case 12:
263
- // 确保目标目录存在
264
- targetComponentsDir = path.resolve(process.cwd(), componentBaseDir, finalCmpName);
265
- _context2.next = 13;
266
- return fs.ensureDir(targetComponentsDir);
267
- case 13:
268
- _context2.prev = 13;
269
- _context2.next = 14;
270
- return fs.copy(cmpSourcePath, targetComponentsDir);
271
- case 14:
272
- _context2.next = 17;
273
- break;
274
- case 15:
275
- _context2.prev = 15;
276
- _t5 = _context2["catch"](13);
277
- errorLog("\u81EA\u5B9A\u4E49\u7EC4\u4EF6\u6A21\u677F\u4E0B\u8F7D\u5931\u8D25\uFF1A" + (_t5.message || _t5), spinner);
278
- // 只删除解压目录,保留 zip 源文件
279
- _context2.next = 16;
280
- return fs.remove(extractPath);
281
- case 16:
282
- return _context2.abrupt("return", false);
283
- case 17:
284
- _context2.prev = 17;
285
- // 标准化 componentBaseDir,去掉开头的 ./ 并统一路径分隔符
286
- normalizedComponentBaseDir = componentBaseDir.replace(/^\.\//, '').replace(/\\/g, '/');
287
- /**
288
- * 递归复制文件,排除 componentBaseDir 目录
289
- * @param {string} sourceDir 源目录
290
- * @param {string} targetRoot 目标根目录(项目根目录)
291
- * @param {string} excludeDir 要排除的目录(相对于源目录)
292
- */
293
- _copyOtherFiles = /*#__PURE__*/function () {
294
- var _ref2 = asyncToGenerator(/*#__PURE__*/index.mark(function _callee(sourceDir, targetRoot, excludeDir) {
295
- var items, _iterator, _step, item, sourcePath, stat, fileName, relativePath, normalizedRelativePath, targetPath, targetExists, sourcePackageJson, targetPackageJson, newPackageJsonDeps, newDeps, mergedPackageJson, sourceResolvedPath, targetResolvedPath, targetContent, sourceConfig, targetConfig, mergedConfig, moduleExportMatch, fileHeader, lastBraceIndex, targetFileDir, configString, mergedContent, sourceTsconfigJson, targetTsconfigJson, mergedTsconfigJson, _t, _t2;
296
- return index.wrap(function (_context) {
297
- while (1) switch (_context.prev = _context.next) {
298
- case 0:
299
- _context.next = 1;
300
- return fs.readdir(sourceDir);
301
- case 1:
302
- items = _context.sent;
303
- _iterator = _createForOfIteratorHelperLoose(items);
304
- case 2:
305
- if ((_step = _iterator()).done) {
306
- _context.next = 29;
307
- break;
308
- }
309
- item = _step.value;
310
- sourcePath = path.join(sourceDir, item); // 当前源文件路径
311
- _context.next = 3;
312
- return fs.stat(sourcePath);
313
- case 3:
314
- stat = _context.sent;
315
- // 当前源文件状态
316
- fileName = path.basename(sourcePath); // 当前源文件名称
317
- // 计算相对于解压根目录的路径
318
- relativePath = path.relative(extractPath, sourcePath);
319
- normalizedRelativePath = relativePath.replace(/\\/g, '/'); // 跳过 componentBaseDir 目录及其子目录
320
- if (!(normalizedRelativePath.startsWith(excludeDir + '/') || normalizedRelativePath === excludeDir)) {
321
- _context.next = 4;
322
- break;
323
- }
324
- return _context.abrupt("continue", 28);
325
- case 4:
326
- targetPath = path.join(targetRoot, relativePath); // 目标文件路径
327
- if (!stat.isDirectory()) {
328
- _context.next = 6;
329
- break;
330
- }
331
- _context.next = 5;
332
- return _copyOtherFiles(sourcePath, targetRoot, excludeDir);
333
- case 5:
334
- _context.next = 28;
335
- break;
336
- case 6:
337
- if (!stat.isFile()) {
338
- _context.next = 28;
339
- break;
340
- }
341
- _context.next = 7;
342
- return fs.pathExists(targetPath);
343
- case 7:
344
- targetExists = _context.sent;
345
- if (targetExists) {
346
- _context.next = 10;
347
- break;
348
- }
349
- _context.next = 8;
350
- return fs.ensureDir(path.dirname(targetPath));
351
- case 8:
352
- _context.next = 9;
353
- return fs.copy(sourcePath, targetPath);
354
- case 9:
355
- _context.next = 28;
356
- break;
357
- case 10:
358
- if (!(fileName === 'package.json')) {
359
- _context.next = 14;
360
- break;
361
- }
362
- _context.next = 11;
363
- return fs.readJson(sourcePath);
364
- case 11:
365
- sourcePackageJson = _context.sent;
366
- _context.next = 12;
367
- return fs.readJson(targetPath);
368
- case 12:
369
- targetPackageJson = _context.sent;
370
- newPackageJsonDeps = _.omit(sourcePackageJson.dependencies, Object.keys(targetPackageJson.dependencies));
371
- newDeps = Object.keys(newPackageJsonDeps);
372
- if (newDeps.length > 0) {
373
- warningLog("\u68C0\u6D4B\u5230 package.json \u4E2D\u65B0\u589E\u4E86 " + newDeps.length + " \u4E2A\u4F9D\u8D56\u5305\uFF1A" + newDeps.join(', '));
374
- warningLog("\u4E3A\u786E\u4FDD\u7EC4\u4EF6\u6B63\u5E38\u8FD0\u884C\uFF0C\u8BF7\u6267\u884C\u4EE5\u4E0B\u547D\u4EE4\u5B89\u88C5\u4F9D\u8D56\uFF1Anpm install \u6216 yarn install");
375
- }
376
- // 合并 package.json:将源文件的配置合并到目标文件中
377
- // 注意:_.merge 会修改第一个参数,所以先克隆目标对象
378
- mergedPackageJson = _.merge({}, sourcePackageJson, targetPackageJson);
379
- _context.next = 13;
380
- return fs.writeJson(targetPath, mergedPackageJson, {
381
- spaces: 2
382
- });
383
- case 13:
384
- _context.next = 28;
385
- break;
386
- case 14:
387
- if (!(fileName === 'neo.config.js')) {
388
- _context.next = 21;
389
- break;
390
- }
391
- _context.prev = 15;
392
- // 清除 require 缓存,确保读取最新内容
393
- sourceResolvedPath = require.resolve(sourcePath);
394
- targetResolvedPath = require.resolve(targetPath);
395
- delete require.cache[sourceResolvedPath];
396
- delete require.cache[targetResolvedPath];
397
-
398
- // 读取源文件和目标文件的原始内容
399
- _context.next = 16;
400
- return fs.readFile(sourcePath, 'utf8');
401
- case 16:
402
- _context.sent;
403
- _context.next = 17;
404
- return fs.readFile(targetPath, 'utf8');
405
- case 17:
406
- targetContent = _context.sent;
407
- // 读取源文件和目标文件的配置对象(函数调用会被执行)
408
- sourceConfig = require(sourcePath);
409
- targetConfig = require(targetPath); // 合并配置:源配置合并到目标配置(目标配置优先级更高)
410
- mergedConfig = _.merge({}, sourceConfig, targetConfig); // 提取目标文件的头部(module.exports 之前的内容)
411
- moduleExportMatch = targetContent.match(/^([\s\S]*?)(module\.exports\s*=\s*\{[\s\S]*\};?\s*)$/);
412
- fileHeader = '';
413
- if (moduleExportMatch) {
414
- fileHeader = moduleExportMatch[1];
415
- } else {
416
- // 如果没有找到 module.exports,尝试提取到最后一个大括号之前的内容
417
- lastBraceIndex = targetContent.lastIndexOf('module.exports');
418
- if (lastBraceIndex > 0) {
419
- fileHeader = targetContent.substring(0, lastBraceIndex);
420
- } else {
421
- // 如果都没有找到,使用默认头部
422
- fileHeader = "'use strict';\nconst path = require('path');\n\n// 统一路径解析\nfunction resolve(dir) {\n return path.resolve(__dirname, dir);\n}\n\n";
423
- }
424
- }
425
-
426
- // 获取目标文件的目录,用于路径转换(resolve() 基于 __dirname)
427
- targetFileDir = path.dirname(targetPath); // 将合并后的配置对象转换为格式化的字符串
428
- configString = formatConfigObject(mergedConfig, 0, targetFileDir); // 组合完整的文件内容
429
- mergedContent = fileHeader + 'module.exports = ' + configString + ';\n'; // 写回文件
430
- _context.next = 18;
431
- return fs.writeFile(targetPath, mergedContent, 'utf8');
432
- case 18:
433
- _context.next = 20;
434
- break;
435
- case 19:
436
- _context.prev = 19;
437
- _t = _context["catch"](15);
438
- spinner.warn(consoleTag + "\u5408\u5E76 neo.config.js \u914D\u7F6E\u6587\u4EF6\u65F6\u51FA\u73B0\u8B66\u544A\uFF1A" + (_t.message || _t));
439
- case 20:
440
- _context.next = 28;
441
- break;
442
- case 21:
443
- if (!(fileName === 'tsconfig.json')) {
444
- _context.next = 28;
445
- break;
446
- }
447
- _context.prev = 22;
448
- sourceTsconfigJson = parseTsConfigWithTypeScript(sourcePath); // 先判断 targetPath 是否存在,如果存在则合并,否则直接写入
449
- _context.next = 23;
450
- return fs.pathExists(targetPath);
451
- case 23:
452
- if (!_context.sent) {
453
- _context.next = 25;
454
- break;
455
- }
456
- targetTsconfigJson = parseTsConfigWithTypeScript(targetPath); // 合并配置:源配置合并到目标配置(目标配置优先级更高)
457
- mergedTsconfigJson = _.merge({}, sourceTsconfigJson, targetTsconfigJson); // 使用 writeJson 写入,确保 JSON 格式正确(所有键名都会被正确序列化)
458
- _context.next = 24;
459
- return fs.writeJson(targetPath, mergedTsconfigJson, {
460
- spaces: 2
461
- });
462
- case 24:
463
- _context.next = 26;
464
- break;
465
- case 25:
466
- _context.next = 26;
467
- return fs.writeJson(targetPath, sourceTsconfigJson, {
468
- spaces: 2
469
- });
470
- case 26:
471
- _context.next = 28;
472
- break;
473
- case 27:
474
- _context.prev = 27;
475
- _t2 = _context["catch"](22);
476
- spinner.warn(consoleTag + "\u5408\u5E76 tsconfig.json \u914D\u7F6E\u6587\u4EF6\u65F6\u51FA\u73B0\u8B66\u544A\uFF1A" + (_t2.message || _t2));
477
- case 28:
478
- _context.next = 2;
479
- break;
480
- case 29:
481
- case "end":
482
- return _context.stop();
483
- }
484
- }, _callee, null, [[15, 19], [22, 27]]);
485
- }));
486
- return function copyOtherFiles(_x3, _x4, _x5) {
487
- return _ref2.apply(this, arguments);
488
- };
489
- }(); // 开始处理源码中其他文件
490
- _context2.next = 18;
491
- return _copyOtherFiles(extractPath, process.cwd(), normalizedComponentBaseDir);
492
- case 18:
493
- _context2.next = 20;
494
- break;
495
- case 19:
496
- _context2.prev = 19;
497
- _t6 = _context2["catch"](17);
498
- spinner.warn(consoleTag + "\u5904\u7406\u6E90\u7801\u6587\u4EF6\u51FA\u73B0\u8B66\u544A\uFF1A" + (_t6.message || _t6));
499
- case 20:
500
- _context2.next = 21;
501
- return fs.remove(extractPath);
502
- case 21:
503
- successLog("\u5DF2\u6210\u529F\u4ECE zip \u5305\u89E3\u6790\u81EA\u5B9A\u4E49\u7EC4\u4EF6\uFF08" + finalCmpName + "\uFF09!", spinner);
504
- return _context2.abrupt("return", true);
505
- case 22:
506
- _context2.prev = 22;
507
- _t7 = _context2["catch"](1);
508
- errorLog("\u4ECE zip \u5305\u521B\u5EFA\u81EA\u5B9A\u4E49\u7EC4\u4EF6\u5931\u8D25\uFF08" + finalCmpName + "\uFF09\uFF1A" + (_t7.message || _t7), spinner);
509
- // 清理解压目录,保留 zip 源文件
510
- _extractPath = path.join(tempDir, finalCmpName);
511
- _context2.next = 23;
512
- return fs.pathExists(_extractPath);
513
- case 23:
514
- if (!_context2.sent) {
515
- _context2.next = 24;
516
- break;
517
- }
518
- _context2.next = 24;
519
- return fs.remove(_extractPath);
520
- case 24:
521
- return _context2.abrupt("return", false);
522
- case 25:
523
- case "end":
524
- return _context2.stop();
525
- }
526
- }, _callee2, null, [[1, 22], [4, 6], [7, 9], [13, 15], [17, 19]]);
527
- }));
528
- return _createCmpByZip.apply(this, arguments);
529
- }
530
- module.exports = createCmpByZip;