修复异常
This commit is contained in:
27
bin/pages.js
27
bin/pages.js
@@ -1,22 +1,25 @@
|
|||||||
const axios = require('axios')
|
const axios = require('axios')
|
||||||
const {chalkTag, findApp, fsExtra, fs} = require("./tools");
|
const {chalkTag, findPages, fsExtra, fs} = require("./tools");
|
||||||
let apps = {list: [], desc: "用于产品库主页面获取应用使用"}
|
let apps = {list: [], desc: "用于产品库主页面获取应用使用"}
|
||||||
const getFileInfo = (app, file) => {
|
const getFileInfo = (app, file) => {
|
||||||
let vue = fs.readFileSync(file).toString()
|
let vue = fs.readFileSync(file).toString()
|
||||||
if (/customNavigation/.test(vue)) {
|
if (/appName/.test(vue)) {
|
||||||
app.style = {navigationStyle: "custom"}
|
let appName = vue.replace(/[\s\S]*(appName:.+),[\s\S]*/gm, '$1')
|
||||||
} else if (/appName/.test(vue)) {
|
app.label = appName.replace(/(appName:|["'])/g, '')
|
||||||
let appName = vue.replace(/[\s\S]*(appName:.+),[\s\S]*/gm, '$1'),
|
if (/customNavigation/.test(vue)) {
|
||||||
title = appName.replace(/(appName:|["'])/g, '')
|
app.style = {navigationStyle: "custom"}
|
||||||
app.style = {navigationBarTitleText: title}
|
} else
|
||||||
|
app.style = {navigationBarTitleText: app.label}
|
||||||
}
|
}
|
||||||
|
/AppPhotoAlbum/.test(app.name)
|
||||||
if (/^App/.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')})
|
apps.list.push({id: name, name, label, path: `/mods/${name}/${name}`, libPath: file?.replace(/\\/g, '/')?.replace(/^src(\/.+)\.vue/, '$1')})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
const saveApps = app => {
|
const saveApps = app => {
|
||||||
if (app.list.length > 0) {
|
if (app.list.length > 0) {
|
||||||
|
console.log(app.list)
|
||||||
axios.post("http://192.168.1.87:12525/node/wechatapps/addOrUpdate", app).then(res => {
|
axios.post("http://192.168.1.87:12525/node/wechatapps/addOrUpdate", app).then(res => {
|
||||||
if (res?.code == 0) chalkTag.done("产品库目录已同步至后台数据库...")
|
if (res?.code == 0) chalkTag.done("产品库目录已同步至后台数据库...")
|
||||||
}).catch(() => 0)
|
}).catch(() => 0)
|
||||||
@@ -45,8 +48,8 @@ const start = () => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
Promise.all([
|
Promise.all([
|
||||||
findApp('src/components/pages', file => {
|
findPages('src/components/pages', file => {
|
||||||
if (/.+\\[^\\]+\\[^\\]+\.vue/g.test(file)) {
|
if (/.+\\pages\\[^\\]+\.vue/g.test(file)) {
|
||||||
let app = {
|
let app = {
|
||||||
path: file.replace(/^src\\components\\pages\\(.*).vue/g, '$1').replace(/\\/g, '/')
|
path: file.replace(/^src\\components\\pages\\(.*).vue/g, '$1').replace(/\\/g, '/')
|
||||||
}
|
}
|
||||||
@@ -54,7 +57,7 @@ const start = () => {
|
|||||||
return json.subPackages[1].pages.push(app)
|
return json.subPackages[1].pages.push(app)
|
||||||
}
|
}
|
||||||
}),
|
}),
|
||||||
findApp('src/mods', file => {
|
findPages('src/mods', file => {
|
||||||
if (/.+\\App[^\\]+\\[^\\]+\.vue/g.test(file)) {
|
if (/.+\\App[^\\]+\\[^\\]+\.vue/g.test(file)) {
|
||||||
let app = {
|
let app = {
|
||||||
name: file.replace(/.*\\([^\\]+).vue/g, '$1'),
|
name: file.replace(/.*\\([^\\]+).vue/g, '$1'),
|
||||||
@@ -64,7 +67,7 @@ const start = () => {
|
|||||||
return json.subPackages[0].pages.push(app)
|
return json.subPackages[0].pages.push(app)
|
||||||
}
|
}
|
||||||
}),
|
}),
|
||||||
findApp('src/project', file => {
|
findPages('src/project', file => {
|
||||||
if (/.+\\App[^\\]+\\[^\\]+\.vue/g.test(file)) {
|
if (/.+\\App[^\\]+\\[^\\]+\.vue/g.test(file)) {
|
||||||
let app = {
|
let app = {
|
||||||
name: file.replace(/.*\\([^\\]+).vue/g, '$1'),
|
name: file.replace(/.*\\([^\\]+).vue/g, '$1'),
|
||||||
|
|||||||
17
bin/tools.js
17
bin/tools.js
@@ -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') => {
|
const copyFiles = (dir, source = 'src/mods') => {
|
||||||
chalkTag.info(`开始扫描${source}...`)
|
chalkTag.info(`开始扫描${source}...`)
|
||||||
return new Promise(resolve => {
|
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}
|
||||||
|
|||||||
Reference in New Issue
Block a user