@apdesign/code-style-react 1.1.4 → 1.1.5

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@apdesign/code-style-react",
3
- "version": "1.1.4",
3
+ "version": "1.1.5",
4
4
  "scripts": {},
5
5
  "bin": {
6
6
  "apdesign-code-style": "cli.js"
@@ -31,6 +31,8 @@ async function runEslint() {
31
31
  // 默认并发数为 CPU 核心数,但不超过 8
32
32
  let maxWorkers = Math.min(os.cpus().length, 8);
33
33
 
34
+ let branchArg = null;
35
+
34
36
  // 找到 --max-workers 参数
35
37
  const maxWorkersArgIndex = args.indexOf('--max-workers');
36
38
  if (maxWorkersArgIndex !== -1 && args[maxWorkersArgIndex + 1]) {
@@ -44,12 +46,22 @@ async function runEslint() {
44
46
  let targetPath = process.cwd();
45
47
  for (let i = 0; i < args.length; i++) {
46
48
  if (i === maxWorkersArgIndex || i === maxWorkersArgIndex + 1) continue;
47
- targetPath = args[i] || process.cwd();
48
- break;
49
+ if (!targetPath || targetPath === process.cwd()) {
50
+ targetPath = args[i];
51
+ continue;
52
+ }
53
+ }
54
+
55
+ // 检查是否有分支参数 (--branch <branchName>)
56
+ const branchIndex = args.indexOf('--branch');
57
+ if (branchIndex !== -1 && args[branchIndex + 1]) {
58
+ branchArg = args[branchIndex + 1];
49
59
  }
50
60
 
51
- console.log(`目标路径: ${targetPath}`);
52
- console.log(`使用并发数: ${maxWorkers}`);
61
+ console.log(`\n[ESLint 启动配置]`);
62
+ console.log(`- 检查路径: ${targetPath}`);
63
+ console.log(`- 并发进程数: ${maxWorkers}`);
64
+ console.log('');
53
65
 
54
66
  // 路径解析
55
67
  let rootDir = path.resolve(targetPath);
@@ -80,14 +92,12 @@ async function runEslint() {
80
92
  }
81
93
 
82
94
  const gitRoot = gitRootResult.stdout.trim();
83
- console.log('Git 根目录:', gitRoot);
84
95
 
85
96
  let targetBranch = 'master';
86
97
  if (targetPath !== process.cwd()) {
87
98
  const lastDir = path.basename(rootDir);
88
99
  targetBranch = `master-${lastDir.split('-').pop()}`;
89
100
  }
90
- console.log('目标分支:', targetBranch);
91
101
 
92
102
  // 获取当前分支
93
103
  const currentBranchResult = spawnSync('git', ['rev-parse', '--abbrev-ref', 'HEAD'], {
@@ -102,7 +112,12 @@ async function runEslint() {
102
112
  }
103
113
 
104
114
  const currentBranch = currentBranchResult.stdout.trim();
105
- console.log('当前分支:', currentBranch);
115
+
116
+ console.log(`[Git 信息]`);
117
+ console.log(`- 仓库根目录: ${gitRoot}`);
118
+ console.log(`- 当前分支: ${currentBranch}`);
119
+ console.log(`- 目标分支: ${branchArg || targetBranch}`);
120
+ console.log('');
106
121
 
107
122
  const statusResult = spawnSync('git', ['status', '--porcelain'], {
108
123
  cwd: gitRoot,
@@ -111,13 +126,13 @@ async function runEslint() {
111
126
  });
112
127
  if (statusResult.status === 0 && statusResult.stdout.trim()) {
113
128
  console.warn(
114
- '当前分支有未提交的更改,切换分支可能失败或覆盖未提交内容,请确保已保存或提交更改!',
129
+ '⚠️ 检测到当前分支有未提交的更改,切换分支可能失败或导致代码丢失,请先提交或暂存更改!\n',
115
130
  );
116
131
  }
117
132
 
118
133
  // 切换分支并拉取最新代码
119
- if (currentBranch !== targetBranch) {
120
- console.log(`切换到分支 ${targetBranch} ...`);
134
+ if (!branchArg && currentBranch !== targetBranch) {
135
+ console.log(`➡️ 切换到分支 ${targetBranch} ...`);
121
136
  const checkout = spawnSync('git', ['checkout', targetBranch], {
122
137
  cwd: gitRoot,
123
138
  stdio: 'inherit',
@@ -127,9 +142,11 @@ async function runEslint() {
127
142
  console.error(`切换分支失败`);
128
143
  process.exit(1);
129
144
  }
145
+ } else if (branchArg) {
146
+ console.log(`➡️ 使用指定分支 ${branchArg} `);
130
147
  }
131
148
 
132
- console.log('拉取最新代码...');
149
+ console.log('⬇️ 正在拉取最新代码...');
133
150
  const pull = spawnSync('git', ['pull'], {
134
151
  cwd: gitRoot,
135
152
  stdio: 'inherit',
@@ -148,8 +165,6 @@ async function runEslint() {
148
165
  console.log(`检查目录: ${eslintTarget}`);
149
166
  }
150
167
 
151
- // 并行 ESLint
152
- console.log('并行执行 ESLint...');
153
168
  const allFiles = glob.sync('**/*.{js,jsx,ts,tsx}', { cwd: eslintTarget, absolute: true });
154
169
  if (allFiles.length === 0) {
155
170
  console.log('没有需要检查的文件');
@@ -166,7 +181,12 @@ async function runEslint() {
166
181
  let finished = 0;
167
182
  let hasError = false;
168
183
 
169
- console.log(`总文件数: ${allFiles.length}, 分成 ${chunks.length} 个 chunk 并行执行`);
184
+ // 并行 ESLint
185
+ console.log(`[ESLint 执行]`);
186
+ console.log(`- 共计文件: ${allFiles.length}`);
187
+ console.log(`- 拆分任务: ${chunks.length} 个`);
188
+ console.log('');
189
+ console.log('🚀 开始并行执行 ESLint ...\n');
170
190
 
171
191
  chunks.forEach((chunk) => {
172
192
  const eslint = spawn(