2021-09-29 13:19:19 +08:00
|
|
|
import path from 'path'
|
2021-09-26 01:29:07 +08:00
|
|
|
import helper from 'components-helper'
|
2021-09-29 13:19:19 +08:00
|
|
|
import { epPackage, epOutput, projRoot } from './utils/paths'
|
2021-09-26 01:29:07 +08:00
|
|
|
import { getPackageManifest } from './utils/pkg'
|
|
|
|
import type { TaskFunction } from 'gulp'
|
|
|
|
import type { InstallOptions } from 'components-helper/lib/type'
|
|
|
|
|
|
|
|
const reComponentName: InstallOptions['reComponentName'] = (title: string) =>
|
|
|
|
`el-${title
|
|
|
|
.replace(/\B([A-Z])/g, '-$1')
|
|
|
|
.replace(/[ ]+/g, '-')
|
|
|
|
.toLowerCase()}`
|
|
|
|
|
|
|
|
const reDocUrl: InstallOptions['reDocUrl'] = (fileName, header) => {
|
|
|
|
const docs = 'https://element-plus.org/en-US/component/'
|
2021-09-30 17:22:26 +08:00
|
|
|
const _header = header ? header.replaceAll(/\s+/g, '-').toLowerCase() : ''
|
|
|
|
|
|
|
|
return `${docs}${fileName}.html${_header ? '#' : ''}${_header}`
|
2021-09-26 01:29:07 +08:00
|
|
|
}
|
|
|
|
|
2021-09-30 15:36:39 +08:00
|
|
|
const reWebTypesSource: InstallOptions['reWebTypesSource'] = (title) => {
|
|
|
|
const symbol = `El${title
|
|
|
|
.replaceAll(/-/g, ' ')
|
|
|
|
.replaceAll(/^\w|\s+\w/g, (item) => {
|
|
|
|
return item.trim().toUpperCase()
|
|
|
|
})}`
|
|
|
|
|
|
|
|
return { symbol }
|
|
|
|
}
|
|
|
|
|
2021-09-26 01:29:07 +08:00
|
|
|
const reAttribute: InstallOptions['reAttribute'] = (value, key) => {
|
|
|
|
const _value = value.match(/^\*\*(.*)\*\*$/)
|
|
|
|
const str = _value ? _value[1] : value
|
|
|
|
|
|
|
|
if (key === 'Name' && /^(-|—)$/.test(str)) {
|
|
|
|
return 'default'
|
|
|
|
} else if (str === '' || /^(-|—)$/.test(str)) {
|
|
|
|
return undefined
|
|
|
|
} else if (key === 'Attribute' && /v-model:(.+)/.test(str)) {
|
|
|
|
const _str = str.match(/v-model:(.+)/)
|
|
|
|
return _str ? _str[1] : undefined
|
|
|
|
} else if (key === 'Attribute' && /v-model/.test(str)) {
|
|
|
|
return 'model-value'
|
|
|
|
} else if (key === 'Attribute') {
|
|
|
|
return str.replace(/\B([A-Z])/g, '-$1').toLowerCase()
|
|
|
|
} else if (key === 'Type') {
|
|
|
|
return str
|
|
|
|
.replace(/\s*\/\s*/g, '|')
|
|
|
|
.replace(/\s*,\s*/g, '|')
|
|
|
|
.replace(/\(.*\)/g, '')
|
|
|
|
.toLowerCase()
|
|
|
|
} else if (key === 'Accepted Values') {
|
|
|
|
return /\[.+\]\(.+\)/.test(str) || /^\*$/.test(str)
|
|
|
|
? undefined
|
|
|
|
: str.replace(/`/g, '')
|
2021-10-04 08:26:51 +08:00
|
|
|
} else if (key === 'Subtags') {
|
|
|
|
return str
|
|
|
|
? `el-${str
|
|
|
|
.replaceAll(/\s*\/\s*/g, '/el-')
|
|
|
|
.replaceAll(/\B([A-Z])/g, '-$1')
|
|
|
|
.replaceAll(/\s+/g, '-')
|
|
|
|
.toLowerCase()}`
|
|
|
|
: undefined
|
2021-09-26 01:29:07 +08:00
|
|
|
} else {
|
|
|
|
return str
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export const buildHelper: TaskFunction = (done) => {
|
|
|
|
const { name, version } = getPackageManifest(epPackage)
|
|
|
|
|
|
|
|
const tagVer = process.env.TAG_VERSION
|
|
|
|
const _version = tagVer
|
|
|
|
? tagVer.startsWith('v')
|
|
|
|
? tagVer.slice(1)
|
|
|
|
: tagVer
|
|
|
|
: version!
|
|
|
|
|
|
|
|
helper({
|
|
|
|
name: name!,
|
|
|
|
version: _version,
|
2021-09-29 13:19:19 +08:00
|
|
|
entry: `${path.resolve(
|
|
|
|
projRoot,
|
|
|
|
'docs/en-US/component'
|
|
|
|
)}/!(datetime-picker|message-box|message).md`,
|
2021-09-26 01:29:07 +08:00
|
|
|
outDir: epOutput,
|
|
|
|
reComponentName,
|
|
|
|
reDocUrl,
|
2021-09-30 15:36:39 +08:00
|
|
|
reWebTypesSource,
|
2021-09-26 01:29:07 +08:00
|
|
|
reAttribute,
|
|
|
|
props: 'Attributes',
|
|
|
|
propsName: 'Attribute',
|
|
|
|
propsOptions: 'Accepted Values',
|
|
|
|
eventsName: 'Event Name',
|
|
|
|
tableRegExp:
|
|
|
|
'#+\\s+(.*\\s*Attributes|.*\\s*Events|.*\\s*Slots|.*\\s*Directives)\\s*\\n+(\\|?.+\\|.+)\\n\\|?\\s*:?-+:?\\s*\\|.+((\\n\\|?.+\\|.+)+)',
|
|
|
|
})
|
|
|
|
|
|
|
|
done()
|
|
|
|
}
|