-
Notifications
You must be signed in to change notification settings - Fork 4.7k
/
constants.ts
304 lines (285 loc) · 8.02 KB
/
constants.ts
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
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
import * as os from 'os'
import chalk, { Chalk } from 'chalk'
export const CSS_EXT: string[] = ['.css', '.scss', '.sass', '.less', '.styl', '.wxss', '.acss']
export const SCSS_EXT: string[] = ['.scss']
export const JS_EXT: string[] = ['.js', '.jsx']
export const TS_EXT: string[] = ['.ts', '.tsx']
export const UX_EXT: string[] = ['.ux']
export const REG_JS: RegExp = /\.js(\?.*)?$/
export const REG_SCRIPT: RegExp = /\.(js|jsx)(\?.*)?$/
export const REG_TYPESCRIPT: RegExp = /\.(tsx|ts)(\?.*)?$/
export const REG_SCRIPTS: RegExp = /\.[tj]sx?$/i
export const REG_SASS: RegExp = /\.(s[ac]ss)$/
export const REG_LESS: RegExp = /\.less$/
export const REG_STYLUS: RegExp = /\.styl$/
export const REG_STYLE: RegExp = /\.(css|scss|sass|less|styl|wxss|acss)(\?.*)?$/
export const REG_MEDIA: RegExp = /\.(mp4|webm|ogg|mp3|wav|flac|aac)(\?.*)?$/
export const REG_IMAGE: RegExp = /\.(png|jpe?g|gif|bpm|svg|webp)(\?.*)?$/
export const REG_FONT: RegExp = /\.(woff2?|eot|ttf|otf)(\?.*)?$/
export const REG_JSON: RegExp = /\.json(\?.*)?$/
export const REG_UX: RegExp = /\.ux(\?.*)?$/
export const REG_WXML_IMPORT: RegExp = /<import(.*)?src=(?:(?:'([^']*)')|(?:"([^"]*)"))/gi
export const REG_URL: RegExp = /^(?:(?:(?:https?|ftp):)?\/\/)(?:\S+(?::\S*)?@)?(?:(?!(?:10|127)(?:\.\d{1,3}){3})(?!(?:169\.254|192\.168)(?:\.\d{1,3}){2})(?!172\.(?:1[6-9]|2\d|3[0-1])(?:\.\d{1,3}){2})(?:[1-9]\d?|1\d\d|2[01]\d|22[0-3])(?:\.(?:1?\d{1,2}|2[0-4]\d|25[0-5])){2}(?:\.(?:[1-9]\d?|1\d\d|2[0-4]\d|25[0-4]))|(?:(?:[a-z\u00a1-\uffff0-9]-*)*[a-z\u00a1-\uffff0-9]+)(?:\.(?:[a-z\u00a1-\uffff0-9]-*)*[a-z\u00a1-\uffff0-9]+)*(?:\.(?:[a-z\u00a1-\uffff]{2,}))\.?)(?::\d{2,5})?(?:[/?#]\S*)?$/i
export const CSS_IMPORT_REG: RegExp = /@import (["'])(.+?)\1;/g
export const NODE_MODULES = 'node_modules'
export const NODE_MODULES_REG = /(.*)node_modules/
export const enum BUILD_TYPES {
WEAPP = 'weapp',
SWAN = 'swan',
ALIPAY = 'alipay',
TT = 'tt',
UI = 'ui',
PLUGIN = 'plugin',
QUICKAPP = 'quickapp',
QQ = 'qq',
JD = 'jd'
}
export const enum TEMPLATE_TYPES {
WEAPP = '.wxml',
SWAN = '.swan',
ALIPAY = '.axml',
TT = '.ttml',
QUICKAPP = '.ux',
QQ = '.qml',
JD = '.jxml'
}
export const enum STYLE_TYPES {
WEAPP = '.wxss',
SWAN = '.css',
ALIPAY = '.acss',
TT = '.ttss',
QUICKAPP = '.css',
QQ = '.qss',
JD = '.jxss'
}
export const enum SCRIPT_TYPES {
WEAPP = '.js',
SWAN = '.js',
ALIPAY = '.js',
TT = '.js',
QUICKAPP = '.js',
QQ = '.js',
JD = '.js'
}
export const enum CONFIG_TYPES {
WEAPP = '.json',
SWAN = '.json',
ALIPAY = '.json',
TT = '.json',
QUICKAPP = '.json',
QQ = '.json',
JD = '.json'
}
export type IMINI_APP_FILE_TYPE = {
TEMPL: TEMPLATE_TYPES,
STYLE: STYLE_TYPES,
SCRIPT: SCRIPT_TYPES,
CONFIG: CONFIG_TYPES
}
export type IMINI_APP_FILES = {
[key: string]: IMINI_APP_FILE_TYPE
}
export const MINI_APP_FILES: IMINI_APP_FILES = {
[BUILD_TYPES.WEAPP]: {
TEMPL: TEMPLATE_TYPES.WEAPP,
STYLE: STYLE_TYPES.WEAPP,
SCRIPT: SCRIPT_TYPES.WEAPP,
CONFIG: CONFIG_TYPES.WEAPP
},
[BUILD_TYPES.SWAN]: {
TEMPL: TEMPLATE_TYPES.SWAN,
STYLE: STYLE_TYPES.SWAN,
SCRIPT: SCRIPT_TYPES.SWAN,
CONFIG: CONFIG_TYPES.SWAN
},
[BUILD_TYPES.ALIPAY]: {
TEMPL: TEMPLATE_TYPES.ALIPAY,
STYLE: STYLE_TYPES.ALIPAY,
SCRIPT: SCRIPT_TYPES.ALIPAY,
CONFIG: CONFIG_TYPES.ALIPAY
},
[BUILD_TYPES.TT]: {
TEMPL: TEMPLATE_TYPES.TT,
STYLE: STYLE_TYPES.TT,
SCRIPT: SCRIPT_TYPES.TT,
CONFIG: CONFIG_TYPES.TT
},
[BUILD_TYPES.QUICKAPP]: {
TEMPL: TEMPLATE_TYPES.QUICKAPP,
STYLE: STYLE_TYPES.QUICKAPP,
SCRIPT: SCRIPT_TYPES.QUICKAPP,
CONFIG: CONFIG_TYPES.QUICKAPP
},
[BUILD_TYPES.QQ]: {
TEMPL: TEMPLATE_TYPES.QQ,
STYLE: STYLE_TYPES.QQ,
SCRIPT: SCRIPT_TYPES.QQ,
CONFIG: CONFIG_TYPES.QQ
},
[BUILD_TYPES.JD]: {
TEMPL: TEMPLATE_TYPES.JD,
STYLE: STYLE_TYPES.JD,
SCRIPT: SCRIPT_TYPES.JD,
CONFIG: CONFIG_TYPES.JD
}
}
export const CONFIG_MAP = {
[BUILD_TYPES.WEAPP]: {
navigationBarTitleText: 'navigationBarTitleText',
navigationBarBackgroundColor: 'navigationBarBackgroundColor',
enablePullDownRefresh: 'enablePullDownRefresh',
list: 'list',
text: 'text',
iconPath: 'iconPath',
selectedIconPath: 'selectedIconPath',
color: 'color'
},
[BUILD_TYPES.SWAN]: {
navigationBarTitleText: 'navigationBarTitleText',
navigationBarBackgroundColor: 'navigationBarBackgroundColor',
enablePullDownRefresh: 'enablePullDownRefresh',
list: 'list',
text: 'text',
iconPath: 'iconPath',
selectedIconPath: 'selectedIconPath',
color: 'color'
},
[BUILD_TYPES.TT]: {
navigationBarTitleText: 'navigationBarTitleText',
navigationBarBackgroundColor: 'navigationBarBackgroundColor',
enablePullDownRefresh: 'enablePullDownRefresh',
list: 'list',
text: 'text',
iconPath: 'iconPath',
selectedIconPath: 'selectedIconPath',
color: 'color'
},
[BUILD_TYPES.ALIPAY]: {
navigationBarTitleText: 'defaultTitle',
navigationBarBackgroundColor: 'titleBarColor',
enablePullDownRefresh: 'pullRefresh',
list: 'items',
text: 'name',
iconPath: 'icon',
selectedIconPath: 'activeIcon',
color: 'textColor'
},
[BUILD_TYPES.QUICKAPP]: {
navigationBarTitleText: 'titleBarText',
navigationBarBackgroundColor: 'titleBarBackgroundColor',
navigationBarTextStyle: 'titleBarTextColor',
pageOrientation: 'orientation',
list: 'list',
text: 'text',
iconPath: 'iconPath',
selectedIconPath: 'selectedIconPath',
backgroundTextStyle: false,
onReachBottomDistance: false,
backgroundColorBottom: false,
backgroundColorTop: false,
enablePullDownRefresh: false,
navigationStyle: 'navigationStyle'
},
[BUILD_TYPES.QQ]: {
navigationBarTitleText: 'navigationBarTitleText',
navigationBarBackgroundColor: 'navigationBarBackgroundColor',
enablePullDownRefresh: 'enablePullDownRefresh',
list: 'list',
text: 'text',
iconPath: 'iconPath',
selectedIconPath: 'selectedIconPath',
color: 'color'
},
[BUILD_TYPES.JD]: {
navigationBarTitleText: 'navigationBarTitleText',
navigationBarBackgroundColor: 'navigationBarBackgroundColor',
enablePullDownRefresh: 'enablePullDownRefresh',
list: 'list',
text: 'text',
iconPath: 'iconPath',
selectedIconPath: 'selectedIconPath',
color: 'color'
}
}
export const taroJsComponents = '@tarojs/components'
export const taroJsQuickAppComponents = '@tarojs/components-qa'
export const taroJsFramework = '@tarojs/taro'
export const taroJsRedux = '@tarojs/redux'
export const DEVICE_RATIO_NAME = 'deviceRatio'
export const isWindows = os.platform() === 'win32'
export const QUICKAPP_SPECIAL_COMPONENTS = new Set<string>([
'View',
'Text'
])
export enum PARSE_AST_TYPE {
ENTRY = 'ENTRY',
PAGE = 'PAGE',
COMPONENT = 'COMPONENT',
NORMAL = 'NORMAL',
STATIC = 'STATIC'
}
export const enum processTypeEnum {
START = 'start',
CREATE = 'create',
COMPILE = 'compile',
CONVERT = 'convert',
COPY = 'copy',
GENERATE = 'generate',
MODIFY = 'modify',
ERROR = 'error',
WARNING = 'warning',
UNLINK = 'unlink',
REFERENCE = 'reference'
}
export interface IProcessTypeMap {
[key: string] : {
name: string,
color: string | Chalk
}
}
export const processTypeMap: IProcessTypeMap = {
[processTypeEnum.CREATE]: {
name: '创建',
color: 'cyan'
},
[processTypeEnum.COMPILE]: {
name: '编译',
color: 'green'
},
[processTypeEnum.CONVERT]: {
name: '转换',
color: chalk.rgb(255, 136, 0)
},
[processTypeEnum.COPY]: {
name: '拷贝',
color: 'magenta'
},
[processTypeEnum.GENERATE]: {
name: '生成',
color: 'blue'
},
[processTypeEnum.MODIFY]: {
name: '修改',
color: 'yellow'
},
[processTypeEnum.ERROR]: {
name: '错误',
color: 'red'
},
[processTypeEnum.WARNING]: {
name: '警告',
color: 'yellowBright'
},
[processTypeEnum.UNLINK]: {
name: '删除',
color: 'magenta'
},
[processTypeEnum.START]: {
name: '启动',
color: 'green'
},
[processTypeEnum.REFERENCE]: {
name: '引用',
color: 'blue'
}
}