/**
* 生成各分包薄壳页面(通用模板页,module 参数由注册表驱动)
* 用法:node scripts/gen-pages.mjs
*/
import fs from 'node:fs'
import path from 'node:path'
import { fileURLToPath } from 'node:url'
const root = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '..')
const BILL_PKGS = [
'packageBasic', 'packageMaterial', 'packagePurchase', 'packageSales',
'packageRetail', 'packageWarehouse', 'packageFinance', 'packageProductionLogistics'
]
const REPORT_PKGS = ['packageReport']
const LIST_VUE = `
+
`
const DETAIL_VUE = `
`
const EDIT_VUE = `
`
const REPORT_LIST_VUE = `
`
function write(rel, content) {
const file = path.join(root, 'src', rel)
fs.mkdirSync(path.dirname(file), { recursive: true })
fs.writeFileSync(file, content, 'utf8')
console.log('generated:', rel)
}
for (const pkg of BILL_PKGS) {
write(`${pkg}/pages/list.vue`, LIST_VUE)
write(`${pkg}/pages/detail.vue`, DETAIL_VUE)
write(`${pkg}/pages/edit.vue`, EDIT_VUE)
}
for (const pkg of REPORT_PKGS) {
write(`${pkg}/pages/list.vue`, REPORT_LIST_VUE)
}
// pages.json:为列表页开启下拉刷新
const pagesJsonPath = path.join(root, 'src', 'pages.json')
const pagesJson = JSON.parse(fs.readFileSync(pagesJsonPath, 'utf8'))
for (const sub of pagesJson.subPackages) {
for (const page of sub.pages) {
if (page.path === 'pages/list') {
page.style = { ...page.style, enablePullDownRefresh: true }
}
}
}
fs.writeFileSync(pagesJsonPath, JSON.stringify(pagesJson, null, 2) + '\n', 'utf8')
console.log('pages.json: enablePullDownRefresh applied to list pages')