Skip to content

Commit

Permalink
fix: entry catalog for .vue
Browse files Browse the repository at this point in the history
  • Loading branch information
zwwill committed Dec 5, 2018
1 parent 8ccfb58 commit 978381a
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 38 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
'use strict'
const { getAppObj } = require('./util')
const { getAppObj } = require('../util')

// 获取指定目录下符合glob的所有文件
module.exports = function(file) {
Expand Down
49 changes: 49 additions & 0 deletions lib/func/pagesEntry.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
'use strict'
const path = require( 'path' )
const { getAppObj } = require('../util')
const fs = require('fs')

const matchPath = function (p) {
const files = [path.resolve(`src/${p}.js`),path.resolve(`src/${p}.vue`)]
return fs.existsSync(files[0]) && files[0] || fs.existsSync(files[1]) && files[1]
}

// 获取指定目录下符合glob的所有文件
module.exports = function(file, whileList = []) {
let entries = {},
mainObj = {},
pages,
subpackages

try {
mainObj = getAppObj(file) || {}
pages = mainObj.pages || []
subpackages = mainObj.subpackages || mainObj.subPackages || []

pages.forEach(p=>{
// const _p = p.replace(/^pages(\/[^\/]*)(\/[^\/]*)?/,($0,$1,$2)=>{return `pages${$1}${$2||$1}`})
matchPath(p) && (entries[p] = matchPath(p))
})
subpackages.forEach(sp=>{
let {root, pages} = sp
if(root && pages.length>0){
pages.forEach(p=>{
// const _p = p.replace(/^pages(\/[^\/]*)(\/[^\/]*)?/,($0,$1,$2)=>{return `pages${$1}${$2||$1}`})
matchPath(`${root}/${p}`) && (entries[`${root}/${p}`] = matchPath(`${root}/${p}`))
})
}
})

// 白名单筛选
if(whileList.length > 0){
for(let p in entries){
whileList.indexOf(p) === -1 && (delete entries[p])
}
}

} catch (e) {
console.log(e)
}

return entries
}
4 changes: 2 additions & 2 deletions lib/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const pagesEntry = require( './pagesEntry' )
const getSubPackagesRoot = require( './getSubPackagesRoot' )
const pagesEntry = require( './func/pagesEntry' )
const getSubPackagesRoot = require( './func/getSubPackagesRoot' )

module.exports = {
pagesEntry,
Expand Down
34 changes: 0 additions & 34 deletions lib/pagesEntry.js

This file was deleted.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@megalo/entry",
"version": "0.1.0",
"version": "0.1.1",
"description": "",
"main": "lib/index.js",
"scripts": {
Expand Down

0 comments on commit 978381a

Please sign in to comment.