Files
biz-mobile-cloud-zax/scripts/batch-strip-crud-titles.mjs
T
2026-08-27 14:29:23 +08:00

39 lines
1.0 KiB
JavaScript

import fs from "fs"
import path from "path"
import { fileURLToPath } from "url"
const __dirname = path.dirname(fileURLToPath(import.meta.url))
const pagesDir = path.join(__dirname, "../src/pages")
function walk(dir, 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
}
let count = 0
for (const file of walk(pagesDir)) {
let content = fs.readFileSync(file, "utf8")
const lines = content.split("\n")
let changed = false
const next = lines.map((line) => {
if (!line.includes("crud-layout")) return line
if (line.includes(":title")) return line
const stripped = line.replace(/\s+title="[^"]*"/g, "")
if (stripped !== line) {
changed = true
return stripped
}
return line
})
if (changed) {
fs.writeFileSync(file, next.join("\n"))
count++
console.log("stripped title:", path.relative(pagesDir, file))
}
}
console.log("done,", count, "files")