@yangrunchi/a_6 1.0.7 → 1.0.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/Tools/svn-utils.js +31 -16
  2. package/package.json +1 -1
@@ -37,6 +37,20 @@ function isSvnAvailable() {
37
37
  return checkSvnEnvironment();
38
38
  }
39
39
 
40
+ // 从给定路径向上查找包含 .svn 的目录(包含自身)
41
+ function findSvnRoot(startPath) {
42
+ let dir = startPath;
43
+ while (dir) {
44
+ if (fs.existsSync(path.join(dir, '.svn'))) {
45
+ return dir;
46
+ }
47
+ const parent = path.dirname(dir);
48
+ if (parent === dir) break;
49
+ dir = parent;
50
+ }
51
+ return null;
52
+ }
53
+
40
54
  function runCommand(svnPath, description) {
41
55
  if (!isSvnAvailable()) {
42
56
  console.log(`⚠️ ${description}跳过: SVN环境问题`);
@@ -44,18 +58,16 @@ function runCommand(svnPath, description) {
44
58
  }
45
59
 
46
60
  try {
47
- // 计算项目根目录(从 svnPath 向上查找包含 .svn 的目录)
48
- let projectRoot = svnPath;
49
- while (projectRoot && !fs.existsSync(path.join(projectRoot, '.svn'))) {
50
- const parent = path.dirname(projectRoot);
51
- if (parent === projectRoot) break;
52
- projectRoot = parent;
61
+ // svnPath 向上查找 .svn,找不到则从 M2_PROJECT_ROOT 查找
62
+ let projectRoot = findSvnRoot(svnPath);
63
+ if (!projectRoot && process.env.M2_PROJECT_ROOT) {
64
+ projectRoot = findSvnRoot(process.env.M2_PROJECT_ROOT);
53
65
  }
54
66
 
55
67
  const result = spawnSync('svn', ['update', svnPath], {
56
68
  encoding: 'utf8',
57
69
  stdio: 'inherit',
58
- cwd: projectRoot || undefined
70
+ cwd: projectRoot || process.cwd()
59
71
  });
60
72
 
61
73
  if (result.status === 0) {
@@ -81,12 +93,10 @@ function runCommit(filePaths, description) {
81
93
  // 如果传入的是数组,转换为多个参数
82
94
  const paths = Array.isArray(filePaths) ? filePaths : [filePaths];
83
95
 
84
- // 计算项目根目录(从第一个文件路径向上查找包含 .svn 的目录)
85
- let projectRoot = paths[0];
86
- while (projectRoot && !fs.existsSync(path.join(projectRoot, '.svn'))) {
87
- const parent = path.dirname(projectRoot);
88
- if (parent === projectRoot) break;
89
- projectRoot = parent;
96
+ // 从文件路径向上查找 .svn,找不到则从 M2_PROJECT_ROOT 查找
97
+ let projectRoot = findSvnRoot(paths[0]);
98
+ if (!projectRoot && process.env.M2_PROJECT_ROOT) {
99
+ projectRoot = findSvnRoot(process.env.M2_PROJECT_ROOT);
90
100
  }
91
101
 
92
102
  const args = ['commit', ...paths, '-m', description];
@@ -95,7 +105,7 @@ function runCommit(filePaths, description) {
95
105
  encoding: 'buffer',
96
106
  env: { ...process.env, LANG: 'zh_CN.UTF-8' },
97
107
  stdio: 'inherit',
98
- cwd: projectRoot || undefined
108
+ cwd: projectRoot || process.cwd()
99
109
  });
100
110
 
101
111
  if (result.status === 0) {
@@ -143,9 +153,13 @@ function cleanDirectory(targetPath) {
143
153
  */
144
154
  function getSVNAuthor(projectRoot, fallbackAuthor) {
145
155
  try {
156
+ // 找到 SVN 工作目录作为 cwd
157
+ const svnCwd = findSvnRoot(projectRoot) || process.env.M2_PROJECT_ROOT || projectRoot;
158
+
146
159
  // 获取当前仓库的地址(用于匹配 svn auth 中的 realm)
147
160
  const reposUrl = execSync(`svn info --show-item=repos-root-url "${projectRoot}"`, {
148
- encoding: 'utf-8'
161
+ encoding: 'utf-8',
162
+ cwd: svnCwd
149
163
  }).trim();
150
164
 
151
165
  // 提取仓库主机地址(如 "192.168.13.64"),兼容有无端口号、不同协议
@@ -153,7 +167,8 @@ function getSVNAuthor(projectRoot, fallbackAuthor) {
153
167
 
154
168
  // 解析 svn auth 输出,匹配当前仓库的用户名
155
169
  const authOutput = execSync('svn auth --non-interactive', {
156
- encoding: 'utf-8'
170
+ encoding: 'utf-8',
171
+ cwd: svnCwd
157
172
  });
158
173
 
159
174
  // 按分隔线分割每个认证条目
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@yangrunchi/a_6",
3
- "version": "1.0.7",
3
+ "version": "1.0.9",
4
4
  "description": "996M2 客户端 Node.js 工具集 — 协议同步、自动生成代码、CSV配置、SVN管理、BAT脚本管理器",
5
5
  "main": "index.js",
6
6
  "bin": {