|
| 1 | +import { modulePathResolverPlugin } from '@wc-toolkit/module-path-resolver'; |
| 2 | +import { cemValidatorPlugin } from '@wc-toolkit/cem-validator'; |
| 3 | +import { getTsProgram, typeParserPlugin } from '@wc-toolkit/type-parser'; |
| 4 | +import { cemInheritancePlugin } from '@wc-toolkit/cem-inheritance'; |
| 5 | + |
| 6 | +export default { |
| 7 | + /** Globs to analyze */ |
| 8 | + globs: ['src/**/*.ts'], |
| 9 | + /** Globs to exclude */ |
| 10 | + exclude: [ |
| 11 | + '_docs/**/*', |
| 12 | + 'src/**/*.bench.ts', |
| 13 | + 'src/**/*.definition.ts', |
| 14 | + 'src/**/*.options.ts', |
| 15 | + 'src/**/*.spec.ts', |
| 16 | + 'src/**/*.stories.ts', |
| 17 | + 'src/**/*.styles.ts', |
| 18 | + 'src/**/*.template.ts', |
| 19 | + 'src/**/define.ts', |
| 20 | + 'src/**/index.ts', |
| 21 | + ], |
| 22 | + /** Enable special handling for fast */ |
| 23 | + fast: true, |
| 24 | + /** Provide custom plugins */ |
| 25 | + plugins: [ |
| 26 | + modulePathResolverPlugin({ |
| 27 | + modulePathTemplate: (modulePath, name, tagName) => `./dist/esm/${getFolderName(name)}/${getFileName(name)}`, |
| 28 | + definitionPathTemplate: (modulePath, name, tagName) => `./dist/esm/${getFolderName(name)}/define.js`, |
| 29 | + typeDefinitionPathTemplate: (modulePath, name, tagName) => `./dist/dts/${getFolderName(name)}/index.d.ts`, |
| 30 | + }), |
| 31 | + typeParserPlugin(), |
| 32 | + cemInheritancePlugin(), |
| 33 | + cemValidatorPlugin({ |
| 34 | + rules: { |
| 35 | + packageJson: { |
| 36 | + main: 'off', |
| 37 | + module: 'off', |
| 38 | + types: 'off', |
| 39 | + }, |
| 40 | + manifest: { |
| 41 | + schemaVersion: 'off', |
| 42 | + }, |
| 43 | + }, |
| 44 | + }), |
| 45 | + ], |
| 46 | + |
| 47 | + /** Overrides default module creation: */ |
| 48 | + overrideModuleCreation({ ts, globs }) { |
| 49 | + const program = getTsProgram(ts, globs, 'tsconfig.json'); |
| 50 | + return program.getSourceFiles().filter(sf => globs.find(glob => sf.fileName.includes(glob))); |
| 51 | + }, |
| 52 | +}; |
| 53 | + |
| 54 | +function getFolderName(baseName) { |
| 55 | + // Convert "BaseAccordionItem" to "accordion-item" |
| 56 | + return baseName |
| 57 | + .replace(/^Base/, '') // Remove the "Base" prefix |
| 58 | + .replace(/([a-z])([A-Z])/g, '$1-$2') // Convert camelCase to kebab-case |
| 59 | + .toLowerCase(); |
| 60 | +} |
| 61 | + |
| 62 | +function getFileName(baseName) { |
| 63 | + // Convert "BaseAccordionItem" to "accordion-item" |
| 64 | + const kebabCaseName = baseName |
| 65 | + .replace(/^Base/, '') // Remove the "Base" prefix |
| 66 | + .replace(/([a-z])([A-Z])/g, '$1-$2') // Convert camelCase to kebab-case |
| 67 | + .toLowerCase(); |
| 68 | + |
| 69 | + // Construct the file path |
| 70 | + return `${kebabCaseName}${baseName.includes('Base') ? '.base' : ''}.js`; |
| 71 | +} |
0 commit comments