@yangrunchi/a_6 1.0.8 → 1.1.0

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.
@@ -78,8 +78,7 @@ try {
78
78
  }
79
79
 
80
80
  // 自动获取 SVN 账户名(覆盖 config.author)
81
- const projectRootForAuthor = path.resolve(__dirname, '../../..');
82
- config.author = getSVNAuthor(projectRootForAuthor, config.author);
81
+ config.author = getSVNAuthor(projectRoot, config.author);
83
82
  console.log('✅ 已加载配置, 作者:', config.author);
84
83
 
85
84
  console.log('🚀 开始生成 funcData 类...');
@@ -133,7 +132,8 @@ function commitToSvn(filePath, action, responseCount = 0, requestCount = 0) {
133
132
 
134
133
  try {
135
134
  const fileName = path.basename(filePath);
136
- const projectRootForSvn = path.resolve(__dirname, '../../..');
135
+ // 使用模块级 projectRoot 而非 __dirname 推算(npm 全局安装时 __dirname 在 node_modules 下)
136
+ const projectRootForSvn = projectRoot;
137
137
 
138
138
  let isVersioned = false;
139
139
  try {
@@ -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,25 +58,10 @@ 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;
53
- }
54
-
55
- // 如果从 svnPath 向上找不到 .svn,尝试用 M2_PROJECT_ROOT 环境变量
56
- if (!projectRoot || !fs.existsSync(path.join(projectRoot, '.svn'))) {
57
- if (process.env.M2_PROJECT_ROOT) {
58
- projectRoot = process.env.M2_PROJECT_ROOT;
59
- // 从项目根目录向上查找 .svn(.svn 通常在项目根目录或上级)
60
- while (projectRoot && !fs.existsSync(path.join(projectRoot, '.svn'))) {
61
- const parent = path.dirname(projectRoot);
62
- if (parent === projectRoot) break;
63
- projectRoot = parent;
64
- }
65
- }
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);
66
65
  }
67
66
 
68
67
  const result = spawnSync('svn', ['update', svnPath], {
@@ -94,24 +93,10 @@ function runCommit(filePaths, description) {
94
93
  // 如果传入的是数组,转换为多个参数
95
94
  const paths = Array.isArray(filePaths) ? filePaths : [filePaths];
96
95
 
97
- // 计算项目根目录(从第一个文件路径向上查找包含 .svn 的目录)
98
- let projectRoot = paths[0];
99
- while (projectRoot && !fs.existsSync(path.join(projectRoot, '.svn'))) {
100
- const parent = path.dirname(projectRoot);
101
- if (parent === projectRoot) break;
102
- projectRoot = parent;
103
- }
104
-
105
- // 如果从文件路径向上找不到 .svn,尝试用 M2_PROJECT_ROOT 环境变量
106
- if (!projectRoot || !fs.existsSync(path.join(projectRoot, '.svn'))) {
107
- if (process.env.M2_PROJECT_ROOT) {
108
- projectRoot = process.env.M2_PROJECT_ROOT;
109
- while (projectRoot && !fs.existsSync(path.join(projectRoot, '.svn'))) {
110
- const parent = path.dirname(projectRoot);
111
- if (parent === projectRoot) break;
112
- projectRoot = parent;
113
- }
114
- }
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);
115
100
  }
116
101
 
117
102
  const args = ['commit', ...paths, '-m', description];
@@ -168,9 +153,13 @@ function cleanDirectory(targetPath) {
168
153
  */
169
154
  function getSVNAuthor(projectRoot, fallbackAuthor) {
170
155
  try {
156
+ // 找到 SVN 工作目录作为 cwd
157
+ const svnCwd = findSvnRoot(projectRoot) || process.env.M2_PROJECT_ROOT || projectRoot;
158
+
171
159
  // 获取当前仓库的地址(用于匹配 svn auth 中的 realm)
172
160
  const reposUrl = execSync(`svn info --show-item=repos-root-url "${projectRoot}"`, {
173
- encoding: 'utf-8'
161
+ encoding: 'utf-8',
162
+ cwd: svnCwd
174
163
  }).trim();
175
164
 
176
165
  // 提取仓库主机地址(如 "192.168.13.64"),兼容有无端口号、不同协议
@@ -178,7 +167,8 @@ function getSVNAuthor(projectRoot, fallbackAuthor) {
178
167
 
179
168
  // 解析 svn auth 输出,匹配当前仓库的用户名
180
169
  const authOutput = execSync('svn auth --non-interactive', {
181
- encoding: 'utf-8'
170
+ encoding: 'utf-8',
171
+ cwd: svnCwd
182
172
  });
183
173
 
184
174
  // 按分隔线分割每个认证条目
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@yangrunchi/a_6",
3
- "version": "1.0.8",
3
+ "version": "1.1.0",
4
4
  "description": "996M2 客户端 Node.js 工具集 — 协议同步、自动生成代码、CSV配置、SVN管理、BAT脚本管理器",
5
5
  "main": "index.js",
6
6
  "bin": {