mirror of
https://gitee.com/vant-contrib/vant.git
synced 2025-04-06 03:57:59 +08:00
feat(markdown-vetur): 支持生成 attributes.json 的 options 属性 (#8545)
* feat(markdown-vetur): 支持生成 attributes.json 的 options 属性 * fix(markdown-vetur): 没有可选值不添加 options 属性
This commit is contained in:
parent
805916b6e0
commit
74e2b10b74
@ -1,6 +1,6 @@
|
|||||||
/* eslint-disable no-continue */
|
/* eslint-disable no-continue */
|
||||||
import { Articals } from './parser';
|
import { Articals } from './parser';
|
||||||
import { formatType, removeVersion, toKebabCase } from './utils';
|
import { formatOptions, formatType, removeVersion, toKebabCase } from './utils';
|
||||||
import { VueTag } from './type';
|
import { VueTag } from './type';
|
||||||
|
|
||||||
function formatComponentName(name: string, tagPrefix: string) {
|
function formatComponentName(name: string, tagPrefix: string) {
|
||||||
@ -64,11 +64,12 @@ export function formatter(
|
|||||||
const tag = findTag(vueTags, name);
|
const tag = findTag(vueTags, name);
|
||||||
|
|
||||||
table.body.forEach((line) => {
|
table.body.forEach((line) => {
|
||||||
const [name, desc, type, defaultVal] = line;
|
const [name, desc, type, defaultVal, options] = line;
|
||||||
tag.attributes!.push({
|
tag.attributes!.push({
|
||||||
name: removeVersion(name),
|
name: removeVersion(name),
|
||||||
default: defaultVal,
|
default: defaultVal,
|
||||||
description: desc,
|
description: desc,
|
||||||
|
options: formatOptions(options),
|
||||||
value: {
|
value: {
|
||||||
type: formatType(type),
|
type: formatType(type),
|
||||||
kind: 'expression',
|
kind: 'expression',
|
||||||
|
@ -20,6 +20,7 @@ export type VueAttribute = {
|
|||||||
name: string;
|
name: string;
|
||||||
default: string;
|
default: string;
|
||||||
description: string;
|
description: string;
|
||||||
|
options: string[]
|
||||||
value: {
|
value: {
|
||||||
kind: 'expression';
|
kind: 'expression';
|
||||||
type: string;
|
type: string;
|
||||||
@ -44,6 +45,7 @@ export type VeturTags = Record<string, VeturTag>;
|
|||||||
export type VeturAttribute = {
|
export type VeturAttribute = {
|
||||||
type: string;
|
type: string;
|
||||||
description: string;
|
description: string;
|
||||||
|
options?: string[];
|
||||||
};
|
};
|
||||||
|
|
||||||
export type VeturAttributes = Record<string, VeturAttribute>;
|
export type VeturAttributes = Record<string, VeturAttribute>;
|
||||||
|
@ -20,3 +20,9 @@ export function formatType(type: string) {
|
|||||||
export function normalizePath(path: string): string {
|
export function normalizePath(path: string): string {
|
||||||
return path.replace(/\\/g, '/');
|
return path.replace(/\\/g, '/');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// `default` `primary` -> ['default', 'primary']
|
||||||
|
export function formatOptions(options?: string) {
|
||||||
|
if (!options) return []
|
||||||
|
return options.replace(/`/g, '').split(' ')
|
||||||
|
}
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import { VueTag, VeturTags, VeturAttributes } from './type';
|
import { VueTag, VeturTags, VeturAttributes, VeturAttribute } from './type';
|
||||||
|
|
||||||
export function genVeturTags(tags: VueTag[]) {
|
export function genVeturTags(tags: VueTag[]) {
|
||||||
const veturTags: VeturTags = {};
|
const veturTags: VeturTags = {};
|
||||||
@ -18,10 +18,16 @@ export function genVeturAttributes(tags: VueTag[]) {
|
|||||||
tags.forEach(tag => {
|
tags.forEach(tag => {
|
||||||
if (tag.attributes) {
|
if (tag.attributes) {
|
||||||
tag.attributes.forEach(attr => {
|
tag.attributes.forEach(attr => {
|
||||||
veturAttributes[`${tag.name}/${attr.name}`] = {
|
let attribute: VeturAttribute = {
|
||||||
type: attr.value.type,
|
type: attr.value.type,
|
||||||
description: `${attr.description}, 默认值: ${attr.default}`,
|
description: `${attr.description}, 默认值: ${attr.default}`
|
||||||
};
|
}
|
||||||
|
|
||||||
|
if (attr.options.length > 0) {
|
||||||
|
attribute.options = attr.options
|
||||||
|
}
|
||||||
|
|
||||||
|
veturAttributes[`${tag.name}/${attr.name}`] = attribute;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
Loading…
x
Reference in New Issue
Block a user