@idealyst/tooling 1.2.3 → 1.2.4
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/package.json +1 -1
- package/src/vite-plugin.ts +25 -85
package/package.json
CHANGED
package/src/vite-plugin.ts
CHANGED
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
* Usage:
|
|
8
8
|
* ```ts
|
|
9
9
|
* // vite.config.ts
|
|
10
|
-
* import { idealystDocsPlugin } from '@idealyst/tooling
|
|
10
|
+
* import { idealystDocsPlugin } from '@idealyst/tooling';
|
|
11
11
|
*
|
|
12
12
|
* export default defineConfig({
|
|
13
13
|
* plugins: [
|
|
@@ -19,7 +19,7 @@
|
|
|
19
19
|
* });
|
|
20
20
|
* ```
|
|
21
21
|
*
|
|
22
|
-
* Then in your app
|
|
22
|
+
* Then in your app:
|
|
23
23
|
* ```ts
|
|
24
24
|
* import { componentRegistry, componentNames, getComponentsByCategory } from '@idealyst/tooling';
|
|
25
25
|
* ```
|
|
@@ -31,13 +31,6 @@ import * as path from 'path';
|
|
|
31
31
|
import { analyzeComponents } from './analyzer';
|
|
32
32
|
import type { IdealystDocsPluginOptions, ComponentRegistry } from './analyzer/types';
|
|
33
33
|
|
|
34
|
-
// Virtual module for backwards compatibility
|
|
35
|
-
const VIRTUAL_MODULE_ID = 'virtual:idealyst-docs';
|
|
36
|
-
const RESOLVED_VIRTUAL_MODULE_ID = '\0' + VIRTUAL_MODULE_ID;
|
|
37
|
-
|
|
38
|
-
// Marker for the tooling package that needs transformation
|
|
39
|
-
const TOOLING_REGISTRY_MARKER = '@idealyst/tooling';
|
|
40
|
-
|
|
41
34
|
/**
|
|
42
35
|
* Create the Idealyst Docs Vite plugin.
|
|
43
36
|
*/
|
|
@@ -45,7 +38,7 @@ export function idealystDocsPlugin(options: IdealystDocsPluginOptions): Plugin {
|
|
|
45
38
|
let registry: ComponentRegistry | null = null;
|
|
46
39
|
let server: ViteDevServer | null = null;
|
|
47
40
|
|
|
48
|
-
const { debug = false, output
|
|
41
|
+
const { debug = false, output, outputPath } = options;
|
|
49
42
|
|
|
50
43
|
const log = (...args: any[]) => {
|
|
51
44
|
if (debug) console.log('[idealyst-docs]', ...args);
|
|
@@ -56,10 +49,15 @@ export function idealystDocsPlugin(options: IdealystDocsPluginOptions): Plugin {
|
|
|
56
49
|
*/
|
|
57
50
|
function generateRegistry(): ComponentRegistry {
|
|
58
51
|
log('Generating component registry...');
|
|
52
|
+
log('Component paths:', options.componentPaths);
|
|
53
|
+
log('Theme path:', options.themePath);
|
|
59
54
|
|
|
60
55
|
try {
|
|
61
56
|
registry = analyzeComponents(options);
|
|
62
57
|
log(`Generated registry with ${Object.keys(registry).length} components`);
|
|
58
|
+
if (debug) {
|
|
59
|
+
log('Components found:', Object.keys(registry));
|
|
60
|
+
}
|
|
63
61
|
|
|
64
62
|
// Optionally write to file
|
|
65
63
|
if (output === 'file' && outputPath) {
|
|
@@ -82,51 +80,6 @@ export function idealystDocsPlugin(options: IdealystDocsPluginOptions): Plugin {
|
|
|
82
80
|
}
|
|
83
81
|
}
|
|
84
82
|
|
|
85
|
-
/**
|
|
86
|
-
* Generate the virtual module code.
|
|
87
|
-
*/
|
|
88
|
-
function generateModuleCode(): string {
|
|
89
|
-
if (!registry) {
|
|
90
|
-
registry = generateRegistry();
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
return `
|
|
94
|
-
// Auto-generated by @idealyst/tooling
|
|
95
|
-
// This module provides component metadata extracted from TypeScript source
|
|
96
|
-
|
|
97
|
-
export const componentRegistry = ${JSON.stringify(registry, null, 2)};
|
|
98
|
-
|
|
99
|
-
// Helper to get component names
|
|
100
|
-
export const componentNames = Object.keys(componentRegistry);
|
|
101
|
-
|
|
102
|
-
// Helper to get components by category
|
|
103
|
-
export function getComponentsByCategory(category) {
|
|
104
|
-
return Object.entries(componentRegistry)
|
|
105
|
-
.filter(([_, def]) => def.category === category)
|
|
106
|
-
.map(([name]) => name);
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
// Helper to get prop config for playground
|
|
110
|
-
export function getPropConfig(componentName) {
|
|
111
|
-
const def = componentRegistry[componentName];
|
|
112
|
-
if (!def) return {};
|
|
113
|
-
|
|
114
|
-
return Object.entries(def.props).reduce((acc, [key, prop]) => {
|
|
115
|
-
if (prop.values && prop.values.length > 0) {
|
|
116
|
-
acc[key] = { type: 'select', options: prop.values, default: prop.default };
|
|
117
|
-
} else if (prop.type === 'boolean') {
|
|
118
|
-
acc[key] = { type: 'boolean', default: prop.default ?? false };
|
|
119
|
-
} else if (prop.type === 'string') {
|
|
120
|
-
acc[key] = { type: 'text', default: prop.default ?? '' };
|
|
121
|
-
} else if (prop.type === 'number') {
|
|
122
|
-
acc[key] = { type: 'number', default: prop.default ?? 0 };
|
|
123
|
-
}
|
|
124
|
-
return acc;
|
|
125
|
-
}, {});
|
|
126
|
-
}
|
|
127
|
-
`;
|
|
128
|
-
}
|
|
129
|
-
|
|
130
83
|
return {
|
|
131
84
|
name: 'idealyst-docs',
|
|
132
85
|
|
|
@@ -134,18 +87,6 @@ export function getPropConfig(componentName) {
|
|
|
134
87
|
server = _server;
|
|
135
88
|
},
|
|
136
89
|
|
|
137
|
-
resolveId(id) {
|
|
138
|
-
if (id === VIRTUAL_MODULE_ID) {
|
|
139
|
-
return RESOLVED_VIRTUAL_MODULE_ID;
|
|
140
|
-
}
|
|
141
|
-
},
|
|
142
|
-
|
|
143
|
-
load(id) {
|
|
144
|
-
if (id === RESOLVED_VIRTUAL_MODULE_ID) {
|
|
145
|
-
return generateModuleCode();
|
|
146
|
-
}
|
|
147
|
-
},
|
|
148
|
-
|
|
149
90
|
// Transform @idealyst/tooling to inject the actual registry
|
|
150
91
|
transform(code, id) {
|
|
151
92
|
// Check if this is the tooling package's index file
|
|
@@ -153,7 +94,7 @@ export function getPropConfig(componentName) {
|
|
|
153
94
|
const isToolingSrc = id.includes('/packages/tooling/src/index.ts');
|
|
154
95
|
|
|
155
96
|
if (isToolingIndex || isToolingSrc) {
|
|
156
|
-
log(`Transforming tooling index: ${id}`);
|
|
97
|
+
console.log(`[idealyst-docs] Transforming tooling index: ${id}`);
|
|
157
98
|
|
|
158
99
|
if (!registry) {
|
|
159
100
|
registry = generateRegistry();
|
|
@@ -162,21 +103,26 @@ export function getPropConfig(componentName) {
|
|
|
162
103
|
// Replace the placeholder exports with actual values
|
|
163
104
|
let transformed = code;
|
|
164
105
|
|
|
165
|
-
// Replace: export const componentRegistry
|
|
106
|
+
// Replace: export const componentRegistry = {};
|
|
107
|
+
// Note: TypeScript types are stripped before transform, so we match JS not TS
|
|
166
108
|
transformed = transformed.replace(
|
|
167
|
-
/export const componentRegistry
|
|
109
|
+
/export const componentRegistry\s*=\s*\{\s*\};?/,
|
|
168
110
|
`export const componentRegistry = ${JSON.stringify(registry, null, 2)};`
|
|
169
111
|
);
|
|
170
112
|
|
|
171
|
-
|
|
113
|
+
log(`Code transformed: ${code !== transformed}`);
|
|
114
|
+
|
|
115
|
+
// Replace: export const componentNames = [];
|
|
116
|
+
// Note: TypeScript types are stripped before transform
|
|
172
117
|
transformed = transformed.replace(
|
|
173
|
-
/export const componentNames
|
|
118
|
+
/export const componentNames\s*=\s*\[\s*\];?/,
|
|
174
119
|
`export const componentNames = ${JSON.stringify(Object.keys(registry))};`
|
|
175
120
|
);
|
|
176
121
|
|
|
177
122
|
// Replace getComponentsByCategory with actual implementation that uses the real registry
|
|
123
|
+
// Match JS version (no type annotations)
|
|
178
124
|
transformed = transformed.replace(
|
|
179
|
-
/export function getComponentsByCategory\(category
|
|
125
|
+
/export function getComponentsByCategory\(category\)\s*\{[\s\S]*?^\}/m,
|
|
180
126
|
`export function getComponentsByCategory(category) {
|
|
181
127
|
return Object.entries(componentRegistry)
|
|
182
128
|
.filter(([_, def]) => def.category === category)
|
|
@@ -185,8 +131,9 @@ export function getPropConfig(componentName) {
|
|
|
185
131
|
);
|
|
186
132
|
|
|
187
133
|
// Replace getPropConfig with actual implementation
|
|
134
|
+
// Match JS version (no type annotations)
|
|
188
135
|
transformed = transformed.replace(
|
|
189
|
-
/export function getPropConfig\(componentName
|
|
136
|
+
/export function getPropConfig\(componentName\)\s*\{[\s\S]*?^\}/m,
|
|
190
137
|
`export function getPropConfig(componentName) {
|
|
191
138
|
const def = componentRegistry[componentName];
|
|
192
139
|
if (!def) return {};
|
|
@@ -230,21 +177,14 @@ export function getPropConfig(componentName) {
|
|
|
230
177
|
// Clear cached registry
|
|
231
178
|
registry = null;
|
|
232
179
|
|
|
233
|
-
// Invalidate the
|
|
234
|
-
const mod = server.moduleGraph.getModuleById(RESOLVED_VIRTUAL_MODULE_ID);
|
|
235
|
-
if (mod) {
|
|
236
|
-
server.moduleGraph.invalidateModule(mod);
|
|
237
|
-
}
|
|
238
|
-
|
|
239
|
-
// Also invalidate the tooling module if it's loaded
|
|
180
|
+
// Invalidate the tooling module to trigger re-transform
|
|
240
181
|
const toolingMods = Array.from(server.moduleGraph.idToModuleMap.values())
|
|
241
182
|
.filter(m => m.id && (m.id.includes('@idealyst/tooling') || m.id.includes('/packages/tooling/src/index')));
|
|
242
183
|
|
|
243
|
-
|
|
244
|
-
modsToInvalidate.forEach(m => server.moduleGraph.invalidateModule(m));
|
|
184
|
+
toolingMods.forEach(m => server.moduleGraph.invalidateModule(m));
|
|
245
185
|
|
|
246
|
-
if (
|
|
247
|
-
return
|
|
186
|
+
if (toolingMods.length > 0) {
|
|
187
|
+
return toolingMods;
|
|
248
188
|
}
|
|
249
189
|
}
|
|
250
190
|
},
|