@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.
Files changed (76) hide show
  1. package/LICENSE +13 -0
  2. package/README.md +334 -0
  3. package/lib/build-tools.js +616 -0
  4. package/lib/build-tools.js.map +1 -0
  5. package/lib/cjs/index.js +34 -0
  6. package/lib/cjs/index.js.map +1 -0
  7. package/lib/cjs/package.json +3 -0
  8. package/lib/cjs/parsers/frontmatter.js +25 -0
  9. package/lib/cjs/parsers/frontmatter.js.map +1 -0
  10. package/lib/cjs/plugin.js +142 -0
  11. package/lib/cjs/plugin.js.map +1 -0
  12. package/lib/cjs/presets/index.js +12 -0
  13. package/lib/cjs/presets/index.js.map +1 -0
  14. package/lib/cjs/presets/raw.js +25 -0
  15. package/lib/cjs/presets/raw.js.map +1 -0
  16. package/lib/cjs/presets/skill.js +224 -0
  17. package/lib/cjs/presets/skill.js.map +1 -0
  18. package/lib/cjs/types.js +6 -0
  19. package/lib/cjs/types.js.map +1 -0
  20. package/lib/cjs/utils/asset-copy.js +61 -0
  21. package/lib/cjs/utils/asset-copy.js.map +1 -0
  22. package/lib/cjs/utils/asset-discovery.js +100 -0
  23. package/lib/cjs/utils/asset-discovery.js.map +1 -0
  24. package/lib/cjs/utils/widget-compiler.js +115 -0
  25. package/lib/cjs/utils/widget-compiler.js.map +1 -0
  26. package/lib/esm/index.js +26 -0
  27. package/lib/esm/index.js.map +1 -0
  28. package/lib/esm/parsers/frontmatter.js +19 -0
  29. package/lib/esm/parsers/frontmatter.js.map +1 -0
  30. package/lib/esm/plugin.js +136 -0
  31. package/lib/esm/plugin.js.map +1 -0
  32. package/lib/esm/presets/index.js +6 -0
  33. package/lib/esm/presets/index.js.map +1 -0
  34. package/lib/esm/presets/raw.js +22 -0
  35. package/lib/esm/presets/raw.js.map +1 -0
  36. package/lib/esm/presets/skill.js +221 -0
  37. package/lib/esm/presets/skill.js.map +1 -0
  38. package/lib/esm/types.js +5 -0
  39. package/lib/esm/types.js.map +1 -0
  40. package/lib/esm/utils/asset-copy.js +54 -0
  41. package/lib/esm/utils/asset-copy.js.map +1 -0
  42. package/lib/esm/utils/asset-discovery.js +94 -0
  43. package/lib/esm/utils/asset-discovery.js.map +1 -0
  44. package/lib/esm/utils/widget-compiler.js +76 -0
  45. package/lib/esm/utils/widget-compiler.js.map +1 -0
  46. package/lib/types/index.d.ts +24 -0
  47. package/lib/types/index.d.ts.map +1 -0
  48. package/lib/types/parsers/frontmatter.d.ts +19 -0
  49. package/lib/types/parsers/frontmatter.d.ts.map +1 -0
  50. package/lib/types/plugin.d.ts +10 -0
  51. package/lib/types/plugin.d.ts.map +1 -0
  52. package/lib/types/presets/index.d.ts +6 -0
  53. package/lib/types/presets/index.d.ts.map +1 -0
  54. package/lib/types/presets/raw.d.ts +16 -0
  55. package/lib/types/presets/raw.d.ts.map +1 -0
  56. package/lib/types/presets/skill.d.ts +139 -0
  57. package/lib/types/presets/skill.d.ts.map +1 -0
  58. package/lib/types/types.d.ts +113 -0
  59. package/lib/types/types.d.ts.map +1 -0
  60. package/lib/types/utils/asset-copy.d.ts +20 -0
  61. package/lib/types/utils/asset-copy.d.ts.map +1 -0
  62. package/lib/types/utils/asset-discovery.d.ts +38 -0
  63. package/lib/types/utils/asset-discovery.d.ts.map +1 -0
  64. package/lib/types/utils/widget-compiler.d.ts +15 -0
  65. package/lib/types/utils/widget-compiler.d.ts.map +1 -0
  66. package/package.json +67 -0
  67. package/src/index.ts +45 -0
  68. package/src/parsers/frontmatter.ts +32 -0
  69. package/src/plugin.ts +158 -0
  70. package/src/presets/index.ts +6 -0
  71. package/src/presets/raw.ts +24 -0
  72. package/src/presets/skill.ts +271 -0
  73. package/src/types.ts +137 -0
  74. package/src/utils/asset-copy.ts +63 -0
  75. package/src/utils/asset-discovery.ts +138 -0
  76. 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
+ }