From 16bfc4a5ef875120a2e7085d40df55a322aaeaa4 Mon Sep 17 00:00:00 2001 From: Sacha STAFYNIAK Date: Sat, 11 Mar 2023 12:45:05 +0100 Subject: [PATCH 1/2] feat: allow using regex or function in exclude option --- playground/nuxt.config.ts | 5 ++++- src/options.ts | 2 +- src/parser.ts | 17 ++++++++++++++++- 3 files changed, 21 insertions(+), 3 deletions(-) diff --git a/playground/nuxt.config.ts b/playground/nuxt.config.ts index dfe624c..a3aeaa3 100644 --- a/playground/nuxt.config.ts +++ b/playground/nuxt.config.ts @@ -24,7 +24,10 @@ export default defineNuxtConfig({ ], componentMeta: { - debug: 2 + debug: 2, + exclude: [/test/i, (component: any) => { + return component.global + }] }, pinceau: { diff --git a/src/options.ts b/src/options.ts index 5f1d50b..363316b 100644 --- a/src/options.ts +++ b/src/options.ts @@ -8,7 +8,7 @@ export interface ModuleOptions { debug?: boolean | 2 componentDirs: (string | ComponentsDir)[] components?: ComponentsOptions[] - exclude?: string[] + exclude?: (string | RegExp | ((component: any) => boolean))[] checkerOptions?: MetaCheckerOptions transformers?: ((component: any, code: string) => ({ component: any; code: string }))[] } diff --git a/src/parser.ts b/src/parser.ts index db27a64..32a1f8a 100644 --- a/src/parser.ts +++ b/src/parser.ts @@ -23,6 +23,21 @@ export function useComponentMetaParser ( const outputPath = join(outputDir, 'component-meta') + const isExcluded = (component: any) => { + return exclude.find((excludeRule) => { + switch (typeof excludeRule) { + case 'string': + return component.filePath.includes(excludeRule) + case 'object': + return excludeRule instanceof RegExp ? excludeRule.test(component.filePath) : false + case 'function': + return excludeRule(component) + default: + return false + } + }) + } + /** * Initialize component data object from components */ @@ -30,7 +45,7 @@ export function useComponentMetaParser ( ...(_components || []).reduce( (acc: any, component: any) => { // Locally support exclude as it seem broken from createComponentMetaCheckerByJsonConfig - if (exclude.find(excludePath => component.filePath.includes(excludePath))) { return acc } + if (isExcluded(component)) { return acc } if (!component.filePath || !component.pascalName) { return acc } From ea46c8ec0759c0e22f6132f7a3ca49d1e6ce2b33 Mon Sep 17 00:00:00 2001 From: Sacha STAFYNIAK Date: Mon, 13 Mar 2023 12:24:01 +0100 Subject: [PATCH 2/2] chore: remove exclude from component meta checker --- src/parser.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/parser.ts b/src/parser.ts index 32a1f8a..5cb2b1c 100644 --- a/src/parser.ts +++ b/src/parser.ts @@ -83,8 +83,7 @@ export function useComponentMetaParser ( include: [ '**/*', ...componentDirs.map(dir => `${typeof dir === 'string' ? dir : (dir?.path || '')}/**/*`) - ], - exclude + ] }, checkerOptions )