forked from wuchao/uniapp-h5
52 lines
1.8 KiB
JavaScript
52 lines
1.8 KiB
JavaScript
|
import fs from 'fs'
|
||
|
import path from 'path'
|
||
|
import config from './custom.page.js'
|
||
|
|
||
|
const { pages, pagesInclude } = config
|
||
|
|
||
|
const getPages = () => {
|
||
|
const srcPath = path.resolve(__dirname, pages)
|
||
|
// console.log('00',srcPath);
|
||
|
// console.log('01',fs.readdirSync(srcPath));
|
||
|
//所有的模块
|
||
|
const allModule = fs.readdirSync(srcPath);
|
||
|
// console.log('allModule',allModule);
|
||
|
//指定特定页面的模块
|
||
|
const completeModule = pagesInclude.filter(item => item.indexOf('.vue') === -1)
|
||
|
// console.log('completeModule',completeModule);
|
||
|
//需要排除的整个模块
|
||
|
const excludeModule = allModule.filter(item => !completeModule.includes(item))
|
||
|
// console.log('excludeModule',excludeModule);
|
||
|
//指定特定页面的模块
|
||
|
const targetpageModule = pagesInclude.filter(item => item.indexOf('.vue') >= 0)
|
||
|
// console.log(targetpageModule);
|
||
|
const targetModule = targetpageModule.reduce((acc,cur) => {
|
||
|
const [dir,file] = cur.split('/');
|
||
|
if(Array.isArray(acc[dir])){
|
||
|
acc[dir].push(file)
|
||
|
}else{
|
||
|
acc[dir] = [file]
|
||
|
}
|
||
|
return acc
|
||
|
},{})
|
||
|
// console.log(targetModule);
|
||
|
// console.log(fs.readdirSync(path.resolve(__dirname,pages,'xyyk')));
|
||
|
//需要排除的特定的页面
|
||
|
const excludePages = [];
|
||
|
Object.keys(targetModule).forEach((ele,index) => {
|
||
|
if(excludeModule.includes(ele)){
|
||
|
excludeModule.splice(excludeModule.indexOf(ele),1)
|
||
|
}
|
||
|
const targetPages = fs.readdirSync(path.resolve(__dirname,pages,ele)).filter(element => element.indexOf('.vue') >= 0)
|
||
|
const targetExclude = targetPages.filter(elem => !targetModule[ele].includes(elem)).map(current => `${ele}/${current}`)
|
||
|
excludePages.push(...targetExclude)
|
||
|
})
|
||
|
console.log('排除的模块以及页面',[...excludeModule,...excludePages]);
|
||
|
return [...excludeModule,...excludePages]
|
||
|
}
|
||
|
|
||
|
export default getPages
|
||
|
|
||
|
|
||
|
|