@idealyst/tooling 1.2.23 → 1.2.25

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.
@@ -1,199 +0,0 @@
1
- /**
2
- * Idealyst Docs Vite Plugin
3
- *
4
- * Generates a component registry at build time by analyzing TypeScript source.
5
- * Replaces placeholder exports from @idealyst/tooling with actual generated values.
6
- *
7
- * Usage:
8
- * ```ts
9
- * // vite.config.ts
10
- * import { idealystDocsPlugin } from '@idealyst/tooling';
11
- *
12
- * export default defineConfig({
13
- * plugins: [
14
- * idealystDocsPlugin({
15
- * componentPaths: ['../../packages/components/src'],
16
- * themePath: '../../packages/theme/src/lightTheme.ts',
17
- * }),
18
- * ],
19
- * });
20
- * ```
21
- *
22
- * Then in your app:
23
- * ```ts
24
- * import { componentRegistry, componentNames, getComponentsByCategory } from '@idealyst/tooling';
25
- * ```
26
- */
27
-
28
- import type { Plugin } from 'vite';
29
- import * as fs from 'fs';
30
- import * as path from 'path';
31
- import { analyzeComponents } from './analyzer';
32
- import type { IdealystDocsPluginOptions, ComponentRegistry } from './analyzer/types';
33
-
34
- /**
35
- * Create the Idealyst Docs Vite plugin.
36
- */
37
- export function idealystDocsPlugin(options: IdealystDocsPluginOptions): Plugin {
38
- let registry: ComponentRegistry | null = null;
39
-
40
- const { debug = false, output, outputPath } = options;
41
-
42
- const log = (...args: any[]) => {
43
- if (debug) console.log('[idealyst-docs]', ...args);
44
- };
45
-
46
- /**
47
- * Generate the registry by analyzing components.
48
- */
49
- function generateRegistry(): ComponentRegistry {
50
- log('Generating component registry...');
51
- log('Component paths:', options.componentPaths);
52
- log('Theme path:', options.themePath);
53
-
54
- try {
55
- registry = analyzeComponents(options);
56
- log(`Generated registry with ${Object.keys(registry).length} components`);
57
- if (debug) {
58
- log('Components found:', Object.keys(registry));
59
- }
60
-
61
- // Optionally write to file
62
- if (output === 'file' && outputPath) {
63
- const outputDir = path.dirname(outputPath);
64
- if (!fs.existsSync(outputDir)) {
65
- fs.mkdirSync(outputDir, { recursive: true });
66
- }
67
- fs.writeFileSync(
68
- outputPath,
69
- `// Auto-generated by @idealyst/tooling - DO NOT EDIT\n` +
70
- `export const componentRegistry = ${JSON.stringify(registry, null, 2)} as const;\n`
71
- );
72
- log(`Wrote registry to ${outputPath}`);
73
- }
74
-
75
- return registry;
76
- } catch (error) {
77
- console.error('[idealyst-docs] Error generating registry:', error);
78
- return {};
79
- }
80
- }
81
-
82
- return {
83
- name: 'idealyst-docs',
84
-
85
- // Transform @idealyst/tooling to inject the actual registry
86
- transform(code, id) {
87
- // Check if this is the tooling package's index file
88
- const isToolingIndex = id.includes('@idealyst/tooling') && id.endsWith('index.ts');
89
- const isToolingSrc = id.includes('/packages/tooling/src/index.ts');
90
-
91
- if (isToolingIndex || isToolingSrc) {
92
- console.log(`[idealyst-docs] Transforming tooling index: ${id}`);
93
-
94
- if (!registry) {
95
- registry = generateRegistry();
96
- }
97
-
98
- // Replace the placeholder exports with actual values
99
- let transformed = code;
100
-
101
- // Replace: export const componentRegistry = {};
102
- // Note: TypeScript types are stripped before transform, so we match JS not TS
103
- transformed = transformed.replace(
104
- /export const componentRegistry\s*=\s*\{\s*\};?/,
105
- `export const componentRegistry = ${JSON.stringify(registry, null, 2)};`
106
- );
107
-
108
- log(`Code transformed: ${code !== transformed}`);
109
-
110
- // Replace: export const componentNames = [];
111
- // Note: TypeScript types are stripped before transform
112
- transformed = transformed.replace(
113
- /export const componentNames\s*=\s*\[\s*\];?/,
114
- `export const componentNames = ${JSON.stringify(Object.keys(registry))};`
115
- );
116
-
117
- // Replace getComponentsByCategory with actual implementation that uses the real registry
118
- // Match JS version (no type annotations)
119
- transformed = transformed.replace(
120
- /export function getComponentsByCategory\(category\)\s*\{[\s\S]*?^\}/m,
121
- `export function getComponentsByCategory(category) {
122
- return Object.entries(componentRegistry)
123
- .filter(([_, def]) => def.category === category)
124
- .map(([name]) => name);
125
- }`
126
- );
127
-
128
- // Replace getPropConfig with actual implementation
129
- // Match JS version (no type annotations)
130
- transformed = transformed.replace(
131
- /export function getPropConfig\(componentName\)\s*\{[\s\S]*?^\}/m,
132
- `export function getPropConfig(componentName) {
133
- const def = componentRegistry[componentName];
134
- if (!def) return {};
135
- return Object.entries(def.props).reduce((acc, [key, prop]) => {
136
- if (prop.values && prop.values.length > 0) {
137
- acc[key] = { type: 'select', options: prop.values, default: prop.default };
138
- } else if (prop.type === 'boolean') {
139
- acc[key] = { type: 'boolean', default: prop.default ?? false };
140
- } else if (prop.type === 'string') {
141
- acc[key] = { type: 'text', default: prop.default ?? '' };
142
- } else if (prop.type === 'number') {
143
- acc[key] = { type: 'number', default: prop.default ?? 0 };
144
- }
145
- return acc;
146
- }, {});
147
- }`
148
- );
149
-
150
- return {
151
- code: transformed,
152
- map: null,
153
- };
154
- }
155
-
156
- return null;
157
- },
158
-
159
- // Regenerate on component file changes
160
- handleHotUpdate({ file, server }) {
161
- // Check if the changed file is a component file
162
- const isComponentFile =
163
- options.componentPaths.some(p => file.includes(path.resolve(p))) &&
164
- (file.endsWith('.ts') || file.endsWith('.tsx'));
165
-
166
- // Check if the changed file is the theme file
167
- const isThemeFile = file.includes(path.resolve(options.themePath));
168
-
169
- if (isComponentFile || isThemeFile) {
170
- log(`File changed: ${file}, regenerating registry...`);
171
-
172
- // Clear cached registry
173
- registry = null;
174
-
175
- // Invalidate the tooling module to trigger re-transform
176
- const toolingMods = Array.from(server.moduleGraph.idToModuleMap.values())
177
- .filter(m => m.id && (m.id.includes('@idealyst/tooling') || m.id.includes('/packages/tooling/src/index')));
178
-
179
- toolingMods.forEach(m => server.moduleGraph.invalidateModule(m));
180
-
181
- if (toolingMods.length > 0) {
182
- return toolingMods;
183
- }
184
- }
185
- },
186
-
187
- // Generate on build
188
- buildStart() {
189
- registry = generateRegistry();
190
- },
191
- };
192
- }
193
-
194
- /**
195
- * Standalone function to generate registry (for MCP server or CLI).
196
- */
197
- export function generateComponentRegistry(options: IdealystDocsPluginOptions): ComponentRegistry {
198
- return analyzeComponents(options);
199
- }