naive-ui/scripts/rename.js
07akioni 487001d697 build: add changelog to site, refactor loader based on suffix
.demo.md for component demo
.demo-entry.md for demo entry
.md for common docs
2020-08-19 23:30:04 +08:00

27 lines
743 B
JavaScript

const fs = require('fs')
const path = require('path')
async function * walk (dir) {
for await (const d of await fs.promises.opendir(dir)) {
const entry = path.join(dir, d.name)
if (d.isDirectory()) yield * walk(entry)
else if (d.isFile()) yield entry
}
}
// Then, use it with a simple async for loop
async function main () {
for await (const p of walk('./demo/documentation')) {
// console.log(p)
// if (/index\.md$/.test(p)) {
// // console.log(p.replace(/index\.md$/, 'index.demo-entry.md'))
// fs.renameSync(p, p.replace(/index\.md$/, 'index.demo-entry.md'))
// }
if (/\.md$/.test(p) && !/demo-entry\.md$/.test(p)) {
fs.renameSync(p, p.replace(/\.md$/, '.demo.md'))
}
}
}
main()