@tpitre/story-ui 4.6.3 → 4.7.0
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/dist/story-generator/enhancedComponentDiscovery.d.ts +6 -1
- package/dist/story-generator/enhancedComponentDiscovery.d.ts.map +1 -1
- package/dist/story-generator/enhancedComponentDiscovery.js +62 -13
- package/dist/story-generator/framework-adapters/angular-adapter.d.ts +9 -0
- package/dist/story-generator/framework-adapters/angular-adapter.d.ts.map +1 -1
- package/dist/story-generator/framework-adapters/angular-adapter.js +54 -0
- package/dist/story-generator/framework-adapters/base-adapter.d.ts +10 -0
- package/dist/story-generator/framework-adapters/base-adapter.d.ts.map +1 -1
- package/dist/story-generator/framework-adapters/react-adapter.d.ts +9 -0
- package/dist/story-generator/framework-adapters/react-adapter.d.ts.map +1 -1
- package/dist/story-generator/framework-adapters/react-adapter.js +46 -0
- package/dist/story-generator/framework-adapters/svelte-adapter.d.ts +9 -0
- package/dist/story-generator/framework-adapters/svelte-adapter.d.ts.map +1 -1
- package/dist/story-generator/framework-adapters/svelte-adapter.js +58 -0
- package/dist/story-generator/framework-adapters/vue-adapter.d.ts +9 -0
- package/dist/story-generator/framework-adapters/vue-adapter.d.ts.map +1 -1
- package/dist/story-generator/framework-adapters/vue-adapter.js +74 -0
- package/dist/story-generator/framework-adapters/web-components-adapter.d.ts +13 -0
- package/dist/story-generator/framework-adapters/web-components-adapter.d.ts.map +1 -1
- package/dist/story-generator/framework-adapters/web-components-adapter.js +80 -0
- package/package.json +1 -1
|
@@ -16,7 +16,12 @@ export declare class EnhancedComponentDiscovery {
|
|
|
16
16
|
private config;
|
|
17
17
|
private discoveredComponents;
|
|
18
18
|
private validateAvailableComponents;
|
|
19
|
+
private frameworkAdapter;
|
|
19
20
|
constructor(config: StoryUIConfig);
|
|
21
|
+
/**
|
|
22
|
+
* Create the appropriate framework adapter based on config
|
|
23
|
+
*/
|
|
24
|
+
private createFrameworkAdapter;
|
|
20
25
|
/**
|
|
21
26
|
* Discover components from all available sources
|
|
22
27
|
* Priority: 1. Dynamic Discovery 2. Static Lists 3. Manual Config
|
|
@@ -76,7 +81,7 @@ export declare class EnhancedComponentDiscovery {
|
|
|
76
81
|
/**
|
|
77
82
|
* Extract component name from file
|
|
78
83
|
*/
|
|
79
|
-
private
|
|
84
|
+
private extractComponentNames;
|
|
80
85
|
/**
|
|
81
86
|
* Extract props from file content
|
|
82
87
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"enhancedComponentDiscovery.d.ts","sourceRoot":"","sources":["../../story-generator/enhancedComponentDiscovery.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,mBAAmB,EAAE,MAAM,yBAAyB,CAAC;AAC9D,OAAO,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAC;
|
|
1
|
+
{"version":3,"file":"enhancedComponentDiscovery.d.ts","sourceRoot":"","sources":["../../story-generator/enhancedComponentDiscovery.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,mBAAmB,EAAE,MAAM,yBAAyB,CAAC;AAC9D,OAAO,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAC;AAWtD,MAAM,WAAW,eAAe;IAC9B,IAAI,EAAE,KAAK,GAAG,OAAO,GAAG,iBAAiB,GAAG,YAAY,CAAC;IACzD,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,CAAC,EAAE,MAAM,EAAE,CAAC;CACrB;AAED,MAAM,WAAW,iBAAkB,SAAQ,mBAAmB;IAC5D,MAAM,EAAE,eAAe,CAAC;IACxB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,QAAQ,CAAC,EAAE,MAAM,EAAE,CAAC;IACpB,YAAY,CAAC,EAAE,MAAM,EAAE,CAAC;IACxB,WAAW,CAAC,EAAE,OAAO,CAAC;CACvB;AAED,qBAAa,0BAA0B;IACrC,OAAO,CAAC,MAAM,CAAgB;IAC9B,OAAO,CAAC,oBAAoB,CAA6C;IACzE,OAAO,CA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A0B,IAAI,MAAM,EAAE;CAMvC"}
|
|
@@ -2,11 +2,36 @@ import fs from 'fs';
|
|
|
2
2
|
import path from 'path';
|
|
3
3
|
import { DynamicPackageDiscovery } from './dynamicPackageDiscovery.js';
|
|
4
4
|
import { logger } from './logger.js';
|
|
5
|
+
import { ReactAdapter } from './framework-adapters/react-adapter.js';
|
|
6
|
+
import { VueAdapter } from './framework-adapters/vue-adapter.js';
|
|
7
|
+
import { AngularAdapter } from './framework-adapters/angular-adapter.js';
|
|
8
|
+
import { SvelteAdapter } from './framework-adapters/svelte-adapter.js';
|
|
9
|
+
import { WebComponentsAdapter } from './framework-adapters/web-components-adapter.js';
|
|
5
10
|
export class EnhancedComponentDiscovery {
|
|
6
11
|
constructor(config) {
|
|
7
12
|
this.discoveredComponents = new Map();
|
|
8
13
|
this.validateAvailableComponents = new Set();
|
|
9
14
|
this.config = config;
|
|
15
|
+
this.frameworkAdapter = this.createFrameworkAdapter();
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Create the appropriate framework adapter based on config
|
|
19
|
+
*/
|
|
20
|
+
createFrameworkAdapter() {
|
|
21
|
+
const framework = (this.config.componentFramework || 'react');
|
|
22
|
+
switch (framework) {
|
|
23
|
+
case 'vue':
|
|
24
|
+
return new VueAdapter();
|
|
25
|
+
case 'angular':
|
|
26
|
+
return new AngularAdapter();
|
|
27
|
+
case 'svelte':
|
|
28
|
+
return new SvelteAdapter();
|
|
29
|
+
case 'web-components':
|
|
30
|
+
return new WebComponentsAdapter();
|
|
31
|
+
case 'react':
|
|
32
|
+
default:
|
|
33
|
+
return new ReactAdapter();
|
|
34
|
+
}
|
|
10
35
|
}
|
|
11
36
|
/**
|
|
12
37
|
* Discover components from all available sources
|
|
@@ -609,15 +634,22 @@ export class EnhancedComponentDiscovery {
|
|
|
609
634
|
if (!fs.existsSync(source.path)) {
|
|
610
635
|
return;
|
|
611
636
|
}
|
|
612
|
-
|
|
637
|
+
// Use adapter's file patterns if source doesn't specify patterns
|
|
638
|
+
const defaultPatterns = this.frameworkAdapter.getComponentFilePatterns()
|
|
639
|
+
.map(p => p.replace('**/', '')); // Convert glob to simpler patterns
|
|
640
|
+
const files = this.findComponentFiles(source.path, source.patterns || defaultPatterns);
|
|
613
641
|
for (const file of files) {
|
|
614
642
|
// Skip story files, test files, and other non-component files
|
|
615
643
|
if (this.isNonComponentFile(file)) {
|
|
616
644
|
continue;
|
|
617
645
|
}
|
|
618
646
|
const content = fs.readFileSync(file, 'utf-8');
|
|
619
|
-
|
|
620
|
-
|
|
647
|
+
// Use framework adapter for component extraction
|
|
648
|
+
const componentNames = this.frameworkAdapter.extractComponentNamesFromFile(file, content);
|
|
649
|
+
for (const componentName of componentNames) {
|
|
650
|
+
if (this.discoveredComponents.has(componentName)) {
|
|
651
|
+
continue;
|
|
652
|
+
}
|
|
621
653
|
// Skip Story UI components and other internal components
|
|
622
654
|
if (this.shouldSkipComponent(componentName, content)) {
|
|
623
655
|
continue;
|
|
@@ -701,18 +733,35 @@ export class EnhancedComponentDiscovery {
|
|
|
701
733
|
/**
|
|
702
734
|
* Extract component name from file
|
|
703
735
|
*/
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
736
|
+
extractComponentNames(filePath, content) {
|
|
737
|
+
const names = new Set();
|
|
738
|
+
// 1. Check for inline exports: export function/const/class Name
|
|
739
|
+
const inlineExportRegex = /export\s+(default\s+)?(function|const|class)\s+([A-Z][A-Za-z0-9]*)/g;
|
|
740
|
+
let match;
|
|
741
|
+
while ((match = inlineExportRegex.exec(content)) !== null) {
|
|
742
|
+
names.add(match[3]);
|
|
743
|
+
}
|
|
744
|
+
// 2. Check for grouped exports: export { Name1, Name2 }
|
|
745
|
+
const groupedExportRegex = /export\s*\{\s*([^}]+)\s*\}/g;
|
|
746
|
+
while ((match = groupedExportRegex.exec(content)) !== null) {
|
|
747
|
+
const exports = match[1].split(',');
|
|
748
|
+
for (const exp of exports) {
|
|
749
|
+
// Handle "Name" or "Name as Alias" - we want the original name
|
|
750
|
+
const namePart = exp.trim().split(/\s+as\s+/)[0].trim();
|
|
751
|
+
// Only include PascalCase names (components start with uppercase)
|
|
752
|
+
if (/^[A-Z][A-Za-z0-9]*$/.test(namePart)) {
|
|
753
|
+
names.add(namePart);
|
|
754
|
+
}
|
|
755
|
+
}
|
|
709
756
|
}
|
|
710
|
-
//
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
757
|
+
// 3. Fallback to filename if no exports found
|
|
758
|
+
if (names.size === 0) {
|
|
759
|
+
const fileName = path.basename(filePath, path.extname(filePath));
|
|
760
|
+
if (fileName !== 'index' && /^[A-Z]/.test(fileName)) {
|
|
761
|
+
names.add(fileName);
|
|
762
|
+
}
|
|
714
763
|
}
|
|
715
|
-
return
|
|
764
|
+
return Array.from(names);
|
|
716
765
|
}
|
|
717
766
|
/**
|
|
718
767
|
* Extract props from file content
|
|
@@ -13,6 +13,15 @@ export declare class AngularAdapter extends BaseFrameworkAdapter {
|
|
|
13
13
|
readonly name = "Angular";
|
|
14
14
|
readonly supportedStoryFrameworks: StoryFramework[];
|
|
15
15
|
readonly defaultExtension = ".stories.ts";
|
|
16
|
+
/**
|
|
17
|
+
* Get glob patterns for Angular component files
|
|
18
|
+
*/
|
|
19
|
+
getComponentFilePatterns(): string[];
|
|
20
|
+
/**
|
|
21
|
+
* Extract component names from an Angular source file.
|
|
22
|
+
* Handles @Component decorators and NgModule exports.
|
|
23
|
+
*/
|
|
24
|
+
extractComponentNamesFromFile(filePath: string, content: string): string[];
|
|
16
25
|
generateSystemPrompt(config: StoryUIConfig, options?: StoryGenerationOptions): string;
|
|
17
26
|
generateExamples(config: StoryUIConfig): string;
|
|
18
27
|
generateSampleStory(config: StoryUIConfig, components: DiscoveredComponent[]): string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"angular-adapter.d.ts","sourceRoot":"","sources":["../../../story-generator/framework-adapters/angular-adapter.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;
|
|
1
|
+
{"version":3,"file":"angular-adapter.d.ts","sourceRoot":"","sources":["../../../story-generator/framework-adapters/angular-adapter.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAGH,OAAO,EACL,aAAa,EACb,cAAc,EACd,sBAAsB,EACvB,MAAM,YAAY,CAAC;AACpB,OAAO,EAAE,oBAAoB,EAAE,MAAM,mBAAmB,CAAC;AACzD,OAAO,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAC;AACzD,OAAO,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAC;AAE/D,qBAAa,cAAe,SAAQ,oBAAoB;IACtD,QAAQ,CAAC,IAAI,EAAE,aAAa,CAAa;IACzC,QAAQ,CAAC,IAAI,aAAa;IAC1B,QAAQ,CAAC,wBAAwB,EAAE,cAAc,EAAE,CAGjD;IACF,QAAQ,CAAC,gBAAgB,iBAAiB;IAE1C;;OAEG;IACH,wBAAwB,IAAI,MAAM,EAAE;IAIpC;;;OAGG;IACH,6BAA6B,CAAC,QAAQ,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,MAAM,EAAE;IAmD1E,oBAAoB,CAClB,MAAM,EAAE,aAAa,EACrB,OAAO,CAAC,EAAE,sBAAsB,GAC/B,MAAM;IAuJT,gBAAgB,CAAC,MAAM,EAAE,aAAa,GAAG,MAAM;IAsL/C,mBAAmB,CACjB,MAAM,EAAE,aAAa,EACrB,UAAU,EAAE,mBAAmB,EAAE,GAChC,MAAM;IAqDT,gBAAgB,CAAC,OAAO,CAAC,EAAE,sBAAsB,GAAG,MAAM;IA4B1D;;OAEG;IACH,OAAO,CAAC,WAAW;IAOnB;;OAEG;IACH,WAAW,CAAC,YAAY,EAAE,MAAM,GAAG,MAAM;IAkBzC;;OAEG;IACH,QAAQ,CAAC,YAAY,EAAE,MAAM,GAAG;QAAE,KAAK,EAAE,OAAO,CAAC;QAAC,MAAM,EAAE,MAAM,EAAE,CAAA;KAAE;CA+CrE;AAED;;GAEG;AACH,wBAAgB,oBAAoB,IAAI,cAAc,CAErD"}
|
|
@@ -16,6 +16,60 @@ export class AngularAdapter extends BaseFrameworkAdapter {
|
|
|
16
16
|
];
|
|
17
17
|
this.defaultExtension = '.stories.ts';
|
|
18
18
|
}
|
|
19
|
+
/**
|
|
20
|
+
* Get glob patterns for Angular component files
|
|
21
|
+
*/
|
|
22
|
+
getComponentFilePatterns() {
|
|
23
|
+
return ['**/*.component.ts', '**/*.ts'];
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Extract component names from an Angular source file.
|
|
27
|
+
* Handles @Component decorators and NgModule exports.
|
|
28
|
+
*/
|
|
29
|
+
extractComponentNamesFromFile(filePath, content) {
|
|
30
|
+
const names = new Set();
|
|
31
|
+
// Pattern 1: @Component decorator with class
|
|
32
|
+
// @Component({ selector: 'app-name' }) export class NameComponent
|
|
33
|
+
const componentRegex = /@Component\s*\(\s*\{[\s\S]*?\}\s*\)\s*export\s+class\s+(\w+)/g;
|
|
34
|
+
let match;
|
|
35
|
+
while ((match = componentRegex.exec(content)) !== null) {
|
|
36
|
+
names.add(match[1]);
|
|
37
|
+
}
|
|
38
|
+
// Pattern 2: NgModule exports array - for barrel files
|
|
39
|
+
const exportsArrayRegex = /exports\s*:\s*\[([\s\S]*?)\]/g;
|
|
40
|
+
while ((match = exportsArrayRegex.exec(content)) !== null) {
|
|
41
|
+
const exportsContent = match[1];
|
|
42
|
+
const componentNames = exportsContent
|
|
43
|
+
.split(',')
|
|
44
|
+
.map(item => item.trim())
|
|
45
|
+
.filter(item => item && !item.startsWith('//') && /^[A-Z]/.test(item));
|
|
46
|
+
componentNames.forEach(name => names.add(name));
|
|
47
|
+
}
|
|
48
|
+
// Pattern 3: Named exports from barrel files
|
|
49
|
+
// export { NameComponent } from './name.component'
|
|
50
|
+
const namedExportRegex = /export\s*\{\s*([^}]+)\s*\}\s*from\s*['"`]([^'"`]+)['"`]/g;
|
|
51
|
+
while ((match = namedExportRegex.exec(content)) !== null) {
|
|
52
|
+
const exports = match[1].split(',');
|
|
53
|
+
for (const exp of exports) {
|
|
54
|
+
const namePart = exp.trim().split(/\s+as\s+/).pop()?.trim() || '';
|
|
55
|
+
if (/^[A-Z][A-Za-z0-9]*(?:Component)?$/.test(namePart)) {
|
|
56
|
+
names.add(namePart);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
// Pattern 4: export * from './path' - track for further resolution
|
|
61
|
+
// (handled at discovery level, not here)
|
|
62
|
+
// Filter out non-components (services, modules, etc.)
|
|
63
|
+
const filteredNames = Array.from(names).filter(name => {
|
|
64
|
+
// Keep if ends with Component or doesn't end with Service/Module/Directive/Pipe
|
|
65
|
+
return name.endsWith('Component') ||
|
|
66
|
+
(!name.endsWith('Service') &&
|
|
67
|
+
!name.endsWith('Module') &&
|
|
68
|
+
!name.endsWith('Directive') &&
|
|
69
|
+
!name.endsWith('Pipe'));
|
|
70
|
+
});
|
|
71
|
+
return filteredNames;
|
|
72
|
+
}
|
|
19
73
|
generateSystemPrompt(config, options) {
|
|
20
74
|
if (config.systemPrompt) {
|
|
21
75
|
return config.systemPrompt;
|
|
@@ -16,6 +16,16 @@ export declare abstract class BaseFrameworkAdapter implements FrameworkAdapter {
|
|
|
16
16
|
abstract readonly name: string;
|
|
17
17
|
abstract readonly supportedStoryFrameworks: StoryFramework[];
|
|
18
18
|
abstract readonly defaultExtension: string;
|
|
19
|
+
/**
|
|
20
|
+
* Get glob patterns for component files in this framework.
|
|
21
|
+
* Used by component discovery to find relevant files.
|
|
22
|
+
*/
|
|
23
|
+
abstract getComponentFilePatterns(): string[];
|
|
24
|
+
/**
|
|
25
|
+
* Extract component names from a source file.
|
|
26
|
+
* Framework-specific implementation to detect component exports.
|
|
27
|
+
*/
|
|
28
|
+
abstract extractComponentNamesFromFile(filePath: string, content: string): string[];
|
|
19
29
|
/**
|
|
20
30
|
* Generate the system prompt for this framework
|
|
21
31
|
*/
|
|
@@ -1 +1 @@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O,CAAC,EAAE,sBAAsB,GAAG,MAAM;IAEnE;;OAEG;IACH,SAAS,CAAC,GAAG,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI;IAIpE;;OAEG;IACH,SAAS,CAAC,cAAc,IAAI,MAAM;CA2DnC"}
|
|
@@ -13,6 +13,15 @@ export declare class ReactAdapter extends BaseFrameworkAdapter {
|
|
|
13
13
|
readonly name = "React";
|
|
14
14
|
readonly supportedStoryFrameworks: StoryFramework[];
|
|
15
15
|
readonly defaultExtension = ".stories.tsx";
|
|
16
|
+
/**
|
|
17
|
+
* Get glob patterns for React component files
|
|
18
|
+
*/
|
|
19
|
+
getComponentFilePatterns(): string[];
|
|
20
|
+
/**
|
|
21
|
+
* Extract component names from a React source file.
|
|
22
|
+
* Handles both inline exports and grouped exports.
|
|
23
|
+
*/
|
|
24
|
+
extractComponentNamesFromFile(filePath: string, content: string): string[];
|
|
16
25
|
generateSystemPrompt(config: StoryUIConfig, options?: StoryGenerationOptions): string;
|
|
17
26
|
/**
|
|
18
27
|
* FIX #2: Detect if the project uses Chakra UI v3
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"react-adapter.d.ts","sourceRoot":"","sources":["../../../story-generator/framework-adapters/react-adapter.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;
|
|
1
|
+
{"version":3,"file":"react-adapter.d.ts","sourceRoot":"","sources":["../../../story-generator/framework-adapters/react-adapter.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAGH,OAAO,EACL,aAAa,EACb,cAAc,EACd,sBAAsB,EACvB,MAAM,YAAY,CAAC;AACpB,OAAO,EAAE,oBAAoB,EAAE,MAAM,mBAAmB,CAAC;AACzD,OAAO,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAC;AACzD,OAAO,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAC;AAE/D,qBAAa,YAAa,SAAQ,oBAAoB;IACpD,QAAQ,CAAC,IAAI,EAAE,aAAa,CAAW;IACvC,QAAQ,CAAC,IAAI,WAAW;IACxB,QAAQ,CAAC,wBAAwB,EAAE,cAAc,EAAE,CAIjD;IACF,QAAQ,CAAC,gBAAgB,kBAAkB;IAE3C;;OAEG;IACH,wBAAwB,IAAI,MAAM,EAAE;IAIpC;;;OAGG;IACH,6BAA6B,CAAC,QAAQ,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,MAAM,EAAE;IAyC1E,oBAAoB,CAClB,MAAM,EAAE,aAAa,EACrB,OAAO,CAAC,EAAE,sBAAsB,GAC/B,MAAM;IA+GT;;OAEG;IACH,OAAO,CAAC,iBAAiB;IASzB,gBAAgB,CAAC,MAAM,EAAE,aAAa,GAAG,MAAM;IAkE/C,mBAAmB,CACjB,MAAM,EAAE,aAAa,EACrB,UAAU,EAAE,mBAAmB,EAAE,GAChC,MAAM;IA4CT,gBAAgB,CAAC,OAAO,CAAC,EAAE,sBAAsB,GAAG,MAAM;IA0B1D;;OAEG;IACH,WAAW,CAAC,YAAY,EAAE,MAAM,GAAG,MAAM;IA4BzC;;OAEG;IACH,QAAQ,CAAC,YAAY,EAAE,MAAM,GAAG;QAAE,KAAK,EAAE,OAAO,CAAC;QAAC,MAAM,EAAE,MAAM,EAAE,CAAA;KAAE;CA2BrE;AAED;;GAEG;AACH,wBAAgB,kBAAkB,IAAI,YAAY,CAEjD"}
|
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
* Generates Storybook stories for React components.
|
|
5
5
|
* Supports CSF 3.0 format with TypeScript.
|
|
6
6
|
*/
|
|
7
|
+
import * as path from 'path';
|
|
7
8
|
import { BaseFrameworkAdapter } from './base-adapter.js';
|
|
8
9
|
export class ReactAdapter extends BaseFrameworkAdapter {
|
|
9
10
|
constructor() {
|
|
@@ -17,6 +18,51 @@ export class ReactAdapter extends BaseFrameworkAdapter {
|
|
|
17
18
|
];
|
|
18
19
|
this.defaultExtension = '.stories.tsx';
|
|
19
20
|
}
|
|
21
|
+
/**
|
|
22
|
+
* Get glob patterns for React component files
|
|
23
|
+
*/
|
|
24
|
+
getComponentFilePatterns() {
|
|
25
|
+
return ['**/*.tsx', '**/*.jsx', '**/*.ts', '**/*.js'];
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Extract component names from a React source file.
|
|
29
|
+
* Handles both inline exports and grouped exports.
|
|
30
|
+
*/
|
|
31
|
+
extractComponentNamesFromFile(filePath, content) {
|
|
32
|
+
const names = new Set();
|
|
33
|
+
// 1. Check for inline exports: export function/const/class Name
|
|
34
|
+
const inlineExportRegex = /export\s+(default\s+)?(function|const|class)\s+([A-Z][A-Za-z0-9]*)/g;
|
|
35
|
+
let match;
|
|
36
|
+
while ((match = inlineExportRegex.exec(content)) !== null) {
|
|
37
|
+
names.add(match[3]);
|
|
38
|
+
}
|
|
39
|
+
// 2. Check for grouped exports: export { Name1, Name2 }
|
|
40
|
+
const groupedExportRegex = /export\s*\{\s*([^}]+)\s*\}/g;
|
|
41
|
+
while ((match = groupedExportRegex.exec(content)) !== null) {
|
|
42
|
+
const exports = match[1].split(',');
|
|
43
|
+
for (const exp of exports) {
|
|
44
|
+
// Handle "Name" or "Name as Alias" - we want the original name
|
|
45
|
+
const namePart = exp.trim().split(/\s+as\s+/)[0].trim();
|
|
46
|
+
// Only include PascalCase names (components start with uppercase)
|
|
47
|
+
if (/^[A-Z][A-Za-z0-9]*$/.test(namePart)) {
|
|
48
|
+
names.add(namePart);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
// 3. Check for React.forwardRef patterns
|
|
53
|
+
const forwardRefRegex = /export\s+const\s+([A-Z][A-Za-z0-9]*)\s*=\s*(?:React\.)?forwardRef/g;
|
|
54
|
+
while ((match = forwardRefRegex.exec(content)) !== null) {
|
|
55
|
+
names.add(match[1]);
|
|
56
|
+
}
|
|
57
|
+
// 4. Fallback to filename if no exports found
|
|
58
|
+
if (names.size === 0) {
|
|
59
|
+
const fileName = path.basename(filePath, path.extname(filePath));
|
|
60
|
+
if (fileName !== 'index' && /^[A-Z]/.test(fileName)) {
|
|
61
|
+
names.add(fileName);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
return Array.from(names);
|
|
65
|
+
}
|
|
20
66
|
generateSystemPrompt(config, options) {
|
|
21
67
|
if (config.systemPrompt) {
|
|
22
68
|
return config.systemPrompt;
|
|
@@ -13,6 +13,15 @@ export declare class SvelteAdapter extends BaseFrameworkAdapter {
|
|
|
13
13
|
readonly name = "Svelte";
|
|
14
14
|
readonly supportedStoryFrameworks: StoryFramework[];
|
|
15
15
|
readonly defaultExtension = ".stories.svelte";
|
|
16
|
+
/**
|
|
17
|
+
* Get glob patterns for Svelte component files
|
|
18
|
+
*/
|
|
19
|
+
getComponentFilePatterns(): string[];
|
|
20
|
+
/**
|
|
21
|
+
* Extract component names from a Svelte source file.
|
|
22
|
+
* Handles .svelte files and barrel exports.
|
|
23
|
+
*/
|
|
24
|
+
extractComponentNamesFromFile(filePath: string, content: string): string[];
|
|
16
25
|
generateSystemPrompt(config: StoryUIConfig, options?: StoryGenerationOptions): string;
|
|
17
26
|
generateExamples(config: StoryUIConfig): string;
|
|
18
27
|
generateSampleStory(config: StoryUIConfig, components: DiscoveredComponent[]): string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"svelte-adapter.d.ts","sourceRoot":"","sources":["../../../story-generator/framework-adapters/svelte-adapter.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;
|
|
1
|
+
{"version":3,"file":"svelte-adapter.d.ts","sourceRoot":"","sources":["../../../story-generator/framework-adapters/svelte-adapter.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAGH,OAAO,EACL,aAAa,EACb,cAAc,EACd,sBAAsB,EACvB,MAAM,YAAY,CAAC;AACpB,OAAO,EAAE,oBAAoB,EAAE,MAAM,mBAAmB,CAAC;AACzD,OAAO,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAC;AACzD,OAAO,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAC;AAE/D,qBAAa,aAAc,SAAQ,oBAAoB;IACrD,QAAQ,CAAC,IAAI,EAAE,aAAa,CAAY;IACxC,QAAQ,CAAC,IAAI,YAAY;IACzB,QAAQ,CAAC,wBAAwB,EAAE,cAAc,EAAE,CAGjD;IACF,QAAQ,CAAC,gBAAgB,qBAAqB;IAE9C;;OAEG;IACH,wBAAwB,IAAI,MAAM,EAAE;IAIpC;;;OAGG;IACH,6BAA6B,CAAC,QAAQ,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,MAAM,EAAE;IAoD1E,oBAAoB,CAClB,MAAM,EAAE,aAAa,EACrB,OAAO,CAAC,EAAE,sBAAsB,GAC/B,MAAM;IAgJT,gBAAgB,CAAC,MAAM,EAAE,aAAa,GAAG,MAAM;IA2H/C,mBAAmB,CACjB,MAAM,EAAE,aAAa,EACrB,UAAU,EAAE,mBAAmB,EAAE,GAChC,MAAM;IAqCT,gBAAgB,CAAC,OAAO,CAAC,EAAE,sBAAsB,GAAG,MAAM;IAmB1D;;OAEG;IACH,WAAW,CAAC,YAAY,EAAE,MAAM,GAAG,MAAM;IA8HzC;;OAEG;IACH,QAAQ,CAAC,YAAY,EAAE,MAAM,GAAG;QAAE,KAAK,EAAE,OAAO,CAAC;QAAC,MAAM,EAAE,MAAM,EAAE,CAAA;KAAE;IA2CpE;;OAEG;IACH,eAAe,CACb,UAAU,EAAE,mBAAmB,EAAE,EACjC,MAAM,EAAE,aAAa,GACpB,MAAM;CAWV;AAED;;GAEG;AACH,wBAAgB,mBAAmB,IAAI,aAAa,CAEnD"}
|
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
* Generates Storybook stories for Svelte components.
|
|
5
5
|
* Supports both Svelte 4 and Svelte 5 (runes).
|
|
6
6
|
*/
|
|
7
|
+
import * as path from 'path';
|
|
7
8
|
import { BaseFrameworkAdapter } from './base-adapter.js';
|
|
8
9
|
export class SvelteAdapter extends BaseFrameworkAdapter {
|
|
9
10
|
constructor() {
|
|
@@ -16,6 +17,63 @@ export class SvelteAdapter extends BaseFrameworkAdapter {
|
|
|
16
17
|
];
|
|
17
18
|
this.defaultExtension = '.stories.svelte';
|
|
18
19
|
}
|
|
20
|
+
/**
|
|
21
|
+
* Get glob patterns for Svelte component files
|
|
22
|
+
*/
|
|
23
|
+
getComponentFilePatterns() {
|
|
24
|
+
return ['**/*.svelte', '**/*.ts', '**/*.js'];
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Extract component names from a Svelte source file.
|
|
28
|
+
* Handles .svelte files and barrel exports.
|
|
29
|
+
*/
|
|
30
|
+
extractComponentNamesFromFile(filePath, content) {
|
|
31
|
+
const names = new Set();
|
|
32
|
+
// For .svelte files, derive name from filename
|
|
33
|
+
if (filePath.endsWith('.svelte')) {
|
|
34
|
+
const fileName = path.basename(filePath, '.svelte');
|
|
35
|
+
// Skip SvelteKit special files
|
|
36
|
+
if (fileName.startsWith('+')) {
|
|
37
|
+
return [];
|
|
38
|
+
}
|
|
39
|
+
// If already PascalCase, use as-is; otherwise convert kebab-case/snake_case
|
|
40
|
+
if (/^[A-Z][a-zA-Z0-9]*$/.test(fileName)) {
|
|
41
|
+
names.add(fileName);
|
|
42
|
+
}
|
|
43
|
+
else {
|
|
44
|
+
// Convert kebab-case or snake_case to PascalCase
|
|
45
|
+
const pascalName = fileName
|
|
46
|
+
.split(/[-_]/)
|
|
47
|
+
.map(part => part.charAt(0).toUpperCase() + part.slice(1))
|
|
48
|
+
.join('');
|
|
49
|
+
if (/^[A-Z]/.test(pascalName)) {
|
|
50
|
+
names.add(pascalName);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
return Array.from(names);
|
|
54
|
+
}
|
|
55
|
+
// For .ts/.js barrel files
|
|
56
|
+
// Pattern: export { default as ComponentName } from './Component.svelte'
|
|
57
|
+
const barrelExportRegex = /export\s*\{\s*default\s+as\s+([A-Z][a-zA-Z0-9]*)\s*\}\s*from\s*['"`]([^'"`]+\.svelte)['"`]/g;
|
|
58
|
+
let match;
|
|
59
|
+
while ((match = barrelExportRegex.exec(content)) !== null) {
|
|
60
|
+
names.add(match[1]);
|
|
61
|
+
}
|
|
62
|
+
// Pattern: export { ComponentName } from './path'
|
|
63
|
+
const namedExportRegex = /export\s*\{\s*([^}]+)\s*\}\s*from\s*['"`]([^'"`]+)['"`]/g;
|
|
64
|
+
while ((match = namedExportRegex.exec(content)) !== null) {
|
|
65
|
+
const exports = match[1].split(',');
|
|
66
|
+
for (const exp of exports) {
|
|
67
|
+
const namePart = exp.trim().split(/\s+as\s+/).pop()?.trim() || '';
|
|
68
|
+
if (/^[A-Z][A-Za-z0-9]*$/.test(namePart)) {
|
|
69
|
+
names.add(namePart);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
// Pattern: export * from './Component.svelte'
|
|
74
|
+
// These need to be resolved at discovery level
|
|
75
|
+
return Array.from(names);
|
|
76
|
+
}
|
|
19
77
|
generateSystemPrompt(config, options) {
|
|
20
78
|
if (config.systemPrompt) {
|
|
21
79
|
return config.systemPrompt;
|
|
@@ -13,6 +13,15 @@ export declare class VueAdapter extends BaseFrameworkAdapter {
|
|
|
13
13
|
readonly name = "Vue";
|
|
14
14
|
readonly supportedStoryFrameworks: StoryFramework[];
|
|
15
15
|
readonly defaultExtension = ".stories.ts";
|
|
16
|
+
/**
|
|
17
|
+
* Get glob patterns for Vue component files
|
|
18
|
+
*/
|
|
19
|
+
getComponentFilePatterns(): string[];
|
|
20
|
+
/**
|
|
21
|
+
* Extract component names from a Vue source file.
|
|
22
|
+
* Handles .vue SFCs and barrel files.
|
|
23
|
+
*/
|
|
24
|
+
extractComponentNamesFromFile(filePath: string, content: string): string[];
|
|
16
25
|
generateSystemPrompt(config: StoryUIConfig, options?: StoryGenerationOptions): string;
|
|
17
26
|
generateExamples(config: StoryUIConfig): string;
|
|
18
27
|
generateSampleStory(config: StoryUIConfig, components: DiscoveredComponent[]): string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"vue-adapter.d.ts","sourceRoot":"","sources":["../../../story-generator/framework-adapters/vue-adapter.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;
|
|
1
|
+
{"version":3,"file":"vue-adapter.d.ts","sourceRoot":"","sources":["../../../story-generator/framework-adapters/vue-adapter.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAGH,OAAO,EACL,aAAa,EACb,cAAc,EACd,sBAAsB,EACvB,MAAM,YAAY,CAAC;AACpB,OAAO,EAAE,oBAAoB,EAAE,MAAM,mBAAmB,CAAC;AACzD,OAAO,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAC;AACzD,OAAO,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAC;AAE/D,qBAAa,UAAW,SAAQ,oBAAoB;IAClD,QAAQ,CAAC,IAAI,EAAE,aAAa,CAAS;IACrC,QAAQ,CAAC,IAAI,SAAS;IACtB,QAAQ,CAAC,wBAAwB,EAAE,cAAc,EAAE,CAIjD;IACF,QAAQ,CAAC,gBAAgB,iBAAiB;IAE1C;;OAEG;IACH,wBAAwB,IAAI,MAAM,EAAE;IAIpC;;;OAGG;IACH,6BAA6B,CAAC,QAAQ,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,MAAM,EAAE;IAkE1E,oBAAoB,CAClB,MAAM,EAAE,aAAa,EACrB,OAAO,CAAC,EAAE,sBAAsB,GAC/B,MAAM;IA+FT,gBAAgB,CAAC,MAAM,EAAE,aAAa,GAAG,MAAM;IAuH/C,mBAAmB,CACjB,MAAM,EAAE,aAAa,EACrB,UAAU,EAAE,mBAAmB,EAAE,GAChC,MAAM;IA4CT,gBAAgB,CAAC,OAAO,CAAC,EAAE,sBAAsB,GAAG,MAAM;IAsB1D;;OAEG;IACH,WAAW,CAAC,YAAY,EAAE,MAAM,GAAG,MAAM;IA8CzC;;OAEG;IACH,QAAQ,CAAC,YAAY,EAAE,MAAM,GAAG;QAAE,KAAK,EAAE,OAAO,CAAC;QAAC,MAAM,EAAE,MAAM,EAAE,CAAA;KAAE;CAuBrE;AAED;;GAEG;AACH,wBAAgB,gBAAgB,IAAI,UAAU,CAE7C"}
|
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
* Generates Storybook stories for Vue 3 components.
|
|
5
5
|
* Supports Composition API and Options API.
|
|
6
6
|
*/
|
|
7
|
+
import * as path from 'path';
|
|
7
8
|
import { BaseFrameworkAdapter } from './base-adapter.js';
|
|
8
9
|
export class VueAdapter extends BaseFrameworkAdapter {
|
|
9
10
|
constructor() {
|
|
@@ -17,6 +18,79 @@ export class VueAdapter extends BaseFrameworkAdapter {
|
|
|
17
18
|
];
|
|
18
19
|
this.defaultExtension = '.stories.ts';
|
|
19
20
|
}
|
|
21
|
+
/**
|
|
22
|
+
* Get glob patterns for Vue component files
|
|
23
|
+
*/
|
|
24
|
+
getComponentFilePatterns() {
|
|
25
|
+
return ['**/*.vue', '**/*.ts', '**/*.js'];
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Extract component names from a Vue source file.
|
|
29
|
+
* Handles .vue SFCs and barrel files.
|
|
30
|
+
*/
|
|
31
|
+
extractComponentNamesFromFile(filePath, content) {
|
|
32
|
+
const names = new Set();
|
|
33
|
+
// For .vue files, derive name from filename or defineComponent name
|
|
34
|
+
if (filePath.endsWith('.vue')) {
|
|
35
|
+
// Try to extract name from defineComponent({ name: 'ComponentName' })
|
|
36
|
+
const defineComponentNameRegex = /defineComponent\s*\(\s*\{[^]*?name\s*:\s*['"`]([A-Z][a-zA-Z0-9]*)['"`]/;
|
|
37
|
+
const nameMatch = content.match(defineComponentNameRegex);
|
|
38
|
+
if (nameMatch) {
|
|
39
|
+
names.add(nameMatch[1]);
|
|
40
|
+
}
|
|
41
|
+
else {
|
|
42
|
+
// Try Options API name property
|
|
43
|
+
const optionsNameRegex = /name\s*:\s*['"`]([A-Z][a-zA-Z0-9]*)['"`]/;
|
|
44
|
+
const optionsMatch = content.match(optionsNameRegex);
|
|
45
|
+
if (optionsMatch) {
|
|
46
|
+
names.add(optionsMatch[1]);
|
|
47
|
+
}
|
|
48
|
+
else {
|
|
49
|
+
// Fallback to filename
|
|
50
|
+
const fileName = path.basename(filePath, '.vue');
|
|
51
|
+
// If already PascalCase, use as-is; otherwise convert kebab-case/snake_case
|
|
52
|
+
if (/^[A-Z][a-zA-Z0-9]*$/.test(fileName)) {
|
|
53
|
+
names.add(fileName);
|
|
54
|
+
}
|
|
55
|
+
else {
|
|
56
|
+
// Convert kebab-case or snake_case to PascalCase
|
|
57
|
+
const pascalName = fileName
|
|
58
|
+
.split(/[-_]/)
|
|
59
|
+
.map(part => part.charAt(0).toUpperCase() + part.slice(1))
|
|
60
|
+
.join('');
|
|
61
|
+
if (/^[A-Z]/.test(pascalName)) {
|
|
62
|
+
names.add(pascalName);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
return Array.from(names);
|
|
68
|
+
}
|
|
69
|
+
// For .ts/.js barrel files, look for re-exports
|
|
70
|
+
// Pattern: export { default as ComponentName } from './Component.vue'
|
|
71
|
+
const barrelExportRegex = /export\s*\{\s*default\s+as\s+([A-Z][a-zA-Z0-9]*)\s*\}\s*from\s*['"`]([^'"`]+\.vue)['"`]/g;
|
|
72
|
+
let match;
|
|
73
|
+
while ((match = barrelExportRegex.exec(content)) !== null) {
|
|
74
|
+
names.add(match[1]);
|
|
75
|
+
}
|
|
76
|
+
// Pattern: export { ComponentName } from './path'
|
|
77
|
+
const namedExportRegex = /export\s*\{\s*([^}]+)\s*\}\s*from\s*['"`]([^'"`]+)['"`]/g;
|
|
78
|
+
while ((match = namedExportRegex.exec(content)) !== null) {
|
|
79
|
+
const exports = match[1].split(',');
|
|
80
|
+
for (const exp of exports) {
|
|
81
|
+
const namePart = exp.trim().split(/\s+as\s+/).pop()?.trim() || '';
|
|
82
|
+
if (/^[A-Z][A-Za-z0-9]*$/.test(namePart)) {
|
|
83
|
+
names.add(namePart);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
// Pattern: export const ComponentName = ...
|
|
88
|
+
const constExportRegex = /export\s+const\s+([A-Z][A-Za-z0-9]*)\s*=/g;
|
|
89
|
+
while ((match = constExportRegex.exec(content)) !== null) {
|
|
90
|
+
names.add(match[1]);
|
|
91
|
+
}
|
|
92
|
+
return Array.from(names);
|
|
93
|
+
}
|
|
20
94
|
generateSystemPrompt(config, options) {
|
|
21
95
|
if (config.systemPrompt) {
|
|
22
96
|
return config.systemPrompt;
|
|
@@ -13,6 +13,19 @@ export declare class WebComponentsAdapter extends BaseFrameworkAdapter {
|
|
|
13
13
|
readonly name = "Web Components";
|
|
14
14
|
readonly supportedStoryFrameworks: StoryFramework[];
|
|
15
15
|
readonly defaultExtension = ".stories.ts";
|
|
16
|
+
/**
|
|
17
|
+
* Get glob patterns for Web Component files
|
|
18
|
+
*/
|
|
19
|
+
getComponentFilePatterns(): string[];
|
|
20
|
+
/**
|
|
21
|
+
* Extract component names from a Web Component source file.
|
|
22
|
+
* Handles vanilla customElements.define, Lit @customElement, and Stencil @Component.
|
|
23
|
+
*/
|
|
24
|
+
extractComponentNamesFromFile(filePath: string, content: string): string[];
|
|
25
|
+
/**
|
|
26
|
+
* Convert a kebab-case tag name to PascalCase
|
|
27
|
+
*/
|
|
28
|
+
private tagToPascalCase;
|
|
16
29
|
generateSystemPrompt(config: StoryUIConfig, options?: StoryGenerationOptions): string;
|
|
17
30
|
generateExamples(config: StoryUIConfig): string;
|
|
18
31
|
generateSampleStory(config: StoryUIConfig, components: DiscoveredComponent[]): string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"web-components-adapter.d.ts","sourceRoot":"","sources":["../../../story-generator/framework-adapters/web-components-adapter.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;
|
|
1
|
+
{"version":3,"file":"web-components-adapter.d.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MAAM,EAAE,CAAA;KAAE;IAwBpE;;OAEG;IACH,eAAe,CACb,UAAU,EAAE,mBAAmB,EAAE,EACjC,MAAM,EAAE,aAAa,GACpB,MAAM;CAYV;AAED;;GAEG;AACH,wBAAgB,0BAA0B,IAAI,oBAAoB,CAEjE"}
|
|
@@ -16,6 +16,86 @@ export class WebComponentsAdapter extends BaseFrameworkAdapter {
|
|
|
16
16
|
];
|
|
17
17
|
this.defaultExtension = '.stories.ts';
|
|
18
18
|
}
|
|
19
|
+
/**
|
|
20
|
+
* Get glob patterns for Web Component files
|
|
21
|
+
*/
|
|
22
|
+
getComponentFilePatterns() {
|
|
23
|
+
return ['**/*.ts', '**/*.js', '**/custom-elements.json'];
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Extract component names from a Web Component source file.
|
|
27
|
+
* Handles vanilla customElements.define, Lit @customElement, and Stencil @Component.
|
|
28
|
+
*/
|
|
29
|
+
extractComponentNamesFromFile(filePath, content) {
|
|
30
|
+
const names = new Set();
|
|
31
|
+
// Check for Custom Elements Manifest (preferred)
|
|
32
|
+
if (filePath.endsWith('custom-elements.json')) {
|
|
33
|
+
try {
|
|
34
|
+
const manifest = JSON.parse(content);
|
|
35
|
+
if (manifest.modules) {
|
|
36
|
+
for (const module of manifest.modules) {
|
|
37
|
+
if (module.declarations) {
|
|
38
|
+
for (const declaration of module.declarations) {
|
|
39
|
+
if (declaration.customElement && declaration.tagName) {
|
|
40
|
+
// Convert tag-name to PascalCase
|
|
41
|
+
const pascalName = this.tagToPascalCase(declaration.tagName);
|
|
42
|
+
names.add(pascalName);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
return Array.from(names);
|
|
49
|
+
}
|
|
50
|
+
catch {
|
|
51
|
+
// Invalid JSON, continue with regex patterns
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
// Pattern 1: Vanilla customElements.define('tag-name', ClassName) with named class
|
|
55
|
+
const vanillaDefineNamedRegex = /customElements\.define\(\s*['"]([a-z][\w-]*)['"],\s*([A-Z][A-Za-z0-9]*)\s*[),]/g;
|
|
56
|
+
let match;
|
|
57
|
+
while ((match = vanillaDefineNamedRegex.exec(content)) !== null) {
|
|
58
|
+
names.add(match[2]); // Use the class name
|
|
59
|
+
}
|
|
60
|
+
// Pattern 1b: Vanilla customElements.define('tag-name', class extends...) - inline class
|
|
61
|
+
// For inline classes, convert tag name to PascalCase
|
|
62
|
+
const vanillaDefineInlineRegex = /customElements\.define\(\s*['"]([a-z][\w-]*)['"],\s*class\s+extends/gi;
|
|
63
|
+
while ((match = vanillaDefineInlineRegex.exec(content)) !== null) {
|
|
64
|
+
const pascalName = this.tagToPascalCase(match[1]);
|
|
65
|
+
names.add(pascalName);
|
|
66
|
+
}
|
|
67
|
+
// Pattern 2: Lit @customElement('tag-name') decorator (handles multiline)
|
|
68
|
+
const litDecoratorRegex = /@customElement\(\s*['"]([a-z][\w-]*)['"][^)]*\)[\s\S]*?(?:export\s+)?class\s+([A-Z][A-Za-z0-9]*)/g;
|
|
69
|
+
while ((match = litDecoratorRegex.exec(content)) !== null) {
|
|
70
|
+
names.add(match[2]); // Use the class name
|
|
71
|
+
}
|
|
72
|
+
// Pattern 3: Stencil @Component({ tag: 'tag-name' }) decorator
|
|
73
|
+
const stencilRegex = /@Component\(\s*\{[^}]*tag:\s*['"]([a-z][\w-]*)['"][^}]*\}\s*\)\s*(?:export\s+)?class\s+(\w+)/gi;
|
|
74
|
+
while ((match = stencilRegex.exec(content)) !== null) {
|
|
75
|
+
names.add(match[2]); // Use the class name
|
|
76
|
+
}
|
|
77
|
+
// Pattern 4: Named exports from barrel files
|
|
78
|
+
const namedExportRegex = /export\s*\{\s*([^}]+)\s*\}\s*from\s*['"`]([^'"`]+)['"`]/g;
|
|
79
|
+
while ((match = namedExportRegex.exec(content)) !== null) {
|
|
80
|
+
const exports = match[1].split(',');
|
|
81
|
+
for (const exp of exports) {
|
|
82
|
+
const namePart = exp.trim().split(/\s+as\s+/).pop()?.trim() || '';
|
|
83
|
+
if (/^[A-Z][A-Za-z0-9]*$/.test(namePart)) {
|
|
84
|
+
names.add(namePart);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
return Array.from(names);
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Convert a kebab-case tag name to PascalCase
|
|
92
|
+
*/
|
|
93
|
+
tagToPascalCase(tagName) {
|
|
94
|
+
return tagName
|
|
95
|
+
.split('-')
|
|
96
|
+
.map(part => part.charAt(0).toUpperCase() + part.slice(1).toLowerCase())
|
|
97
|
+
.join('');
|
|
98
|
+
}
|
|
19
99
|
generateSystemPrompt(config, options) {
|
|
20
100
|
if (config.systemPrompt) {
|
|
21
101
|
return config.systemPrompt;
|