Files
dvcp_v2_wxcp_app/bin/serve.js

71 lines
2.0 KiB
JavaScript
Raw Normal View History

2022-05-20 09:46:21 +08:00
const {chalkTag, findPages, fs, fsExtra} = require("./tools");
2023-03-16 09:39:16 +08:00
2022-06-08 16:32:02 +08:00
let apps = {list: [], desc: "用于产品库主页面获取应用使用", type: 'wxwork'}
2022-05-20 09:46:21 +08:00
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')
2022-05-23 15:23:10 +08:00
app.label = appName.replace(/(appName:|["'])/g, '').trim()
2022-05-20 09:46:21 +08:00
if (/customNavigation/.test(vue)) {
app.style = {navigationStyle: "custom"}
} else
app.style = {navigationBarTitleText: app.label}
}
}
2023-03-16 09:39:16 +08:00
const start = () => {
chalkTag.info('开始生成pages.json...')
let json = {
easycom: {
2021-12-13 10:16:08 +08:00
"^u-(.*)": "uview-ui/components/u-$1/u-$1.vue",
"^(Ai|V)(.*)": "@/components/$1$2.vue"
},
2021-11-17 17:13:52 +08:00
pages: [
{path: 'pages/loading'},
2021-12-13 10:16:08 +08:00
{path: 'pages/login'}
2021-11-17 17:13:52 +08:00
],
globalStyle: {
pageOrientation: "auto",
navigationStyle: "custom"
}
}
2022-05-20 09:46:21 +08:00
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)
2021-12-15 14:37:20 +08:00
}
2022-05-20 09:46:21 +08:00
}),
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)
2022-02-21 14:42:50 +08:00
}
2022-05-20 09:46:21 +08:00
}),
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)
2022-02-21 14:42:50 +08:00
}
2022-05-20 09:46:21 +08:00
})
]).then(() => {
2023-03-16 09:39:16 +08:00
fsExtra.outputJson('src/config.json', {apps: apps.list})
2022-02-16 15:10:40 +08:00
fsExtra.outputJson('src/pages.json', json, () => {
chalkTag.done('生成pages.json')
})
})
}
start();