'f'
mh-two-thousand-and-two
2024-04-12 26f2711ef9461961fb953e2b497bd314ef95e345
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
const path = require('path')
const {
  hasOwn
} = require('./util')
 
const {
  getJson,
  parseJson
} = require('./json')
 
const defaultRouter = {
  mode: 'hash',
  base: '/'
}
 
const defaultAsync = {
  loading: 'AsyncLoading',
  error: 'AsyncError',
  delay: 200,
  timeout: 60000
}
 
const networkTimeout = {
  request: 60000,
  connectSocket: 60000,
  uploadFile: 60000,
  downloadFile: 60000
}
 
function getManifestJson () {
  return getJson('manifest.json')
}
 
function parseManifestJson (content) {
  return parseJson(content)
}
 
function getNetworkTimeout (manifestJson) {
  if (!manifestJson) {
    manifestJson = getManifestJson()
  }
  return Object.assign({}, networkTimeout, manifestJson.networkTimeout || {})
}
 
function getH5Options (manifestJson) {
  if (!manifestJson) {
    manifestJson = getManifestJson()
  }
 
  const h5 = manifestJson[process.env.UNI_SUB_PLATFORM || process.env.UNI_PLATFORM] || {}
 
  h5.appid = (manifestJson.appid || '').replace('__UNI__', '')
 
  h5.title = h5.title || manifestJson.name || ''
 
  h5.router = Object.assign({}, defaultRouter, h5.router || {})
 
  h5.async = Object.assign({}, defaultAsync, h5.async || {})
 
  let base = h5.router.base
 
  if (!base.startsWith('/') && !base.startsWith('./')) {
    base = '/' + base
  }
  if (!base.endsWith('/')) {
    base = base + '/'
  }
  // 相对路径仅支持 hash 模式
  if (base.startsWith('./')) {
    h5.router.mode = defaultRouter.mode
  }
 
  h5.router.base = base
 
  if (process.env.NODE_ENV === 'production') { // 生产模式,启用 publicPath
    h5.publicPath = h5.publicPath || base
 
    if (!h5.publicPath.endsWith('/')) {
      h5.publicPath = h5.publicPath + '/'
    }
  } else { // 其他模式,启用 base
    if (base.startsWith('./')) {
      // 在开发模式, publicPath 如果为 './' webpack-dev-server 匹配文件时会失败
      h5.publicPath = base.substr(1)
    } else {
      h5.publicPath = base
    }
  }
 
  /* eslint-disable no-mixed-operators */
  h5.template = h5.template && path.resolve(process.env.UNI_INPUT_DIR, h5.template) || path.resolve(require('./util')
    .getCLIContext(), 'public/index.html')
 
  h5.devServer = h5.devServer || {}
 
  // 插件修改 h5Options
  global.uniPlugin.configureH5.forEach(configureH5 => {
    configureH5(h5)
  })
 
  return h5
}
 
function isEnableUniPushV1 (manifestJson, platform) {
  if (!manifestJson) {
    manifestJson = getManifestJson()
  }
  if (isEnableUniPushV2(manifestJson, platform)) {
    return false
  }
  if (platform === 'app-plus') {
    const platformOptions = manifestJson[platform]
    const sdkConfigs = platformOptions && platformOptions.distribute && platformOptions.distribute.sdkConfigs
    const push = sdkConfigs && sdkConfigs.push
    if (push && hasOwn(push, 'unipush')) {
      return true
    }
  }
  return false
}
 
function isEnableUniPushV2 (manifestJson, platform) {
  if (!manifestJson) {
    manifestJson = getManifestJson()
  }
  const platformOptions = manifestJson[platform]
  if (platform === 'app-plus') {
    const sdkConfigs = platformOptions && platformOptions.distribute && platformOptions.distribute.sdkConfigs
    const unipush = sdkConfigs && sdkConfigs.push && sdkConfigs.push.unipush
    return (
      /* eslint-disable eqeqeq */
      unipush && unipush.version == '2'
    )
  }
  return platformOptions && platformOptions.unipush && platformOptions.unipush.enable === true
}
 
function isEnableSecureNetwork (manifestJson, platform) {
  if (!manifestJson) {
    manifestJson = getManifestJson()
  }
  const platformOptions = manifestJson[platform]
  if (platform === 'app-plus') {
    return !!(
      platformOptions && platformOptions.modules && platformOptions.modules.SecureNetwork
    )
  }
  return platformOptions && platformOptions.secureNetwork && platformOptions.secureNetwork.enable === true
}
 
function isUniPushOffline (manifestJson) {
  if (!manifestJson) {
    manifestJson = getManifestJson()
  }
  const platformOptions = manifestJson['app-plus']
  const sdkConfigs = platformOptions && platformOptions.distribute && platformOptions.distribute.sdkConfigs
  const unipush = sdkConfigs && sdkConfigs.push && sdkConfigs.push.unipush
  return unipush && unipush.offline === true
}
 
function hasPushModule (manifestJson) {
  if (!manifestJson) {
    manifestJson = getManifestJson()
  }
  const platformOptions = manifestJson['app-plus']
  return platformOptions && platformOptions.modules && platformOptions.modules.Push
}
 
module.exports = {
  getManifestJson,
  parseManifestJson,
  getNetworkTimeout,
  getH5Options,
  isEnableUniPushV1,
  isEnableUniPushV2,
  isUniPushOffline,
  hasPushModule,
  isEnableSecureNetwork
}