const {chalkTag, findPages, fs, fsExtra} = require("./tools"); let apps = {list: [], desc: "用于产品库主页面获取应用使用", type: 'wxwork'} const getFileInfo = (app, file) => { let vue = fs.readFileSync(file).toString() if (/appName/.test(vue)) { let appName = vue.replace(/[\s\S]*(appName:.+),[\s\S]*/gm, '$1') app.label = appName.replace(/(appName:|["'])/g, '').trim() if (/customNavigation/.test(vue)) { app.style = {navigationStyle: "custom"} } else app.style = {navigationBarTitleText: app.label} } } const start = () => { chalkTag.info('开始生成pages.json...') let json = { easycom: { "^u-(.*)": "uview-ui/components/u-$1/u-$1.vue", "^(Ai|V)(.*)": "@/components/$1$2.vue" }, pages: [ {path: 'pages/loading'}, {path: 'pages/login'} ], globalStyle: { pageOrientation: "auto", navigationStyle: "custom" } } Promise.all([ findPages('src/components/pages', file => { if (/.+\\[^\\]+\\[^\\]+\.vue/g.test(file)) { let app = { path: file.replace(/^src\\(.*).vue/g, '$1').replace(/\\/g, '/') } getFileInfo(app, file) return json.pages.push(app) } }), findPages('src/apps', file => { if (/.+\\App[^\\]+\\[^\\]+\.vue/g.test(file)) { let app = { name: file.replace(/.*\\([^\\]+).vue/g, '$1'), path: file.replace(/^src\\(.*).vue/g, '$1').replace(/\\/g, '/') } getFileInfo(app, file) return json.pages.push(app) } }), findPages('src/project', file => { if (/.+\\App[^\\]+\\[^\\]+\.vue/g.test(file)) { let app = { name: file.replace(/.*\\([^\\]+).vue/g, '$1'), path: file.replace(/^src\\(.*).vue/g, '$1').replace(/\\/g, '/') } getFileInfo(app, file) return json.pages.push(app) } }) ]).then(() => { fsExtra.outputJson('src/config.json', {apps: apps.list}) fsExtra.outputJson('src/pages.json', json, () => { chalkTag.done('生成pages.json') }) }) } start();