From f0babad99525d2dee40d18d100e32564472e8280 Mon Sep 17 00:00:00 2001 From: aixianling Date: Thu, 12 May 2022 11:26:36 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E5=BC=82=E5=B8=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bin/pages.js | 27 +++++++++++++++------------ bin/tools.js | 17 ++++++++++++++++- 2 files changed, 31 insertions(+), 13 deletions(-) diff --git a/bin/pages.js b/bin/pages.js index a2e1469..004d22d 100644 --- a/bin/pages.js +++ b/bin/pages.js @@ -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'), diff --git a/bin/tools.js b/bin/tools.js index 8ea4c5d..e7d2163 100644 --- a/bin/tools.js +++ b/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') => { 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}