Skip to content

Commit 6807b69

Browse files
committed
feat: include option to generate components meta
1 parent 9e638d1 commit 6807b69

File tree

2 files changed

+24
-4
lines changed

2 files changed

+24
-4
lines changed

src/module.ts

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ export default defineNuxtModule<ModuleOptions>({
4343
'nuxt/dist/app/components/nuxt-route-announcer',
4444
'nuxt/dist/app/components/nuxt-stubs',
4545
],
46+
include: [],
4647
metaFields: {
4748
type: true,
4849
props: true,
@@ -107,6 +108,24 @@ export default defineNuxtModule<ModuleOptions>({
107108
async setup (options, nuxt) {
108109
const resolver = createResolver(import.meta.url)
109110

111+
const isComponentIncluded = (component: any) => {
112+
if (!options?.globalsOnly) { return true }
113+
114+
if (component.global) { return true }
115+
116+
return (options.include || []).find((excludeRule) => {
117+
switch (typeof excludeRule) {
118+
case 'string':
119+
return component.pascalName === excludeRule || component.filePath.includes(excludeRule)
120+
case 'object':
121+
return excludeRule instanceof RegExp ? excludeRule.test(component.filePath) : false
122+
case 'function':
123+
return excludeRule(component)
124+
default:
125+
return false
126+
}
127+
})
128+
}
110129

111130
// Retrieve transformers
112131
let transformers = options?.transformers || []
@@ -148,10 +167,7 @@ export default defineNuxtModule<ModuleOptions>({
148167
})
149168

150169
nuxt.hook('components:extend', async (_components) => {
151-
components = _components
152-
153-
// Support `globalsOnly` option
154-
if (options?.globalsOnly) { components = components.filter(c => c.global) }
170+
components = _components.filter(isComponentIncluded)
155171

156172
// Load external components definitions
157173
metaSources = await loadExternalSources(options.metaSources)

src/options.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,10 @@ export interface ModuleOptions {
3333
* Component paths and/or path regexps to be excluded.
3434
*/
3535
exclude?: (string | RegExp | ((component: any) => boolean))[]
36+
/**
37+
* Component paths and/or path regexps to be included.
38+
*/
39+
include?: (string | RegExp | ((component: any) => boolean))[]
3640
/**
3741
* vue-component-meta checker options.
3842
*/

0 commit comments

Comments
 (0)