@vertesia/build-tools 0.80.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/LICENSE +13 -0
- package/README.md +334 -0
- package/lib/build-tools.js +616 -0
- package/lib/build-tools.js.map +1 -0
- package/lib/cjs/index.js +34 -0
- package/lib/cjs/index.js.map +1 -0
- package/lib/cjs/package.json +3 -0
- package/lib/cjs/parsers/frontmatter.js +25 -0
- package/lib/cjs/parsers/frontmatter.js.map +1 -0
- package/lib/cjs/plugin.js +142 -0
- package/lib/cjs/plugin.js.map +1 -0
- package/lib/cjs/presets/index.js +12 -0
- package/lib/cjs/presets/index.js.map +1 -0
- package/lib/cjs/presets/raw.js +25 -0
- package/lib/cjs/presets/raw.js.map +1 -0
- package/lib/cjs/presets/skill.js +224 -0
- package/lib/cjs/presets/skill.js.map +1 -0
- package/lib/cjs/types.js +6 -0
- package/lib/cjs/types.js.map +1 -0
- package/lib/cjs/utils/asset-copy.js +61 -0
- package/lib/cjs/utils/asset-copy.js.map +1 -0
- package/lib/cjs/utils/asset-discovery.js +100 -0
- package/lib/cjs/utils/asset-discovery.js.map +1 -0
- package/lib/cjs/utils/widget-compiler.js +115 -0
- package/lib/cjs/utils/widget-compiler.js.map +1 -0
- package/lib/esm/index.js +26 -0
- package/lib/esm/index.js.map +1 -0
- package/lib/esm/parsers/frontmatter.js +19 -0
- package/lib/esm/parsers/frontmatter.js.map +1 -0
- package/lib/esm/plugin.js +136 -0
- package/lib/esm/plugin.js.map +1 -0
- package/lib/esm/presets/index.js +6 -0
- package/lib/esm/presets/index.js.map +1 -0
- package/lib/esm/presets/raw.js +22 -0
- package/lib/esm/presets/raw.js.map +1 -0
- package/lib/esm/presets/skill.js +221 -0
- package/lib/esm/presets/skill.js.map +1 -0
- package/lib/esm/types.js +5 -0
- package/lib/esm/types.js.map +1 -0
- package/lib/esm/utils/asset-copy.js +54 -0
- package/lib/esm/utils/asset-copy.js.map +1 -0
- package/lib/esm/utils/asset-discovery.js +94 -0
- package/lib/esm/utils/asset-discovery.js.map +1 -0
- package/lib/esm/utils/widget-compiler.js +76 -0
- package/lib/esm/utils/widget-compiler.js.map +1 -0
- package/lib/types/index.d.ts +24 -0
- package/lib/types/index.d.ts.map +1 -0
- package/lib/types/parsers/frontmatter.d.ts +19 -0
- package/lib/types/parsers/frontmatter.d.ts.map +1 -0
- package/lib/types/plugin.d.ts +10 -0
- package/lib/types/plugin.d.ts.map +1 -0
- package/lib/types/presets/index.d.ts +6 -0
- package/lib/types/presets/index.d.ts.map +1 -0
- package/lib/types/presets/raw.d.ts +16 -0
- package/lib/types/presets/raw.d.ts.map +1 -0
- package/lib/types/presets/skill.d.ts +139 -0
- package/lib/types/presets/skill.d.ts.map +1 -0
- package/lib/types/types.d.ts +113 -0
- package/lib/types/types.d.ts.map +1 -0
- package/lib/types/utils/asset-copy.d.ts +20 -0
- package/lib/types/utils/asset-copy.d.ts.map +1 -0
- package/lib/types/utils/asset-discovery.d.ts +38 -0
- package/lib/types/utils/asset-discovery.d.ts.map +1 -0
- package/lib/types/utils/widget-compiler.d.ts +15 -0
- package/lib/types/utils/widget-compiler.d.ts.map +1 -0
- package/package.json +67 -0
- package/src/index.ts +45 -0
- package/src/parsers/frontmatter.ts +32 -0
- package/src/plugin.ts +158 -0
- package/src/presets/index.ts +6 -0
- package/src/presets/raw.ts +24 -0
- package/src/presets/skill.ts +271 -0
- package/src/types.ts +137 -0
- package/src/utils/asset-copy.ts +63 -0
- package/src/utils/asset-discovery.ts +138 -0
- package/src/utils/widget-compiler.ts +98 -0
|
@@ -0,0 +1,98 @@
|
|
|
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
|
+
}
|