Skip to content

Commit 16bfc4a

Browse files
feat: allow using regex or function in exclude option
1 parent 09d18a4 commit 16bfc4a

File tree

3 files changed

+21
-3
lines changed

3 files changed

+21
-3
lines changed

playground/nuxt.config.ts

+4-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,10 @@ export default defineNuxtConfig({
2424
],
2525

2626
componentMeta: {
27-
debug: 2
27+
debug: 2,
28+
exclude: [/test/i, (component: any) => {
29+
return component.global
30+
}]
2831
},
2932

3033
pinceau: {

src/options.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ export interface ModuleOptions {
88
debug?: boolean | 2
99
componentDirs: (string | ComponentsDir)[]
1010
components?: ComponentsOptions[]
11-
exclude?: string[]
11+
exclude?: (string | RegExp | ((component: any) => boolean))[]
1212
checkerOptions?: MetaCheckerOptions
1313
transformers?: ((component: any, code: string) => ({ component: any; code: string }))[]
1414
}

src/parser.ts

+16-1
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,29 @@ export function useComponentMetaParser (
2323

2424
const outputPath = join(outputDir, 'component-meta')
2525

26+
const isExcluded = (component: any) => {
27+
return exclude.find((excludeRule) => {
28+
switch (typeof excludeRule) {
29+
case 'string':
30+
return component.filePath.includes(excludeRule)
31+
case 'object':
32+
return excludeRule instanceof RegExp ? excludeRule.test(component.filePath) : false
33+
case 'function':
34+
return excludeRule(component)
35+
default:
36+
return false
37+
}
38+
})
39+
}
40+
2641
/**
2742
* Initialize component data object from components
2843
*/
2944
const components = {
3045
...(_components || []).reduce(
3146
(acc: any, component: any) => {
3247
// Locally support exclude as it seem broken from createComponentMetaCheckerByJsonConfig
33-
if (exclude.find(excludePath => component.filePath.includes(excludePath))) { return acc }
48+
if (isExcluded(component)) { return acc }
3449

3550
if (!component.filePath || !component.pascalName) { return acc }
3651

0 commit comments

Comments
 (0)