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,141 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
4
+
5
+ const require$$0 = require('fs-extra');
6
+ const require$$1 = require('node:path');
7
+ const require$$2 = require('adm-zip');
8
+ const require$$2$1 = require('lodash');
9
+ const neoParams = require('../neoParams.js');
10
+ const hasNeoProject = require('./hasNeoProject.js');
11
+
12
+ var createCmpProjectZip;
13
+ var hasRequiredCreateCmpProjectZip;
14
+
15
+ function requireCreateCmpProjectZip () {
16
+ if (hasRequiredCreateCmpProjectZip) return createCmpProjectZip;
17
+ hasRequiredCreateCmpProjectZip = 1;
18
+ const fs = require$$0;
19
+ const path = require$$1;
20
+ const AdmZip = require$$2;
21
+ const _ = require$$2$1;
22
+ const { consoleTag } = neoParams.__require(); // 输出标记
23
+ const hasNeoProject$1 = hasNeoProject.__require();
24
+
25
+ /**
26
+ * 创建自定义组件源码 zip 包
27
+ * @param {*} cmpType 自定义组件名称
28
+ * @returns {string} zip 文件路径
29
+ */
30
+ createCmpProjectZip = function (cmpType, _projectPath, assetsRoot) {
31
+ const projectRoot = _projectPath || process.cwd();
32
+ const finalAssetsRoot = assetsRoot || path.join(projectRoot, 'dist');
33
+
34
+ if (!hasNeoProject$1(_projectPath)) {
35
+ console.error(`${consoleTag}当前目录不是自定义组件项目,请在自定义组件项目目录下执行。`);
36
+ process.exit(1);
37
+ }
38
+
39
+ if (!cmpType) {
40
+ console.error(`${consoleTag}自定义组件名称不能为空`);
41
+ process.exit(1);
42
+ }
43
+
44
+ const zip = new AdmZip();
45
+
46
+ // 需要排除的目录和文件
47
+ const excludeDirs = ['node_modules', '.neo-cli', 'dist'];
48
+ const excludeFiles = ['.eslintcache', 'auth.config.js'];
49
+
50
+ /**
51
+ * 判断文件/目录是否应该被排除
52
+ * @param {string} filePath 文件路径
53
+ * @param {string} relativePath 相对路径
54
+ * @returns {boolean} 是否应该排除
55
+ */
56
+ const shouldExclude = (filePath, relativePath) => {
57
+ const name = path.basename(filePath);
58
+ const stat = fs.statSync(filePath);
59
+
60
+ // 排除指定的目录
61
+ if (stat.isDirectory() && excludeDirs.includes(name)) {
62
+ return true;
63
+ }
64
+
65
+ // 排除指定的文件
66
+ if (stat.isFile() && excludeFiles.includes(name)) {
67
+ return true;
68
+ }
69
+
70
+ // 对于 src/components 目录,只包含 cmpType 子目录
71
+ // 处理逻辑:如果路径是 src/components/xxx,且 xxx 不是 cmpType,则排除
72
+ if (relativePath.startsWith('src/components')) {
73
+ const relativeToComponents = path.relative('src/components', relativePath);
74
+ // 如果相对路径不为空,说明已经在 components 的子目录中
75
+ if (relativeToComponents && relativeToComponents !== '.') {
76
+ const firstPart = relativeToComponents.split(path.sep)[0];
77
+ // 如果第一个部分不是 cmpType,则排除
78
+ if (firstPart !== cmpType) {
79
+ return true;
80
+ }
81
+ }
82
+ }
83
+
84
+ return false;
85
+ };
86
+
87
+ /**
88
+ * 递归遍历目录并添加到 zip
89
+ * @param {string} dirPath 目录路径
90
+ * @param {string} relativePath 相对路径(用于 zip 中的路径)
91
+ */
92
+ const addDirectoryToZip = (dirPath, relativePath = '') => {
93
+ try {
94
+ const items = fs.readdirSync(dirPath);
95
+
96
+ items.forEach((item) => {
97
+ const itemPath = path.join(dirPath, item);
98
+ const itemRelativePath = relativePath ? path.join(relativePath, item) : item;
99
+
100
+ // 检查是否应该排除
101
+ if (shouldExclude(itemPath, itemRelativePath)) {
102
+ return;
103
+ }
104
+
105
+ const stat = fs.statSync(itemPath);
106
+
107
+ if (stat.isDirectory()) {
108
+ // 递归处理子目录
109
+ addDirectoryToZip(itemPath, itemRelativePath);
110
+ } else if (stat.isFile()) {
111
+ // 添加文件到 zip,保持相对路径结构
112
+ const fileContent = fs.readFileSync(itemPath);
113
+ zip.addFile(itemRelativePath, fileContent);
114
+ }
115
+ });
116
+ } catch (error) {
117
+ console.error(`${consoleTag}遍历目录失败 (${dirPath}):`, error.message);
118
+ }
119
+ };
120
+
121
+ // 开始遍历项目根目录
122
+ addDirectoryToZip(projectRoot);
123
+
124
+ // 生成 zip 文件名
125
+ const zipFileName = `${_.camelCase(cmpType)}Source.zip`;
126
+ const zipPath = path.join(finalAssetsRoot, zipFileName);
127
+
128
+ // 如果已存在同名 zip 文件,先删除
129
+ if (fs.existsSync(zipPath)) {
130
+ fs.removeSync(zipPath);
131
+ }
132
+
133
+ // 写入 zip 文件
134
+ zip.writeZip(zipPath);
135
+
136
+ return zipPath;
137
+ };
138
+ return createCmpProjectZip;
139
+ }
140
+
141
+ exports.__require = requireCreateCmpProjectZip;
@@ -0,0 +1,99 @@
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 require$$2 = require('lodash');
8
+ const pathUtils = require('../pathUtils.js');
9
+
10
+ var getEntries;
11
+ var hasRequiredGetEntries;
12
+
13
+ function requireGetEntries () {
14
+ if (hasRequiredGetEntries) return getEntries;
15
+ hasRequiredGetEntries = 1;
16
+ const fs = require$$0;
17
+ const path = require$$1;
18
+ const _ = require$$2;
19
+ const { resolveToCurrentRoot } = pathUtils.__require();
20
+
21
+ /**
22
+ * 从指定目录获取组件入口文件
23
+ * @param {*} defaultComponentsDir 默认组件目录
24
+ * @returns 组件入口文件
25
+ */
26
+ getEntries = (defaultComponentsDir = './src/components', cmpType) => {
27
+ const widgetEntries = {};
28
+ const linkDebugEntries = {
29
+ index: []
30
+ };
31
+ const cmpTypes = []; // 用于记录组件名称
32
+ const defaultExports = {}; // 用于记录默认导出
33
+ const componentsBaseDir = resolveToCurrentRoot(defaultComponentsDir);
34
+ if (!fs.existsSync(componentsBaseDir)) {
35
+ console.error(`未找到组件目录,请检查 ${defaultComponentsDir} 目录是否存在`);
36
+
37
+ // 退出进程
38
+ process.exit(1);
39
+ }
40
+
41
+ try {
42
+ // 读取指定目录下的所有文件
43
+ let widgetDirs = [];
44
+ if (cmpType) {
45
+ // 如果传入了 cmpType,则只读取指定组件目录
46
+ widgetDirs = [cmpType];
47
+ } else {
48
+ widgetDirs = fs.readdirSync(componentsBaseDir);
49
+ }
50
+
51
+ // 遍历所有目录
52
+ widgetDirs.forEach((dir) => {
53
+ const filePath = path.join(componentsBaseDir, dir);
54
+ // 获取文件状态
55
+ const stat = fs.statSync(filePath);
56
+ // 如果文件是目录,则递归处理子目录
57
+ if (stat.isDirectory() && !dir.startsWith('.') && dir !== 'node_modules') {
58
+ const curCmpPath = path.join(componentsBaseDir, dir);
59
+ const curCmpName = dir; // _.camelCase(dir);
60
+ const cmpNameKey = _.camelCase(curCmpName);
61
+
62
+ // 记录组件类型
63
+ cmpTypes.push(curCmpName);
64
+
65
+ fs.readdirSync(curCmpPath)
66
+ .filter((file) => file.match(/[index|register|model]\.(tsx?|jsx?|vue)$/))
67
+ .map((file) => path.join(defaultComponentsDir, curCmpName, file))
68
+ .forEach((filePath) => {
69
+ const curPath = `./${filePath}`;
70
+ if (filePath.match(/register\.[tj]sx?$/)) {
71
+ widgetEntries[cmpNameKey] = curPath;
72
+ } else if (filePath.match(/model\.[tj]sx?$/)) {
73
+ widgetEntries[`${cmpNameKey}Model`] = curPath;
74
+ } else if (filePath.match(/index\.(tsx?|jsx?|vue)$/)) {
75
+ // 组件内容文件
76
+ defaultExports[cmpNameKey] = path.resolve(filePath); // 记录默认导出
77
+ }
78
+ linkDebugEntries.index.push(curPath);
79
+ });
80
+ }
81
+ });
82
+ } catch (error) {
83
+ console.error('获取自定义组件入口文件失败(getEntries):', error);
84
+
85
+ // 退出进程
86
+ process.exit(1);
87
+ }
88
+
89
+ return {
90
+ widgetEntries,
91
+ linkDebugEntries,
92
+ cmpTypes,
93
+ defaultExports
94
+ };
95
+ };
96
+ return getEntries;
97
+ }
98
+
99
+ exports.__require = requireGetEntries;
@@ -0,0 +1,129 @@
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 require$$2 = require('lodash');
8
+ const pathUtils = require('../pathUtils.js');
9
+ const getCmpRegisterCode = require('../cmpUtils/getCmpRegisterCode.js');
10
+ const getCmpModelRegisterCode = require('../cmpUtils/getCmpModelRegisterCode.js');
11
+
12
+ var getEntriesWithAutoRegister;
13
+ var hasRequiredGetEntriesWithAutoRegister;
14
+
15
+ function requireGetEntriesWithAutoRegister () {
16
+ if (hasRequiredGetEntriesWithAutoRegister) return getEntriesWithAutoRegister;
17
+ hasRequiredGetEntriesWithAutoRegister = 1;
18
+ const fs = require$$0;
19
+ const path = require$$1;
20
+ const _ = require$$2;
21
+ const { resolveToCurrentRoot } = pathUtils.__require();
22
+ const getCmpRegisterCode$1 = getCmpRegisterCode.__require();
23
+ const getCmpModelRegisterCode$1 = getCmpModelRegisterCode.__require();
24
+ /**
25
+ * 从指定目录获取组件入口文件,并自动创建对应的注册文件
26
+ * @param {*} defaultComponentsDir 默认组件目录
27
+ * @returns 组件入口文件
28
+ */
29
+ getEntriesWithAutoRegister = (defaultComponentsDir = './src/components', cmpType) => {
30
+ const widgetEntries = {};
31
+ const linkDebugEntries = {
32
+ index: []
33
+ };
34
+ const cmpTypes = []; // 用于记录组件名称
35
+ const defaultExports = {}; // 用于记录默认导出
36
+ const componentsBaseDir = resolveToCurrentRoot(defaultComponentsDir);
37
+ if (!fs.existsSync(componentsBaseDir)) {
38
+ console.error(`未找到组件目录,请检查 ${defaultComponentsDir} 目录是否存在`);
39
+
40
+ // 退出进程
41
+ process.exit(1);
42
+ }
43
+
44
+ // 创建存放 cli 的临时目录
45
+ const cliTempDir = resolveToCurrentRoot('./.neo-cli');
46
+ if (!fs.existsSync(cliTempDir)) {
47
+ fs.mkdirSync(cliTempDir);
48
+ }
49
+
50
+ try {
51
+ // 读取指定目录下的所有文件
52
+ let widgetDirs = [];
53
+ if (cmpType) {
54
+ // 如果传入了 cmpType,则只读取指定组件目录
55
+ widgetDirs = [cmpType];
56
+ } else {
57
+ widgetDirs = fs.readdirSync(componentsBaseDir);
58
+ }
59
+
60
+ // 遍历所有目录
61
+ widgetDirs.forEach((dir) => {
62
+ // 当前自定义组件目录
63
+ const widgetPath = path.join(componentsBaseDir, dir);
64
+ // 获取文件状态
65
+ const stat = fs.statSync(widgetPath);
66
+ // 如果文件是目录,则递归处理子目录
67
+ if (stat.isDirectory() && !dir.startsWith('.') && dir !== 'node_modules') {
68
+ // 当前自定义组件名称
69
+ const curCmpName = dir; // _.camelCase(dir);
70
+ const cmpNameKey = _.camelCase(curCmpName);
71
+
72
+ // 记录组件类型
73
+ cmpTypes.push(curCmpName);
74
+
75
+ // 当前自定义组件临时目录
76
+ const cmpTempDir = `${cliTempDir}/${curCmpName}`;
77
+ if (!fs.existsSync(cmpTempDir)) {
78
+ fs.mkdirSync(cmpTempDir);
79
+ }
80
+
81
+ fs.readdirSync(widgetPath)
82
+ .filter((file) => file.match(/(index|model)\.(tsx?|jsx?|vue)$/))
83
+ .map((file) => path.join(defaultComponentsDir, curCmpName, file))
84
+ .forEach((filePath) => {
85
+ if (filePath.match(/index\.(tsx?|jsx?|vue)$/)) {
86
+ // 记录默认导出
87
+ defaultExports[cmpNameKey] = path.resolve(filePath);
88
+
89
+ // 自动创建对应的注册文件
90
+ const registerContent = getCmpRegisterCode$1(componentsBaseDir, curCmpName);
91
+ const registerDir = `${cmpTempDir}/register.js`;
92
+
93
+ // 写入注册文件
94
+ fs.writeFileSync(registerDir, registerContent);
95
+
96
+ widgetEntries[cmpNameKey] = registerDir;
97
+ linkDebugEntries.index.push(registerDir);
98
+ } else if (filePath.match(/model\.[tj]sx?$/)) {
99
+ // 自动创建对应的模型注册文件
100
+ const modelRegisterContent = getCmpModelRegisterCode$1(componentsBaseDir, curCmpName);
101
+ const modelRegisterDir = `${cmpTempDir}/model.js`;
102
+
103
+ // 写入模型注册文件
104
+ fs.writeFileSync(modelRegisterDir, modelRegisterContent);
105
+
106
+ widgetEntries[`${cmpNameKey}Model`] = modelRegisterDir;
107
+ linkDebugEntries.index.push(modelRegisterDir);
108
+ }
109
+ });
110
+ }
111
+ });
112
+ } catch (error) {
113
+ console.error('获取自定义组件入口文件失败(getEntriesWithAutoRegister):', error);
114
+
115
+ // 退出进程
116
+ process.exit(1);
117
+ }
118
+
119
+ return {
120
+ widgetEntries,
121
+ linkDebugEntries,
122
+ cmpTypes,
123
+ defaultExports
124
+ };
125
+ };
126
+ return getEntriesWithAutoRegister;
127
+ }
128
+
129
+ exports.__require = requireGetEntriesWithAutoRegister;
@@ -0,0 +1,34 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
4
+
5
+ const require$$0 = require('fs-extra');
6
+ const require$$1 = require('node:path');
7
+
8
+ var hasNeoProject;
9
+ var hasRequiredHasNeoProject;
10
+
11
+ function requireHasNeoProject () {
12
+ if (hasRequiredHasNeoProject) return hasNeoProject;
13
+ hasRequiredHasNeoProject = 1;
14
+ const fs = require$$0;
15
+ const path = require$$1;
16
+
17
+ /**
18
+ * 判断当前是否存在 自定义组件项目
19
+ * 备注:neo.config.js 和 package.json 必须同时存在才算作 自定义组件项目
20
+ */
21
+ hasNeoProject = function (_projectPath) {
22
+ const projectPath = _projectPath || process.cwd();
23
+ const neoConfigPath = path.resolve(projectPath, 'neo.config.js');
24
+ const packagePath = path.resolve(projectPath, 'package.json');
25
+
26
+ if (fs.existsSync(neoConfigPath) && fs.existsSync(packagePath)) {
27
+ return true;
28
+ }
29
+ return false;
30
+ };
31
+ return hasNeoProject;
32
+ }
33
+
34
+ exports.__require = requireHasNeoProject;
@@ -0,0 +1,117 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
4
+
5
+ const require$$1 = require('node:path');
6
+ const require$$0 = require('node:fs');
7
+ const require$$2 = require('open');
8
+ const require$$3 = require('ora');
9
+ const neoParams = require('../neoParams.js');
10
+ const common = require('../common.js');
11
+
12
+ var openProject_1;
13
+ var hasRequiredOpenProject;
14
+
15
+ function requireOpenProject () {
16
+ if (hasRequiredOpenProject) return openProject_1;
17
+ hasRequiredOpenProject = 1;
18
+ const path = require$$1;
19
+ const fs = require$$0;
20
+ const open = require$$2;
21
+ const ora = require$$3;
22
+ const { consoleTag } = neoParams.__require();
23
+ const { errorLog } = common.__require();
24
+
25
+ /**
26
+ * 打开自定义组件项目
27
+ */
28
+ const openProject = async function (editorType, targetPath) {
29
+ const targetDir = targetPath ? path.resolve(targetPath) : process.cwd();
30
+
31
+ // 检查目录是否存在
32
+ if (!fs.existsSync(targetDir)) {
33
+ errorLog(`目录不存在: ${targetDir}`);
34
+ process.exit(1);
35
+ }
36
+
37
+ // 检查是否为目录
38
+ const stats = fs.statSync(targetDir);
39
+ if (!stats.isDirectory()) {
40
+ errorLog(`路径不是目录: ${targetDir}`);
41
+ process.exit(1);
42
+ }
43
+
44
+ const isMac = process.platform === 'darwin';
45
+ const isWindows = process.platform === 'win32';
46
+ const isLinux = process.platform === 'linux';
47
+
48
+ // 构建编辑器配置列表(按优先级排序)
49
+ let editorConfigs = [];
50
+ let editorName = '编辑器';
51
+
52
+ // 根据编辑器类型和平台构建配置列表
53
+ if (editorType === 'cursor') {
54
+ editorName = 'Cursor';
55
+ // macOS 可以使用应用名称或命令名称
56
+ if (isMac) {
57
+ editorConfigs = [{ app: { name: 'cursor' } }, { app: { name: 'Cursor' } }];
58
+ } else if (isWindows || isLinux) {
59
+ editorConfigs = [{ app: { name: 'cursor' } }];
60
+ }
61
+ } else if (editorType === 'vscode' || editorType === 'code') {
62
+ editorName = 'Visual Studio Code';
63
+ if (isMac) {
64
+ editorConfigs = [{ app: { name: 'code' } }, { app: { name: 'Visual Studio Code' } }];
65
+ } else if (isWindows || isLinux) {
66
+ editorConfigs = [{ app: { name: 'code' } }];
67
+ }
68
+ } else {
69
+ // 自动检测:优先尝试 Cursor,如果失败则尝试 VSCode
70
+ if (isMac) {
71
+ editorConfigs = [
72
+ { app: { name: 'cursor' } },
73
+ { app: { name: 'Cursor' } },
74
+ { app: { name: 'code' } },
75
+ { app: { name: 'Visual Studio Code' } }
76
+ ];
77
+ } else if (isWindows || isLinux) {
78
+ editorConfigs = [{ app: { name: 'cursor' } }, { app: { name: 'code' } }];
79
+ }
80
+ }
81
+
82
+ if (editorConfigs.length === 0) {
83
+ errorLog(`不支持的操作系统: ${process.platform}`);
84
+ process.exit(1);
85
+ }
86
+
87
+ const spinner = ora(`${consoleTag}正在尝试使用 ${editorName} 打开项目: ${targetDir}`).start();
88
+
89
+ // 尝试打开编辑器
90
+ const tryOpenEditor = async (index) => {
91
+ if (index >= editorConfigs.length) {
92
+ errorLog(
93
+ `无法打开编辑器,已尝试所有可用方式。\n 请确保已安装 Cursor 或 Visual Studio Code 并将其添加到系统 PATH 中。`,
94
+ spinner
95
+ );
96
+ process.exit(1);
97
+ }
98
+
99
+ const config = editorConfigs[index];
100
+ try {
101
+ await open(targetDir, config);
102
+ spinner.stop();
103
+ // 成功打开,不需要继续尝试
104
+ } catch (error) {
105
+ // 如果当前配置失败,尝试下一个
106
+ await tryOpenEditor(index + 1);
107
+ }
108
+ };
109
+
110
+ await tryOpenEditor(0);
111
+ };
112
+
113
+ openProject_1 = openProject;
114
+ return openProject_1;
115
+ }
116
+
117
+ exports.__require = requireOpenProject;
@@ -0,0 +1,47 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
4
+
5
+ const require$$0 = require('node:fs');
6
+ require('lodash');
7
+ const pathUtils = require('../pathUtils.js');
8
+
9
+ var updatePublishLog;
10
+ var hasRequiredUpdatePublishLog;
11
+
12
+ function requireUpdatePublishLog () {
13
+ if (hasRequiredUpdatePublishLog) return updatePublishLog;
14
+ hasRequiredUpdatePublishLog = 1;
15
+ const fs = require$$0;
16
+ const { resolveToCurrentRoot } = pathUtils.__require();
17
+ /**
18
+ * 更新发布日志
19
+ */
20
+ updatePublishLog = function (curHistoryData) {
21
+ // 创建存放 cli 的临时目录
22
+ const cliTempDir = resolveToCurrentRoot('./.neo-cli');
23
+ if (!fs.existsSync(cliTempDir)) {
24
+ fs.mkdirSync(cliTempDir);
25
+ }
26
+
27
+ const historyFile = `${cliTempDir}/history.json`;
28
+ let historyData = {};
29
+ if (fs.existsSync(historyFile)) {
30
+ // 读取历史文件
31
+ try {
32
+ historyData = JSON.parse(fs.readFileSync(historyFile, 'utf8'));
33
+ } catch (error) {
34
+ console.error('读取历史文件失败:', error);
35
+ historyData = {};
36
+ }
37
+ }
38
+ const historyKey = new Date().toString();
39
+ historyData[historyKey] = curHistoryData;
40
+
41
+ // 更新历史文件
42
+ fs.writeFileSync(historyFile, JSON.stringify(historyData, null, 2));
43
+ };
44
+ return updatePublishLog;
45
+ }
46
+
47
+ exports.__require = requireUpdatePublishLog;
@@ -0,0 +1,71 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
4
+
5
+ const require$$0 = require('fs-extra');
6
+ const require$$1 = require('node:path');
7
+
8
+ var replaceInFilesByMap_1;
9
+ var hasRequiredReplaceInFilesByMap;
10
+
11
+ function requireReplaceInFilesByMap () {
12
+ if (hasRequiredReplaceInFilesByMap) return replaceInFilesByMap_1;
13
+ hasRequiredReplaceInFilesByMap = 1;
14
+ const fs = require$$0;
15
+ const path = require$$1;
16
+
17
+ /**
18
+ * 全局替换项目中的指定字符串
19
+ * @param dir 项目目录
20
+ * @param needReplaceStrMap {
21
+ * [oldStr]: newStr
22
+ * }
23
+ * @param fileExtensions 文件扩展名
24
+ */
25
+ function replaceInFilesByMap(
26
+ dir,
27
+ needReplaceStrMap = {},
28
+ fileExtensions = ['.js', '.jsx', '.ts', '.tsx', '.vue', '.html', '.css', '.scss', '.json']
29
+ ) {
30
+ try {
31
+ // 读取指定目录下的所有文件
32
+ const files = fs.readdirSync(dir);
33
+
34
+ // 遍历所有文件
35
+ files.forEach((file) => {
36
+ const filePath = path.join(dir, file);
37
+ // 获取文件状态
38
+ const stat = fs.statSync(filePath);
39
+ // 如果文件是目录,则递归处理子目录
40
+ if (stat.isDirectory() && !file.startsWith('.') && file !== 'node_modules') {
41
+ // 递归处理子目录
42
+ replaceInFilesByMap(filePath, needReplaceStrMap, fileExtensions);
43
+ } else if (stat.isFile()) {
44
+ // 检查文件扩展名
45
+ const ext = path.extname(file);
46
+ if (fileExtensions.includes(ext)) {
47
+ if (needReplaceStrMap &&Object.keys(needReplaceStrMap).length > 0) {
48
+ let content = fs.readFileSync(filePath, 'utf8');
49
+ Object.keys(needReplaceStrMap).forEach((key) => {
50
+ const oldStr = key;
51
+ const newStr = needReplaceStrMap[key];
52
+ if (content.includes(oldStr)) {
53
+ content = content.replace(new RegExp(oldStr, 'g'), newStr); // 全局替换
54
+ }
55
+ });
56
+ // 写入文件(更新文件内容)
57
+ fs.writeFileSync(filePath, content, 'utf8');
58
+ }
59
+ }
60
+ }
61
+ });
62
+ } catch (error) {
63
+ console.error('replaceInFiles 运行失败:', error);
64
+ }
65
+ }
66
+
67
+ replaceInFilesByMap_1 = replaceInFilesByMap;
68
+ return replaceInFilesByMap_1;
69
+ }
70
+
71
+ exports.__require = requireReplaceInFilesByMap;