@vertesia/build-tools 1.2.0 → 1.4.0-dev.20260614.160504Z
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/README.md +3 -3
- package/lib/bin/build.d.ts +35 -0
- package/lib/bin/build.d.ts.map +1 -0
- package/lib/bin/build.js +79 -0
- package/lib/bin/build.js.map +1 -0
- package/lib/bin/config.d.ts +24 -0
- package/lib/bin/config.d.ts.map +1 -0
- package/lib/bin/config.js +91 -0
- package/lib/bin/config.js.map +1 -0
- package/lib/core/compilers/widget.d.ts +27 -0
- package/lib/core/compilers/widget.d.ts.map +1 -0
- package/lib/core/compilers/widget.js +37 -0
- package/lib/core/compilers/widget.js.map +1 -0
- package/lib/{types → core}/parsers/frontmatter.d.ts +1 -1
- package/lib/core/parsers/frontmatter.d.ts.map +1 -0
- package/lib/{esm → core}/parsers/frontmatter.js +1 -1
- package/lib/core/parsers/frontmatter.js.map +1 -0
- package/lib/core/transformers/index.d.ts +10 -0
- package/lib/core/transformers/index.d.ts.map +1 -0
- package/lib/core/transformers/index.js +10 -0
- package/lib/core/transformers/index.js.map +1 -0
- package/lib/{types/presets → core/transformers}/prompt.d.ts +7 -21
- package/lib/core/transformers/prompt.d.ts.map +1 -0
- package/lib/{esm/presets → core/transformers}/prompt.js +17 -14
- package/lib/core/transformers/prompt.js.map +1 -0
- package/lib/core/transformers/raw.d.ts.map +1 -0
- package/lib/{esm/presets → core/transformers}/raw.js +2 -2
- package/lib/core/transformers/raw.js.map +1 -0
- package/lib/core/transformers/skill-collection.d.ts.map +1 -0
- package/lib/{esm/presets → core/transformers}/skill-collection.js +5 -12
- package/lib/core/transformers/skill-collection.js.map +1 -0
- package/lib/core/transformers/skill.d.ts +111 -0
- package/lib/core/transformers/skill.d.ts.map +1 -0
- package/lib/{esm/presets → core/transformers}/skill.js +70 -51
- package/lib/core/transformers/skill.js.map +1 -0
- package/lib/core/transformers/template-collection.d.ts.map +1 -0
- package/lib/{esm/presets → core/transformers}/template-collection.js +5 -12
- package/lib/core/transformers/template-collection.js.map +1 -0
- package/lib/{types/presets → core/transformers}/template.d.ts +7 -22
- package/lib/core/transformers/template.d.ts.map +1 -0
- package/lib/{esm/presets → core/transformers}/template.js +16 -11
- package/lib/core/transformers/template.js.map +1 -0
- package/lib/{types → core}/types.d.ts +5 -61
- package/lib/core/types.d.ts.map +1 -0
- package/lib/core/types.js +6 -0
- package/lib/{cjs → core}/types.js.map +1 -1
- package/lib/core/utils/asset-copy.d.ts.map +1 -0
- package/lib/core/utils/asset-copy.js.map +1 -0
- package/lib/core/utils/asset-discovery.d.ts.map +1 -0
- package/lib/{esm → core}/utils/asset-discovery.js +4 -4
- package/lib/core/utils/asset-discovery.js.map +1 -0
- package/lib/core/utils/template-asset-discovery.d.ts.map +1 -0
- package/lib/{esm → core}/utils/template-asset-discovery.js +3 -7
- package/lib/core/utils/template-asset-discovery.js.map +1 -0
- package/lib/import-transform/builtins.d.ts +21 -0
- package/lib/import-transform/builtins.d.ts.map +1 -0
- package/lib/import-transform/builtins.js +50 -0
- package/lib/import-transform/builtins.js.map +1 -0
- package/lib/import-transform/chunk-emitter.d.ts +24 -0
- package/lib/import-transform/chunk-emitter.d.ts.map +1 -0
- package/lib/import-transform/chunk-emitter.js +35 -0
- package/lib/import-transform/chunk-emitter.js.map +1 -0
- package/lib/import-transform/detector.d.ts +24 -0
- package/lib/import-transform/detector.d.ts.map +1 -0
- package/lib/import-transform/detector.js +34 -0
- package/lib/import-transform/detector.js.map +1 -0
- package/lib/import-transform/index.d.ts +47 -0
- package/lib/import-transform/index.d.ts.map +1 -0
- package/lib/import-transform/index.js +115 -0
- package/lib/import-transform/index.js.map +1 -0
- package/lib/import-transform/patterns.d.ts +25 -0
- package/lib/import-transform/patterns.d.ts.map +1 -0
- package/lib/import-transform/patterns.js +27 -0
- package/lib/import-transform/patterns.js.map +1 -0
- package/lib/import-transform/resolver.d.ts +23 -0
- package/lib/import-transform/resolver.d.ts.map +1 -0
- package/lib/import-transform/resolver.js +30 -0
- package/lib/import-transform/resolver.js.map +1 -0
- package/lib/import-transform/rewriter.d.ts +21 -0
- package/lib/import-transform/rewriter.d.ts.map +1 -0
- package/lib/import-transform/rewriter.js +30 -0
- package/lib/import-transform/rewriter.js.map +1 -0
- package/lib/import-transform/scanner.d.ts +17 -0
- package/lib/import-transform/scanner.d.ts.map +1 -0
- package/lib/import-transform/scanner.js +46 -0
- package/lib/import-transform/scanner.js.map +1 -0
- package/lib/index.d.ts +39 -0
- package/lib/index.d.ts.map +1 -0
- package/lib/index.js +43 -0
- package/lib/index.js.map +1 -0
- package/lib/vite/api-server.d.ts +54 -0
- package/lib/vite/api-server.d.ts.map +1 -0
- package/lib/vite/api-server.js +94 -0
- package/lib/vite/api-server.js.map +1 -0
- package/lib/vite/dev-server.d.ts +42 -0
- package/lib/vite/dev-server.d.ts.map +1 -0
- package/lib/vite/dev-server.js +111 -0
- package/lib/vite/dev-server.js.map +1 -0
- package/lib/vite/index.d.ts +15 -0
- package/lib/vite/index.d.ts.map +1 -0
- package/lib/vite/index.js +15 -0
- package/lib/vite/index.js.map +1 -0
- package/package.json +38 -28
- package/src/bin/build.ts +83 -0
- package/src/bin/config.ts +113 -0
- package/src/core/compilers/widget.ts +69 -0
- package/src/{parsers → core/parsers}/frontmatter.ts +2 -2
- package/src/core/transformers/index.ts +27 -0
- package/src/{presets → core/transformers}/prompt.ts +35 -32
- package/src/{presets → core/transformers}/raw.ts +2 -2
- package/src/{presets → core/transformers}/skill-collection.ts +5 -12
- package/src/{presets → core/transformers}/skill.ts +119 -99
- package/src/{presets → core/transformers}/template-collection.ts +76 -83
- package/src/{presets → core/transformers}/template.ts +121 -116
- package/src/core/types.ts +71 -0
- package/src/{utils → core/utils}/asset-copy.ts +3 -2
- package/src/{utils → core/utils}/asset-discovery.ts +5 -5
- package/src/{utils → core/utils}/template-asset-discovery.ts +70 -77
- package/src/import-transform/builtins.ts +56 -0
- package/src/import-transform/chunk-emitter.ts +60 -0
- package/src/import-transform/detector.ts +56 -0
- package/src/import-transform/index.ts +171 -0
- package/src/import-transform/patterns.ts +34 -0
- package/src/import-transform/resolver.ts +57 -0
- package/src/import-transform/rewriter.ts +48 -0
- package/src/import-transform/scanner.ts +55 -0
- package/src/index.ts +67 -42
- package/src/vite/api-server.ts +142 -0
- package/src/vite/dev-server.ts +128 -0
- package/src/vite/index.ts +15 -0
- package/lib/build-tools.js +0 -2031
- package/lib/build-tools.js.map +0 -1
- package/lib/cjs/index.js +0 -43
- package/lib/cjs/index.js.map +0 -1
- package/lib/cjs/package.json +0 -3
- package/lib/cjs/parsers/frontmatter.js +0 -25
- package/lib/cjs/parsers/frontmatter.js.map +0 -1
- package/lib/cjs/plugin.js +0 -150
- package/lib/cjs/plugin.js.map +0 -1
- package/lib/cjs/presets/index.js +0 -25
- package/lib/cjs/presets/index.js.map +0 -1
- package/lib/cjs/presets/prompt.js +0 -185
- package/lib/cjs/presets/prompt.js.map +0 -1
- package/lib/cjs/presets/raw.js +0 -25
- package/lib/cjs/presets/raw.js.map +0 -1
- package/lib/cjs/presets/skill-collection.js +0 -83
- package/lib/cjs/presets/skill-collection.js.map +0 -1
- package/lib/cjs/presets/skill.js +0 -272
- package/lib/cjs/presets/skill.js.map +0 -1
- package/lib/cjs/presets/template-collection.js +0 -80
- package/lib/cjs/presets/template-collection.js.map +0 -1
- package/lib/cjs/presets/template.js +0 -105
- package/lib/cjs/presets/template.js.map +0 -1
- package/lib/cjs/types.js +0 -6
- package/lib/cjs/utils/asset-copy.js +0 -61
- package/lib/cjs/utils/asset-copy.js.map +0 -1
- package/lib/cjs/utils/asset-discovery.js +0 -100
- package/lib/cjs/utils/asset-discovery.js.map +0 -1
- package/lib/cjs/utils/template-asset-discovery.js +0 -63
- package/lib/cjs/utils/template-asset-discovery.js.map +0 -1
- package/lib/cjs/utils/widget-compiler.js +0 -115
- package/lib/cjs/utils/widget-compiler.js.map +0 -1
- package/lib/cjs/vite.js +0 -45
- package/lib/cjs/vite.js.map +0 -1
- package/lib/esm/index.js +0 -26
- package/lib/esm/index.js.map +0 -1
- package/lib/esm/parsers/frontmatter.js.map +0 -1
- package/lib/esm/plugin.js +0 -144
- package/lib/esm/plugin.js.map +0 -1
- package/lib/esm/presets/index.js +0 -10
- package/lib/esm/presets/index.js.map +0 -1
- package/lib/esm/presets/prompt.js.map +0 -1
- package/lib/esm/presets/raw.js.map +0 -1
- package/lib/esm/presets/skill-collection.js.map +0 -1
- package/lib/esm/presets/skill.js.map +0 -1
- package/lib/esm/presets/template-collection.js.map +0 -1
- package/lib/esm/presets/template.js.map +0 -1
- package/lib/esm/types.js +0 -5
- package/lib/esm/types.js.map +0 -1
- package/lib/esm/utils/asset-copy.js.map +0 -1
- package/lib/esm/utils/asset-discovery.js.map +0 -1
- package/lib/esm/utils/template-asset-discovery.js.map +0 -1
- package/lib/esm/utils/widget-compiler.js +0 -76
- package/lib/esm/utils/widget-compiler.js.map +0 -1
- package/lib/esm/vite.js +0 -42
- package/lib/esm/vite.js.map +0 -1
- package/lib/types/index.d.ts +0 -24
- package/lib/types/index.d.ts.map +0 -1
- package/lib/types/parsers/frontmatter.d.ts.map +0 -1
- package/lib/types/plugin.d.ts +0 -10
- package/lib/types/plugin.d.ts.map +0 -1
- package/lib/types/presets/index.d.ts +0 -10
- package/lib/types/presets/index.d.ts.map +0 -1
- package/lib/types/presets/prompt.d.ts.map +0 -1
- package/lib/types/presets/raw.d.ts.map +0 -1
- package/lib/types/presets/skill-collection.d.ts.map +0 -1
- package/lib/types/presets/skill.d.ts +0 -361
- package/lib/types/presets/skill.d.ts.map +0 -1
- package/lib/types/presets/template-collection.d.ts.map +0 -1
- package/lib/types/presets/template.d.ts.map +0 -1
- package/lib/types/types.d.ts.map +0 -1
- package/lib/types/utils/asset-copy.d.ts.map +0 -1
- package/lib/types/utils/asset-discovery.d.ts.map +0 -1
- package/lib/types/utils/template-asset-discovery.d.ts.map +0 -1
- package/lib/types/utils/widget-compiler.d.ts +0 -15
- package/lib/types/utils/widget-compiler.d.ts.map +0 -1
- package/lib/types/vite.d.ts +0 -32
- package/lib/types/vite.d.ts.map +0 -1
- package/src/plugin.ts +0 -166
- package/src/presets/index.ts +0 -10
- package/src/types.ts +0 -140
- package/src/utils/widget-compiler.ts +0 -98
- package/src/vite.ts +0 -45
- /package/lib/{types/presets → core/transformers}/raw.d.ts +0 -0
- /package/lib/{types/presets → core/transformers}/skill-collection.d.ts +0 -0
- /package/lib/{types/presets → core/transformers}/template-collection.d.ts +0 -0
- /package/lib/{types → core}/utils/asset-copy.d.ts +0 -0
- /package/lib/{esm → core}/utils/asset-copy.js +0 -0
- /package/lib/{types → core}/utils/asset-discovery.d.ts +0 -0
- /package/lib/{types → core}/utils/template-asset-discovery.d.ts +0 -0
package/src/plugin.ts
DELETED
|
@@ -1,166 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Core Rollup plugin implementation for transforming imports
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
import type { Plugin } from 'rollup';
|
|
6
|
-
import { readFileSync } from 'node:fs';
|
|
7
|
-
import path from 'node:path';
|
|
8
|
-
import type { PluginConfig, TransformerRule, AssetFile } from './types.js';
|
|
9
|
-
import { copyAssets } from './utils/asset-copy.js';
|
|
10
|
-
import { compileWidgets } from './utils/widget-compiler.js';
|
|
11
|
-
import type { WidgetMetadata } from './utils/asset-discovery.js';
|
|
12
|
-
|
|
13
|
-
/**
|
|
14
|
-
* Creates a Rollup plugin that transforms imports based on configured rules
|
|
15
|
-
*/
|
|
16
|
-
export function vertesiaImportPlugin(config: PluginConfig): Plugin {
|
|
17
|
-
const { transformers, assetsDir = './dist', widgetConfig } = config;
|
|
18
|
-
|
|
19
|
-
if (!transformers || transformers.length === 0) {
|
|
20
|
-
throw new Error('vertesiaImportPlugin: At least one transformer must be configured');
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
// Track assets to copy and widgets to compile
|
|
24
|
-
const assetsToProcess: AssetFile[] = [];
|
|
25
|
-
const widgetsToCompile: WidgetMetadata[] = [];
|
|
26
|
-
const shouldCopyAssets = assetsDir !== false;
|
|
27
|
-
const shouldCompileWidgets = widgetConfig !== undefined && assetsDir !== false;
|
|
28
|
-
|
|
29
|
-
return {
|
|
30
|
-
name: 'vertesia-import-plugin',
|
|
31
|
-
|
|
32
|
-
/**
|
|
33
|
-
* Resolve import IDs to handle pattern-based imports
|
|
34
|
-
*/
|
|
35
|
-
resolveId(source: string, importer: string | undefined) {
|
|
36
|
-
// Check if any transformer pattern matches
|
|
37
|
-
for (const transformer of transformers) {
|
|
38
|
-
if (transformer.pattern.test(source)) {
|
|
39
|
-
// Handle relative imports
|
|
40
|
-
if (source.startsWith('.') && importer) {
|
|
41
|
-
const cleanSource = source.replace(transformer.pattern, '');
|
|
42
|
-
// Strip query parameters from importer to get the file path
|
|
43
|
-
const cleanImporter = importer.indexOf('?') >= 0
|
|
44
|
-
? importer.substring(0, importer.indexOf('?'))
|
|
45
|
-
: importer;
|
|
46
|
-
// Always use dirname to get the directory containing the importer
|
|
47
|
-
const baseDir = path.dirname(cleanImporter);
|
|
48
|
-
const resolved = path.resolve(baseDir, cleanSource);
|
|
49
|
-
// Return with the pattern suffix to identify it in load
|
|
50
|
-
const suffix = source.match(transformer.pattern)?.[0] || '';
|
|
51
|
-
return resolved + suffix;
|
|
52
|
-
}
|
|
53
|
-
return source;
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
return null; // Let other plugins handle it
|
|
57
|
-
},
|
|
58
|
-
|
|
59
|
-
/**
|
|
60
|
-
* Load and transform the file content
|
|
61
|
-
*/
|
|
62
|
-
async load(id: string) {
|
|
63
|
-
// Find matching transformer
|
|
64
|
-
let matchedTransformer: TransformerRule | undefined;
|
|
65
|
-
let cleanId = id;
|
|
66
|
-
|
|
67
|
-
for (const transformer of transformers) {
|
|
68
|
-
if (transformer.pattern.test(id)) {
|
|
69
|
-
matchedTransformer = transformer;
|
|
70
|
-
// Remove query parameters to get actual file path
|
|
71
|
-
// For example: '/path/file.md?skill' -> '/path/file.md'
|
|
72
|
-
// '/path/file.html?raw' -> '/path/file.html'
|
|
73
|
-
const queryIndex = id.indexOf('?');
|
|
74
|
-
cleanId = queryIndex >= 0 ? id.substring(0, queryIndex) : id;
|
|
75
|
-
break;
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
if (!matchedTransformer) {
|
|
80
|
-
return null; // Not for us
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
try {
|
|
84
|
-
// Read file content (skip for virtual transforms)
|
|
85
|
-
const content = matchedTransformer.virtual
|
|
86
|
-
? ''
|
|
87
|
-
: readFileSync(cleanId, 'utf-8');
|
|
88
|
-
|
|
89
|
-
// Transform the content
|
|
90
|
-
const result = await matchedTransformer.transform(content, cleanId);
|
|
91
|
-
|
|
92
|
-
// Collect assets if any
|
|
93
|
-
if (result.assets && shouldCopyAssets) {
|
|
94
|
-
assetsToProcess.push(...result.assets);
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
// Collect widgets if any
|
|
98
|
-
if (result.widgets && shouldCompileWidgets) {
|
|
99
|
-
widgetsToCompile.push(...result.widgets);
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
// Validate if schema provided
|
|
103
|
-
if (matchedTransformer.schema) {
|
|
104
|
-
const validation = matchedTransformer.schema.safeParse(result.data);
|
|
105
|
-
if (!validation.success) {
|
|
106
|
-
const errors = validation.error.errors
|
|
107
|
-
.map((err) => ` - ${err.path.join('.')}: ${err.message}`)
|
|
108
|
-
.join('\n');
|
|
109
|
-
throw new Error(
|
|
110
|
-
`Validation failed for ${id}:\n${errors}`
|
|
111
|
-
);
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
// Generate code
|
|
116
|
-
const imports = result.imports ? result.imports.join('\n') + '\n\n' : '';
|
|
117
|
-
if (result.code) {
|
|
118
|
-
// Custom code provided - prepend imports
|
|
119
|
-
return imports + result.code;
|
|
120
|
-
} else {
|
|
121
|
-
// Default: export data (escape if string, otherwise stringify as JSON)
|
|
122
|
-
const dataJson = JSON.stringify(result.data, null, 2);
|
|
123
|
-
return `${imports}export default ${dataJson};`;
|
|
124
|
-
}
|
|
125
|
-
} catch (error) {
|
|
126
|
-
const message = error instanceof Error ? error.message : String(error);
|
|
127
|
-
this.error(`Failed to transform ${id}: ${message}`);
|
|
128
|
-
}
|
|
129
|
-
},
|
|
130
|
-
|
|
131
|
-
/**
|
|
132
|
-
* Copy assets and compile widgets after all modules are loaded
|
|
133
|
-
*/
|
|
134
|
-
async buildEnd() {
|
|
135
|
-
// Copy script assets
|
|
136
|
-
if (shouldCopyAssets && assetsToProcess.length > 0) {
|
|
137
|
-
try {
|
|
138
|
-
const copied = copyAssets(assetsToProcess, assetsDir as string);
|
|
139
|
-
console.log(`Copied ${copied} asset file(s) to ${assetsDir}`);
|
|
140
|
-
} catch (error) {
|
|
141
|
-
const message = error instanceof Error ? error.message : String(error);
|
|
142
|
-
this.warn(`Failed to copy assets: ${message}`);
|
|
143
|
-
}
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
// Compile widgets
|
|
147
|
-
if (shouldCompileWidgets && widgetsToCompile.length > 0) {
|
|
148
|
-
try {
|
|
149
|
-
const widgetsDir = config.widgetsDir || 'widgets';
|
|
150
|
-
const outputDir = path.join(assetsDir as string, widgetsDir);
|
|
151
|
-
|
|
152
|
-
console.log(`Compiling ${widgetsToCompile.length} widget(s)...`);
|
|
153
|
-
const compiled = await compileWidgets(
|
|
154
|
-
widgetsToCompile,
|
|
155
|
-
outputDir,
|
|
156
|
-
widgetConfig
|
|
157
|
-
);
|
|
158
|
-
console.log(`Compiled ${compiled} widget(s) to ${outputDir}`);
|
|
159
|
-
} catch (error) {
|
|
160
|
-
const message = error instanceof Error ? error.message : String(error);
|
|
161
|
-
this.error(`Failed to compile widgets: ${message}`);
|
|
162
|
-
}
|
|
163
|
-
}
|
|
164
|
-
}
|
|
165
|
-
};
|
|
166
|
-
}
|
package/src/presets/index.ts
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Preset transformers for common use cases
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
export { skillTransformer, SkillDefinitionSchema, SkillPropertiesSchema, type SkillDefinition, type SkillContentType } from './skill.js';
|
|
6
|
-
export { skillCollectionTransformer } from './skill-collection.js';
|
|
7
|
-
export { templateTransformer, RenderingTemplateDefinitionSchema, type RenderingTemplateDefinition } from './template.js';
|
|
8
|
-
export { templateCollectionTransformer } from './template-collection.js';
|
|
9
|
-
export { rawTransformer } from './raw.js';
|
|
10
|
-
export { promptTransformer, PromptDefinitionSchema, type PromptDefinition, type PromptContentType, PromptRole, TemplateType } from './prompt.js';
|
package/src/types.ts
DELETED
|
@@ -1,140 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Type definitions for the Vertesia Rollup Import Plugin
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
import type { Plugin } from 'rollup';
|
|
6
|
-
import type { z } from 'zod';
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* Asset file to be copied during build
|
|
10
|
-
*/
|
|
11
|
-
export interface AssetFile {
|
|
12
|
-
/** Source file path (absolute) */
|
|
13
|
-
sourcePath: string;
|
|
14
|
-
|
|
15
|
-
/** Relative destination path within assets directory */
|
|
16
|
-
destPath: string;
|
|
17
|
-
|
|
18
|
-
/** Asset type for categorization */
|
|
19
|
-
type: 'script' | 'template';
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
/**
|
|
23
|
-
* Result of a transform function
|
|
24
|
-
*/
|
|
25
|
-
export interface TransformResult {
|
|
26
|
-
/** The data to export (can be text or JSON object) */
|
|
27
|
-
data: unknown;
|
|
28
|
-
|
|
29
|
-
/** Optional: additional imports to inject at the top of the generated module */
|
|
30
|
-
imports?: string[];
|
|
31
|
-
|
|
32
|
-
/** Optional: custom code to generate instead of default JSON export */
|
|
33
|
-
code?: string;
|
|
34
|
-
|
|
35
|
-
/** Optional: additional asset files to copy */
|
|
36
|
-
assets?: AssetFile[];
|
|
37
|
-
|
|
38
|
-
/** Optional: widget metadata for compilation */
|
|
39
|
-
widgets?: Array<{ name: string; path: string }>;
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
/**
|
|
43
|
-
* Transform function that converts file content into exportable data
|
|
44
|
-
*/
|
|
45
|
-
export type TransformFunction = (
|
|
46
|
-
content: string,
|
|
47
|
-
filePath: string
|
|
48
|
-
) => TransformResult | Promise<TransformResult>;
|
|
49
|
-
|
|
50
|
-
/**
|
|
51
|
-
* Configuration for a single import transformer rule
|
|
52
|
-
*/
|
|
53
|
-
export interface TransformerRule {
|
|
54
|
-
/** Pattern to match import paths (e.g., /\.md\?skill$/ or /\?raw$/) */
|
|
55
|
-
pattern: RegExp;
|
|
56
|
-
|
|
57
|
-
/** Transform function to convert file content */
|
|
58
|
-
transform: TransformFunction;
|
|
59
|
-
|
|
60
|
-
/** Optional: Zod schema for validation */
|
|
61
|
-
schema?: z.ZodType<any>;
|
|
62
|
-
|
|
63
|
-
/** Optional: If true, the transformer generates virtual modules (no file to read) */
|
|
64
|
-
virtual?: boolean;
|
|
65
|
-
|
|
66
|
-
/** Optional: additional options for this transformer */
|
|
67
|
-
options?: Record<string, unknown>;
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
/**
|
|
71
|
-
* Widget compilation configuration
|
|
72
|
-
*/
|
|
73
|
-
export interface WidgetConfig {
|
|
74
|
-
/**
|
|
75
|
-
* External dependencies that should not be bundled
|
|
76
|
-
* Default: ['react', 'react-dom', 'react/jsx-runtime']
|
|
77
|
-
*/
|
|
78
|
-
external?: string[];
|
|
79
|
-
|
|
80
|
-
/**
|
|
81
|
-
* Path to tsconfig.json for widget compilation
|
|
82
|
-
* Default: './tsconfig.json'
|
|
83
|
-
*/
|
|
84
|
-
tsconfig?: string;
|
|
85
|
-
|
|
86
|
-
/**
|
|
87
|
-
* Additional options to pass to @rollup/plugin-typescript
|
|
88
|
-
*/
|
|
89
|
-
typescript?: Record<string, unknown>;
|
|
90
|
-
|
|
91
|
-
/**
|
|
92
|
-
* Minify widget output
|
|
93
|
-
* Default: false
|
|
94
|
-
*/
|
|
95
|
-
minify?: boolean;
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
/**
|
|
99
|
-
* Plugin configuration
|
|
100
|
-
*/
|
|
101
|
-
export interface PluginConfig {
|
|
102
|
-
/** Array of transformer rules to apply */
|
|
103
|
-
transformers: TransformerRule[];
|
|
104
|
-
|
|
105
|
-
/**
|
|
106
|
-
* Root directory for asset output (scripts, widgets, etc.)
|
|
107
|
-
* - If specified: assets will be copied to this directory
|
|
108
|
-
* - If false: asset copying is disabled
|
|
109
|
-
* - Default: './dist'
|
|
110
|
-
*/
|
|
111
|
-
assetsDir?: string | false;
|
|
112
|
-
|
|
113
|
-
/**
|
|
114
|
-
* Directory for script files relative to assetsDir
|
|
115
|
-
* Default: 'scripts'
|
|
116
|
-
*/
|
|
117
|
-
scriptsDir?: string;
|
|
118
|
-
|
|
119
|
-
/**
|
|
120
|
-
* Directory for widget files relative to assetsDir
|
|
121
|
-
* Default: 'widgets'
|
|
122
|
-
*/
|
|
123
|
-
widgetsDir?: string;
|
|
124
|
-
|
|
125
|
-
/**
|
|
126
|
-
* Widget compilation configuration
|
|
127
|
-
* If provided, discovered widgets will be automatically compiled
|
|
128
|
-
*/
|
|
129
|
-
widgetConfig?: WidgetConfig;
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
/**
|
|
133
|
-
* Type for transformer presets
|
|
134
|
-
*/
|
|
135
|
-
export type TransformerPreset = TransformerRule;
|
|
136
|
-
|
|
137
|
-
/**
|
|
138
|
-
* Plugin factory return type
|
|
139
|
-
*/
|
|
140
|
-
export type VertesiaImportPlugin = (config: PluginConfig) => Plugin;
|
|
@@ -1,98 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Widget compilation utility using Rollup
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
import { rollup, type RollupOptions, type Plugin } from 'rollup';
|
|
6
|
-
import path from 'node:path';
|
|
7
|
-
import type { WidgetConfig } from '../types.js';
|
|
8
|
-
import type { WidgetMetadata } from './asset-discovery.js';
|
|
9
|
-
|
|
10
|
-
/**
|
|
11
|
-
* Default external dependencies for widgets
|
|
12
|
-
*/
|
|
13
|
-
const DEFAULT_EXTERNALS = [
|
|
14
|
-
'react',
|
|
15
|
-
'react-dom',
|
|
16
|
-
'react/jsx-runtime',
|
|
17
|
-
'react/jsx-dev-runtime',
|
|
18
|
-
'react-dom/client'
|
|
19
|
-
];
|
|
20
|
-
|
|
21
|
-
/**
|
|
22
|
-
* Compile widgets using Rollup
|
|
23
|
-
*
|
|
24
|
-
* @param widgets - Array of widget metadata to compile
|
|
25
|
-
* @param outputDir - Directory to write compiled widgets
|
|
26
|
-
* @param config - Widget compilation configuration
|
|
27
|
-
* @returns Number of widgets compiled
|
|
28
|
-
*/
|
|
29
|
-
export async function compileWidgets(
|
|
30
|
-
widgets: WidgetMetadata[],
|
|
31
|
-
outputDir: string,
|
|
32
|
-
config: WidgetConfig = {}
|
|
33
|
-
): Promise<number> {
|
|
34
|
-
if (widgets.length === 0) {
|
|
35
|
-
return 0;
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
const {
|
|
39
|
-
external = DEFAULT_EXTERNALS,
|
|
40
|
-
tsconfig = './tsconfig.json',
|
|
41
|
-
typescript: typescriptOptions = {},
|
|
42
|
-
minify = false
|
|
43
|
-
} = config;
|
|
44
|
-
|
|
45
|
-
// Build each widget separately to get individual bundles
|
|
46
|
-
const buildPromises = widgets.map(async (widget) => {
|
|
47
|
-
// Dynamically import plugins - use any to bypass TypeScript module resolution issues
|
|
48
|
-
const typescript = (await import('@rollup/plugin-typescript' as any)).default as any;
|
|
49
|
-
const nodeResolve = (await import('@rollup/plugin-node-resolve' as any)).default as any;
|
|
50
|
-
const commonjs = (await import('@rollup/plugin-commonjs' as any)).default as any;
|
|
51
|
-
|
|
52
|
-
const plugins: Plugin[] = [
|
|
53
|
-
typescript({
|
|
54
|
-
tsconfig,
|
|
55
|
-
declaration: false,
|
|
56
|
-
sourceMap: true,
|
|
57
|
-
...typescriptOptions
|
|
58
|
-
}),
|
|
59
|
-
nodeResolve({
|
|
60
|
-
browser: true,
|
|
61
|
-
preferBuiltins: false,
|
|
62
|
-
extensions: ['.tsx', '.ts', '.jsx', '.js']
|
|
63
|
-
}),
|
|
64
|
-
commonjs()
|
|
65
|
-
];
|
|
66
|
-
|
|
67
|
-
// Add minification if requested
|
|
68
|
-
if (minify) {
|
|
69
|
-
const { terser } = await import('rollup-plugin-terser' as any);
|
|
70
|
-
plugins.push(
|
|
71
|
-
terser({
|
|
72
|
-
compress: {
|
|
73
|
-
drop_console: false
|
|
74
|
-
}
|
|
75
|
-
})
|
|
76
|
-
);
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
const rollupConfig: RollupOptions = {
|
|
80
|
-
input: widget.path,
|
|
81
|
-
output: {
|
|
82
|
-
file: path.join(outputDir, `${widget.name}.js`),
|
|
83
|
-
format: 'es',
|
|
84
|
-
sourcemap: true,
|
|
85
|
-
inlineDynamicImports: true
|
|
86
|
-
},
|
|
87
|
-
external,
|
|
88
|
-
plugins
|
|
89
|
-
};
|
|
90
|
-
|
|
91
|
-
const bundle = await rollup(rollupConfig);
|
|
92
|
-
await bundle.write(rollupConfig.output as any);
|
|
93
|
-
await bundle.close();
|
|
94
|
-
});
|
|
95
|
-
|
|
96
|
-
await Promise.all(buildPromises);
|
|
97
|
-
return widgets.length;
|
|
98
|
-
}
|
package/src/vite.ts
DELETED
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Vite-specific helpers for tool server development.
|
|
3
|
-
*
|
|
4
|
-
* Provides a pre-configured Vite plugin that handles SKILL.md, prompt,
|
|
5
|
-
* and raw file imports — the same transforms used by rollup at build time.
|
|
6
|
-
*
|
|
7
|
-
* @example
|
|
8
|
-
* ```typescript
|
|
9
|
-
* // vite.server.config.ts
|
|
10
|
-
* import { defineConfig } from 'vite';
|
|
11
|
-
* import devServer from '@hono/vite-dev-server';
|
|
12
|
-
* import { vertesiaDevServerPlugin } from '@vertesia/build-tools/vite';
|
|
13
|
-
*
|
|
14
|
-
* export default defineConfig({
|
|
15
|
-
* plugins: [
|
|
16
|
-
* vertesiaDevServerPlugin(),
|
|
17
|
-
* devServer({ entry: 'tools/server.ts' }),
|
|
18
|
-
* ],
|
|
19
|
-
* });
|
|
20
|
-
* ```
|
|
21
|
-
*/
|
|
22
|
-
|
|
23
|
-
import type { Plugin } from 'rollup';
|
|
24
|
-
import { vertesiaImportPlugin } from './plugin.js';
|
|
25
|
-
import { skillTransformer, rawTransformer, promptTransformer } from './presets/index.js';
|
|
26
|
-
import type { PluginConfig } from './types.js';
|
|
27
|
-
|
|
28
|
-
/**
|
|
29
|
-
* Creates a pre-configured Vite plugin for tool server dev mode.
|
|
30
|
-
* Includes skill, prompt, and raw file transformers with asset copying disabled
|
|
31
|
-
* (assets are only needed at build time, not during dev).
|
|
32
|
-
*
|
|
33
|
-
* @param overrides - Optional overrides for the plugin config
|
|
34
|
-
*/
|
|
35
|
-
export function vertesiaDevServerPlugin(overrides?: Partial<PluginConfig>): Plugin {
|
|
36
|
-
return vertesiaImportPlugin({
|
|
37
|
-
transformers: [
|
|
38
|
-
skillTransformer,
|
|
39
|
-
promptTransformer,
|
|
40
|
-
rawTransformer,
|
|
41
|
-
],
|
|
42
|
-
assetsDir: false,
|
|
43
|
-
...overrides,
|
|
44
|
-
});
|
|
45
|
-
}
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|