zen-gitsync 2.7.16 → 2.8.1
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 +1 -1
- package/scripts/README_COLOR_CONVERTER.md +196 -0
- package/scripts/README_FONTSIZE_CONVERTER.md +278 -0
- package/scripts/README_SPACING_CONVERTER.md +126 -0
- package/scripts/README_STYLE_VARS.md +180 -0
- package/scripts/convert-colors-to-vars.cjs +272 -0
- package/scripts/convert-fontsize-to-vars.cjs +207 -0
- package/scripts/convert-spacing-to-vars.cjs +242 -0
- package/scripts/convert-to-standard-vars.cjs +268 -0
- package/src/ui/public/assets/index-BUCtbv5L.css +1 -0
- package/src/ui/public/assets/index-eW9KcCVJ.js +80 -0
- package/src/ui/public/assets/{vendor-CV-gp1cL.js → vendor-CzyB8oRh.js} +19 -19
- package/src/ui/public/index.html +3 -3
- package/src/ui/public/assets/index-DC2ZmrV6.js +0 -80
- package/src/ui/public/assets/index-XBl7lo3-.css +0 -1
- package/src/ui/public/assets/vscode-twqwGmNt.webp +0 -0
|
@@ -0,0 +1,242 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 将项目中所有 padding、margin、gap 相关属性的 px 值转换为标准的 CSS 变量
|
|
3
|
+
*
|
|
4
|
+
* 支持的属性:
|
|
5
|
+
* - padding, padding-top, padding-right, padding-bottom, padding-left
|
|
6
|
+
* - margin, margin-top, margin-right, margin-bottom, margin-left
|
|
7
|
+
* - gap, row-gap, column-gap
|
|
8
|
+
*
|
|
9
|
+
* 标准间距映射:
|
|
10
|
+
* 1px => 1px (保持原样,边框等特殊用途)
|
|
11
|
+
* 2px => var(--spacing-xs)
|
|
12
|
+
* 3px => 3px (保持原样,特殊值)
|
|
13
|
+
* 4px => var(--spacing-sm)
|
|
14
|
+
* 5px => 5px (保持原样,特殊值)
|
|
15
|
+
* 6px => 6px (保持原样,常用于紧凑布局)
|
|
16
|
+
* 8px => var(--spacing-base)
|
|
17
|
+
* 10px => 10px (保持原样,特殊值)
|
|
18
|
+
* 12px => var(--spacing-md)
|
|
19
|
+
* 16px => var(--spacing-lg)
|
|
20
|
+
* 18px => 18px (保持原样,字体相关)
|
|
21
|
+
* 20px => var(--spacing-xl)
|
|
22
|
+
* 24px => var(--spacing-2xl)
|
|
23
|
+
* 32px => var(--spacing-3xl)
|
|
24
|
+
* 40px => 40px (保持原样,大间距特殊值)
|
|
25
|
+
*
|
|
26
|
+
* 使用方式:
|
|
27
|
+
* node scripts/convert-spacing-to-vars.js [--strict]
|
|
28
|
+
*
|
|
29
|
+
* --strict: 严格模式,只替换精确匹配的值(2px, 4px, 8px, 12px, 16px, 20px, 24px, 32px)
|
|
30
|
+
* 默认模式:只替换标准间距值,保留特殊值(如 1px, 3px, 5px, 6px, 10px, 18px 等)
|
|
31
|
+
*/
|
|
32
|
+
|
|
33
|
+
const fs = require('fs');
|
|
34
|
+
const path = require('path');
|
|
35
|
+
|
|
36
|
+
// 获取命令行参数
|
|
37
|
+
const args = process.argv.slice(2);
|
|
38
|
+
const isStrictMode = args.includes('--strict');
|
|
39
|
+
|
|
40
|
+
// 间距映射表(精确匹配标准间距)
|
|
41
|
+
const SPACING_MAP = {
|
|
42
|
+
'2px': 'var(--spacing-xs)', // 2px
|
|
43
|
+
'4px': 'var(--spacing-sm)', // 4px
|
|
44
|
+
'8px': 'var(--spacing-base)', // 8px
|
|
45
|
+
'12px': 'var(--spacing-md)', // 12px
|
|
46
|
+
'16px': 'var(--spacing-lg)', // 16px
|
|
47
|
+
'20px': 'var(--spacing-xl)', // 20px
|
|
48
|
+
'24px': 'var(--spacing-2xl)', // 24px
|
|
49
|
+
'32px': 'var(--spacing-3xl)', // 32px
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
console.log(`\n运行模式: ${isStrictMode ? '严格模式(只替换标准间距)' : '默认模式(只替换标准间距)'}\n`);
|
|
53
|
+
|
|
54
|
+
// 需要处理的文件扩展名
|
|
55
|
+
const TARGET_EXTENSIONS = ['.vue', '.scss', '.css'];
|
|
56
|
+
|
|
57
|
+
// 需要处理的 CSS 属性(包括所有方向性变体)
|
|
58
|
+
const TARGET_PROPERTIES = [
|
|
59
|
+
'padding',
|
|
60
|
+
'padding-top',
|
|
61
|
+
'padding-right',
|
|
62
|
+
'padding-bottom',
|
|
63
|
+
'padding-left',
|
|
64
|
+
'margin',
|
|
65
|
+
'margin-top',
|
|
66
|
+
'margin-right',
|
|
67
|
+
'margin-bottom',
|
|
68
|
+
'margin-left',
|
|
69
|
+
'gap',
|
|
70
|
+
'row-gap',
|
|
71
|
+
'column-gap',
|
|
72
|
+
];
|
|
73
|
+
|
|
74
|
+
// 统计信息
|
|
75
|
+
let stats = {
|
|
76
|
+
totalFiles: 0,
|
|
77
|
+
modifiedFiles: 0,
|
|
78
|
+
totalReplacements: 0,
|
|
79
|
+
replacementDetails: {},
|
|
80
|
+
};
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* 递归扫描目录
|
|
84
|
+
*/
|
|
85
|
+
function scanDirectory(dir, fileList = []) {
|
|
86
|
+
const files = fs.readdirSync(dir);
|
|
87
|
+
|
|
88
|
+
files.forEach(file => {
|
|
89
|
+
const filePath = path.join(dir, file);
|
|
90
|
+
const stat = fs.statSync(filePath);
|
|
91
|
+
|
|
92
|
+
if (stat.isDirectory()) {
|
|
93
|
+
// 跳过 node_modules 和 .git 目录
|
|
94
|
+
if (file !== 'node_modules' && file !== '.git' && file !== 'dist') {
|
|
95
|
+
scanDirectory(filePath, fileList);
|
|
96
|
+
}
|
|
97
|
+
} else {
|
|
98
|
+
const ext = path.extname(file);
|
|
99
|
+
if (TARGET_EXTENSIONS.includes(ext)) {
|
|
100
|
+
fileList.push(filePath);
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
});
|
|
104
|
+
|
|
105
|
+
return fileList;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* 替换单个 px 值为变量
|
|
110
|
+
*/
|
|
111
|
+
function replacePxValue(value) {
|
|
112
|
+
if (SPACING_MAP[value]) {
|
|
113
|
+
const varName = SPACING_MAP[value];
|
|
114
|
+
// 记录替换详情
|
|
115
|
+
stats.replacementDetails[value] = (stats.replacementDetails[value] || 0) + 1;
|
|
116
|
+
stats.totalReplacements++;
|
|
117
|
+
return varName;
|
|
118
|
+
}
|
|
119
|
+
return value;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
/**
|
|
123
|
+
* 处理文件内容
|
|
124
|
+
*/
|
|
125
|
+
function processFileContent(content) {
|
|
126
|
+
let modified = false;
|
|
127
|
+
let newContent = content;
|
|
128
|
+
|
|
129
|
+
// 构建正则表达式,匹配 padding、margin、gap 属性
|
|
130
|
+
// 支持的格式:
|
|
131
|
+
// 1. padding: 12px;
|
|
132
|
+
// 2. padding: 12px 16px;
|
|
133
|
+
// 3. padding: 12px 16px 12px 16px;
|
|
134
|
+
// 4. padding: 12px var(--spacing-md);
|
|
135
|
+
TARGET_PROPERTIES.forEach(property => {
|
|
136
|
+
// 转义属性名中的连字符(如 padding-top 中的 -)
|
|
137
|
+
const escapedProperty = property.replace(/-/g, '\\-');
|
|
138
|
+
// 匹配属性及其值(包括多个值的情况)
|
|
139
|
+
const regex = new RegExp(
|
|
140
|
+
`(${escapedProperty}\\s*:\\s*)([^;{}]+)(;)`,
|
|
141
|
+
'g'
|
|
142
|
+
);
|
|
143
|
+
|
|
144
|
+
newContent = newContent.replace(regex, (match, prefix, values, suffix) => {
|
|
145
|
+
// 分割多个值
|
|
146
|
+
const parts = values.trim().split(/\s+/);
|
|
147
|
+
let hasChange = false;
|
|
148
|
+
|
|
149
|
+
// 处理每个值
|
|
150
|
+
const newParts = parts.map(part => {
|
|
151
|
+
// 检查是否是 px 值
|
|
152
|
+
if (/^\d+px$/.test(part)) {
|
|
153
|
+
const replaced = replacePxValue(part);
|
|
154
|
+
if (replaced !== part) {
|
|
155
|
+
hasChange = true;
|
|
156
|
+
return replaced;
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
return part;
|
|
160
|
+
});
|
|
161
|
+
|
|
162
|
+
if (hasChange) {
|
|
163
|
+
modified = true;
|
|
164
|
+
return prefix + newParts.join(' ') + suffix;
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
return match;
|
|
168
|
+
});
|
|
169
|
+
});
|
|
170
|
+
|
|
171
|
+
return { content: newContent, modified };
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
/**
|
|
175
|
+
* 处理单个文件
|
|
176
|
+
*/
|
|
177
|
+
function processFile(filePath) {
|
|
178
|
+
try {
|
|
179
|
+
const content = fs.readFileSync(filePath, 'utf8');
|
|
180
|
+
const { content: newContent, modified } = processFileContent(content);
|
|
181
|
+
|
|
182
|
+
if (modified) {
|
|
183
|
+
fs.writeFileSync(filePath, newContent, 'utf8');
|
|
184
|
+
stats.modifiedFiles++;
|
|
185
|
+
console.log(`✅ 已修改: ${filePath}`);
|
|
186
|
+
return true;
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
return false;
|
|
190
|
+
} catch (error) {
|
|
191
|
+
console.error(`❌ 处理文件失败: ${filePath}`, error.message);
|
|
192
|
+
return false;
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
/**
|
|
197
|
+
* 主函数
|
|
198
|
+
*/
|
|
199
|
+
function main() {
|
|
200
|
+
const projectRoot = path.join(__dirname, '..');
|
|
201
|
+
const srcDir = path.join(projectRoot, 'src');
|
|
202
|
+
|
|
203
|
+
console.log('🚀 开始扫描项目文件...\n');
|
|
204
|
+
console.log(`📁 项目根目录: ${projectRoot}`);
|
|
205
|
+
console.log(`📁 扫描目录: ${srcDir}\n`);
|
|
206
|
+
|
|
207
|
+
// 扫描所有目标文件
|
|
208
|
+
const files = scanDirectory(srcDir);
|
|
209
|
+
stats.totalFiles = files.length;
|
|
210
|
+
|
|
211
|
+
console.log(`📊 找到 ${files.length} 个文件需要检查\n`);
|
|
212
|
+
console.log('🔄 开始处理文件...\n');
|
|
213
|
+
|
|
214
|
+
// 处理每个文件
|
|
215
|
+
files.forEach(file => {
|
|
216
|
+
processFile(file);
|
|
217
|
+
});
|
|
218
|
+
|
|
219
|
+
// 输出统计信息
|
|
220
|
+
console.log('\n' + '='.repeat(60));
|
|
221
|
+
console.log('📊 转换统计报告');
|
|
222
|
+
console.log('='.repeat(60));
|
|
223
|
+
console.log(`总文件数: ${stats.totalFiles}`);
|
|
224
|
+
console.log(`修改文件数: ${stats.modifiedFiles}`);
|
|
225
|
+
console.log(`总替换次数: ${stats.totalReplacements}`);
|
|
226
|
+
console.log('\n📋 替换详情:');
|
|
227
|
+
|
|
228
|
+
Object.entries(stats.replacementDetails)
|
|
229
|
+
.sort((a, b) => b[1] - a[1])
|
|
230
|
+
.forEach(([px, count]) => {
|
|
231
|
+
console.log(` ${px} => ${SPACING_MAP[px]}: ${count} 次`);
|
|
232
|
+
});
|
|
233
|
+
|
|
234
|
+
console.log('\n✨ 转换完成!');
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
// 运行主函数
|
|
238
|
+
if (require.main === module) {
|
|
239
|
+
main();
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
module.exports = { processFileContent, replacePxValue };
|
|
@@ -0,0 +1,268 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 将项目中的 border-radius 和 box-shadow 值转换为标准的 CSS 变量
|
|
3
|
+
*
|
|
4
|
+
* 标准映射规则:
|
|
5
|
+
*
|
|
6
|
+
* border-radius:
|
|
7
|
+
* 2px => var(--radius-xs)
|
|
8
|
+
* 3px => var(--radius-sm)
|
|
9
|
+
* 4px => var(--radius-base)
|
|
10
|
+
* 6px => var(--radius-md)
|
|
11
|
+
* 8px => var(--radius-lg)
|
|
12
|
+
* 12px => var(--radius-xl)
|
|
13
|
+
*
|
|
14
|
+
* box-shadow:
|
|
15
|
+
* 0 1px 3px rgba(0, 0, 0, 0.04) => var(--shadow-sm)
|
|
16
|
+
* 0 1px 4px rgba(0, 0, 0, 0.04) => var(--shadow-base)
|
|
17
|
+
* 0 2px 8px rgba(0, 0, 0, 0.08) => var(--shadow-md)
|
|
18
|
+
* 0 4px 12px rgba(0, 0, 0, 0.08) => var(--shadow-lg)
|
|
19
|
+
* 0 8px 24px rgba(0, 0, 0, 0.12) => var(--shadow-xl)
|
|
20
|
+
*
|
|
21
|
+
* 使用方式:
|
|
22
|
+
* node scripts/convert-to-standard-vars.js [--dry-run]
|
|
23
|
+
*
|
|
24
|
+
* --dry-run: 仅预览更改,不实际修改文件
|
|
25
|
+
*/
|
|
26
|
+
|
|
27
|
+
const fs = require('fs');
|
|
28
|
+
const path = require('path');
|
|
29
|
+
|
|
30
|
+
// 获取命令行参数
|
|
31
|
+
const args = process.argv.slice(2);
|
|
32
|
+
const isDryRun = args.includes('--dry-run');
|
|
33
|
+
|
|
34
|
+
// border-radius 映射表
|
|
35
|
+
const RADIUS_MAP = {
|
|
36
|
+
'2px': 'var(--radius-xs)',
|
|
37
|
+
'3px': 'var(--radius-sm)',
|
|
38
|
+
'4px': 'var(--radius-base)',
|
|
39
|
+
'6px': 'var(--radius-md)',
|
|
40
|
+
'8px': 'var(--radius-lg)',
|
|
41
|
+
'12px': 'var(--radius-xl)',
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
// box-shadow 映射表(精确匹配)
|
|
45
|
+
const SHADOW_MAP = {
|
|
46
|
+
// 基础阴影
|
|
47
|
+
'0 1px 3px rgba(0, 0, 0, 0.04)': 'var(--shadow-sm)',
|
|
48
|
+
'0 1px 4px rgba(0, 0, 0, 0.04)': 'var(--shadow-base)',
|
|
49
|
+
'0 2px 8px rgba(0, 0, 0, 0.08)': 'var(--shadow-md)',
|
|
50
|
+
'0 4px 12px rgba(0, 0, 0, 0.08)': 'var(--shadow-lg)',
|
|
51
|
+
'0 8px 24px rgba(0, 0, 0, 0.12)': 'var(--shadow-xl)',
|
|
52
|
+
|
|
53
|
+
// 常见变体(不同透明度)
|
|
54
|
+
'0 2px 8px rgba(0, 0, 0, 0.1)': 'var(--shadow-md)',
|
|
55
|
+
'0 4px 12px rgba(0, 0, 0, 0.1)': 'var(--shadow-lg)',
|
|
56
|
+
'0 2px 6px rgba(0, 0, 0, 0.1)': 'var(--shadow-sm)',
|
|
57
|
+
'0 2px 12px rgba(0, 0, 0, 0.08)': 'var(--shadow-md)',
|
|
58
|
+
'0 4px 16px rgba(0, 0, 0, 0.12)': 'var(--shadow-lg)',
|
|
59
|
+
|
|
60
|
+
// 交互阴影
|
|
61
|
+
'0 4px 12px rgba(0, 0, 0, 0.08)': 'var(--shadow-hover)',
|
|
62
|
+
'0 2px 6px rgba(0, 0, 0, 0.12)': 'var(--shadow-active)',
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
// 需要处理的文件扩展名
|
|
66
|
+
const TARGET_EXTENSIONS = ['.vue', '.scss', '.css'];
|
|
67
|
+
|
|
68
|
+
// 统计信息
|
|
69
|
+
let stats = {
|
|
70
|
+
totalFiles: 0,
|
|
71
|
+
modifiedFiles: 0,
|
|
72
|
+
radiusReplacements: 0,
|
|
73
|
+
shadowReplacements: 0,
|
|
74
|
+
radiusDetails: {},
|
|
75
|
+
shadowDetails: {},
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* 递归扫描目录
|
|
80
|
+
*/
|
|
81
|
+
function scanDirectory(dir, fileList = []) {
|
|
82
|
+
const files = fs.readdirSync(dir);
|
|
83
|
+
|
|
84
|
+
files.forEach(file => {
|
|
85
|
+
const filePath = path.join(dir, file);
|
|
86
|
+
const stat = fs.statSync(filePath);
|
|
87
|
+
|
|
88
|
+
if (stat.isDirectory()) {
|
|
89
|
+
if (file !== 'node_modules' && file !== '.git' && file !== 'dist') {
|
|
90
|
+
scanDirectory(filePath, fileList);
|
|
91
|
+
}
|
|
92
|
+
} else {
|
|
93
|
+
const ext = path.extname(file);
|
|
94
|
+
if (TARGET_EXTENSIONS.includes(ext)) {
|
|
95
|
+
fileList.push(filePath);
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
return fileList;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* 处理文件内容
|
|
105
|
+
*/
|
|
106
|
+
function processFileContent(content) {
|
|
107
|
+
let modified = false;
|
|
108
|
+
let newContent = content;
|
|
109
|
+
|
|
110
|
+
// 1. 处理 border-radius
|
|
111
|
+
const radiusRegex = /(border-radius\s*:\s*)(\d+px)(;)/g;
|
|
112
|
+
newContent = newContent.replace(radiusRegex, (match, prefix, value, suffix) => {
|
|
113
|
+
if (RADIUS_MAP[value]) {
|
|
114
|
+
stats.radiusDetails[value] = (stats.radiusDetails[value] || 0) + 1;
|
|
115
|
+
stats.radiusReplacements++;
|
|
116
|
+
modified = true;
|
|
117
|
+
return prefix + RADIUS_MAP[value] + suffix;
|
|
118
|
+
}
|
|
119
|
+
return match;
|
|
120
|
+
});
|
|
121
|
+
|
|
122
|
+
// 2. 处理 box-shadow(精确匹配)
|
|
123
|
+
Object.keys(SHADOW_MAP).forEach(shadowValue => {
|
|
124
|
+
const escapedValue = shadowValue.replace(/[()]/g, '\\$&');
|
|
125
|
+
const shadowRegex = new RegExp(`(box-shadow\\s*:\\s*)(${escapedValue})(;)`, 'g');
|
|
126
|
+
|
|
127
|
+
if (newContent.match(shadowRegex)) {
|
|
128
|
+
stats.shadowDetails[shadowValue] = (stats.shadowDetails[shadowValue] || 0) + 1;
|
|
129
|
+
stats.shadowReplacements++;
|
|
130
|
+
modified = true;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
newContent = newContent.replace(shadowRegex, (match, prefix, value, suffix) => {
|
|
134
|
+
return prefix + SHADOW_MAP[shadowValue] + suffix;
|
|
135
|
+
});
|
|
136
|
+
});
|
|
137
|
+
|
|
138
|
+
// 3. 处理 box-shadow 的模糊匹配(针对未精确匹配的常见模式)
|
|
139
|
+
const generalShadowRegex = /(box-shadow\s*:\s*)(0\s+\d+px\s+\d+px\s+rgba\([^)]+\))(;)/g;
|
|
140
|
+
newContent = newContent.replace(generalShadowRegex, (match, prefix, value, suffix) => {
|
|
141
|
+
// 如果已经被精确匹配处理过,跳过
|
|
142
|
+
if (SHADOW_MAP[value]) {
|
|
143
|
+
return match;
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
// 根据模糊程度和偏移量选择合适的阴影
|
|
147
|
+
const normalized = value.replace(/\s+/g, ' ').trim();
|
|
148
|
+
|
|
149
|
+
// 小阴影:offset <= 2px, blur <= 4px
|
|
150
|
+
if (normalized.match(/0\s+[12]px\s+[234]px/)) {
|
|
151
|
+
stats.shadowDetails[value] = (stats.shadowDetails[value] || 0) + 1;
|
|
152
|
+
stats.shadowReplacements++;
|
|
153
|
+
modified = true;
|
|
154
|
+
return prefix + 'var(--shadow-sm)' + suffix;
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
// 中等阴影:offset 2-4px, blur 6-12px
|
|
158
|
+
if (normalized.match(/0\s+[234]px\s+(6|8|10|12)px/)) {
|
|
159
|
+
stats.shadowDetails[value] = (stats.shadowDetails[value] || 0) + 1;
|
|
160
|
+
stats.shadowReplacements++;
|
|
161
|
+
modified = true;
|
|
162
|
+
return prefix + 'var(--shadow-md)' + suffix;
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
// 大阴影:offset 4-8px, blur 12-24px
|
|
166
|
+
if (normalized.match(/0\s+[4-8]px\s+(12|16|20|24)px/)) {
|
|
167
|
+
stats.shadowDetails[value] = (stats.shadowDetails[value] || 0) + 1;
|
|
168
|
+
stats.shadowReplacements++;
|
|
169
|
+
modified = true;
|
|
170
|
+
return prefix + 'var(--shadow-lg)' + suffix;
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
return match;
|
|
174
|
+
});
|
|
175
|
+
|
|
176
|
+
return { content: newContent, modified };
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
/**
|
|
180
|
+
* 处理单个文件
|
|
181
|
+
*/
|
|
182
|
+
function processFile(filePath) {
|
|
183
|
+
try {
|
|
184
|
+
const content = fs.readFileSync(filePath, 'utf8');
|
|
185
|
+
const { content: newContent, modified } = processFileContent(content);
|
|
186
|
+
|
|
187
|
+
if (modified) {
|
|
188
|
+
if (!isDryRun) {
|
|
189
|
+
fs.writeFileSync(filePath, newContent, 'utf8');
|
|
190
|
+
}
|
|
191
|
+
stats.modifiedFiles++;
|
|
192
|
+
console.log(`${isDryRun ? '📋 [预览]' : '✅'} ${filePath}`);
|
|
193
|
+
return true;
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
return false;
|
|
197
|
+
} catch (error) {
|
|
198
|
+
console.error(`❌ 处理文件失败: ${filePath}`, error.message);
|
|
199
|
+
return false;
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
/**
|
|
204
|
+
* 主函数
|
|
205
|
+
*/
|
|
206
|
+
function main() {
|
|
207
|
+
const projectRoot = path.join(__dirname, '..');
|
|
208
|
+
const srcDir = path.join(projectRoot, 'src');
|
|
209
|
+
|
|
210
|
+
console.log('🚀 开始标准化 CSS 样式变量...\n');
|
|
211
|
+
console.log(`📁 项目根目录: ${projectRoot}`);
|
|
212
|
+
console.log(`📁 扫描目录: ${srcDir}`);
|
|
213
|
+
console.log(`模式: ${isDryRun ? '预览模式(不会修改文件)' : '修改模式'}\n`);
|
|
214
|
+
|
|
215
|
+
// 扫描所有目标文件
|
|
216
|
+
const files = scanDirectory(srcDir);
|
|
217
|
+
stats.totalFiles = files.length;
|
|
218
|
+
|
|
219
|
+
console.log(`📊 找到 ${files.length} 个文件需要检查\n`);
|
|
220
|
+
console.log('🔄 开始处理文件...\n');
|
|
221
|
+
|
|
222
|
+
// 处理每个文件
|
|
223
|
+
files.forEach(file => {
|
|
224
|
+
processFile(file);
|
|
225
|
+
});
|
|
226
|
+
|
|
227
|
+
// 输出统计信息
|
|
228
|
+
console.log('\n' + '='.repeat(60));
|
|
229
|
+
console.log('📊 转换统计报告');
|
|
230
|
+
console.log('='.repeat(60));
|
|
231
|
+
console.log(`总文件数: ${stats.totalFiles}`);
|
|
232
|
+
console.log(`修改文件数: ${stats.modifiedFiles}`);
|
|
233
|
+
console.log(`border-radius 替换次数: ${stats.radiusReplacements}`);
|
|
234
|
+
console.log(`box-shadow 替换次数: ${stats.shadowReplacements}`);
|
|
235
|
+
|
|
236
|
+
if (Object.keys(stats.radiusDetails).length > 0) {
|
|
237
|
+
console.log('\n📋 border-radius 替换详情:');
|
|
238
|
+
Object.entries(stats.radiusDetails)
|
|
239
|
+
.sort((a, b) => b[1] - a[1])
|
|
240
|
+
.forEach(([px, count]) => {
|
|
241
|
+
console.log(` ${px} => ${RADIUS_MAP[px]}: ${count} 次`);
|
|
242
|
+
});
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
if (Object.keys(stats.shadowDetails).length > 0) {
|
|
246
|
+
console.log('\n📋 box-shadow 替换详情:');
|
|
247
|
+
Object.entries(stats.shadowDetails)
|
|
248
|
+
.sort((a, b) => b[1] - a[1])
|
|
249
|
+
.forEach(([shadow, count]) => {
|
|
250
|
+
const mapped = SHADOW_MAP[shadow] || '(模糊匹配)';
|
|
251
|
+
console.log(` ${shadow} => ${mapped}: ${count} 次`);
|
|
252
|
+
});
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
if (isDryRun) {
|
|
256
|
+
console.log('\n💡 提示: 这是预览模式,文件未被修改');
|
|
257
|
+
console.log(' 移除 --dry-run 参数以实际应用更改');
|
|
258
|
+
} else {
|
|
259
|
+
console.log('\n✨ 转换完成!');
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
// 运行主函数
|
|
264
|
+
if (require.main === module) {
|
|
265
|
+
main();
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
module.exports = { processFileContent };
|