index.v3.js 3.1 KB
Newer Older
fxy060608's avatar
fxy060608 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
const path = require('path')

const {
  normalizePath
} = require('@dcloudio/uni-cli-shared')

const {
  parsePages,
  addPageUsingComponents
} = require('@dcloudio/uni-cli-shared/lib/pages')

const {
  parseStyle
} = require('../../util')

const definePages = require('./define-pages')
const appConfigService = require('./app-config-service')

fxy060608's avatar
fxy060608 已提交
19 20 21 22 23 24 25 26
function getTabBarPages (appJson) {
  return appJson.tabBar &&
    appJson.tabBar.list &&
    appJson.tabBar.list.length &&
    appJson.tabBar.list
}

function isTabBarPage (pathName, tabBarPages) {
fxy060608's avatar
fxy060608 已提交
27
  return tabBarPages && tabBarPages.find(item => item.pagePath === pathName)
fxy060608's avatar
fxy060608 已提交
28 29
}

fxy060608's avatar
fxy060608 已提交
30 31 32 33 34 35
function parseEntryPagePath (appJson, manifestJson) {
  const argsJsonStr = manifestJson.plus.arguments
  if (argsJsonStr) {
    try {
      const args = JSON.parse(argsJsonStr)
      const pathName = args.path || args.pathName
fxy060608's avatar
fxy060608 已提交
36
      if (pathName && appJson.pages[0] !== pathName) {
fxy060608's avatar
fxy060608 已提交
37
        appJson.entryPagePath = pathName
fxy060608's avatar
fxy060608 已提交
38 39 40
        if (!isTabBarPage(pathName, getTabBarPages(appJson))) {
          appJson.realEntryPagePath = appJson.pages[0]
        }
fxy060608's avatar
fxy060608 已提交
41 42 43 44 45 46 47
      }
    } catch (e) {}
  }
  if (!appJson.entryPagePath) {
    appJson.entryPagePath = appJson.pages[0]
  }
}
fxy060608's avatar
fxy060608 已提交
48

fxy060608's avatar
fxy060608 已提交
49 50 51 52
module.exports = function (appJson, manifestJson, {
  pagesJson,
  manifest,
  normalizeNetworkTimeout
fxy060608's avatar
fxy060608 已提交
53 54
}) {
  parseEntryPagePath(appJson, manifestJson)
fxy060608's avatar
fxy060608 已提交
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77

  // timeout
  normalizeNetworkTimeout(appJson)
  appJson.page = Object.create(null)

  const addPage = function (pagePath, windowOptions, nvue) {
    // 缓存页面级usingComponents
    addPageUsingComponents(pagePath, windowOptions.usingComponents)
    delete windowOptions.usingComponents
    appJson.page[pagePath] = {
      window: windowOptions,
      nvue
    }
  }
  parsePages(pagesJson, function (page) {
    addPage(page.path, parseStyle(page.style), !!page.nvue)
  }, function (root, page) {
    addPage(normalizePath(path.join(root, page.path)), parseStyle(page.style, root), !!page.nvue)
  })
  // nvue 权限
  manifestJson.permissions.UniNView = {
    'description': 'UniNView原生渲染'
  }
fxy060608's avatar
fxy060608 已提交
78

fxy060608's avatar
fxy060608 已提交
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94
  manifestJson.plus.launchwebview.id = '1' // 首页 id 固定 为 1
  // 删除首页 style 中的 uni-app 配置(不注入 app-view.js)
  delete manifestJson.plus.launchwebview['uni-app']

  if (appJson.page[appJson.entryPagePath].nvue) { // 首页是 nvue
    manifestJson.launch_path = '' // 首页地址为空
    manifestJson.plus.launchwebview.uniNView = {
      path: appJson.entryPagePath
    }
    if (manifestJson.plus.tabBar) {
      manifestJson.plus.tabBar.child = ['lauchwebview']
    }
  } else {
    manifestJson.plus.launch_path = '__uniappview.html' // 首页地址固定
  }

Q
qiang 已提交
95 96 97 98
  // nvue 首页启动模式
  manifestJson.plus['uni-app'].nvueLaunchMode = manifestJson.plus.nvueLaunchMode === 'fast' ? 'fast' : 'normal'
  delete manifestJson.plus.nvueLaunchMode

fxy060608's avatar
fxy060608 已提交
99 100 101 102
  manifest.name = 'manifest.json'
  manifest.content = JSON.stringify(manifest.content)
  delete appJson.nvue
  return [manifest, definePages(appJson), appConfigService(appJson)]
Q
qiang 已提交
103
}