Files
dvcp_v2_wxcp_app/bin/serve.js

89 lines
2.8 KiB
JavaScript
Raw Normal View History

2022-05-20 09:46:21 +08:00
const {chalkTag, findPages, fs, fsExtra} = require("./tools");
const axios = require("axios");
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}
}
2022-06-08 16:32:02 +08:00
if (/^App/.test(app.name) && app.label) {
2022-05-20 09:46:21 +08:00
let {name, label} = app,
2022-12-06 09:38:30 +08:00
path = app.path.replace(/.+[\\\/]([^\\\/]+)[\\\/]([^\\\/]+)$/g, `/apps/$1/$2`)
2022-05-31 09:55:33 +08:00
apps.list.push({
2022-05-31 10:38:53 +08:00
id: file.replace(/\.\/?(vue)?/g, '').replace(/[\\\/]/g, '_'),
2022-05-31 09:55:33 +08:00
name,
label,
path,
libPath: file.replace(/\\/g, '/').replace(/^src(\/.+)\.vue/, '$1'),
type: 'wxwork'
})
}
}
2022-05-20 09:46:21 +08:00
const saveApps = app => {
if (app.list.length > 0) {
2022-12-15 10:42:01 +08:00
axios.post("http://192.168.1.87:12525/node/wechatapps/addOrUpdate", app, {timeout: 1000}).then(res => {
2022-06-08 16:32:02 +08:00
if (res.data.code == 0) chalkTag.done("产品库目录已同步至后台数据库...")
2022-12-06 09:38:30 +08:00
}).catch(err => 0).finally(() => fsExtra.outputJson('src/config.json', {apps: app.list}))
2022-05-20 09:46:21 +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(() => {
saveApps(apps)
2022-02-16 15:10:40 +08:00
fsExtra.outputJson('src/pages.json', json, () => {
chalkTag.done('生成pages.json')
})
})
}
start();