| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869 |
- /**
- * 根据 H5 或小程序环境切换 pages.json 配置
- * 用法: node scripts/switch-pages.js h5 | node scripts/switch-pages.js mp-weixin
- */
- const fs = require('fs')
- const path = require('path')
- const pagesJsonPath = path.resolve(__dirname, '../src/pages.json')
- // H5 页面配置
- const h5Pages = [
- {
- path: 'pages/h5/index'
- }
- ]
- // 小程序页面配置
- const mpPages = [
- {
- path: 'pages/devices/index',
- style: {
- navigationBarTitleText: '我的设备'
- }
- },
- {
- path: 'pages/index/result',
- style: {
- navigationBarTitleText: '配网结果'
- }
- },
- {
- path: 'pages/index/index',
- style: {
- navigationBarTitleText: '设备配网'
- }
- },
- {
- path: 'pages/login/login',
- style: {
- navigationBarTitleText: '登录'
- }
- },
- {
- path: 'pages/login/register',
- style: {
- navigationBarTitleText: '注册'
- }
- }
- ]
- const target = process.argv[2]
- if (!target || !['h5', 'mp-weixin'].includes(target)) {
- console.log('请指定目标平台: h5 或 mp-weixin')
- process.exit(1)
- }
- try {
- const pagesJson = JSON.parse(fs.readFileSync(pagesJsonPath, 'utf-8'))
-
- pagesJson.pages = target === 'h5' ? h5Pages : mpPages
-
- fs.writeFileSync(pagesJsonPath, JSON.stringify(pagesJson, null, '\t'), 'utf-8')
- console.log(`已切换到 ${target} 模式`)
- } catch (err) {
- console.error('切换失败:', err)
- process.exit(1)
- }
|