-
Notifications
You must be signed in to change notification settings - Fork 389
Expand file tree
/
Copy pathconvertor.js
More file actions
53 lines (50 loc) · 1.77 KB
/
convertor.js
File metadata and controls
53 lines (50 loc) · 1.77 KB
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
import { LIFECYCLE, lifecycleProxyMap, pageMode } from '../platform/patch/lifecycle/index'
import { mergeLifecycle } from './mergeLifecycle'
import { error, extend } from '@mpxjs/utils'
import wxToAliRule from './wxToAli'
import wxToWebRule from './wxToWeb'
import wxToSwanRule from './wxToSwan'
import wxToQqRule from './wxToQq'
import wxToTtRule from './wxToTt'
import wxToDdRule from './wxToDd'
import wxToJdRule from './wxToJd'
import wxToReactRule from './wxToReact'
import wxToKsRule from './wxToKs'
/**
* 转换规则包含四点
* lifecycle [object] 生命周期
* lifecycleProxyMap [object] 代理规则
* pageMode [string] 页面生命周期合并模式,是否为blend
* support [boolean]当前平台是否支持blend
* convert [function] 自定义转换函数, 接收一个options
*/
const defaultConvertRule = {
lifecycle: mergeLifecycle(LIFECYCLE),
lifecycleProxyMap: lifecycleProxyMap,
pageMode,
support: !!pageMode,
convert: null
}
const rulesMap = {
local: extend({}, defaultConvertRule),
default: defaultConvertRule,
wxToWeb: wxToWebRule,
wxToAli: wxToAliRule,
wxToSwan: wxToSwanRule,
wxToQq: extend({}, defaultConvertRule, wxToQqRule),
wxToTt: extend({}, defaultConvertRule, wxToTtRule),
wxToDd: extend({}, defaultConvertRule, wxToDdRule),
wxToJd: extend({}, defaultConvertRule, wxToJdRule),
wxToIos: extend({}, defaultConvertRule, wxToReactRule),
wxToAndroid: extend({}, defaultConvertRule, wxToReactRule),
wxToHarmony: extend({}, defaultConvertRule, wxToReactRule),
wxToKs: extend({}, defaultConvertRule, wxToKsRule)
}
export function getConvertRule (convertMode) {
const rule = rulesMap[convertMode]
if (!rule || !rule.lifecycle) {
error(`Absence of convert rule for ${convertMode}, please check.`)
} else {
return rule
}
}