-
Notifications
You must be signed in to change notification settings - Fork 1
/
buildWebTypes.js
75 lines (63 loc) · 1.67 KB
/
buildWebTypes.js
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
import helper from "components-helper"
helper({
name: 'sss-ui-plus',
"version": "0.2.2-beta-1",
entry: 'docs/comps/basic/button/*.md',
outDir: '.',
reComponentName,
reDocUrl,
reAttribute,
reWebTypesSource,
space: 2,
props:'props',
propsName:'属性名',
propsDescription:'说明',
propsType:'类型',
propsDefault:'默认值',
separator:'/'
})
function reComponentName(title) {
console.log(title)
return (
's-' +
title
.replace(/\B([A-Z])/g, '-$1')
.replace(/[ ]+/g, '-')
.toLowerCase()
)
}
function reWebTypesSource(title) {
const symbol =
'S' +
title
.replace(/-/, ' ')
.replace(/^\w|\s+\w/g, (item) => item.trim().toUpperCase())
return { symbol }
}
function reDocUrl(fileName, header, path) {
const url = (path.split('/').slice(1,-1).join('/') +'/').toLowerCase()
const docs = 'https://sssui.4everland.app/'
const _header = header ? header.replace(/[ ]+/g, '-') : undefined
return docs + url + (_header ? ('#' + _header).toLowerCase() : '')
}
function reAttribute(str, key) {
switch (str) {
case '':
case '-':
case '—':
return undefined
case 'v-model':
return 'model-value'
default:
if (key === 'Subtags') {
return str
? str
.split('/')
.map((name) => reComponentName(name.trim()))
.join('/')
: str
} else {
return str.replace(/`([^`]+)`/g, '$1')
}
}
}