mirror of
https://gitee.com/vant-contrib/vant.git
synced 2025-04-06 03:57:59 +08:00
perf(@vant/cli): generate smaller web-types.json (#11226)
This commit is contained in:
parent
8dcfb5c29a
commit
842c92d3c9
@ -1,11 +1,6 @@
|
|||||||
/* eslint-disable no-continue */
|
/* eslint-disable no-continue */
|
||||||
import { Articles } from './parser.js';
|
import { Articles } from './parser.js';
|
||||||
import {
|
import { formatType, removeVersion, toKebabCase } from './utils.js';
|
||||||
formatOptions,
|
|
||||||
formatType,
|
|
||||||
removeVersion,
|
|
||||||
toKebabCase,
|
|
||||||
} from './utils.js';
|
|
||||||
import { VueEventArgument, VueTag } from './type.js';
|
import { VueEventArgument, VueTag } from './type.js';
|
||||||
|
|
||||||
function formatComponentName(name: string, tagPrefix: string) {
|
function formatComponentName(name: string, tagPrefix: string) {
|
||||||
@ -66,9 +61,6 @@ function findTag(vueTags: VueTag[], name: string) {
|
|||||||
|
|
||||||
const newTag: VueTag = {
|
const newTag: VueTag = {
|
||||||
name,
|
name,
|
||||||
slots: [],
|
|
||||||
events: [],
|
|
||||||
attributes: [],
|
|
||||||
};
|
};
|
||||||
|
|
||||||
vueTags.push(newTag);
|
vueTags.push(newTag);
|
||||||
@ -107,12 +99,16 @@ 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, options] = line;
|
const [name, desc, type, defaultVal] = line;
|
||||||
tag.attributes!.push({
|
|
||||||
|
if (!tag.attributes) {
|
||||||
|
tag.attributes = [];
|
||||||
|
}
|
||||||
|
|
||||||
|
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',
|
||||||
@ -128,7 +124,12 @@ export function formatter(
|
|||||||
|
|
||||||
table.body.forEach((line) => {
|
table.body.forEach((line) => {
|
||||||
const [name, desc, args] = line;
|
const [name, desc, args] = line;
|
||||||
tag.events!.push({
|
|
||||||
|
if (!tag.events) {
|
||||||
|
tag.events = [];
|
||||||
|
}
|
||||||
|
|
||||||
|
tag.events.push({
|
||||||
name: removeVersion(name),
|
name: removeVersion(name),
|
||||||
description: desc,
|
description: desc,
|
||||||
arguments: formatArguments(args),
|
arguments: formatArguments(args),
|
||||||
@ -143,7 +144,12 @@ export function formatter(
|
|||||||
|
|
||||||
table.body.forEach((line) => {
|
table.body.forEach((line) => {
|
||||||
const [name, desc] = line;
|
const [name, desc] = line;
|
||||||
tag.slots!.push({
|
|
||||||
|
if (!tag.slots) {
|
||||||
|
tag.slots = [];
|
||||||
|
}
|
||||||
|
|
||||||
|
tag.slots.push({
|
||||||
name: removeVersion(name),
|
name: removeVersion(name),
|
||||||
description: desc,
|
description: desc,
|
||||||
});
|
});
|
||||||
|
@ -36,7 +36,7 @@ export async function parseAndWrite(options: Options) {
|
|||||||
const webTypes = genWebTypes(vueTags, options);
|
const webTypes = genWebTypes(vueTags, options);
|
||||||
fse.outputFileSync(
|
fse.outputFileSync(
|
||||||
join(options.outputDir, 'web-types.json'),
|
join(options.outputDir, 'web-types.json'),
|
||||||
JSON.stringify(webTypes, null, 2)
|
JSON.stringify(webTypes)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -20,7 +20,6 @@ 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;
|
||||||
|
@ -20,9 +20,3 @@ 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(' ');
|
|
||||||
}
|
|
||||||
|
@ -12,8 +12,8 @@ export function genWebTypes(tags: VueTag[], options: Options) {
|
|||||||
html: {
|
html: {
|
||||||
tags,
|
tags,
|
||||||
attributes: [],
|
attributes: [],
|
||||||
'types-syntax': 'typescript',
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
'js-types-syntax': 'typescript',
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user