chore: 添加修复长按菜单语法错误的脚本
This commit is contained in:
119
scripts/fix-longpress-syntax.js
Normal file
119
scripts/fix-longpress-syntax.js
Normal file
@@ -0,0 +1,119 @@
|
|||||||
|
/**
|
||||||
|
* 修复 show-menu-by-longpress 的错误用法
|
||||||
|
* 将 :show-menu-by-longpress="true" 替换为 show-menu-by-longpress
|
||||||
|
* 使用方法:node scripts/fix-longpress-syntax.js
|
||||||
|
*/
|
||||||
|
|
||||||
|
const fs = require('fs')
|
||||||
|
const path = require('path')
|
||||||
|
|
||||||
|
// 需要处理的目录
|
||||||
|
const dirs = [
|
||||||
|
'components',
|
||||||
|
'components-diy',
|
||||||
|
'pages',
|
||||||
|
'pages_goods',
|
||||||
|
'pages_order',
|
||||||
|
'pages_promotion',
|
||||||
|
'pages_tool',
|
||||||
|
'uni_modules'
|
||||||
|
]
|
||||||
|
|
||||||
|
// 排除的目录
|
||||||
|
const excludeDirs = [
|
||||||
|
'node_modules',
|
||||||
|
'.git',
|
||||||
|
'unpackage',
|
||||||
|
'dist'
|
||||||
|
]
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 检查是否应该排除
|
||||||
|
*/
|
||||||
|
function shouldExclude(filePath) {
|
||||||
|
return excludeDirs.some(dir => filePath.includes(dir))
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 修复单个文件
|
||||||
|
*/
|
||||||
|
function fixFile(filePath) {
|
||||||
|
let content = fs.readFileSync(filePath, 'utf-8')
|
||||||
|
let modified = false
|
||||||
|
|
||||||
|
// 错误的写法1: :show-menu-by-longpress="true"
|
||||||
|
// 错误的写法2: :show-menu-by-longpress='true'
|
||||||
|
const wrongPatterns = [
|
||||||
|
/:show-menu-by-longpress\s*=\s*["']true["']/gi,
|
||||||
|
/:show-menu-by-longpress\s*=\s*\{true\}/gi
|
||||||
|
]
|
||||||
|
|
||||||
|
wrongPatterns.forEach(pattern => {
|
||||||
|
if (pattern.test(content)) {
|
||||||
|
content = content.replace(pattern, 'show-menu-by-longpress')
|
||||||
|
modified = true
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
// 确保属性后有空格或结束符
|
||||||
|
content = content.replace(/show-menu-by-longpress\/>/g, 'show-menu-by-longpress />')
|
||||||
|
content = content.replace(/show-menu-by-longpress>/g, 'show-menu-by-longpress >')
|
||||||
|
|
||||||
|
if (modified) {
|
||||||
|
fs.writeFileSync(filePath, content, 'utf-8')
|
||||||
|
console.log(`✓ 已修复: ${filePath}`)
|
||||||
|
return 1
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 递归遍历目录
|
||||||
|
*/
|
||||||
|
function walkDir(dir, callback) {
|
||||||
|
if (shouldExclude(dir)) return
|
||||||
|
|
||||||
|
try {
|
||||||
|
const files = fs.readdirSync(dir)
|
||||||
|
|
||||||
|
files.forEach(file => {
|
||||||
|
const filePath = path.join(dir, file)
|
||||||
|
|
||||||
|
if (shouldExclude(filePath)) return
|
||||||
|
|
||||||
|
const stat = fs.statSync(filePath)
|
||||||
|
|
||||||
|
if (stat.isDirectory()) {
|
||||||
|
walkDir(filePath, callback)
|
||||||
|
} else if (file.endsWith('.vue')) {
|
||||||
|
callback(filePath)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
} catch (err) {
|
||||||
|
console.error(`✗ 无法读取目录: ${dir}`)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 主程序
|
||||||
|
let totalFiles = 0
|
||||||
|
let fixedFiles = 0
|
||||||
|
|
||||||
|
console.log('开始修复 show-menu-by-longpress 语法...\n')
|
||||||
|
|
||||||
|
dirs.forEach(dir => {
|
||||||
|
const fullPath = path.join(__dirname, '..', dir)
|
||||||
|
if (fs.existsSync(fullPath)) {
|
||||||
|
walkDir(fullPath, (filePath) => {
|
||||||
|
totalFiles++
|
||||||
|
fixedFiles += fixFile(filePath)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
console.log(`\n修复完成!`)
|
||||||
|
console.log(`总共扫描: ${totalFiles} 个文件`)
|
||||||
|
console.log(`成功修复: ${fixedFiles} 个文件`)
|
||||||
|
console.log(`\n正确的用法:`);
|
||||||
|
console.log(` <image src="..." show-menu-by-longpress></image>`);
|
||||||
|
console.log(` <image src="..." :show-menu-by-longpress="condition"></image> (如果需要动态控制)`);
|
||||||
Reference in New Issue
Block a user