marketingSaaS-front_ui/custom.page.js

90 lines
2.8 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import fs from 'fs'
import path from 'path'
/**
* 注意,打包主模板页面(pages/index)先删掉dis文件夹再.gitignore 注释掉dist
* 打包其它模板需要保留dist
*/
const config = {
pages: './src/pages',
// 吉林工行
// pagesInclude: ['jlgh/coupon.vue', 'jlgh/redeem.vue'],
// pagesInclude: ['jlgh/index.vue'],
// pagesInclude: ['jlgh/login.vue'],
// pagesInclude: ['jlgh/orderDetail.vue'],
// 主模版 -- 白板模板
// pagesInclude: ['index'],
// 兴业银行
// pagesInclude: ['xyyh'],
// 云南邮储
// pagesInclude: ['ynyc/login.vue'],
// pagesInclude: ['ynyc/index.vue'],
// 广州移动
// pagesInclude: ['gzyd/login.vue'],
pagesInclude: ['gzyd/index.vue'],
}
export function getPages() {
const srcPath = path.resolve(__dirname, config.pages)
// 所有的模块
const allModule = fs.readdirSync(srcPath)
// 指定的完整模块
const completeModule = config.pagesInclude.filter((item) => item.indexOf('.vue') === -1)
// 需要排除的整个模块
const excludeModule = allModule.filter((item) => !completeModule.includes(item))
// 指定特定页面的模块
const targetpageModule = config.pagesInclude.filter((item) => item.indexOf('.vue') >= 0)
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
}, {})
// 需要排除的特定的页面
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, config.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])
console.log('打包的模块和页面--->', config.pagesInclude)
return {
exclude: [...excludeModule, ...excludePages],
include: config.pagesInclude,
}
}
export function createOutputDir(pageInfo) {
const _pages = pageInfo.filter((item) => item.indexOf('.vue') > -1)
if (!_pages.length) {
return pageInfo.join('-')
} else {
const temp = _pages.reduce((acc, cur) => {
const [dir, file] = cur.split('/')
if (Array.isArray(acc[dir])) {
acc[dir].push(file)
} else {
acc[dir] = [file]
}
return acc
}, {})
const result = Object.entries(temp)[0]
return `${result[0]}-${result[1].join('-').replace(/.vue/g, '')}`
}
}
export default {
getPages,
createOutputDir,
}