更改小程序同步策略

This commit is contained in:
aixianling
2023-03-16 10:18:51 +08:00
parent a3e1694d4f
commit 3d3a9608aa
3 changed files with 55 additions and 10 deletions

View File

@@ -1,4 +1,3 @@
const axios = require('axios')
const {chalkTag, findPages, fsExtra, fs} = require("./tools");
const PageBase = require("dvcp-wui/utils/PageBase");
let apps = {list: [], desc: "用于产品库主页面获取应用使用", type: "mp"}
@@ -16,13 +15,6 @@ const getFileInfo = (app, file) => {
})
}
}
const saveApps = app => {
if (app.list.length > 0) {
axios.post("http://192.168.1.87:12525/node/wechatapps/addOrUpdate", app).then(res => {
if (res?.data?.code == 0) chalkTag.done("产品库目录已同步至后台数据库...")
}).catch(err => 0).finally(() => fsExtra.outputJson('src/config.json', {apps: app.list}))
}
}
const start = () => {
chalkTag.info('开始生成pages.json...')
let json = {
@@ -67,7 +59,7 @@ const start = () => {
}
})
]).then(() => {
saveApps(apps)
fsExtra.outputJson('src/config.json', {apps: apps.list})
fsExtra.outputJson('src/pages.json', json, () => {
chalkTag.done('生成pages.json')
})

52
bin/sync.js Normal file
View File

@@ -0,0 +1,52 @@
const {chalkTag, fs, findPages} = require("./tools");
const axios = require("axios");
const PageBase = require("dvcp-wui/utils/PageBase");
let apps = {list: [], desc: "用于产品库主页面获取应用使用", type: 'mp'}
const saveApps = app => {
if (app.list.length > 0) {
return axios.post("http://192.168.1.87:12525/node/wechatapps/addOrUpdate", app, {timeout: 1000}).then(res => {
if (res.data.code == 0) chalkTag.done("产品库目录已同步至后台数据库...")
}).catch(err => {
console.log(err)
})
}
}
const getFileInfo = (app, file) => {
if (/^App/.test(app.name) && app.label) {
let {name, label} = app,
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'
})
}
}
const start = () => {
chalkTag.info('开始同步数据到数据库')
Promise.all([
findPages('src/components/pages', file => {
if (/.+[\\\/]pages[\\\/][^\\\/]+\.vue/g.test(file)) {
const app = new PageBase(file.replace(/^src[\\\/]components[\\\/]pages[\\\/](.*).vue/g, '$1').replace(/[\\\/]/g, '/'), fs.readFileSync(file).toString())
return getFileInfo(app, file)
}
}),
findPages('src/mods', file => {
if (/.+[\\\/]App[^\\\/]+[\\\/][^\\\/]+\.vue/g.test(file)) {
const app = new PageBase(file.replace(/^src[\\\/]mods[\\\/](.*).vue/g, '$1').replace(/[\\\/]/g, '/'), fs.readFileSync(file).toString())
return getFileInfo(app, file)
}
}),
findPages('src/project', file => {
if (/.+[\\\/]App[^\\\/]+[\\\/][^\\\/]+\.vue/g.test(file)) {
const app = new PageBase(file.replace(/^src[\\\/]project[\\\/](.*).vue/g, '$1').replace(/[\\\/]/g, '/'), fs.readFileSync(file).toString())
return getFileInfo(app, file)
}
})
]).then(() => saveApps(apps)).finally(() => chalkTag.done('同步完成'))
}
start()

View File

@@ -7,7 +7,8 @@
"dev": "node bin/pages.js&&cross-env NODE_ENV=development VUE_APP_CW_MODE=dev UNI_PLATFORM=mp-weixin vue-cli-service uni-build --watch",
"pages": "node bin/pages.js",
"lib": "npm unpublish --workspaces -f&&npm publish --workspaces",
"clean": "node bin/clean.js"
"clean": "node bin/clean.js",
"sync": "node bin/sync.js"
},
"files": [
"lib"