vue-component-meta 3.2.4 → 3.2.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +124 -141
- package/package.json +4 -4
package/README.md
CHANGED
|
@@ -1,194 +1,177 @@
|
|
|
1
1
|
# vue-component-meta
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
<p>
|
|
4
|
+
<a href="https://www.npmjs.com/package/vue-component-meta"><img src="https://img.shields.io/npm/v/vue-component-meta.svg?labelColor=18181B&color=1584FC" alt="NPM version"></a>
|
|
5
|
+
<a href="https://github.com/vuejs/language-tools/blob/master/LICENSE"><img src="https://img.shields.io/github/license/vuejs/language-tools.svg?labelColor=18181B&color=1584FC" alt="License"></a>
|
|
6
|
+
</p>
|
|
4
7
|
|
|
5
|
-
|
|
8
|
+
Statically extract metadata such as props, events, slots, and exposed from Vue components. Useful for auto-generating component documentation or displaying component APIs in tools like Storybook.
|
|
6
9
|
|
|
7
|
-
|
|
10
|
+
## Installation
|
|
8
11
|
|
|
9
|
-
```
|
|
10
|
-
|
|
11
|
-
|
|
12
|
+
```bash
|
|
13
|
+
npm install vue-component-meta typescript
|
|
14
|
+
```
|
|
12
15
|
|
|
13
|
-
|
|
14
|
-
import { createChecker } from 'vue-component-meta'
|
|
16
|
+
## Usage
|
|
15
17
|
|
|
16
|
-
|
|
18
|
+
### Create a Checker from tsconfig.json
|
|
17
19
|
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
schema: { ignore: ['MyIgnoredNestedProps'] },
|
|
21
|
-
printer: { newLine: 1 },
|
|
22
|
-
}
|
|
20
|
+
```typescript
|
|
21
|
+
import { createChecker } from 'vue-component-meta';
|
|
23
22
|
|
|
24
|
-
const
|
|
25
|
-
//
|
|
26
|
-
|
|
27
|
-
checkerOptions,
|
|
28
|
-
)
|
|
29
|
-
```
|
|
23
|
+
const checker = createChecker('/path/to/tsconfig.json', {
|
|
24
|
+
schema: true, // Enable schema parsing
|
|
25
|
+
});
|
|
30
26
|
|
|
31
|
-
|
|
27
|
+
const meta = checker.getComponentMeta('/path/to/MyComponent.vue');
|
|
28
|
+
```
|
|
32
29
|
|
|
33
|
-
|
|
34
|
-
import * as url from 'url'
|
|
35
|
-
import path from 'path'
|
|
30
|
+
### Create a Checker from JSON Configuration
|
|
36
31
|
|
|
37
|
-
|
|
32
|
+
```typescript
|
|
33
|
+
import { createCheckerByJson } from 'vue-component-meta';
|
|
38
34
|
|
|
39
|
-
const
|
|
40
|
-
|
|
35
|
+
const checker = createCheckerByJson('/project/root', {
|
|
36
|
+
include: ['src/**/*.vue'],
|
|
37
|
+
compilerOptions: { /* ... */ },
|
|
38
|
+
vueCompilerOptions: { /* ... */ },
|
|
39
|
+
});
|
|
41
40
|
```
|
|
42
41
|
|
|
43
|
-
|
|
42
|
+
## API
|
|
44
43
|
|
|
45
|
-
###
|
|
44
|
+
### `checker.getComponentMeta(filePath, exportName?)`
|
|
46
45
|
|
|
47
|
-
|
|
46
|
+
Get the metadata of a component. `exportName` defaults to `'default'`.
|
|
48
47
|
|
|
49
|
-
|
|
50
|
-
- **`description`**: Extracted from JSDoc comments above the component export (for TypeScript/JavaScript files)
|
|
48
|
+
The returned `ComponentMeta` object contains:
|
|
51
49
|
|
|
52
|
-
```
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
50
|
+
```typescript
|
|
51
|
+
interface ComponentMeta {
|
|
52
|
+
name?: string;
|
|
53
|
+
description?: string;
|
|
54
|
+
type: TypeMeta;
|
|
55
|
+
props: PropertyMeta[];
|
|
56
|
+
events: EventMeta[];
|
|
57
|
+
slots: SlotMeta[];
|
|
58
|
+
exposed: ExposeMeta[];
|
|
59
|
+
}
|
|
60
60
|
```
|
|
61
61
|
|
|
62
|
-
|
|
63
|
-
```ts
|
|
64
|
-
meta.name // 'MyComponent'
|
|
65
|
-
meta.description // 'My awesome component description'
|
|
66
|
-
```
|
|
62
|
+
### `checker.getExportNames(filePath)`
|
|
67
63
|
|
|
68
|
-
|
|
64
|
+
Get all export names of a file.
|
|
69
65
|
|
|
70
|
-
`
|
|
66
|
+
### `checker.updateFile(filePath, content)`
|
|
71
67
|
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
},
|
|
80
|
-
```
|
|
68
|
+
Update file content (for virtual files or live editing).
|
|
69
|
+
|
|
70
|
+
### `checker.deleteFile(filePath)`
|
|
71
|
+
|
|
72
|
+
Remove a file from the project.
|
|
73
|
+
|
|
74
|
+
### `checker.reload()`
|
|
81
75
|
|
|
82
|
-
|
|
76
|
+
Reload the tsconfig.json configuration.
|
|
83
77
|
|
|
84
|
-
|
|
85
|
-
>
|
|
86
|
-
> Do note that `meta.props` will be array of props so you can't access it via `meta.props.<prop-name>`. Moreover, `meta.props` will also contain some global prop which you can identify via `prop.global` property.
|
|
78
|
+
### `checker.clearCache()`
|
|
87
79
|
|
|
88
|
-
|
|
80
|
+
Clear cached file content.
|
|
89
81
|
|
|
90
|
-
|
|
82
|
+
### `checker.getProgram()`
|
|
91
83
|
|
|
92
|
-
|
|
84
|
+
Get the underlying TypeScript Program instance.
|
|
93
85
|
|
|
94
|
-
|
|
86
|
+
## Metadata Structures
|
|
95
87
|
|
|
96
|
-
|
|
88
|
+
### PropertyMeta (Props)
|
|
97
89
|
|
|
98
|
-
```
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
90
|
+
```typescript
|
|
91
|
+
interface PropertyMeta {
|
|
92
|
+
name: string;
|
|
93
|
+
description: string; // Read from JSDoc
|
|
94
|
+
type: string; // Type string
|
|
95
|
+
default?: string; // Default value
|
|
96
|
+
required: boolean;
|
|
97
|
+
global: boolean; // Whether it's a global prop
|
|
98
|
+
tags: { name: string; text?: string }[]; // JSDoc tags
|
|
99
|
+
schema: PropertyMetaSchema;
|
|
100
|
+
getDeclarations(): Declaration[];
|
|
101
|
+
getTypeObject(): ts.Type;
|
|
109
102
|
}
|
|
110
103
|
```
|
|
111
104
|
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
```
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
},
|
|
125
|
-
variant: {
|
|
126
|
-
default: 'light',
|
|
127
|
-
},
|
|
128
|
-
}),
|
|
105
|
+
### EventMeta
|
|
106
|
+
|
|
107
|
+
```typescript
|
|
108
|
+
interface EventMeta {
|
|
109
|
+
name: string;
|
|
110
|
+
description: string;
|
|
111
|
+
type: string;
|
|
112
|
+
signature: string;
|
|
113
|
+
tags: { name: string; text?: string }[];
|
|
114
|
+
schema: PropertyMetaSchema[];
|
|
115
|
+
getDeclarations(): Declaration[];
|
|
116
|
+
getTypeObject(): ts.Type | undefined;
|
|
129
117
|
}
|
|
130
118
|
```
|
|
131
119
|
|
|
132
|
-
###
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
*/
|
|
144
|
-
variant: {
|
|
145
|
-
type: String,
|
|
146
|
-
default: 'text',
|
|
147
|
-
},
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
export { props }
|
|
120
|
+
### SlotMeta
|
|
121
|
+
|
|
122
|
+
```typescript
|
|
123
|
+
interface SlotMeta {
|
|
124
|
+
name: string;
|
|
125
|
+
description: string;
|
|
126
|
+
type: string;
|
|
127
|
+
tags: { name: string; text?: string }[];
|
|
128
|
+
schema: PropertyMetaSchema;
|
|
129
|
+
getDeclarations(): Declaration[];
|
|
130
|
+
getTypeObject(): ts.Type;
|
|
151
131
|
}
|
|
152
132
|
```
|
|
153
133
|
|
|
154
|
-
###
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
134
|
+
### ExposeMeta
|
|
135
|
+
|
|
136
|
+
```typescript
|
|
137
|
+
interface ExposeMeta {
|
|
138
|
+
name: string;
|
|
139
|
+
description: string;
|
|
140
|
+
type: string;
|
|
141
|
+
tags: { name: string; text?: string }[];
|
|
142
|
+
schema: PropertyMetaSchema;
|
|
143
|
+
getDeclarations(): Declaration[];
|
|
144
|
+
getTypeObject(): ts.Type;
|
|
163
145
|
}
|
|
164
146
|
```
|
|
165
147
|
|
|
166
|
-
|
|
167
|
-
import { disabled } from '@/composables/useProps'
|
|
148
|
+
## Options
|
|
168
149
|
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
}
|
|
150
|
+
```typescript
|
|
151
|
+
interface MetaCheckerOptions {
|
|
152
|
+
schema?: boolean | {
|
|
153
|
+
ignore?: (string | ((name: string, type: ts.Type, typeChecker: ts.TypeChecker) => boolean))[];
|
|
154
|
+
};
|
|
155
|
+
printer?: ts.PrinterOptions;
|
|
156
|
+
}
|
|
174
157
|
```
|
|
175
158
|
|
|
176
|
-
|
|
159
|
+
### `schema`
|
|
177
160
|
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
161
|
+
Controls whether to parse the schema structure of types. Set to `true` to enable, or pass an object to configure types to ignore.
|
|
162
|
+
|
|
163
|
+
```typescript
|
|
164
|
+
const checker = createChecker(tsconfig, {
|
|
165
|
+
schema: {
|
|
166
|
+
ignore: ['HTMLElement', (name) => name.startsWith('Internal')],
|
|
167
|
+
},
|
|
168
|
+
});
|
|
184
169
|
```
|
|
185
170
|
|
|
186
|
-
##
|
|
171
|
+
## Related Packages
|
|
187
172
|
|
|
188
|
-
- [
|
|
173
|
+
- [`vue-component-type-helpers`](../component-type-helpers) - Type helper utilities
|
|
189
174
|
|
|
190
|
-
##
|
|
175
|
+
## License
|
|
191
176
|
|
|
192
|
-
|
|
193
|
-
- [Anu's components' API automation](https://github.com/jd-solanki/anu/blob/main/scripts/gen-component-meta.ts)
|
|
194
|
-
- [Discord chat for dynamic usage](https://discord.com/channels/793943652350427136/1027819645677350912)
|
|
177
|
+
[MIT](https://github.com/vuejs/language-tools/blob/master/LICENSE) License
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "vue-component-meta",
|
|
3
|
-
"version": "3.2.
|
|
3
|
+
"version": "3.2.5",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"files": [
|
|
6
6
|
"**/*.js",
|
|
@@ -13,8 +13,8 @@
|
|
|
13
13
|
"directory": "packages/component-meta"
|
|
14
14
|
},
|
|
15
15
|
"dependencies": {
|
|
16
|
-
"@volar/typescript": "2.4.
|
|
17
|
-
"@vue/language-core": "3.2.
|
|
16
|
+
"@volar/typescript": "2.4.28",
|
|
17
|
+
"@vue/language-core": "3.2.5",
|
|
18
18
|
"path-browserify": "^1.0.1"
|
|
19
19
|
},
|
|
20
20
|
"devDependencies": {
|
|
@@ -29,5 +29,5 @@
|
|
|
29
29
|
"optional": true
|
|
30
30
|
}
|
|
31
31
|
},
|
|
32
|
-
"gitHead": "
|
|
32
|
+
"gitHead": "ee5041d27940cf6f9a5150635d3b13140a9dff54"
|
|
33
33
|
}
|