import * as sass from 'sass' import fs from 'fs' import path from 'path' const ROOT = new URL('../../', import.meta.url).pathname const vars = fs.readFileSync(path.join(ROOT, 'uni.scss'), 'utf8') const files = [] function walk(dir) { for (const f of fs.readdirSync(dir)) { const p = path.join(dir, f) const st = fs.statSync(p) if (st.isDirectory()) { if (['node_modules', 'server', '.git', 'unpackage'].includes(f)) continue walk(p) } else if (f.endsWith('.vue')) files.push(p) } } walk(ROOT) let ok = 0 const errors = [] for (const file of files) { const rel = path.relative(ROOT, file) const src = fs.readFileSync(file, 'utf8') const m = src.match(/]*lang="scss"[^>]*>([\s\S]*?)<\/style>/) if (!m) continue try { sass.compileString(vars + '\n' + m[1], { style: 'expanded', logger: sass.Logger.silent }) ok++ } catch (e) { errors.push(`${rel}: ${e.message.split('\n').slice(0, 2).join(' ')}`) } } console.log(`SCSS 编译通过 ${ok} 个样式块`) for (const e of errors) console.log(' ❌ ' + e) process.exit(errors.length ? 1 : 0)