64 lines
1.8 KiB
JavaScript
64 lines
1.8 KiB
JavaScript
|
|
const fs = require('fs');
|
|||
|
|
const path = require('path');
|
|||
|
|
|
|||
|
|
// 定义要处理的目录
|
|||
|
|
const pagesDir = './pages';
|
|||
|
|
const packageADir = './packageA';
|
|||
|
|
|
|||
|
|
// 定义要排除的文件(首页相关)
|
|||
|
|
const excludePatterns = [/index/i];
|
|||
|
|
|
|||
|
|
// 函数:放大样式值
|
|||
|
|
function scaleStyles(filePath) {
|
|||
|
|
console.log(`Processing ${filePath}`);
|
|||
|
|
|
|||
|
|
// 读取文件内容
|
|||
|
|
const content = fs.readFileSync(filePath, 'utf8');
|
|||
|
|
|
|||
|
|
// 正则表达式匹配所有数值(px 或 rpx 单位)
|
|||
|
|
const pattern = /([:\s])(\d+)(px|rpx)/g;
|
|||
|
|
|
|||
|
|
// 执行替换
|
|||
|
|
const newContent = content.replace(pattern, (match, prefix, value, unit) => {
|
|||
|
|
const scaledValue = Math.round(parseInt(value) * 1.5);
|
|||
|
|
return `${prefix}${scaledValue}${unit}`;
|
|||
|
|
});
|
|||
|
|
|
|||
|
|
// 写回文件
|
|||
|
|
fs.writeFileSync(filePath, newContent, 'utf8');
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
// 函数:递归处理目录
|
|||
|
|
function processDirectory(dir, exclude = false) {
|
|||
|
|
const files = fs.readdirSync(dir);
|
|||
|
|
|
|||
|
|
files.forEach(file => {
|
|||
|
|
const fullPath = path.join(dir, file);
|
|||
|
|
const stats = fs.statSync(fullPath);
|
|||
|
|
|
|||
|
|
if (stats.isDirectory()) {
|
|||
|
|
processDirectory(fullPath, exclude);
|
|||
|
|
} else if (stats.isFile() && path.extname(file) === '.vue') {
|
|||
|
|
if (exclude) {
|
|||
|
|
// 检查是否需要排除
|
|||
|
|
const shouldExclude = excludePatterns.some(pattern => pattern.test(fullPath));
|
|||
|
|
if (!shouldExclude) {
|
|||
|
|
scaleStyles(fullPath);
|
|||
|
|
}
|
|||
|
|
} else {
|
|||
|
|
scaleStyles(fullPath);
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
});
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
// 处理 pages 目录(排除首页相关文件)
|
|||
|
|
console.log('Processing pages directory...');
|
|||
|
|
processDirectory(pagesDir, true);
|
|||
|
|
|
|||
|
|
// 处理 packageA 目录
|
|||
|
|
console.log('Processing packageA directory...');
|
|||
|
|
processDirectory(packageADir);
|
|||
|
|
|
|||
|
|
console.log('Processing completed!');
|