1 Star 1 Fork 0

bfun/el-table-sticky

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
gen-router.js 1.71 KB
一键复制 编辑 原始数据 按行查看 历史
Cell 提交于 2023-06-20 10:56 . Test: 增加筛选表格 demo
const fs = require('fs')
const os = require('os')
const vueDir = './src/views/'
const routerFile = './src/router.js'
fs.readdir(vueDir, function (err, files) {
if (err) {
console.error('❌ Could not list the directory.', err)
return
}
const routes = []
for (const filename of files) {
if (filename.indexOf('.') < 0) {
continue
}
const [name, ext] = filename.split('.')
if (ext !== 'vue') {
continue
}
const routeName = name.replace(/-([a-z])/g, (_, match) => match.toUpperCase())
let routeDescription = ''
const contentFull = fs.readFileSync(`${vueDir}${filename}`, 'utf-8')
// get route description from first line comment
const match = /<!--\s*(.*)\s*-->/g.exec(contentFull.split(os.EOL)[0])
if (match) {
routeDescription = match[1].trim()
}
routes.push(` {
path: '/${name === 'home' ? '' : name}',
name: '${routeName}',${routeDescription ? `\n meta: { description: '${routeDescription}' },` : ''}
component: () => import(/* webpackChunkName: "${routeName}" */ '@/views/${filename}'),
},`)
}
const result =
`// This file is automatically generated by gen-router.js, please do not modify it manually!
import VueRouter from 'vue-router'
import Vue from 'vue'
const packageInfo = require('../package.json')
Vue.use(VueRouter)
const routes = [
${routes.join(os.EOL)}
]
const router = new VueRouter({
mode: 'hash',
routes,
})
router.afterEach((to) => {
document.title = \`\${to.meta?.description} - \${packageInfo.name} \${packageInfo.version}\`
})
export default router
`
fs.writeFile(routerFile, result, 'utf-8', (err) => {
if (err) throw err
console.log(`✅ Router generated successfully in ${routerFile}`)
})
})
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/bfun/el-table-sticky.git
[email protected]:bfun/el-table-sticky.git
bfun
el-table-sticky
el-table-sticky
main

搜索帮助