| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869 |
- const fs = require('fs')
- const path = require('path')
- const roots = [
- path.join(__dirname, '../src/views'),
- path.join(__dirname, '../../saas-mgnui/src/views'),
- path.join(__dirname, '../../adminui/src/views')
- ]
- function walk(dir, files = []) {
- if (!fs.existsSync(dir)) return files
- for (const name of fs.readdirSync(dir)) {
- const full = path.join(dir, name)
- if (fs.statSync(full).isDirectory()) walk(full, files)
- else if (name.endsWith('.vue')) files.push(full)
- }
- return files
- }
- function scan(content) {
- const issues = []
- const m = content.match(/<template>([\s\S]*?)<\/template>/)
- if (!m) return issues
- const tpl = m[1]
- const qIdx = tpl.indexOf('ref="queryForm"')
- if (qIdx >= 0) {
- const formStart = tpl.lastIndexOf('<el-form', qIdx)
- const formEnd = tpl.indexOf('</el-form>', qIdx)
- if (formStart >= 0 && formEnd >= 0) {
- let formBody = tpl.slice(formStart, formEnd + '</el-form>'.length)
- formBody = formBody.replace(/<!--[\s\S]*?-->/g, '')
- const openFi = (formBody.match(/<el-form-item\b/g) || []).length
- const closeFi = (formBody.match(/<\/el-form-item>/g) || []).length
- if (openFi !== closeFi) issues.push(`form-item-balance:${openFi}/${closeFi}`)
- }
- }
- // list-search-actions opened but closed by </el-form> first
- const brokenActions = tpl.match(
- /<el-form-item[^>]*list-search-actions[^>]*>[\s\S]*?(?=<\/el-form>)/g
- )
- if (brokenActions) {
- for (const block of brokenActions) {
- if (!block.includes('</el-form-item>')) {
- if (/<el-form-item\b/.test(block)) issues.push('unclosed-actions-with-nested')
- else issues.push('unclosed-actions')
- } else if (/<el-form-item[^>]*list-search-actions[^>]*>[\s\S]*<el-form-item\b/.test(block)) {
- issues.push('nested-in-actions')
- }
- }
- }
- return issues
- }
- const all = []
- for (const root of roots) {
- for (const file of walk(root)) {
- const issues = scan(fs.readFileSync(file, 'utf8'))
- if (issues.length) all.push({ file, issues })
- }
- }
- console.log('Critical files:', all.length)
- for (const r of all) {
- console.log(r.file.replace(/\\/g, '/'))
- console.log(' ', r.issues.join(', '))
- }
|