Files
dvcp_v2_wechat_app/bin/pages.js

75 lines
2.5 KiB
JavaScript
Raw Normal View History

2022-05-12 11:26:36 +08:00
const {chalkTag, findPages, fsExtra, fs} = require("./tools");
2022-11-03 18:09:39 +08:00
const PageBase = require("dvcp-wui/utils/PageBase");
2022-06-08 16:32:01 +08:00
let apps = {list: [], desc: "用于产品库主页面获取应用使用", type: "mp"}
2022-05-12 09:49:40 +08:00
const getFileInfo = (app, file) => {
if (/^App/.test(app.name)) {
2022-05-16 10:01:40 +08:00
let {name, label} = app,
2022-06-08 16:32:01 +08:00
path = app.path.replace(/.+[\\\/]([^\\\/]+)[\\\/]([^\\\/]+)$/g, `/mods/$1/$2`)
apps.list.push({
id: file.replace(/\.\/?(vue)?/g, '')?.replace(/[\\\/]/g, '_'),
name,
label,
path,
libPath: file?.replace(/\\/g, '/')?.replace(/^src(\/.+)\.vue/, '$1'),
type: 'mp'
})
2022-05-12 09:49:40 +08:00
}
}
2022-02-14 17:25:54 +08:00
const start = () => {
chalkTag.info('开始生成pages.json...')
let json = {
easycom: {
"^u-(.*)": "uview-ui/components/u-$1/u-$1.vue",
2023-03-20 19:08:04 +08:00
"^(Ai|V)(.*)": "@/components/$1$2/$1$2.vue",
2022-02-14 17:25:54 +08:00
},
pages: [
{path: 'pages/home', style: {navigationBarTitleText: "小程序应用库"}}
],
subPackages: [
{root: "mods/", pages: []},
{root: "components/pages/", pages: []},
{root: "project/", pages: []},
2022-02-14 17:25:54 +08:00
],
globalStyle: {
pageOrientation: "auto",
navigationBarTextStyle: "white",
2023-03-20 19:08:04 +08:00
navigationBarBackgroundColor: "#4181FF",
"mp-weixin": {
"usingComponents": {
"cell": "plugin://materialPlugin/cell"
}
}
2022-02-14 17:25:54 +08:00
}
}
Promise.all([
2022-05-12 11:26:36 +08:00
findPages('src/components/pages', file => {
if (/.+\\pages\\[^\\]+\.vue/g.test(file)) {
2022-11-03 18:09:39 +08:00
const app = new PageBase(file.replace(/^src\\components\\pages\\(.*).vue/g, '$1').replace(/\\/g, '/'), fs.readFileSync(file).toString())
2022-05-12 09:49:40 +08:00
getFileInfo(app, file)
return json.subPackages[1].pages.push(app)
2022-02-14 17:25:54 +08:00
}
}),
2022-05-12 11:26:36 +08:00
findPages('src/mods', file => {
2022-02-14 17:25:54 +08:00
if (/.+\\App[^\\]+\\[^\\]+\.vue/g.test(file)) {
2022-11-03 18:09:39 +08:00
const app = new PageBase(file.replace(/^src\\mods\\(.*).vue/g, '$1').replace(/\\/g, '/'), fs.readFileSync(file).toString())
2022-05-12 09:49:40 +08:00
getFileInfo(app, file)
return json.subPackages[0].pages.push(app)
}
}),
2022-05-12 11:26:36 +08:00
findPages('src/project', file => {
if (/.+\\App[^\\]+\\[^\\]+\.vue/g.test(file)) {
2022-11-03 18:09:39 +08:00
const app = new PageBase(file.replace(/^src\\project\\(.*).vue/g, '$1').replace(/\\/g, '/'), fs.readFileSync(file).toString())
2022-05-12 09:49:40 +08:00
getFileInfo(app, file)
return json.subPackages[2].pages.push(app)
2022-02-14 17:25:54 +08:00
}
})
]).then(() => {
2023-03-16 10:18:51 +08:00
fsExtra.outputJson('src/config.json', {apps: apps.list})
fsExtra.outputJson('src/pages.json', json, () => {
chalkTag.done('生成pages.json')
})
})
2022-02-14 17:25:54 +08:00
}
start();