diff --git a/.gitignore b/.gitignore index cdb796a..badd2ed 100644 --- a/.gitignore +++ b/.gitignore @@ -25,3 +25,4 @@ yarn-error.log* /.hbuilderx/launch.json /src/pages.json /src/mods/project/ +/src/pages/apps.json diff --git a/bin/pages.js b/bin/pages.js index 52f5168..4e9ac34 100644 --- a/bin/pages.js +++ b/bin/pages.js @@ -1,6 +1,7 @@ const fsExtra = require('fs-extra') const path = require('path') const fs = require('fs') +const axios = require('axios') /** * 将函数封装成promise */ @@ -53,23 +54,8 @@ const findApp = (dir, cb) => { }) || []) }) } -/** - * 迁移apps文件 - */ -const copyFiles = (dir, source = 'src/mods') => { - chalkTag.info(`开始扫描${source}...`) - return new Promise(resolve => { - fsExtra.emptyDir(dir, err => { - if (!err) { - fsExtra.copy(source, dir).then(() => { - chalkTag.done(source + ' 扫描完毕') - resolve() - }) - } - }) - }) -} -const setPageStyle = (app, file) => { +let apps = {list: [], desc: "用于产品库主页面获取应用使用"} +const getFileInfo = (app, file) => { let vue = fs.readFileSync(file).toString() if (/customNavigation/.test(vue)) { app.style = {navigationStyle: "custom"} @@ -78,6 +64,13 @@ const setPageStyle = (app, file) => { title = appName.replace(/(appName:|["'])/g, '') app.style = {navigationBarTitleText: title} } + if (/^App/.test(app.name)) { + let {name, style: {navigationBarTitleText: label}} = app + apps.list.push({id: name, name, label, path: `/mods/${name}/${name}`, libPath: file?.replace(/\\/g, '/')?.replace(/^src(\/.+)\.vue/, '$1')}) + } +} +const saveApps = app => { + axios.post("http://localhost:12525/node/wechatapps/addOrUpdate", app).catch(() => 0) } const start = () => { chalkTag.info('开始生成pages.json...') @@ -107,7 +100,7 @@ const start = () => { let app = { path: file.replace(/^src\\components\\pages\\(.*).vue/g, '$1').replace(/\\/g, '/') } - setPageStyle(app, file) + getFileInfo(app, file) return json.subPackages[1].pages.push(app) } }), @@ -117,7 +110,7 @@ const start = () => { name: file.replace(/.*\\([^\\]+).vue/g, '$1'), path: file.replace(/^src\\mods\\(.*).vue/g, '$1').replace(/\\/g, '/') } - setPageStyle(app, file) + getFileInfo(app, file) return json.subPackages[0].pages.push(app) } }), @@ -127,11 +120,12 @@ const start = () => { name: file.replace(/.*\\([^\\]+).vue/g, '$1'), path: file.replace(/^src\\project\\(.*).vue/g, '$1').replace(/\\/g, '/') } - setPageStyle(app, file) + getFileInfo(app, file) return json.subPackages[2].pages.push(app) } }) ]).then(() => { + saveApps(apps) fsExtra.outputJson('src/pages.json', json, () => { chalkTag.done('生成pages.json') }) diff --git a/src/pages/home.vue b/src/pages/home.vue index e3b1baa..8255e4f 100644 --- a/src/pages/home.vue +++ b/src/pages/home.vue @@ -22,10 +22,10 @@