45 Star 483 Fork 93

gyy/vue-amap
暂停

加入 Gitee
与超过 1400万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
helper.ts 3.47 KB
一键复制 编辑 原始数据 按行查看 历史
gyy 提交于 2023-02-09 19:46 +08:00 . 完成分包以及处理完成打包
import path, {resolve} from 'path'
import helper from 'components-helper'
import {mkdir, mkdirSync} from "fs-extra";
import {getPackageManifest} from './utils/pkg';
import {projRoot, apiRoot} from './utils/paths'
import {withTaskName} from "./utils/gulp";
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, path = '') => {
let suffix = '';
const results = path.match(/\/ide-api\/component\/(\S*)\.md/);
if(results && results.length > 1){
suffix = results[1];
}
const docs = `https://vue-amap.guyixi.cn/zh-cn/component/`
const _header = header ? header.replaceAll(/\s+/g, '-').toLowerCase() : ''
return `${docs}${suffix ? suffix : fileName}.html${_header ? '#' : ''}${_header}`
}
const reWebTypesSource: InstallOptions['reWebTypesSource'] = (title) => {
const symbol = `El${title
.replaceAll(/-/g, ' ')
.replaceAll(/^\w|\s+\w/g, (item) => {
return item.trim().toUpperCase()
})}`
return {symbol}
}
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, '')
} else if (key === 'Subtags') {
return str
? `el-${str
.replaceAll(/\s*\/\s*/g, '/el-')
.replaceAll(/\B([A-Z])/g, '-$1')
.replaceAll(/\s+/g, '-')
.toLowerCase()}`
: undefined
} else {
return str
}
}
export const buildHelper = (pkgRoot: string, outDir: string, type: string): TaskFunction => {
return withTaskName('build helper', (done) => {
mkdirSync(outDir, {recursive: true})
const {name, version} = getPackageManifest(resolve(pkgRoot, 'package.json'));
const entry = path.resolve(apiRoot, type , '**' ,'*.md').replaceAll(/\\/g, '/');
helper({
name: name!,
version,
entry,
outDir,
reComponentName,
reDocUrl,
reWebTypesSource,
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()
})
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
JavaScript
1
https://gitee.com/guyangyang/vue-amap.git
git@gitee.com:guyangyang/vue-amap.git
guyangyang
vue-amap
vue-amap
dev

搜索帮助