修复异常

This commit is contained in:
aixianling
2022-05-12 11:26:36 +08:00
parent 5a4c6103e6
commit f0babad995
2 changed files with 31 additions and 13 deletions

View File

@@ -1,22 +1,25 @@
const axios = require('axios')
const {chalkTag, findApp, fsExtra, fs} = require("./tools");
const {chalkTag, findPages, fsExtra, fs} = require("./tools");
let apps = {list: [], desc: "用于产品库主页面获取应用使用"}
const getFileInfo = (app, file) => {
let vue = fs.readFileSync(file).toString()
if (/customNavigation/.test(vue)) {
app.style = {navigationStyle: "custom"}
} else if (/appName/.test(vue)) {
let appName = vue.replace(/[\s\S]*(appName:.+),[\s\S]*/gm, '$1'),
title = appName.replace(/(appName:|["'])/g, '')
app.style = {navigationBarTitleText: title}
if (/appName/.test(vue)) {
let appName = vue.replace(/[\s\S]*(appName:.+),[\s\S]*/gm, '$1')
app.label = appName.replace(/(appName:|["'])/g, '')
if (/customNavigation/.test(vue)) {
app.style = {navigationStyle: "custom"}
} else
app.style = {navigationBarTitleText: app.label}
}
/AppPhotoAlbum/.test(app.name)
if (/^App/.test(app.name)) {
let {name, style: {navigationBarTitleText: label}} = app
let {name, label} = app
apps.list.push({id: name, name, label, path: `/mods/${name}/${name}`, libPath: file?.replace(/\\/g, '/')?.replace(/^src(\/.+)\.vue/, '$1')})
}
}
const saveApps = app => {
if (app.list.length > 0) {
console.log(app.list)
axios.post("http://192.168.1.87:12525/node/wechatapps/addOrUpdate", app).then(res => {
if (res?.code == 0) chalkTag.done("产品库目录已同步至后台数据库...")
}).catch(() => 0)
@@ -45,8 +48,8 @@ const start = () => {
}
}
Promise.all([
findApp('src/components/pages', file => {
if (/.+\\[^\\]+\\[^\\]+\.vue/g.test(file)) {
findPages('src/components/pages', file => {
if (/.+\\pages\\[^\\]+\.vue/g.test(file)) {
let app = {
path: file.replace(/^src\\components\\pages\\(.*).vue/g, '$1').replace(/\\/g, '/')
}
@@ -54,7 +57,7 @@ const start = () => {
return json.subPackages[1].pages.push(app)
}
}),
findApp('src/mods', file => {
findPages('src/mods', file => {
if (/.+\\App[^\\]+\\[^\\]+\.vue/g.test(file)) {
let app = {
name: file.replace(/.*\\([^\\]+).vue/g, '$1'),
@@ -64,7 +67,7 @@ const start = () => {
return json.subPackages[0].pages.push(app)
}
}),
findApp('src/project', file => {
findPages('src/project', file => {
if (/.+\\App[^\\]+\\[^\\]+\.vue/g.test(file)) {
let app = {
name: file.replace(/.*\\([^\\]+).vue/g, '$1'),

View File

@@ -54,6 +54,21 @@ const findApp = (dir, cb) => {
}) || [])
})
}
const findPages = (dir, cb) => {
fsExtra.ensureDirSync(dir)
return readdir(dir).then(apps => {
return Promise.all(apps.map(e => {
let cPath = path.join(dir, e)
return stat(cPath).then(state => {
if (state.isDirectory()) {
return findPages(cPath, cb)
} else if (state.isFile()) {
cb && cb(cPath)
}
})
}) || [])
})
}
const copyFiles = (dir, source = 'src/mods') => {
chalkTag.info(`开始扫描${source}...`)
return new Promise(resolve => {
@@ -67,4 +82,4 @@ const copyFiles = (dir, source = 'src/mods') => {
})
})
}
module.exports = {findApp, chalkTag, fsExtra, copyFiles, fs, path}
module.exports = {findApp, chalkTag, fsExtra, copyFiles, fs, path, findPages}