zen-gitsync 2.11.39 → 2.12.3
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/LICENSE +190 -21
- package/README.md +695 -695
- package/index.js +25 -11
- package/package.json +2 -2
- package/scripts/convert-colors-to-vars.cjs +286 -272
- package/scripts/convert-fontsize-to-vars.cjs +221 -207
- package/scripts/convert-spacing-to-vars.cjs +256 -242
- package/scripts/convert-to-standard-vars.cjs +282 -268
- package/scripts/release.js +599 -585
- package/src/config.js +350 -336
- package/src/gitCommit.js +455 -440
- package/src/ui/public/assets/EditorView-CbqSI9nw.css +1 -0
- package/src/ui/public/assets/EditorView-GS5cmh99.js +21 -0
- package/src/ui/public/assets/SourceMapView-DyMK80hS.css +1 -0
- package/src/ui/public/assets/SourceMapView-_YRtzmZZ.js +3 -0
- package/src/ui/public/assets/index-ML5Y-5lO.css +1 -0
- package/src/ui/public/assets/index-yky0Sd13.js +73 -0
- package/src/ui/public/assets/{ts.worker-Dth06zuC.js → ts.worker-METxwbDZ.js} +1 -16
- package/src/ui/public/assets/{vendor-B1T2uxYO.js → vendor-DITsiaGj.js} +294 -287
- package/src/ui/public/assets/vendor-q83wvJns.css +1 -0
- package/src/ui/public/index.html +4 -4
- package/src/ui/server/.claude/codediff.txt +6 -0
- package/src/ui/server/index.js +410 -396
- package/src/ui/server/middleware/requestLogger.js +51 -37
- package/src/ui/server/routes/branchStatus.js +101 -87
- package/src/ui/server/routes/code.js +110 -96
- package/src/ui/server/routes/codeAnalysis.js +995 -981
- package/src/ui/server/routes/config.js +1172 -1158
- package/src/ui/server/routes/exec.js +272 -258
- package/src/ui/server/routes/fileOpen.js +279 -265
- package/src/ui/server/routes/fs.js +701 -699
- package/src/ui/server/routes/git/diff.js +352 -338
- package/src/ui/server/routes/git/diffUtils.js +128 -114
- package/src/ui/server/routes/git/stash.js +552 -538
- package/src/ui/server/routes/git/tags.js +172 -158
- package/src/ui/server/routes/git.js +190 -176
- package/src/ui/server/routes/gitOps.js +1179 -1165
- package/src/ui/server/routes/instances.js +38 -24
- package/src/ui/server/routes/npm.js +1023 -1009
- package/src/ui/server/routes/process.js +82 -68
- package/src/ui/server/routes/status.js +67 -53
- package/src/ui/server/routes/terminal.js +319 -305
- package/src/ui/server/socket/registerUiSocketHandlers.js +226 -212
- package/src/ui/server/utils/createSavePortToFile.js +46 -32
- package/src/ui/server/utils/instanceRegistry.js +270 -256
- package/src/ui/server/utils/pathGuard.js +155 -0
- package/src/ui/server/utils/pathGuard.test.js +138 -0
- package/src/ui/server/utils/randomStartPort.js +51 -37
- package/src/ui/server/utils/startServerOnAvailablePort.js +101 -87
- package/src/utils/index.js +1058 -1044
- package/src/ui/public/assets/devopicons-QN4QXivI.woff2 +0 -0
- package/src/ui/public/assets/file-icons-C0jOugUK.woff2 +0 -0
- package/src/ui/public/assets/fontawesome-B-jkhYfk.woff2 +0 -0
- package/src/ui/public/assets/index-BvVl-092.js +0 -95
- package/src/ui/public/assets/index-DXO3Lvqi.css +0 -1
- package/src/ui/public/assets/mfixx-CpAhKOZz.woff2 +0 -0
- package/src/ui/public/assets/octicons-CaZ_fok2.woff2 +0 -0
- package/src/ui/public/assets/vendor-hOO_r_AU.css +0 -1
package/index.js
CHANGED
|
@@ -1,11 +1,25 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
//
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
//
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
1
|
+
// Copyright 2026 xz333221
|
|
2
|
+
//
|
|
3
|
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
// you may not use this file except in compliance with the License.
|
|
5
|
+
// You may obtain a copy of the License at
|
|
6
|
+
//
|
|
7
|
+
// http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
//
|
|
9
|
+
// Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
// See the License for the specific language governing permissions and
|
|
13
|
+
// limitations under the License.
|
|
14
|
+
//
|
|
15
|
+
import config from './src/config.js'
|
|
16
|
+
import startUIServer from './src/ui/server/index.js'
|
|
17
|
+
|
|
18
|
+
// 导出配置
|
|
19
|
+
export { config as default }
|
|
20
|
+
|
|
21
|
+
// 导出启动服务器函数
|
|
22
|
+
export async function startServer(noOpen = false) {
|
|
23
|
+
// 当通过 npm script 启动服务器时,应该保存端口信息
|
|
24
|
+
return startUIServer(noOpen, true) // 传递 savePort=true
|
|
25
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "zen-gitsync",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.12.3",
|
|
4
4
|
"description": "A Git automation platform with interactive commits, scheduled sync, command orchestration, file locking, and a visual GUI.",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"type": "module",
|
|
@@ -65,7 +65,7 @@
|
|
|
65
65
|
"git"
|
|
66
66
|
],
|
|
67
67
|
"author": "",
|
|
68
|
-
"license": "
|
|
68
|
+
"license": "Apache-2.0",
|
|
69
69
|
"bugs": {
|
|
70
70
|
"url": "https://github.com/xz333221/zen-gitsync/issues"
|
|
71
71
|
},
|
|
@@ -1,272 +1,286 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
'#
|
|
37
|
-
'#
|
|
38
|
-
'#
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
'#
|
|
44
|
-
'#
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
'#
|
|
52
|
-
'#
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
'#
|
|
58
|
-
'#
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
'#
|
|
62
|
-
'#
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
'#
|
|
66
|
-
'#
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
'#
|
|
72
|
-
'#
|
|
73
|
-
'#
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
'#
|
|
77
|
-
'#
|
|
78
|
-
'#
|
|
79
|
-
'#
|
|
80
|
-
'#
|
|
81
|
-
|
|
82
|
-
//
|
|
83
|
-
'#
|
|
84
|
-
'#
|
|
85
|
-
'#
|
|
86
|
-
'#
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
'#
|
|
91
|
-
'#
|
|
92
|
-
'#
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
}
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
console.log(
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
}
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
}
|
|
271
|
-
|
|
272
|
-
|
|
1
|
+
// Copyright 2026 xz333221
|
|
2
|
+
//
|
|
3
|
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
// you may not use this file except in compliance with the License.
|
|
5
|
+
// You may obtain a copy of the License at
|
|
6
|
+
//
|
|
7
|
+
// http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
//
|
|
9
|
+
// Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
// See the License for the specific language governing permissions and
|
|
13
|
+
// limitations under the License.
|
|
14
|
+
//
|
|
15
|
+
/**
|
|
16
|
+
* 将项目中硬编码的颜色值转换为 CSS 变量
|
|
17
|
+
*
|
|
18
|
+
* 根据 variables.scss 中定义的颜色变量进行映射
|
|
19
|
+
*
|
|
20
|
+
* 使用方式:
|
|
21
|
+
* node scripts/convert-colors-to-vars.cjs [--dry-run]
|
|
22
|
+
*
|
|
23
|
+
* --dry-run: 预览模式,不实际修改文件
|
|
24
|
+
*/
|
|
25
|
+
|
|
26
|
+
const fs = require('fs');
|
|
27
|
+
const path = require('path');
|
|
28
|
+
|
|
29
|
+
// 获取命令行参数
|
|
30
|
+
const args = process.argv.slice(2);
|
|
31
|
+
const isDryRun = args.includes('--dry-run');
|
|
32
|
+
|
|
33
|
+
// 颜色映射表(基于 variables.scss)
|
|
34
|
+
const COLOR_MAP = {
|
|
35
|
+
// 主色调
|
|
36
|
+
'#409eff': 'var(--color-primary)',
|
|
37
|
+
'#5a67d8': 'var(--color-primary-light)',
|
|
38
|
+
'#337ecc': 'var(--color-primary-dark)',
|
|
39
|
+
'#66b1ff': 'var(--color-primary-light)',
|
|
40
|
+
'#a0cfff': 'var(--color-primary-light)',
|
|
41
|
+
|
|
42
|
+
// 成功色
|
|
43
|
+
'#67c23a': 'var(--color-success)',
|
|
44
|
+
'#10b981': 'var(--color-success-light)',
|
|
45
|
+
'#85ce61': 'var(--color-success)',
|
|
46
|
+
'#b3e19d': 'var(--color-success)',
|
|
47
|
+
|
|
48
|
+
// 警告色
|
|
49
|
+
'#e6a23c': 'var(--color-warning)',
|
|
50
|
+
'#f59e0b': 'var(--color-warning-light)',
|
|
51
|
+
'#ebb563': 'var(--color-warning)',
|
|
52
|
+
'#f3d19e': 'var(--color-warning)',
|
|
53
|
+
|
|
54
|
+
// 危险色
|
|
55
|
+
'#f56c6c': 'var(--color-danger)',
|
|
56
|
+
'#ef4444': 'var(--color-danger-light)',
|
|
57
|
+
'#dc2626': 'var(--color-danger-dark)',
|
|
58
|
+
'#f78989': 'var(--color-danger)',
|
|
59
|
+
|
|
60
|
+
// 信息色
|
|
61
|
+
'#909399': 'var(--color-info)',
|
|
62
|
+
'#8b5cf6': 'var(--color-info-light)',
|
|
63
|
+
|
|
64
|
+
// 基础颜色
|
|
65
|
+
'#ffffff': 'var(--color-white)',
|
|
66
|
+
'#fff': 'var(--color-white)',
|
|
67
|
+
'#000000': 'var(--color-black)',
|
|
68
|
+
'#000': 'var(--color-black)',
|
|
69
|
+
|
|
70
|
+
// 灰色系列
|
|
71
|
+
'#f9fafb': 'var(--color-gray-50)',
|
|
72
|
+
'#f3f4f6': 'var(--color-gray-100)',
|
|
73
|
+
'#e5e7eb': 'var(--color-gray-200)',
|
|
74
|
+
'#d1d5db': 'var(--color-gray-300)',
|
|
75
|
+
'#9ca3af': 'var(--color-gray-400)',
|
|
76
|
+
'#6b7280': 'var(--color-gray-500)',
|
|
77
|
+
'#4b5563': 'var(--color-gray-600)',
|
|
78
|
+
'#374151': 'var(--color-gray-700)',
|
|
79
|
+
'#1f2937': 'var(--color-gray-800)',
|
|
80
|
+
'#111827': 'var(--color-gray-900)',
|
|
81
|
+
|
|
82
|
+
// 文字颜色
|
|
83
|
+
'#303133': 'var(--text-primary)',
|
|
84
|
+
'#606266': 'var(--text-secondary)',
|
|
85
|
+
'#909399': 'var(--text-tertiary)',
|
|
86
|
+
'#c0c4cc': 'var(--text-placeholder)',
|
|
87
|
+
'#a8abb2': 'var(--text-placeholder)',
|
|
88
|
+
|
|
89
|
+
// Git 状态颜色
|
|
90
|
+
'#10b981': 'var(--git-status-added)',
|
|
91
|
+
'#f59e0b': 'var(--git-status-modified)',
|
|
92
|
+
'#ef4444': 'var(--git-status-deleted)',
|
|
93
|
+
'#8b5cf6': 'var(--git-status-untracked)',
|
|
94
|
+
'#f97316': 'var(--git-status-conflicted)',
|
|
95
|
+
|
|
96
|
+
// 背景色(特殊)
|
|
97
|
+
'#f5f5f5': 'var(--bg-page)',
|
|
98
|
+
'#f8fafc': 'var(--bg-container-hover)',
|
|
99
|
+
'#2d2d2d': 'var(--bg-code-dark)',
|
|
100
|
+
'#f6f8fa': 'var(--bg-code)',
|
|
101
|
+
|
|
102
|
+
// 其他常见颜色
|
|
103
|
+
'#f8faff': '#f8faff', // 特殊渐变色,暂时保留
|
|
104
|
+
'#eef4ff': '#eef4ff',
|
|
105
|
+
'#fff2e6': '#fff2e6',
|
|
106
|
+
'#f8f8f2': '#f8f8f2',
|
|
107
|
+
};
|
|
108
|
+
|
|
109
|
+
// 需要处理的文件扩展名
|
|
110
|
+
const TARGET_EXTENSIONS = ['.vue', '.scss', '.css'];
|
|
111
|
+
|
|
112
|
+
// 需要跳过的文件
|
|
113
|
+
const SKIP_FILES = ['variables.scss', 'dark-theme.scss'];
|
|
114
|
+
|
|
115
|
+
// 统计信息
|
|
116
|
+
let stats = {
|
|
117
|
+
totalFiles: 0,
|
|
118
|
+
modifiedFiles: 0,
|
|
119
|
+
totalReplacements: 0,
|
|
120
|
+
replacementDetails: {},
|
|
121
|
+
skippedColors: new Set(),
|
|
122
|
+
};
|
|
123
|
+
|
|
124
|
+
console.log(`\n运行模式: ${isDryRun ? '预览模式(不会修改文件)' : '修改模式'}\n`);
|
|
125
|
+
|
|
126
|
+
/**
|
|
127
|
+
* 递归扫描目录
|
|
128
|
+
*/
|
|
129
|
+
function scanDirectory(dir, fileList = []) {
|
|
130
|
+
const files = fs.readdirSync(dir);
|
|
131
|
+
|
|
132
|
+
files.forEach(file => {
|
|
133
|
+
const filePath = path.join(dir, file);
|
|
134
|
+
const stat = fs.statSync(filePath);
|
|
135
|
+
|
|
136
|
+
if (stat.isDirectory()) {
|
|
137
|
+
if (file !== 'node_modules' && file !== '.git' && file !== 'dist') {
|
|
138
|
+
scanDirectory(filePath, fileList);
|
|
139
|
+
}
|
|
140
|
+
} else {
|
|
141
|
+
const ext = path.extname(file);
|
|
142
|
+
if (TARGET_EXTENSIONS.includes(ext) && !SKIP_FILES.includes(file)) {
|
|
143
|
+
fileList.push(filePath);
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
});
|
|
147
|
+
|
|
148
|
+
return fileList;
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
/**
|
|
152
|
+
* 规范化颜色值(统一为小写)
|
|
153
|
+
*/
|
|
154
|
+
function normalizeColor(color) {
|
|
155
|
+
return color.toLowerCase();
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
/**
|
|
159
|
+
* 处理文件内容
|
|
160
|
+
*/
|
|
161
|
+
function processFileContent(content, filePath) {
|
|
162
|
+
let modified = false;
|
|
163
|
+
let newContent = content;
|
|
164
|
+
|
|
165
|
+
// 匹配 6位 和 3位 十六进制颜色
|
|
166
|
+
const colorRegex = /#([0-9a-fA-F]{6}|[0-9a-fA-F]{3})\b/g;
|
|
167
|
+
|
|
168
|
+
newContent = newContent.replace(colorRegex, (match) => {
|
|
169
|
+
const normalizedColor = normalizeColor(match);
|
|
170
|
+
|
|
171
|
+
// 如果是3位颜色,展开为6位
|
|
172
|
+
let expandedColor = normalizedColor;
|
|
173
|
+
if (normalizedColor.length === 4) {
|
|
174
|
+
expandedColor = '#' + normalizedColor[1] + normalizedColor[1] +
|
|
175
|
+
normalizedColor[2] + normalizedColor[2] +
|
|
176
|
+
normalizedColor[3] + normalizedColor[3];
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
// 查找映射
|
|
180
|
+
const mappedVar = COLOR_MAP[normalizedColor] || COLOR_MAP[expandedColor];
|
|
181
|
+
|
|
182
|
+
if (mappedVar && mappedVar !== match) {
|
|
183
|
+
// 记录替换
|
|
184
|
+
stats.replacementDetails[match] = (stats.replacementDetails[match] || 0) + 1;
|
|
185
|
+
stats.totalReplacements++;
|
|
186
|
+
modified = true;
|
|
187
|
+
return mappedVar;
|
|
188
|
+
} else if (!mappedVar) {
|
|
189
|
+
// 记录未映射的颜色
|
|
190
|
+
stats.skippedColors.add(match);
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
return match;
|
|
194
|
+
});
|
|
195
|
+
|
|
196
|
+
return { content: newContent, modified };
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
/**
|
|
200
|
+
* 处理单个文件
|
|
201
|
+
*/
|
|
202
|
+
function processFile(filePath) {
|
|
203
|
+
try {
|
|
204
|
+
const content = fs.readFileSync(filePath, 'utf8');
|
|
205
|
+
const { content: newContent, modified } = processFileContent(content, filePath);
|
|
206
|
+
|
|
207
|
+
if (modified) {
|
|
208
|
+
if (!isDryRun) {
|
|
209
|
+
fs.writeFileSync(filePath, newContent, 'utf8');
|
|
210
|
+
}
|
|
211
|
+
stats.modifiedFiles++;
|
|
212
|
+
console.log(`${isDryRun ? '📋 [预览]' : '✅'} ${filePath}`);
|
|
213
|
+
return true;
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
return false;
|
|
217
|
+
} catch (error) {
|
|
218
|
+
console.error(`❌ 处理文件失败: ${filePath}`, error.message);
|
|
219
|
+
return false;
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
/**
|
|
224
|
+
* 主函数
|
|
225
|
+
*/
|
|
226
|
+
function main() {
|
|
227
|
+
const projectRoot = path.join(__dirname, '..');
|
|
228
|
+
const srcDir = path.join(projectRoot, 'src');
|
|
229
|
+
|
|
230
|
+
console.log('🚀 开始扫描并转换颜色值...\n');
|
|
231
|
+
console.log(`📁 项目根目录: ${projectRoot}`);
|
|
232
|
+
console.log(`📁 扫描目录: ${srcDir}\n`);
|
|
233
|
+
|
|
234
|
+
// 扫描所有目标文件
|
|
235
|
+
const files = scanDirectory(srcDir);
|
|
236
|
+
stats.totalFiles = files.length;
|
|
237
|
+
|
|
238
|
+
console.log(`📊 找到 ${files.length} 个文件需要检查\n`);
|
|
239
|
+
console.log('🔄 开始处理文件...\n');
|
|
240
|
+
|
|
241
|
+
// 处理每个文件
|
|
242
|
+
files.forEach(file => {
|
|
243
|
+
processFile(file);
|
|
244
|
+
});
|
|
245
|
+
|
|
246
|
+
// 输出统计信息
|
|
247
|
+
console.log('\n' + '='.repeat(60));
|
|
248
|
+
console.log('📊 转换统计报告');
|
|
249
|
+
console.log('='.repeat(60));
|
|
250
|
+
console.log(`总文件数: ${stats.totalFiles}`);
|
|
251
|
+
console.log(`修改文件数: ${stats.modifiedFiles}`);
|
|
252
|
+
console.log(`总替换次数: ${stats.totalReplacements}`);
|
|
253
|
+
|
|
254
|
+
if (Object.keys(stats.replacementDetails).length > 0) {
|
|
255
|
+
console.log('\n📋 替换详情:');
|
|
256
|
+
Object.entries(stats.replacementDetails)
|
|
257
|
+
.sort((a, b) => b[1] - a[1])
|
|
258
|
+
.forEach(([color, count]) => {
|
|
259
|
+
const varName = COLOR_MAP[color.toLowerCase()];
|
|
260
|
+
console.log(` ${color} => ${varName}: ${count} 次`);
|
|
261
|
+
});
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
if (stats.skippedColors.size > 0) {
|
|
265
|
+
console.log('\n⚠️ 未映射的颜色(需要手动检查):');
|
|
266
|
+
Array.from(stats.skippedColors)
|
|
267
|
+
.sort()
|
|
268
|
+
.forEach(color => {
|
|
269
|
+
console.log(` ${color}`);
|
|
270
|
+
});
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
if (isDryRun) {
|
|
274
|
+
console.log('\n💡 提示: 这是预览模式,文件未被修改');
|
|
275
|
+
console.log(' 移除 --dry-run 参数以实际应用更改');
|
|
276
|
+
} else {
|
|
277
|
+
console.log('\n✨ 转换完成!');
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
// 运行主函数
|
|
282
|
+
if (require.main === module) {
|
|
283
|
+
main();
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
module.exports = { processFileContent };
|