@tpitre/story-ui 2.1.5 → 2.3.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/.env.sample +82 -11
- package/README.md +130 -4
- package/dist/cli/deploy.d.ts +17 -0
- package/dist/cli/deploy.d.ts.map +1 -0
- package/dist/cli/deploy.js +696 -0
- package/dist/cli/index.d.ts +3 -0
- package/dist/cli/index.d.ts.map +1 -0
- package/dist/cli/index.js +55 -2
- package/dist/cli/setup.d.ts +11 -0
- package/dist/cli/setup.d.ts.map +1 -0
- package/dist/cli/setup.js +437 -110
- package/dist/mcp-server/index.d.ts +2 -0
- package/dist/mcp-server/index.d.ts.map +1 -0
- package/dist/mcp-server/index.js +138 -6
- package/dist/mcp-server/mcp-stdio-server.d.ts +3 -0
- package/dist/mcp-server/mcp-stdio-server.d.ts.map +1 -0
- package/dist/mcp-server/mcp-stdio-server.js +638 -0
- package/dist/mcp-server/routes/claude.d.ts +3 -0
- package/dist/mcp-server/routes/claude.d.ts.map +1 -0
- package/dist/mcp-server/routes/claude.js +60 -23
- package/dist/mcp-server/routes/components.d.ts +4 -0
- package/dist/mcp-server/routes/components.d.ts.map +1 -0
- package/dist/mcp-server/routes/frameworks.d.ts +38 -0
- package/dist/mcp-server/routes/frameworks.d.ts.map +1 -0
- package/dist/mcp-server/routes/frameworks.js +183 -0
- package/dist/mcp-server/routes/generateStory.d.ts +3 -0
- package/dist/mcp-server/routes/generateStory.d.ts.map +1 -0
- package/dist/mcp-server/routes/generateStory.js +274 -115
- package/dist/mcp-server/routes/generateStoryStream.d.ts +12 -0
- package/dist/mcp-server/routes/generateStoryStream.d.ts.map +1 -0
- package/dist/mcp-server/routes/generateStoryStream.js +947 -0
- package/dist/mcp-server/routes/hybridStories.d.ts +18 -0
- package/dist/mcp-server/routes/hybridStories.d.ts.map +1 -0
- package/dist/mcp-server/routes/hybridStories.js +214 -0
- package/dist/mcp-server/routes/mcpRemote.d.ts +14 -0
- package/dist/mcp-server/routes/mcpRemote.d.ts.map +1 -0
- package/dist/mcp-server/routes/mcpRemote.js +489 -0
- package/dist/mcp-server/routes/memoryStories.d.ts +26 -0
- package/dist/mcp-server/routes/memoryStories.d.ts.map +1 -0
- package/dist/mcp-server/routes/memoryStories.js +13 -7
- package/dist/mcp-server/routes/providers.d.ts +89 -0
- package/dist/mcp-server/routes/providers.d.ts.map +1 -0
- package/dist/mcp-server/routes/providers.js +369 -0
- package/dist/mcp-server/routes/storySync.d.ts +26 -0
- package/dist/mcp-server/routes/storySync.d.ts.map +1 -0
- package/dist/mcp-server/routes/streamTypes.d.ts +110 -0
- package/dist/mcp-server/routes/streamTypes.d.ts.map +1 -0
- package/dist/mcp-server/routes/streamTypes.js +18 -0
- package/dist/mcp-server/sessionManager.d.ts +50 -0
- package/dist/mcp-server/sessionManager.d.ts.map +1 -0
- package/dist/mcp-server/sessionManager.js +125 -0
- package/dist/story-generator/componentBlacklist.d.ts +21 -0
- package/dist/story-generator/componentBlacklist.d.ts.map +1 -0
- package/dist/story-generator/componentBlacklist.js +4 -0
- package/dist/story-generator/componentDiscovery.d.ts +28 -0
- package/dist/story-generator/componentDiscovery.d.ts.map +1 -0
- package/dist/story-generator/componentRegistryGenerator.d.ts +49 -0
- package/dist/story-generator/componentRegistryGenerator.d.ts.map +1 -0
- package/dist/story-generator/componentRegistryGenerator.js +205 -0
- package/dist/story-generator/configLoader.d.ts +33 -0
- package/dist/story-generator/configLoader.d.ts.map +1 -0
- package/dist/story-generator/configLoader.js +8 -1
- package/dist/story-generator/considerationsLoader.d.ts +32 -0
- package/dist/story-generator/considerationsLoader.d.ts.map +1 -0
- package/dist/story-generator/considerationsLoader.js +2 -1
- package/dist/story-generator/documentation-sources.d.ts +28 -0
- package/dist/story-generator/documentation-sources.d.ts.map +1 -0
- package/dist/story-generator/documentationLoader.d.ts +64 -0
- package/dist/story-generator/documentationLoader.d.ts.map +1 -0
- package/dist/story-generator/documentationLoader.js +4 -3
- package/dist/story-generator/dynamicPackageDiscovery.d.ts +97 -0
- package/dist/story-generator/dynamicPackageDiscovery.d.ts.map +1 -0
- package/dist/story-generator/dynamicPackageDiscovery.js +31 -22
- package/dist/story-generator/enhancedComponentDiscovery.d.ts +125 -0
- package/dist/story-generator/enhancedComponentDiscovery.d.ts.map +1 -0
- package/dist/story-generator/enhancedComponentDiscovery.js +162 -21
- package/dist/story-generator/framework-adapters/angular-adapter.d.ts +40 -0
- package/dist/story-generator/framework-adapters/angular-adapter.d.ts.map +1 -0
- package/dist/story-generator/framework-adapters/angular-adapter.js +427 -0
- package/dist/story-generator/framework-adapters/base-adapter.d.ts +75 -0
- package/dist/story-generator/framework-adapters/base-adapter.d.ts.map +1 -0
- package/dist/story-generator/framework-adapters/base-adapter.js +147 -0
- package/dist/story-generator/framework-adapters/framework-detector.d.ts +55 -0
- package/dist/story-generator/framework-adapters/framework-detector.d.ts.map +1 -0
- package/dist/story-generator/framework-adapters/framework-detector.js +323 -0
- package/dist/story-generator/framework-adapters/index.d.ts +97 -0
- package/dist/story-generator/framework-adapters/index.d.ts.map +1 -0
- package/dist/story-generator/framework-adapters/index.js +198 -0
- package/dist/story-generator/framework-adapters/react-adapter.d.ts +40 -0
- package/dist/story-generator/framework-adapters/react-adapter.d.ts.map +1 -0
- package/dist/story-generator/framework-adapters/react-adapter.js +316 -0
- package/dist/story-generator/framework-adapters/svelte-adapter.d.ts +40 -0
- package/dist/story-generator/framework-adapters/svelte-adapter.d.ts.map +1 -0
- package/dist/story-generator/framework-adapters/svelte-adapter.js +372 -0
- package/dist/story-generator/framework-adapters/types.d.ts +182 -0
- package/dist/story-generator/framework-adapters/types.d.ts.map +1 -0
- package/dist/story-generator/framework-adapters/types.js +8 -0
- package/dist/story-generator/framework-adapters/vue-adapter.d.ts +36 -0
- package/dist/story-generator/framework-adapters/vue-adapter.d.ts.map +1 -0
- package/dist/story-generator/framework-adapters/vue-adapter.js +336 -0
- package/dist/story-generator/framework-adapters/web-components-adapter.d.ts +54 -0
- package/dist/story-generator/framework-adapters/web-components-adapter.d.ts.map +1 -0
- package/dist/story-generator/framework-adapters/web-components-adapter.js +387 -0
- package/dist/story-generator/generateStory.d.ts +7 -0
- package/dist/story-generator/generateStory.d.ts.map +1 -0
- package/dist/story-generator/gitignoreManager.d.ts +50 -0
- package/dist/story-generator/gitignoreManager.d.ts.map +1 -0
- package/dist/story-generator/gitignoreManager.js +7 -6
- package/dist/story-generator/imageProcessor.d.ts +80 -0
- package/dist/story-generator/imageProcessor.d.ts.map +1 -0
- package/dist/story-generator/imageProcessor.js +391 -0
- package/dist/story-generator/inMemoryStoryService.d.ts +89 -0
- package/dist/story-generator/inMemoryStoryService.d.ts.map +1 -0
- package/dist/story-generator/llm-providers/base-provider.d.ts +36 -0
- package/dist/story-generator/llm-providers/base-provider.d.ts.map +1 -0
- package/dist/story-generator/llm-providers/base-provider.js +135 -0
- package/dist/story-generator/llm-providers/claude-provider.d.ts +23 -0
- package/dist/story-generator/llm-providers/claude-provider.d.ts.map +1 -0
- package/dist/story-generator/llm-providers/claude-provider.js +414 -0
- package/dist/story-generator/llm-providers/gemini-provider.d.ts +24 -0
- package/dist/story-generator/llm-providers/gemini-provider.d.ts.map +1 -0
- package/dist/story-generator/llm-providers/gemini-provider.js +406 -0
- package/dist/story-generator/llm-providers/index.d.ts +63 -0
- package/dist/story-generator/llm-providers/index.d.ts.map +1 -0
- package/dist/story-generator/llm-providers/index.js +169 -0
- package/dist/story-generator/llm-providers/openai-provider.d.ts +24 -0
- package/dist/story-generator/llm-providers/openai-provider.d.ts.map +1 -0
- package/dist/story-generator/llm-providers/openai-provider.js +458 -0
- package/dist/story-generator/llm-providers/settings-manager.d.ts +75 -0
- package/dist/story-generator/llm-providers/settings-manager.d.ts.map +1 -0
- package/dist/story-generator/llm-providers/settings-manager.js +173 -0
- package/dist/story-generator/llm-providers/story-llm-service.d.ts +79 -0
- package/dist/story-generator/llm-providers/story-llm-service.d.ts.map +1 -0
- package/dist/story-generator/llm-providers/story-llm-service.js +240 -0
- package/dist/story-generator/llm-providers/types.d.ts +153 -0
- package/dist/story-generator/llm-providers/types.d.ts.map +1 -0
- package/dist/story-generator/llm-providers/types.js +8 -0
- package/dist/story-generator/logger.d.ts +14 -0
- package/dist/story-generator/logger.d.ts.map +1 -0
- package/dist/story-generator/logger.js +119 -0
- package/dist/story-generator/postProcessStory.d.ts +6 -0
- package/dist/story-generator/postProcessStory.d.ts.map +1 -0
- package/dist/story-generator/postProcessStory.js +8 -7
- package/dist/story-generator/productionGitignoreManager.d.ts +91 -0
- package/dist/story-generator/productionGitignoreManager.d.ts.map +1 -0
- package/dist/story-generator/productionGitignoreManager.js +11 -10
- package/dist/story-generator/promptGenerator.d.ts +48 -0
- package/dist/story-generator/promptGenerator.d.ts.map +1 -0
- package/dist/story-generator/promptGenerator.js +186 -1
- package/dist/story-generator/storyHistory.d.ts +44 -0
- package/dist/story-generator/storyHistory.d.ts.map +1 -0
- package/dist/story-generator/storySync.d.ts +68 -0
- package/dist/story-generator/storySync.d.ts.map +1 -0
- package/dist/story-generator/storyTracker.d.ts +48 -0
- package/dist/story-generator/storyTracker.d.ts.map +1 -0
- package/dist/story-generator/storyTracker.js +2 -1
- package/dist/story-generator/storyValidator.d.ts +6 -0
- package/dist/story-generator/storyValidator.d.ts.map +1 -0
- package/dist/story-generator/universalDesignSystemAdapter.d.ts +68 -0
- package/dist/story-generator/universalDesignSystemAdapter.d.ts.map +1 -0
- package/dist/story-generator/universalDesignSystemAdapter.js +141 -3
- package/dist/story-generator/urlRedirectService.d.ts +21 -0
- package/dist/story-generator/urlRedirectService.d.ts.map +1 -0
- package/dist/story-generator/urlRedirectService.js +140 -0
- package/dist/story-generator/validateStory.d.ts +19 -0
- package/dist/story-generator/validateStory.d.ts.map +1 -0
- package/dist/story-generator/validateStory.js +6 -2
- package/dist/story-generator/visionPrompts.d.ts +88 -0
- package/dist/story-generator/visionPrompts.d.ts.map +1 -0
- package/dist/story-generator/visionPrompts.js +462 -0
- package/dist/story-ui.config.d.ts +78 -0
- package/dist/story-ui.config.d.ts.map +1 -0
- package/dist/templates/StoryUI/StoryUIPanel.d.ts +4 -0
- package/dist/templates/StoryUI/StoryUIPanel.d.ts.map +1 -0
- package/dist/templates/StoryUI/StoryUIPanel.js +1874 -0
- package/dist/templates/StoryUI/StoryUIPanel.stories.d.ts +18 -0
- package/dist/templates/StoryUI/StoryUIPanel.stories.d.ts.map +1 -0
- package/dist/templates/StoryUI/StoryUIPanel.stories.js +37 -0
- package/dist/templates/StoryUI/index.d.ts +3 -0
- package/dist/templates/StoryUI/index.d.ts.map +1 -0
- package/dist/templates/StoryUI/index.js +2 -0
- package/package.json +35 -4
- package/templates/StoryUI/StoryUIPanel.tsx +1973 -388
- package/templates/StoryUI/index.tsx +1 -1
- package/templates/StoryUI/manager.tsx +264 -0
- package/templates/mcp-config-claude.json +11 -0
- package/templates/mcp-example.md +76 -0
- package/templates/production-app/.env.example +11 -0
- package/templates/production-app/index.html +66 -0
- package/templates/production-app/package.json +30 -0
- package/templates/production-app/public/favicon.svg +5 -0
- package/templates/production-app/src/App.tsx +1157 -0
- package/templates/production-app/src/LivePreviewRenderer.tsx +420 -0
- package/templates/production-app/src/componentRegistry.ts +315 -0
- package/templates/production-app/src/considerations.ts +16 -0
- package/templates/production-app/src/index.css +284 -0
- package/templates/production-app/src/main.tsx +25 -0
- package/templates/production-app/tsconfig.json +32 -0
- package/templates/production-app/tsconfig.node.json +11 -0
- package/templates/production-app/vite.config.ts +83 -0
- package/templates/react-import-rule.json +2 -2
- package/dist/index.js +0 -12
- package/dist/story-ui.config.loader.js +0 -205
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import fs from 'fs';
|
|
2
2
|
import path from 'path';
|
|
3
3
|
import { glob } from 'glob';
|
|
4
|
+
import { logger } from './logger.js';
|
|
4
5
|
export class DocumentationLoader {
|
|
5
6
|
constructor(projectRoot) {
|
|
6
7
|
this.cache = null;
|
|
@@ -32,7 +33,7 @@ export class DocumentationLoader {
|
|
|
32
33
|
if (this.cache && stats.mtimeMs <= this.lastModified) {
|
|
33
34
|
return this.cache;
|
|
34
35
|
}
|
|
35
|
-
|
|
36
|
+
logger.log(`📚 Loading documentation from ${this.docsDir}`);
|
|
36
37
|
const documentation = {
|
|
37
38
|
sources: [],
|
|
38
39
|
guidelines: [],
|
|
@@ -58,7 +59,7 @@ export class DocumentationLoader {
|
|
|
58
59
|
allFiles.push(...matches);
|
|
59
60
|
}
|
|
60
61
|
const files = [...new Set(allFiles)]; // Remove duplicates
|
|
61
|
-
|
|
62
|
+
logger.log(`📄 Found ${files.length} documentation files`);
|
|
62
63
|
// Process each file
|
|
63
64
|
for (const file of files) {
|
|
64
65
|
// Skip README files as they are instructional, not design system documentation
|
|
@@ -82,7 +83,7 @@ export class DocumentationLoader {
|
|
|
82
83
|
// Cache the results
|
|
83
84
|
this.cache = documentation;
|
|
84
85
|
this.lastModified = stats.mtimeMs;
|
|
85
|
-
|
|
86
|
+
logger.log(`✅ Loaded documentation with ${documentation.guidelines.length} guidelines, ${Object.keys(documentation.tokens).length} token categories, ${Object.keys(documentation.patterns).length} patterns`);
|
|
86
87
|
return documentation;
|
|
87
88
|
}
|
|
88
89
|
/**
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
export interface RealPackageComponent {
|
|
2
|
+
name: string;
|
|
3
|
+
isComponent: boolean;
|
|
4
|
+
type: 'function' | 'class' | 'object' | 'unknown';
|
|
5
|
+
__componentPath?: string;
|
|
6
|
+
}
|
|
7
|
+
export interface PackageExports {
|
|
8
|
+
components: RealPackageComponent[];
|
|
9
|
+
allExports: string[];
|
|
10
|
+
packageVersion: string;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Dynamically discovers what components are actually available in an installed package
|
|
14
|
+
*/
|
|
15
|
+
export declare class DynamicPackageDiscovery {
|
|
16
|
+
private packageName;
|
|
17
|
+
private projectRoot;
|
|
18
|
+
constructor(packageName: string, projectRoot?: string);
|
|
19
|
+
/**
|
|
20
|
+
* Get the real exports from the installed package
|
|
21
|
+
*/
|
|
22
|
+
getRealPackageExports(): Promise<PackageExports | null>;
|
|
23
|
+
/**
|
|
24
|
+
* Require the package safely
|
|
25
|
+
*/
|
|
26
|
+
private requirePackage;
|
|
27
|
+
/**
|
|
28
|
+
* Determine if an export is likely a React component
|
|
29
|
+
*/
|
|
30
|
+
private isLikelyComponent;
|
|
31
|
+
/**
|
|
32
|
+
* Check if a name indicates a utility export (not a component)
|
|
33
|
+
*/
|
|
34
|
+
private isUtilityExport;
|
|
35
|
+
/**
|
|
36
|
+
* Check if a function looks like a React component
|
|
37
|
+
*/
|
|
38
|
+
private looksLikeReactComponent;
|
|
39
|
+
/**
|
|
40
|
+
* Check if an object has component-like properties
|
|
41
|
+
*/
|
|
42
|
+
private hasComponentLikeProperties;
|
|
43
|
+
/**
|
|
44
|
+
* Get the type of an export
|
|
45
|
+
*/
|
|
46
|
+
private getExportType;
|
|
47
|
+
/**
|
|
48
|
+
* Get only the component names that should be used for story generation
|
|
49
|
+
*/
|
|
50
|
+
getAvailableComponentNames(): Promise<string[]>;
|
|
51
|
+
/**
|
|
52
|
+
* Validate that a list of component names are actually available
|
|
53
|
+
*/
|
|
54
|
+
validateComponentNames(componentNames: string[]): Promise<{
|
|
55
|
+
valid: string[];
|
|
56
|
+
invalid: string[];
|
|
57
|
+
suggestions: Map<string, string>;
|
|
58
|
+
}>;
|
|
59
|
+
/**
|
|
60
|
+
* Find a similar component name
|
|
61
|
+
*/
|
|
62
|
+
private findSimilarComponent;
|
|
63
|
+
/**
|
|
64
|
+
* Alternative discovery method when package imports fail due to CSS
|
|
65
|
+
* Analyzes package.json exports and TypeScript definitions
|
|
66
|
+
*/
|
|
67
|
+
private discoverFromPackageStructure;
|
|
68
|
+
/**
|
|
69
|
+
* Scan package subdirectories for components (e.g., antd/button, chakra-ui/input)
|
|
70
|
+
*/
|
|
71
|
+
private scanComponentSubdirectories;
|
|
72
|
+
/**
|
|
73
|
+
* Extract component names from TypeScript declaration content
|
|
74
|
+
*/
|
|
75
|
+
private extractComponentsFromTypings;
|
|
76
|
+
/**
|
|
77
|
+
* Check if a name looks like a React component
|
|
78
|
+
*/
|
|
79
|
+
private isComponentName;
|
|
80
|
+
/**
|
|
81
|
+
* Extract component exports from package.json exports field
|
|
82
|
+
*/
|
|
83
|
+
private extractExportsFromPackageJson;
|
|
84
|
+
/**
|
|
85
|
+
* Extract component declarations from TypeScript definition files
|
|
86
|
+
*/
|
|
87
|
+
private extractExportsFromTypeDefinitions;
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Create a dynamic discovery instance for a package
|
|
91
|
+
*/
|
|
92
|
+
export declare function createDynamicDiscovery(packageName: string, projectRoot?: string): DynamicPackageDiscovery;
|
|
93
|
+
/**
|
|
94
|
+
* Quick function to get available components for a package
|
|
95
|
+
*/
|
|
96
|
+
export declare function getPackageComponents(packageName: string, projectRoot?: string): Promise<string[]>;
|
|
97
|
+
//# sourceMappingURL=dynamicPackageDiscovery.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dynamicPackageDiscovery.d.ts","sourceRoot":"","sources":["../../story-generator/dynamicPackageDiscovery.ts"],"names":[],"mappings":"AAMA,MAAM,WAAW,oBAAoB;IACnC,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,OAAO,CAAC;IACrB,IAAI,EAAE,UAAU,GAAG,OAAO,GAAG,QAAQ,GAAG,SAAS,CAAC;IAClD,eAAe,CAAC,EAAE,MAAM,CAAC;CAC1B;AAED,MAAM,WAAW,cAAc;IAC7B,UAAU,EAAE,oBAAoB,EAAE,CAAC;IACnC,UAAU,EAAE,MAAM,EAAE,CAAC;IACrB,cAAc,EAAE,MAAM,CAAC;CACxB;AAED;;GAEG;AACH,qBAAa,uBAAuB;IAClC,OAAO,CAAC,WAAW,CAAS;IAC5B,OAAO,CAAC,WAAW,CAAS;gBAEhB,WAAW,EAAE,MAAM,EAAE,WAAW,GAAE,MAA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logger } from './logger.js';
|
|
4
5
|
/**
|
|
5
6
|
* Dynamically discovers what components are actually available in an installed package
|
|
6
7
|
*/
|
|
@@ -29,7 +30,7 @@ export class DynamicPackageDiscovery {
|
|
|
29
30
|
// Try to require the package and inspect its exports
|
|
30
31
|
const packageExports = await this.requirePackage(this.packageName);
|
|
31
32
|
if (!packageExports) {
|
|
32
|
-
|
|
33
|
+
logger.log(`🔄 Could not directly import ${this.packageName}, falling back to structure analysis`);
|
|
33
34
|
// Don't return null here - fall back to structure discovery
|
|
34
35
|
}
|
|
35
36
|
const components = [];
|
|
@@ -49,14 +50,14 @@ export class DynamicPackageDiscovery {
|
|
|
49
50
|
}
|
|
50
51
|
// Check if we found any actual components
|
|
51
52
|
const componentCount = components.filter(c => c.isComponent).length;
|
|
52
|
-
|
|
53
|
+
logger.log(`📋 Found ${componentCount} components in main ${this.packageName} export`);
|
|
53
54
|
// If no components found in main export, fall back to structure analysis
|
|
54
55
|
if (componentCount === 0) {
|
|
55
|
-
|
|
56
|
+
logger.log(`🔄 No components in main export, falling back to structure analysis for ${this.packageName}...`);
|
|
56
57
|
const structureExports = this.discoverFromPackageStructure();
|
|
57
58
|
if (structureExports) {
|
|
58
59
|
const structureComponentNames = Object.keys(structureExports);
|
|
59
|
-
|
|
60
|
+
logger.log(`📁 Structure analysis found ${structureComponentNames.length} components`);
|
|
60
61
|
// Replace with structure-discovered components
|
|
61
62
|
allExports = structureComponentNames;
|
|
62
63
|
components.length = 0; // Clear the array
|
|
@@ -75,7 +76,7 @@ export class DynamicPackageDiscovery {
|
|
|
75
76
|
}
|
|
76
77
|
else {
|
|
77
78
|
// Failed to import - fall back to structure analysis
|
|
78
|
-
|
|
79
|
+
logger.log(`📁 Import failed, analyzing package structure for ${this.packageName}...`);
|
|
79
80
|
const structureExports = this.discoverFromPackageStructure();
|
|
80
81
|
if (structureExports) {
|
|
81
82
|
allExports = Object.keys(structureExports);
|
|
@@ -91,7 +92,7 @@ export class DynamicPackageDiscovery {
|
|
|
91
92
|
}
|
|
92
93
|
}
|
|
93
94
|
}
|
|
94
|
-
|
|
95
|
+
logger.log(`✅ Discovered ${components.filter(c => c.isComponent).length} components from ${this.packageName} v${packageVersion}`);
|
|
95
96
|
return {
|
|
96
97
|
components,
|
|
97
98
|
allExports,
|
|
@@ -118,7 +119,11 @@ export class DynamicPackageDiscovery {
|
|
|
118
119
|
// Check if this is a CSS import error (common with compiled design systems)
|
|
119
120
|
const errorMessage = importError?.message || String(importError);
|
|
120
121
|
if (errorMessage.includes('.css:') || errorMessage.includes('Unexpected token')) {
|
|
121
|
-
|
|
122
|
+
logger.log(`🔄 ${packageName}: CSS detected, using static analysis (normal for design systems)`);
|
|
123
|
+
return this.discoverFromPackageStructure();
|
|
124
|
+
}
|
|
125
|
+
if (errorMessage.includes('Invalid hook call') || errorMessage.includes('Hooks can only be called')) {
|
|
126
|
+
logger.log(`🔄 ${packageName}: React hooks detected outside component context, using static analysis`);
|
|
122
127
|
return this.discoverFromPackageStructure();
|
|
123
128
|
}
|
|
124
129
|
// Fall back to require (for CommonJS)
|
|
@@ -129,17 +134,21 @@ export class DynamicPackageDiscovery {
|
|
|
129
134
|
}
|
|
130
135
|
}
|
|
131
136
|
catch (error) {
|
|
132
|
-
// Check if this is a CSS import error
|
|
137
|
+
// Check if this is a CSS import error
|
|
133
138
|
const errorMessage = error?.message || String(error);
|
|
134
139
|
if (errorMessage.includes('.css:') || errorMessage.includes('Unexpected token')) {
|
|
135
|
-
|
|
140
|
+
logger.log(`🔄 ${packageName}: CSS detected, using static analysis (normal for design systems)`);
|
|
136
141
|
return this.discoverFromPackageStructure();
|
|
137
142
|
}
|
|
138
143
|
if (errorMessage.includes('window is not defined')) {
|
|
139
|
-
|
|
144
|
+
logger.log(`🔄 ${packageName}: Browser-only component, using static analysis`);
|
|
145
|
+
return this.discoverFromPackageStructure();
|
|
146
|
+
}
|
|
147
|
+
if (errorMessage.includes('Invalid hook call') || errorMessage.includes('Hooks can only be called')) {
|
|
148
|
+
logger.log(`🔄 ${packageName}: React hooks detected outside component context, using static analysis`);
|
|
140
149
|
return this.discoverFromPackageStructure();
|
|
141
150
|
}
|
|
142
|
-
|
|
151
|
+
logger.log(`📋 ${packageName}: Dynamic import failed, using static analysis`);
|
|
143
152
|
return this.discoverFromPackageStructure();
|
|
144
153
|
}
|
|
145
154
|
}
|
|
@@ -335,26 +344,26 @@ export class DynamicPackageDiscovery {
|
|
|
335
344
|
const packagePath = path.join(this.projectRoot, 'node_modules', this.packageName);
|
|
336
345
|
const packageJsonPath = path.join(packagePath, 'package.json');
|
|
337
346
|
if (!fs.existsSync(packageJsonPath)) {
|
|
338
|
-
|
|
347
|
+
logger.log(`📦 No package.json found for ${this.packageName}`);
|
|
339
348
|
return null;
|
|
340
349
|
}
|
|
341
350
|
const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf-8'));
|
|
342
351
|
const exports = {};
|
|
343
352
|
// Method 1: Analyze package.json exports field
|
|
344
353
|
if (packageJson.exports) {
|
|
345
|
-
|
|
354
|
+
logger.log(`📋 Analyzing exports field in ${this.packageName}/package.json`);
|
|
346
355
|
this.extractExportsFromPackageJson(packageJson.exports, exports);
|
|
347
356
|
}
|
|
348
357
|
// Method 2: Look for index.d.ts or main TypeScript declarations
|
|
349
358
|
const typingsPath = packageJson.types || packageJson.typings || './dist/types/index.d.ts';
|
|
350
359
|
const fullTypingsPath = path.join(packagePath, typingsPath);
|
|
351
360
|
if (fs.existsSync(fullTypingsPath)) {
|
|
352
|
-
|
|
361
|
+
logger.log(`📋 Analyzing TypeScript declarations for ${this.packageName}`);
|
|
353
362
|
this.extractExportsFromTypeDefinitions(fullTypingsPath, exports);
|
|
354
363
|
}
|
|
355
364
|
// Method 3: Scan for component subdirectories (for packages like Base Web)
|
|
356
365
|
if (Object.keys(exports).length === 0) {
|
|
357
|
-
|
|
366
|
+
logger.log(`📁 Scanning subdirectories for ${this.packageName} components...`);
|
|
358
367
|
this.scanComponentSubdirectories(packagePath, exports);
|
|
359
368
|
}
|
|
360
369
|
return Object.keys(exports).length > 0 ? exports : null;
|
|
@@ -369,9 +378,9 @@ export class DynamicPackageDiscovery {
|
|
|
369
378
|
*/
|
|
370
379
|
scanComponentSubdirectories(packagePath, result) {
|
|
371
380
|
try {
|
|
372
|
-
|
|
381
|
+
logger.log(`🔍 Scanning ${packagePath} for component subdirectories...`);
|
|
373
382
|
const entries = fs.readdirSync(packagePath, { withFileTypes: true });
|
|
374
|
-
|
|
383
|
+
logger.log(`📁 Found ${entries.length} entries in ${packagePath}`);
|
|
375
384
|
let componentDirsFound = 0;
|
|
376
385
|
for (const entry of entries) {
|
|
377
386
|
if (!entry.isDirectory())
|
|
@@ -388,7 +397,7 @@ export class DynamicPackageDiscovery {
|
|
|
388
397
|
// Look for component exports (functions/classes starting with uppercase)
|
|
389
398
|
const componentExports = this.extractComponentsFromTypings(typingsContent);
|
|
390
399
|
if (componentExports.length > 0) {
|
|
391
|
-
|
|
400
|
+
logger.log(`📦 Found ${componentExports.length} components in ${entry.name}/`);
|
|
392
401
|
// Add each component to the result
|
|
393
402
|
for (const componentName of componentExports) {
|
|
394
403
|
// Create a mock export function for this component
|
|
@@ -404,8 +413,8 @@ export class DynamicPackageDiscovery {
|
|
|
404
413
|
}
|
|
405
414
|
}
|
|
406
415
|
}
|
|
407
|
-
|
|
408
|
-
|
|
416
|
+
logger.log(`✅ Scanned ${componentDirsFound} component directories for ${this.packageName}`);
|
|
417
|
+
logger.log(`📦 Total components found in subdirectories: ${Object.keys(result).length}`);
|
|
409
418
|
}
|
|
410
419
|
catch (error) {
|
|
411
420
|
console.warn(`Failed to scan subdirectories for ${this.packageName}:`, error);
|
|
@@ -484,7 +493,7 @@ export class DynamicPackageDiscovery {
|
|
|
484
493
|
const componentName = key.replace('./', '').split('/').pop();
|
|
485
494
|
if (componentName && /^[A-Z]/.test(componentName)) {
|
|
486
495
|
result[componentName] = `Component_${componentName}`;
|
|
487
|
-
|
|
496
|
+
logger.log(`📍 Found component export: ${componentName}`);
|
|
488
497
|
}
|
|
489
498
|
}
|
|
490
499
|
}
|
|
@@ -512,7 +521,7 @@ export class DynamicPackageDiscovery {
|
|
|
512
521
|
const componentName = match[1];
|
|
513
522
|
if (componentName && /^[A-Z]/.test(componentName)) {
|
|
514
523
|
result[componentName] = `Component_${componentName}`;
|
|
515
|
-
|
|
524
|
+
logger.log(`📍 Found component in .d.ts: ${componentName}`);
|
|
516
525
|
}
|
|
517
526
|
}
|
|
518
527
|
}
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
import { DiscoveredComponent } from './componentDiscovery.js';
|
|
2
|
+
import { StoryUIConfig } from '../story-ui.config.js';
|
|
3
|
+
export interface ComponentSource {
|
|
4
|
+
type: 'npm' | 'local' | 'custom-elements' | 'typescript';
|
|
5
|
+
path: string;
|
|
6
|
+
patterns?: string[];
|
|
7
|
+
}
|
|
8
|
+
export interface EnhancedComponent extends DiscoveredComponent {
|
|
9
|
+
source: ComponentSource;
|
|
10
|
+
docUrl?: string;
|
|
11
|
+
examples?: string[];
|
|
12
|
+
dependencies?: string[];
|
|
13
|
+
isComposite?: boolean;
|
|
14
|
+
}
|
|
15
|
+
export declare class EnhancedComponentDiscovery {
|
|
16
|
+
private config;
|
|
17
|
+
private discoveredComponents;
|
|
18
|
+
private validateAvailableComponents;
|
|
19
|
+
constructor(config: StoryUIConfig);
|
|
20
|
+
/**
|
|
21
|
+
* Discover components from all available sources
|
|
22
|
+
* Priority: 1. Dynamic Discovery 2. Static Lists 3. Manual Config
|
|
23
|
+
*/
|
|
24
|
+
discoverAll(): Promise<EnhancedComponent[]>;
|
|
25
|
+
/**
|
|
26
|
+
* Resolve naming conflicts between different sources
|
|
27
|
+
* Priority: Local > Manual Config > npm packages
|
|
28
|
+
*/
|
|
29
|
+
private resolveComponentConflicts;
|
|
30
|
+
/**
|
|
31
|
+
* Log discovery summary for debugging
|
|
32
|
+
*/
|
|
33
|
+
private logDiscoverySummary;
|
|
34
|
+
/**
|
|
35
|
+
* Get the project root directory from the config
|
|
36
|
+
*/
|
|
37
|
+
private getProjectRoot;
|
|
38
|
+
/**
|
|
39
|
+
* Identify all potential component sources
|
|
40
|
+
*/
|
|
41
|
+
private identifySources;
|
|
42
|
+
/**
|
|
43
|
+
* Auto-discovery removed - now handled by guided installation during init
|
|
44
|
+
* This function is kept for backward compatibility but does nothing
|
|
45
|
+
*/
|
|
46
|
+
private addDesignSystemPackages;
|
|
47
|
+
/**
|
|
48
|
+
* Check if a package is likely to contain React components (not utilities, types, etc.)
|
|
49
|
+
*/
|
|
50
|
+
private isLikelyComponentPackage;
|
|
51
|
+
/**
|
|
52
|
+
* Discover components from npm packages using dynamic runtime discovery
|
|
53
|
+
*/
|
|
54
|
+
private discoverFromNpmPackage;
|
|
55
|
+
/**
|
|
56
|
+
* Get known components for popular design systems
|
|
57
|
+
* Returns a fallback list when dynamic discovery fails
|
|
58
|
+
*/
|
|
59
|
+
private getKnownDesignSystemComponents;
|
|
60
|
+
/**
|
|
61
|
+
* Discover components from local files
|
|
62
|
+
*/
|
|
63
|
+
private discoverFromLocalFiles;
|
|
64
|
+
/**
|
|
65
|
+
* Check if a file should be skipped (stories, tests, etc.)
|
|
66
|
+
*/
|
|
67
|
+
private isNonComponentFile;
|
|
68
|
+
/**
|
|
69
|
+
* Check if a component should be skipped based on name or content
|
|
70
|
+
*/
|
|
71
|
+
private shouldSkipComponent;
|
|
72
|
+
/**
|
|
73
|
+
* Find component files recursively
|
|
74
|
+
*/
|
|
75
|
+
private findComponentFiles;
|
|
76
|
+
/**
|
|
77
|
+
* Extract component name from file
|
|
78
|
+
*/
|
|
79
|
+
private extractComponentName;
|
|
80
|
+
/**
|
|
81
|
+
* Extract props from file content
|
|
82
|
+
*/
|
|
83
|
+
private extractPropsFromFile;
|
|
84
|
+
/**
|
|
85
|
+
* Extract slots from content
|
|
86
|
+
*/
|
|
87
|
+
private extractSlots;
|
|
88
|
+
/**
|
|
89
|
+
* Categorize component based on name and content
|
|
90
|
+
*/
|
|
91
|
+
private categorizeComponent;
|
|
92
|
+
/**
|
|
93
|
+
* Discover from custom elements JSON
|
|
94
|
+
*/
|
|
95
|
+
private discoverFromCustomElements;
|
|
96
|
+
/**
|
|
97
|
+
* Extract props from custom element declaration
|
|
98
|
+
*/
|
|
99
|
+
private extractPropsFromDeclaration;
|
|
100
|
+
/**
|
|
101
|
+
* Discover from TypeScript definitions
|
|
102
|
+
*/
|
|
103
|
+
private discoverFromTypeScript;
|
|
104
|
+
/**
|
|
105
|
+
* Apply manual component configurations
|
|
106
|
+
*/
|
|
107
|
+
private applyManualConfigurations;
|
|
108
|
+
/**
|
|
109
|
+
* Validate that component names actually exist in the discovered package
|
|
110
|
+
*/
|
|
111
|
+
validateComponentNames(componentNames: string[]): Promise<{
|
|
112
|
+
valid: string[];
|
|
113
|
+
invalid: string[];
|
|
114
|
+
suggestions: Map<string, string>;
|
|
115
|
+
}>;
|
|
116
|
+
/**
|
|
117
|
+
* Find a similar component name
|
|
118
|
+
*/
|
|
119
|
+
private findSimilarComponent;
|
|
120
|
+
/**
|
|
121
|
+
* Get the available component names for validation
|
|
122
|
+
*/
|
|
123
|
+
getAvailableComponentNames(): string[];
|
|
124
|
+
}
|
|
125
|
+
//# sourceMappingURL=enhancedComponentDiscovery.d.ts.map
|
|
@@ -0,0 +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;AAItD,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,mB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