@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,61 @@
1
+ "use strict";
2
+ /**
3
+ * Utilities for copying asset files during build
4
+ */
5
+ var __importDefault = (this && this.__importDefault) || function (mod) {
6
+ return (mod && mod.__esModule) ? mod : { "default": mod };
7
+ };
8
+ Object.defineProperty(exports, "__esModule", { value: true });
9
+ exports.copyAssetFile = copyAssetFile;
10
+ exports.copyAssets = copyAssets;
11
+ const node_fs_1 = require("node:fs");
12
+ const node_path_1 = __importDefault(require("node:path"));
13
+ /**
14
+ * Ensure a directory exists, creating it recursively if needed
15
+ */
16
+ function ensureDirectory(dirPath) {
17
+ try {
18
+ (0, node_fs_1.mkdirSync)(dirPath, { recursive: true });
19
+ }
20
+ catch (error) {
21
+ // Ignore if directory already exists
22
+ if (error.code !== 'EEXIST') {
23
+ throw error;
24
+ }
25
+ }
26
+ }
27
+ /**
28
+ * Copy an asset file to its destination
29
+ *
30
+ * @param asset - Asset file information
31
+ * @param assetsRoot - Root directory for assets
32
+ */
33
+ function copyAssetFile(asset, assetsRoot) {
34
+ const destPath = node_path_1.default.join(assetsRoot, asset.destPath);
35
+ const destDir = node_path_1.default.dirname(destPath);
36
+ // Ensure destination directory exists
37
+ ensureDirectory(destDir);
38
+ // Copy file
39
+ try {
40
+ (0, node_fs_1.copyFileSync)(asset.sourcePath, destPath);
41
+ }
42
+ catch (error) {
43
+ throw new Error(`Failed to copy asset from ${asset.sourcePath} to ${destPath}: ${error instanceof Error ? error.message : String(error)}`);
44
+ }
45
+ }
46
+ /**
47
+ * Copy multiple asset files
48
+ *
49
+ * @param assets - Array of asset files to copy
50
+ * @param assetsRoot - Root directory for assets
51
+ * @returns Number of files copied
52
+ */
53
+ function copyAssets(assets, assetsRoot) {
54
+ let copied = 0;
55
+ for (const asset of assets) {
56
+ copyAssetFile(asset, assetsRoot);
57
+ copied++;
58
+ }
59
+ return copied;
60
+ }
61
+ //# sourceMappingURL=asset-copy.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"asset-copy.js","sourceRoot":"","sources":["../../../src/utils/asset-copy.ts"],"names":[],"mappings":";AAAA;;GAEG;;;;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O,MAAM,CAAC;AAClB,CAAC"}
@@ -0,0 +1,100 @@
1
+ "use strict";
2
+ /**
3
+ * Utilities for discovering asset files (scripts, widgets) in skill directories
4
+ */
5
+ var __importDefault = (this && this.__importDefault) || function (mod) {
6
+ return (mod && mod.__esModule) ? mod : { "default": mod };
7
+ };
8
+ Object.defineProperty(exports, "__esModule", { value: true });
9
+ exports.discoverSkillAssets = discoverSkillAssets;
10
+ const node_fs_1 = require("node:fs");
11
+ const node_path_1 = __importDefault(require("node:path"));
12
+ /**
13
+ * Check if a file exists and is a regular file
14
+ */
15
+ function isFile(filePath) {
16
+ try {
17
+ return (0, node_fs_1.statSync)(filePath).isFile();
18
+ }
19
+ catch {
20
+ return false;
21
+ }
22
+ }
23
+ /**
24
+ * Get all files in a directory (non-recursive)
25
+ */
26
+ function getFilesInDirectory(dirPath) {
27
+ try {
28
+ return (0, node_fs_1.readdirSync)(dirPath).filter(file => {
29
+ const fullPath = node_path_1.default.join(dirPath, file);
30
+ return isFile(fullPath);
31
+ });
32
+ }
33
+ catch {
34
+ return [];
35
+ }
36
+ }
37
+ /**
38
+ * Check if a file is a script file (.js or .py)
39
+ */
40
+ function isScriptFile(fileName) {
41
+ return /\.(js|py)$/.test(fileName);
42
+ }
43
+ /**
44
+ * Check if a file is a widget file (.tsx)
45
+ */
46
+ function isWidgetFile(fileName) {
47
+ return /\.tsx$/.test(fileName);
48
+ }
49
+ /**
50
+ * Extract widget name from .tsx file (remove extension)
51
+ */
52
+ function getWidgetName(fileName) {
53
+ return fileName.replace(/\.tsx$/, '');
54
+ }
55
+ /**
56
+ * Discover assets (scripts and widgets) in a skill directory
57
+ *
58
+ * @param skillFilePath - Absolute path to the skill.md file
59
+ * @param options - Asset discovery options
60
+ * @returns Discovered assets and metadata
61
+ */
62
+ function discoverSkillAssets(skillFilePath, options = {}) {
63
+ const skillDir = node_path_1.default.dirname(skillFilePath);
64
+ const files = getFilesInDirectory(skillDir);
65
+ const scripts = [];
66
+ const widgets = [];
67
+ const widgetMetadata = [];
68
+ const assetFiles = [];
69
+ const scriptsDir = options.scriptsDir || 'scripts';
70
+ for (const file of files) {
71
+ const fullPath = node_path_1.default.join(skillDir, file);
72
+ if (isScriptFile(file)) {
73
+ // Script file (.js or .py)
74
+ scripts.push(file);
75
+ assetFiles.push({
76
+ sourcePath: fullPath,
77
+ destPath: node_path_1.default.join(scriptsDir, file),
78
+ type: 'script'
79
+ });
80
+ }
81
+ else if (isWidgetFile(file)) {
82
+ // Widget file (.tsx)
83
+ const widgetName = getWidgetName(file);
84
+ widgets.push(widgetName);
85
+ widgetMetadata.push({
86
+ name: widgetName,
87
+ path: fullPath
88
+ });
89
+ // Note: We don't add widget .tsx files to assetFiles
90
+ // Widgets are compiled by the plugin if widgetConfig is provided
91
+ }
92
+ }
93
+ return {
94
+ scripts,
95
+ widgets,
96
+ widgetMetadata,
97
+ assetFiles
98
+ };
99
+ }
100
+ //# sourceMappingURL=asset-discovery.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"asset-discovery.js","sourceRoot":"","sources":["../../../src/utils/asset-discovery.ts"],"names":[],"mappings":";AAAA;;GAEG;;;;;AAuFH,kDAgDC;AArID,qCAAgD;AAChD,0DAA6B;AA+B7B;;GAEG;AACH,SAAS,MAAM,CAAC,QAAgB;IAC5B,IAAI,CAAC;QACD,OAAO,IAAA,kBAAQ,EAAC,QAAQ,CAAC,CAAC,MAAM,EAAE,CAAC;IACvC,CAAC;IAAC,MAAM,CAAC;QACL,OAAO,KAAK,CAAC;IACjB,CAAC;AACL,CAAC;AAED;;GAEG;AACH,SAAS,mBAAmB,CAAC,OAAe;IACxC,IAAI,CAAC;QACD,OAAO,IAAA,qBAAW,EAAC,OAAO,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,EAAE;YACtC,MAAM,QAAQ,GAAG,mBAAI,CAAC,IAAI,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC;YAC1C,OAAO,MAAM,CAAC,QAAQ,CAAC,CAAC;QAC5B,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AE,QAAQ;aACjB,CAAC,CAAC;QACP,CAAC;aAAM,IAAI,YAAY,CAAC,IAAI,CAAC,EAAE,CAAC;YAC5B,qBAAqB;YACrB,MAAM,UAAU,GAAG,aAAa,CAAC,IAAI,CAAC,CAAC;YACvC,OAAO,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;YACzB,cAAc,CAAC,IAAI,CAAC;gBAChB,IAAI,EAAE,UAAU;gBAChB,IAAI,EAAE,QAAQ;aACjB,CAAC,CAAC;YAEH,qDAAqD;YACrD,iEAAiE;QACrE,CAAC;IACL,CAAC;IAED,OAAO;QACH,OAAO;QACP,OAAO;QACP,cAAc;QACd,UAAU;KACb,CAAC;AACN,CAAC"}
@@ -0,0 +1,115 @@
1
+ "use strict";
2
+ /**
3
+ * Widget compilation utility using Rollup
4
+ */
5
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
6
+ if (k2 === undefined) k2 = k;
7
+ var desc = Object.getOwnPropertyDescriptor(m, k);
8
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
9
+ desc = { enumerable: true, get: function() { return m[k]; } };
10
+ }
11
+ Object.defineProperty(o, k2, desc);
12
+ }) : (function(o, m, k, k2) {
13
+ if (k2 === undefined) k2 = k;
14
+ o[k2] = m[k];
15
+ }));
16
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
17
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
18
+ }) : function(o, v) {
19
+ o["default"] = v;
20
+ });
21
+ var __importStar = (this && this.__importStar) || (function () {
22
+ var ownKeys = function(o) {
23
+ ownKeys = Object.getOwnPropertyNames || function (o) {
24
+ var ar = [];
25
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
26
+ return ar;
27
+ };
28
+ return ownKeys(o);
29
+ };
30
+ return function (mod) {
31
+ if (mod && mod.__esModule) return mod;
32
+ var result = {};
33
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
34
+ __setModuleDefault(result, mod);
35
+ return result;
36
+ };
37
+ })();
38
+ var __importDefault = (this && this.__importDefault) || function (mod) {
39
+ return (mod && mod.__esModule) ? mod : { "default": mod };
40
+ };
41
+ Object.defineProperty(exports, "__esModule", { value: true });
42
+ exports.compileWidgets = compileWidgets;
43
+ const rollup_1 = require("rollup");
44
+ const node_path_1 = __importDefault(require("node:path"));
45
+ /**
46
+ * Default external dependencies for widgets
47
+ */
48
+ const DEFAULT_EXTERNALS = [
49
+ 'react',
50
+ 'react-dom',
51
+ 'react/jsx-runtime',
52
+ 'react/jsx-dev-runtime',
53
+ 'react-dom/client'
54
+ ];
55
+ /**
56
+ * Compile widgets using Rollup
57
+ *
58
+ * @param widgets - Array of widget metadata to compile
59
+ * @param outputDir - Directory to write compiled widgets
60
+ * @param config - Widget compilation configuration
61
+ * @returns Number of widgets compiled
62
+ */
63
+ async function compileWidgets(widgets, outputDir, config = {}) {
64
+ if (widgets.length === 0) {
65
+ return 0;
66
+ }
67
+ const { external = DEFAULT_EXTERNALS, tsconfig = './tsconfig.json', typescript: typescriptOptions = {}, minify = false } = config;
68
+ // Build each widget separately to get individual bundles
69
+ const buildPromises = widgets.map(async (widget) => {
70
+ // Dynamically import plugins - use any to bypass TypeScript module resolution issues
71
+ const typescript = (await Promise.resolve(`${'@rollup/plugin-typescript'}`).then(s => __importStar(require(s)))).default;
72
+ const nodeResolve = (await Promise.resolve(`${'@rollup/plugin-node-resolve'}`).then(s => __importStar(require(s)))).default;
73
+ const commonjs = (await Promise.resolve(`${'@rollup/plugin-commonjs'}`).then(s => __importStar(require(s)))).default;
74
+ const plugins = [
75
+ typescript({
76
+ tsconfig,
77
+ declaration: false,
78
+ sourceMap: true,
79
+ ...typescriptOptions
80
+ }),
81
+ nodeResolve({
82
+ browser: true,
83
+ preferBuiltins: false,
84
+ extensions: ['.tsx', '.ts', '.jsx', '.js']
85
+ }),
86
+ commonjs()
87
+ ];
88
+ // Add minification if requested
89
+ if (minify) {
90
+ const { terser } = await Promise.resolve(`${'rollup-plugin-terser'}`).then(s => __importStar(require(s)));
91
+ plugins.push(terser({
92
+ compress: {
93
+ drop_console: false
94
+ }
95
+ }));
96
+ }
97
+ const rollupConfig = {
98
+ input: widget.path,
99
+ output: {
100
+ file: node_path_1.default.join(outputDir, `${widget.name}.js`),
101
+ format: 'es',
102
+ sourcemap: true,
103
+ inlineDynamicImports: true
104
+ },
105
+ external,
106
+ plugins
107
+ };
108
+ const bundle = await (0, rollup_1.rollup)(rollupConfig);
109
+ await bundle.write(rollupConfig.output);
110
+ await bundle.close();
111
+ });
112
+ await Promise.all(buildPromises);
113
+ return widgets.length;
114
+ }
115
+ //# sourceMappingURL=widget-compiler.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"widget-compiler.js","sourceRoot":"","sources":["../../../src/utils/widget-compiler.ts"],"names":[],"mappings":";AAAA;;GAEG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA0BH,wCAqEC;AA7FD,mCAAiE;AACjE,0DAA6B;AAI7B;;GAEG;AACH,MAAM,iBAAiB,GAAG;IACtB,OAAO;IACP,WAAW;IACX,mBAAmB;IACnB,uBAAuB;IACvB,kBAAkB;CACrB,CAAC;AAEF;;;;;;;GAOG;AACI,KAAK,UAAU,cAAc,CAChC,OAAyB,EACzB,SAAiB,EACjB,SAAuB,EAAE;IAEzB,IAAI,OAAO,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QACvB,OAAO,CAAC,CAAC;IACb,CAAC;IAED,MAAM,EACF,QAAQ,GAAG,iBAAiB,EAC5B,QAAQ,GAAG,iBAAiB,EAC5B,UAAU,EAAE,iBAAiB,GAAG,EAAE,EAClC,MAAM,GAAG,KAAK,EACjB,GAAG,MAAM,CAAC;IAEX,yDAAyD;IACzD,MAAM,aAAa,GAAG,OAAO,CAAC,GAAG,CAAC,KAAK,EAAE,MAAM,EAAE,EAA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C,MAAM,MAAM,CAAC,KAAK,EAAE,CAAC;IACzB,CAAC,CAAC,CAAC;IAEH,MAAM,OAAO,CAAC,GAAG,CAAC,aAAa,CAAC,CAAC;IACjC,OAAO,OAAO,CAAC,MAAM,CAAC;AAC1B,CAAC"}
@@ -0,0 +1,26 @@
1
+ /**
2
+ * Vertesia Rollup Import Plugin
3
+ *
4
+ * A flexible Rollup plugin for transforming imports with custom compilers and validation.
5
+ * Supports preset transformers for common use cases (skills, raw files) and custom transformers.
6
+ *
7
+ * @example
8
+ * ```typescript
9
+ * import { vertesiaImportPlugin, skillTransformer, rawTransformer } from '@vertesia/build-tools';
10
+ *
11
+ * export default {
12
+ * plugins: [
13
+ * vertesiaImportPlugin({
14
+ * transformers: [skillTransformer, rawTransformer]
15
+ * })
16
+ * ]
17
+ * };
18
+ * ```
19
+ */
20
+ // Core plugin
21
+ export { vertesiaImportPlugin } from './plugin.js';
22
+ // Presets
23
+ export { skillTransformer, rawTransformer, SkillDefinitionSchema } from './presets/index.js';
24
+ // Utilities
25
+ export { parseFrontmatter } from './parsers/frontmatter.js';
26
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAEH,cAAc;AACd,OAAO,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAC;AAanD,UAAU;AACV,OAAO,EACH,gBAAgB,EAChB,cAAc,EACd,qBAAqB,EAGxB,MAAM,oBAAoB,CAAC;AAE5B,YAAY;AACZ,OAAO,EAAE,gBAAgB,EAA0B,MAAM,0BAA0B,CAAC"}
@@ -0,0 +1,19 @@
1
+ /**
2
+ * Frontmatter parser utility using gray-matter
3
+ */
4
+ import matter from 'gray-matter';
5
+ /**
6
+ * Parse YAML frontmatter from markdown content
7
+ *
8
+ * @param content - Raw markdown content with optional frontmatter
9
+ * @returns Parsed frontmatter and content
10
+ */
11
+ export function parseFrontmatter(content) {
12
+ const result = matter(content);
13
+ return {
14
+ frontmatter: result.data,
15
+ content: result.content,
16
+ original: content
17
+ };
18
+ }
19
+ //# sourceMappingURL=frontmatter.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"frontmatter.js","sourceRoot":"","sources":["../../../src/parsers/frontmatter.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,MAAM,MAAM,aAAa,CAAC;AAajC;;;;;GAKG;AACH,MAAM,UAAU,gBAAgB,CAAC,OAAe;IAC5C,MAAM,MAAM,GAAG,MAAM,CAAC,OAAO,CAAC,CAAC;IAE/B,OAAO;QACH,WAAW,EAAE,MAAM,CAAC,IAAI;QACxB,OAAO,EAAE,MAAM,CAAC,OAAO;QACvB,QAAQ,EAAE,OAAO;KACpB,CAAC;AACN,CAAC"}
@@ -0,0 +1,136 @@
1
+ /**
2
+ * Core Rollup plugin implementation for transforming imports
3
+ */
4
+ import { readFileSync } from 'node:fs';
5
+ import path from 'node:path';
6
+ import { copyAssets } from './utils/asset-copy.js';
7
+ import { compileWidgets } from './utils/widget-compiler.js';
8
+ /**
9
+ * Creates a Rollup plugin that transforms imports based on configured rules
10
+ */
11
+ export function vertesiaImportPlugin(config) {
12
+ const { transformers, assetsDir = './dist', widgetConfig } = config;
13
+ if (!transformers || transformers.length === 0) {
14
+ throw new Error('vertesiaImportPlugin: At least one transformer must be configured');
15
+ }
16
+ // Track assets to copy and widgets to compile
17
+ const assetsToProcess = [];
18
+ const widgetsToCompile = [];
19
+ const shouldCopyAssets = assetsDir !== false;
20
+ const shouldCompileWidgets = widgetConfig !== undefined && assetsDir !== false;
21
+ return {
22
+ name: 'vertesia-import-plugin',
23
+ /**
24
+ * Resolve import IDs to handle pattern-based imports
25
+ */
26
+ resolveId(source, importer) {
27
+ // Check if any transformer pattern matches
28
+ for (const transformer of transformers) {
29
+ if (transformer.pattern.test(source)) {
30
+ // Handle relative imports
31
+ if (source.startsWith('.') && importer) {
32
+ const cleanSource = source.replace(transformer.pattern, '');
33
+ const resolved = path.resolve(path.dirname(importer), cleanSource);
34
+ // Return with the pattern suffix to identify it in load
35
+ const suffix = source.match(transformer.pattern)?.[0] || '';
36
+ return resolved + suffix;
37
+ }
38
+ return source;
39
+ }
40
+ }
41
+ return null; // Let other plugins handle it
42
+ },
43
+ /**
44
+ * Load and transform the file content
45
+ */
46
+ async load(id) {
47
+ // Find matching transformer
48
+ let matchedTransformer;
49
+ let cleanId = id;
50
+ for (const transformer of transformers) {
51
+ if (transformer.pattern.test(id)) {
52
+ matchedTransformer = transformer;
53
+ // Remove query parameters to get actual file path
54
+ // For example: '/path/file.md?skill' -> '/path/file.md'
55
+ // '/path/file.html?raw' -> '/path/file.html'
56
+ const queryIndex = id.indexOf('?');
57
+ cleanId = queryIndex >= 0 ? id.substring(0, queryIndex) : id;
58
+ break;
59
+ }
60
+ }
61
+ if (!matchedTransformer) {
62
+ return null; // Not for us
63
+ }
64
+ try {
65
+ // Read file content
66
+ const content = readFileSync(cleanId, 'utf-8');
67
+ // Transform the content
68
+ const result = await matchedTransformer.transform(content, cleanId);
69
+ // Collect assets if any
70
+ if (result.assets && shouldCopyAssets) {
71
+ assetsToProcess.push(...result.assets);
72
+ }
73
+ // Collect widgets if any
74
+ if (result.widgets && shouldCompileWidgets) {
75
+ widgetsToCompile.push(...result.widgets);
76
+ }
77
+ // Validate if schema provided
78
+ if (matchedTransformer.schema) {
79
+ const validation = matchedTransformer.schema.safeParse(result.data);
80
+ if (!validation.success) {
81
+ const errors = validation.error.errors
82
+ .map((err) => ` - ${err.path.join('.')}: ${err.message}`)
83
+ .join('\n');
84
+ throw new Error(`Validation failed for ${id}:\n${errors}`);
85
+ }
86
+ }
87
+ // Generate code
88
+ if (result.code) {
89
+ // Custom code provided
90
+ return result.code;
91
+ }
92
+ else {
93
+ // Default: export data (escape if string, otherwise stringify as JSON)
94
+ const imports = result.imports ? result.imports.join('\n') + '\n\n' : '';
95
+ const dataJson = JSON.stringify(result.data, null, 2);
96
+ return `${imports}export default ${dataJson};`;
97
+ }
98
+ }
99
+ catch (error) {
100
+ const message = error instanceof Error ? error.message : String(error);
101
+ this.error(`Failed to transform ${id}: ${message}`);
102
+ }
103
+ },
104
+ /**
105
+ * Copy assets and compile widgets after all modules are loaded
106
+ */
107
+ async buildEnd() {
108
+ // Copy script assets
109
+ if (shouldCopyAssets && assetsToProcess.length > 0) {
110
+ try {
111
+ const copied = copyAssets(assetsToProcess, assetsDir);
112
+ console.log(`Copied ${copied} asset file(s) to ${assetsDir}`);
113
+ }
114
+ catch (error) {
115
+ const message = error instanceof Error ? error.message : String(error);
116
+ this.warn(`Failed to copy assets: ${message}`);
117
+ }
118
+ }
119
+ // Compile widgets
120
+ if (shouldCompileWidgets && widgetsToCompile.length > 0) {
121
+ try {
122
+ const widgetsDir = config.widgetsDir || 'widgets';
123
+ const outputDir = path.join(assetsDir, widgetsDir);
124
+ console.log(`Compiling ${widgetsToCompile.length} widget(s)...`);
125
+ const compiled = await compileWidgets(widgetsToCompile, outputDir, widgetConfig);
126
+ console.log(`Compiled ${compiled} widget(s) to ${outputDir}`);
127
+ }
128
+ catch (error) {
129
+ const message = error instanceof Error ? error.message : String(error);
130
+ this.error(`Failed to compile widgets: ${message}`);
131
+ }
132
+ }
133
+ }
134
+ };
135
+ }
136
+ //# sourceMappingURL=plugin.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"plugin.js","sourceRoot":"","sources":["../../src/plugin.ts"],"names":[],"mappings":"AAAA;;GAEG;AAGH,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACvC,OAAO,IAAI,MAAM,WAAW,CAAC;AAE7B,OAAO,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AACnD,OAAO,EAAE,cAAc,EAAE,MAAM,4BAA4B,CAAC;AAG5D;;GAEG;AACH,MAAM,UAAU,oBAAoB,CAAC,MAAoB;IACrD,MAAM,EAAE,YAAY,EAAE,SAAS,GAAG,QAAQ,EAAE,YAAY,EA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ACJ,CAAC;AACN,CAAC"}
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Preset transformers for common use cases
3
+ */
4
+ export { skillTransformer, SkillDefinitionSchema } from './skill.js';
5
+ export { rawTransformer } from './raw.js';
6
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/presets/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,gBAAgB,EAAE,qBAAqB,EAA+C,MAAM,YAAY,CAAC;AAClH,OAAO,EAAE,cAAc,EAAE,MAAM,UAAU,CAAC"}
@@ -0,0 +1,22 @@
1
+ /**
2
+ * Raw transformer preset for importing file content as strings
3
+ */
4
+ /**
5
+ * Raw transformer preset
6
+ * Transforms any file with ?raw suffix into a string export
7
+ *
8
+ * @example
9
+ * ```typescript
10
+ * import template from './template.html?raw';
11
+ * // template is a string containing the file content
12
+ * ```
13
+ */
14
+ export const rawTransformer = {
15
+ pattern: /\?raw$/,
16
+ transform: (content) => {
17
+ return {
18
+ data: content
19
+ };
20
+ }
21
+ };
22
+ //# sourceMappingURL=raw.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"raw.js","sourceRoot":"","sources":["../../../src/presets/raw.ts"],"names":[],"mappings":"AAAA;;GAEG;AAIH;;;;;;;;;GASG;AACH,MAAM,CAAC,MAAM,cAAc,GAAsB;IAC7C,OAAO,EAAE,QAAQ;IACjB,SAAS,EAAE,CAAC,OAAe,EAAE,EAAE;QAC3B,OAAO;YACH,IAAI,EAAE,OAAO;SAChB,CAAC;IACN,CAAC;CACJ,CAAC"}