76 lines
		
	
	
		
			2.5 KiB
		
	
	
	
		
			JavaScript
		
	
	
	
	
	
			
		
		
	
	
			76 lines
		
	
	
		
			2.5 KiB
		
	
	
	
		
			JavaScript
		
	
	
	
	
	
| const {chalkTag, findPages, fsExtra, fs} = require("./tools");
 | |
| const PageBase = require("dvcp-wui/utils/PageBase");
 | |
| let apps = {list: [], desc: "用于产品库主页面获取应用使用", type: "mp"}
 | |
| const getFileInfo = (app, file) => {
 | |
|   if (/^App/.test(app.name)) {
 | |
|     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('开始生成pages.json...')
 | |
|   let json = {
 | |
|     easycom: {
 | |
|       "^u-(.*)": "uview-ui/components/u-$1/u-$1.vue",
 | |
|       "^(Ai|V)(.*)": "@/components/$1$2/$1$2.vue",
 | |
|     },
 | |
|     pages: [
 | |
|       {path: 'pages/home', style: {navigationBarTitleText: "小程序应用库"}}
 | |
|     ],
 | |
|     subPackages: [
 | |
|       {root: "mods/", pages: []},
 | |
|       {root: "components/pages/", pages: []},
 | |
|       {root: "project/", pages: []},
 | |
|     ],
 | |
|     globalStyle: {
 | |
|       pageOrientation: "auto",
 | |
|       navigationBarTextStyle: "white",
 | |
|       navigationBarBackgroundColor: "#4181FF",
 | |
|       "mp-weixin": {
 | |
|         "usingComponents": {
 | |
|           "cell": "plugin://materialPlugin/cell",
 | |
|           "qplayer": "plugin://player/video"
 | |
|         }
 | |
|       }
 | |
|     }
 | |
|   }
 | |
|   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())
 | |
|         getFileInfo(app, file)
 | |
|         return json.subPackages[1].pages.push(app)
 | |
|       }
 | |
|     }),
 | |
|     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())
 | |
|         getFileInfo(app, file)
 | |
|         return json.subPackages[0].pages.push(app)
 | |
|       }
 | |
|     }),
 | |
|     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())
 | |
|         getFileInfo(app, file)
 | |
|         return json.subPackages[2].pages.push(app)
 | |
|       }
 | |
|     })
 | |
|   ]).then(() => {
 | |
|     fsExtra.outputJson('src/config.json', {apps: apps.list})
 | |
|     fsExtra.outputJson('src/pages.json', json, () => {
 | |
|       chalkTag.done('生成pages.json')
 | |
|     })
 | |
|   })
 | |
| }
 | |
| 
 | |
| start();
 |