@vibe-agent-toolkit/resource-compiler 0.1.11

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 (119) hide show
  1. package/README.md +449 -0
  2. package/bin/vat-compile-resources +8 -0
  3. package/dist/cli/compile-command.d.ts +11 -0
  4. package/dist/cli/compile-command.d.ts.map +1 -0
  5. package/dist/cli/compile-command.js +34 -0
  6. package/dist/cli/compile-command.js.map +1 -0
  7. package/dist/cli/compile-utils.d.ts +41 -0
  8. package/dist/cli/compile-utils.d.ts.map +1 -0
  9. package/dist/cli/compile-utils.js +51 -0
  10. package/dist/cli/compile-utils.js.map +1 -0
  11. package/dist/cli/generate-types-command.d.ts +11 -0
  12. package/dist/cli/generate-types-command.d.ts.map +1 -0
  13. package/dist/cli/generate-types-command.js +107 -0
  14. package/dist/cli/generate-types-command.js.map +1 -0
  15. package/dist/cli/index.d.ts +17 -0
  16. package/dist/cli/index.d.ts.map +1 -0
  17. package/dist/cli/index.js +34 -0
  18. package/dist/cli/index.js.map +1 -0
  19. package/dist/cli/watch-command.d.ts +11 -0
  20. package/dist/cli/watch-command.d.ts.map +1 -0
  21. package/dist/cli/watch-command.js +88 -0
  22. package/dist/cli/watch-command.js.map +1 -0
  23. package/dist/compiler/dts-generator.d.ts +29 -0
  24. package/dist/compiler/dts-generator.d.ts.map +1 -0
  25. package/dist/compiler/dts-generator.js +133 -0
  26. package/dist/compiler/dts-generator.js.map +1 -0
  27. package/dist/compiler/index.d.ts +9 -0
  28. package/dist/compiler/index.d.ts.map +1 -0
  29. package/dist/compiler/index.js +9 -0
  30. package/dist/compiler/index.js.map +1 -0
  31. package/dist/compiler/javascript-generator.d.ts +22 -0
  32. package/dist/compiler/javascript-generator.d.ts.map +1 -0
  33. package/dist/compiler/javascript-generator.js +106 -0
  34. package/dist/compiler/javascript-generator.js.map +1 -0
  35. package/dist/compiler/markdown-compiler.d.ts +30 -0
  36. package/dist/compiler/markdown-compiler.d.ts.map +1 -0
  37. package/dist/compiler/markdown-compiler.js +125 -0
  38. package/dist/compiler/markdown-compiler.js.map +1 -0
  39. package/dist/compiler/markdown-parser.d.ts +32 -0
  40. package/dist/compiler/markdown-parser.d.ts.map +1 -0
  41. package/dist/compiler/markdown-parser.js +126 -0
  42. package/dist/compiler/markdown-parser.js.map +1 -0
  43. package/dist/compiler/types.d.ts +71 -0
  44. package/dist/compiler/types.d.ts.map +1 -0
  45. package/dist/compiler/types.js +5 -0
  46. package/dist/compiler/types.js.map +1 -0
  47. package/dist/index.d.ts +7 -0
  48. package/dist/index.d.ts.map +1 -0
  49. package/dist/index.js +7 -0
  50. package/dist/index.js.map +1 -0
  51. package/dist/language-service/completions.d.ts +27 -0
  52. package/dist/language-service/completions.d.ts.map +1 -0
  53. package/dist/language-service/completions.js +147 -0
  54. package/dist/language-service/completions.js.map +1 -0
  55. package/dist/language-service/definitions.d.ts +14 -0
  56. package/dist/language-service/definitions.d.ts.map +1 -0
  57. package/dist/language-service/definitions.js +140 -0
  58. package/dist/language-service/definitions.js.map +1 -0
  59. package/dist/language-service/diagnostics.d.ts +13 -0
  60. package/dist/language-service/diagnostics.d.ts.map +1 -0
  61. package/dist/language-service/diagnostics.js +169 -0
  62. package/dist/language-service/diagnostics.js.map +1 -0
  63. package/dist/language-service/hover.d.ts +15 -0
  64. package/dist/language-service/hover.d.ts.map +1 -0
  65. package/dist/language-service/hover.js +125 -0
  66. package/dist/language-service/hover.js.map +1 -0
  67. package/dist/language-service/index.d.ts +26 -0
  68. package/dist/language-service/index.d.ts.map +1 -0
  69. package/dist/language-service/index.js +30 -0
  70. package/dist/language-service/index.js.map +1 -0
  71. package/dist/language-service/markdown-cache.d.ts +44 -0
  72. package/dist/language-service/markdown-cache.d.ts.map +1 -0
  73. package/dist/language-service/markdown-cache.js +77 -0
  74. package/dist/language-service/markdown-cache.js.map +1 -0
  75. package/dist/language-service/plugin.d.ts +15 -0
  76. package/dist/language-service/plugin.d.ts.map +1 -0
  77. package/dist/language-service/plugin.js +51 -0
  78. package/dist/language-service/plugin.js.map +1 -0
  79. package/dist/language-service/utils.d.ts +173 -0
  80. package/dist/language-service/utils.d.ts.map +1 -0
  81. package/dist/language-service/utils.js +341 -0
  82. package/dist/language-service/utils.js.map +1 -0
  83. package/dist/transformer/ast-helpers.d.ts +35 -0
  84. package/dist/transformer/ast-helpers.d.ts.map +1 -0
  85. package/dist/transformer/ast-helpers.js +153 -0
  86. package/dist/transformer/ast-helpers.js.map +1 -0
  87. package/dist/transformer/declaration-generator.d.ts +47 -0
  88. package/dist/transformer/declaration-generator.d.ts.map +1 -0
  89. package/dist/transformer/declaration-generator.js +53 -0
  90. package/dist/transformer/declaration-generator.js.map +1 -0
  91. package/dist/transformer/import-detector.d.ts +62 -0
  92. package/dist/transformer/import-detector.d.ts.map +1 -0
  93. package/dist/transformer/import-detector.js +115 -0
  94. package/dist/transformer/import-detector.js.map +1 -0
  95. package/dist/transformer/index.d.ts +11 -0
  96. package/dist/transformer/index.d.ts.map +1 -0
  97. package/dist/transformer/index.js +11 -0
  98. package/dist/transformer/index.js.map +1 -0
  99. package/dist/transformer/module-generator.d.ts +29 -0
  100. package/dist/transformer/module-generator.d.ts.map +1 -0
  101. package/dist/transformer/module-generator.js +48 -0
  102. package/dist/transformer/module-generator.js.map +1 -0
  103. package/dist/transformer/path-resolver.d.ts +32 -0
  104. package/dist/transformer/path-resolver.d.ts.map +1 -0
  105. package/dist/transformer/path-resolver.js +112 -0
  106. package/dist/transformer/path-resolver.js.map +1 -0
  107. package/dist/transformer/transformer.d.ts +46 -0
  108. package/dist/transformer/transformer.d.ts.map +1 -0
  109. package/dist/transformer/transformer.js +89 -0
  110. package/dist/transformer/transformer.js.map +1 -0
  111. package/dist/utils/copy-resources.d.ts +54 -0
  112. package/dist/utils/copy-resources.d.ts.map +1 -0
  113. package/dist/utils/copy-resources.js +77 -0
  114. package/dist/utils/copy-resources.js.map +1 -0
  115. package/dist/utils/index.d.ts +6 -0
  116. package/dist/utils/index.d.ts.map +1 -0
  117. package/dist/utils/index.js +5 -0
  118. package/dist/utils/index.js.map +1 -0
  119. package/package.json +84 -0
@@ -0,0 +1,32 @@
1
+ /**
2
+ * Path resolution utilities for markdown imports
3
+ * Resolves relative and node_modules paths using TypeScript's module resolution
4
+ */
5
+ import ts from 'typescript';
6
+ /**
7
+ * Resolve a markdown import path to an absolute file path
8
+ *
9
+ * @param modulePath - The import path (e.g., "./core.md", "@pkg/prompts/core.md")
10
+ * @param containingFile - The absolute path of the file doing the import
11
+ * @param compilerOptions - TypeScript compiler options for module resolution
12
+ * @returns Absolute path to the markdown file, or null if not found
13
+ *
14
+ * @example
15
+ * ```typescript
16
+ * // Relative import
17
+ * resolveMarkdownPath('./core.md', '/path/to/file.ts', options)
18
+ * // → '/path/to/core.md'
19
+ *
20
+ * // Node modules import
21
+ * resolveMarkdownPath('@pkg/prompts/core.md', '/path/to/file.ts', options)
22
+ * // → '/path/to/node_modules/@pkg/prompts/core.md'
23
+ * ```
24
+ */
25
+ export declare function resolveMarkdownPath(modulePath: string, containingFile: string, compilerOptions: ts.CompilerOptions): string | null;
26
+ /**
27
+ * Create default compiler options for module resolution
28
+ *
29
+ * @returns Default TypeScript compiler options
30
+ */
31
+ export declare function createDefaultCompilerOptions(): ts.CompilerOptions;
32
+ //# sourceMappingURL=path-resolver.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"path-resolver.d.ts","sourceRoot":"","sources":["../../src/transformer/path-resolver.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAMH,OAAO,EAAE,MAAM,YAAY,CAAC;AAE5B;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,mBAAmB,CACjC,UAAU,EAAE,MAAM,EAClB,cAAc,EAAE,MAAM,EACtB,eAAe,EAAE,EAAE,CAAC,eAAe,GAClC,MAAM,GAAG,IAAI,CAef;AA6ED;;;;GAIG;AACH,wBAAgB,4BAA4B,IAAI,EAAE,CAAC,eAAe,CASjE"}
@@ -0,0 +1,112 @@
1
+ /**
2
+ * Path resolution utilities for markdown imports
3
+ * Resolves relative and node_modules paths using TypeScript's module resolution
4
+ */
5
+ import { existsSync } from 'node:fs';
6
+ import { dirname, resolve, join, isAbsolute } from 'node:path';
7
+ import { toForwardSlash } from '@vibe-agent-toolkit/utils';
8
+ import ts from 'typescript';
9
+ /**
10
+ * Resolve a markdown import path to an absolute file path
11
+ *
12
+ * @param modulePath - The import path (e.g., "./core.md", "@pkg/prompts/core.md")
13
+ * @param containingFile - The absolute path of the file doing the import
14
+ * @param compilerOptions - TypeScript compiler options for module resolution
15
+ * @returns Absolute path to the markdown file, or null if not found
16
+ *
17
+ * @example
18
+ * ```typescript
19
+ * // Relative import
20
+ * resolveMarkdownPath('./core.md', '/path/to/file.ts', options)
21
+ * // → '/path/to/core.md'
22
+ *
23
+ * // Node modules import
24
+ * resolveMarkdownPath('@pkg/prompts/core.md', '/path/to/file.ts', options)
25
+ * // → '/path/to/node_modules/@pkg/prompts/core.md'
26
+ * ```
27
+ */
28
+ export function resolveMarkdownPath(modulePath, containingFile, compilerOptions) {
29
+ // Handle relative paths (normalize to forward slashes for cross-platform)
30
+ const normalizedPath = toForwardSlash(modulePath);
31
+ if (normalizedPath.startsWith('./') || normalizedPath.startsWith('../')) {
32
+ return resolveRelativePath(modulePath, containingFile);
33
+ }
34
+ // Handle absolute paths (rare, but possible)
35
+ if (isAbsolute(modulePath)) {
36
+ // eslint-disable-next-line security/detect-non-literal-fs-filename -- Validated absolute path from module resolution
37
+ return existsSync(modulePath) ? modulePath : null;
38
+ }
39
+ // Handle node_modules paths
40
+ return resolveNodeModulesPath(modulePath, containingFile, compilerOptions);
41
+ }
42
+ /**
43
+ * Resolve a relative markdown import path
44
+ *
45
+ * @param modulePath - Relative path (e.g., "./core.md", "../shared/core.md")
46
+ * @param containingFile - Absolute path of the importing file
47
+ * @returns Absolute path to the markdown file, or null if not found
48
+ */
49
+ function resolveRelativePath(modulePath, containingFile) {
50
+ const containingDir = dirname(containingFile);
51
+ const absolutePath = resolve(containingDir, modulePath);
52
+ // eslint-disable-next-line security/detect-non-literal-fs-filename -- Validated path from module resolution
53
+ return existsSync(absolutePath) ? absolutePath : null;
54
+ }
55
+ /**
56
+ * Resolve a node_modules markdown import path
57
+ *
58
+ * @param modulePath - Package path (e.g., "@pkg/prompts/core.md")
59
+ * @param containingFile - Absolute path of the importing file
60
+ * @param compilerOptions - TypeScript compiler options
61
+ * @returns Absolute path to the markdown file, or null if not found
62
+ */
63
+ function resolveNodeModulesPath(modulePath, containingFile, compilerOptions) {
64
+ // Try TypeScript's module resolution
65
+ const result = ts.resolveModuleName(modulePath, containingFile, compilerOptions, ts.sys);
66
+ if (result.resolvedModule) {
67
+ return result.resolvedModule.resolvedFileName;
68
+ }
69
+ // Fallback: manually search node_modules
70
+ return searchNodeModules(modulePath, containingFile);
71
+ }
72
+ /**
73
+ * Manually search node_modules for a markdown file
74
+ *
75
+ * @param modulePath - Package path
76
+ * @param containingFile - Absolute path of the importing file
77
+ * @returns Absolute path to the markdown file, or null if not found
78
+ */
79
+ function searchNodeModules(modulePath, containingFile) {
80
+ let currentDir = dirname(containingFile);
81
+ // Walk up the directory tree looking for node_modules
82
+ while (true) {
83
+ const nodeModulesPath = join(currentDir, 'node_modules', modulePath);
84
+ // eslint-disable-next-line security/detect-non-literal-fs-filename -- Validated path from module resolution
85
+ if (existsSync(nodeModulesPath)) {
86
+ return nodeModulesPath;
87
+ }
88
+ const parentDir = dirname(currentDir);
89
+ if (parentDir === currentDir) {
90
+ // Reached root directory
91
+ break;
92
+ }
93
+ currentDir = parentDir;
94
+ }
95
+ return null;
96
+ }
97
+ /**
98
+ * Create default compiler options for module resolution
99
+ *
100
+ * @returns Default TypeScript compiler options
101
+ */
102
+ export function createDefaultCompilerOptions() {
103
+ return {
104
+ moduleResolution: ts.ModuleResolutionKind.NodeNext,
105
+ target: ts.ScriptTarget.ES2024,
106
+ module: ts.ModuleKind.NodeNext,
107
+ esModuleInterop: true,
108
+ allowSyntheticDefaultImports: true,
109
+ resolveJsonModule: true,
110
+ };
111
+ }
112
+ //# sourceMappingURL=path-resolver.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"path-resolver.js","sourceRoot":"","sources":["../../src/transformer/path-resolver.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AACrC,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AAE/D,OAAO,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAC;AAC3D,OAAO,EAAE,MAAM,YAAY,CAAC;AAE5B;;;;;;;;;;;;;;;;;;GAkBG;AACH,MAAM,UAAU,mBAAmB,CACjC,UAAkB,EAClB,cAAsB,EACtB,eAAmC;IAEnC,0EAA0E;IAC1E,MAAM,cAAc,GAAG,cAAc,CAAC,UAAU,CAAC,CAAC;IAClD,IAAI,cAAc,CAAC,UAAU,CAAC,IAAI,CAAC,IAAI,cAAc,CAAC,UAAU,CAAC,KAAK,CAAC,EAAE,CAAC;QACxE,OAAO,mBAAmB,CAAC,UAAU,EAAE,cAAc,CAAC,CAAC;IACzD,CAAC;IAED,6CAA6C;IAC7C,IAAI,UAAU,CAAC,UAAU,CAAC,EAAE,CAAC;QAC3B,qHAAqH;QACrH,OAAO,UAAU,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,IAAI,CAAC;IACpD,CAAC;IAED,4BAA4B;IAC5B,OAAO,sBAAsB,CAAC,UAAU,EAAE,cAAc,EAAE,eAAe,CAAC,CAAC;AAC7E,CAAC;AAED;;;;;;GAMG;AACH,SAAS,mBAAmB,CAAC,UAAkB,EAAE,cAAsB;IACrE,MAAM,aAAa,GAAG,OAAO,CAAC,cAAc,CAAC,CAAC;IAC9C,MAAM,YAAY,GAAG,OAAO,CAAC,aAAa,EAAE,UAAU,CAAC,CAAC;IAExD,4GAA4G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UAAU,CAAC,QAAQ;QAC9B,eAAe,EAAE,IAAI;QACrB,4BAA4B,EAAE,IAAI;QAClC,iBAAiB,EAAE,IAAI;KACxB,CAAC;AACJ,CAAC"}
@@ -0,0 +1,46 @@
1
+ /**
2
+ * TypeScript transformer for markdown imports
3
+ * Converts: import * as X from './foo.md' → const X = { meta, text, fragments }
4
+ */
5
+ import ts from 'typescript';
6
+ /**
7
+ * Options for the markdown import transformer
8
+ */
9
+ export interface TransformerOptions {
10
+ /** TypeScript compiler options for module resolution */
11
+ compilerOptions?: ts.CompilerOptions;
12
+ /** Enable verbose logging */
13
+ verbose?: boolean;
14
+ }
15
+ /**
16
+ * Create a TypeScript transformer that converts markdown imports to const declarations
17
+ *
18
+ * @param program - The TypeScript program (optional, for better module resolution)
19
+ * @param options - Transformer options
20
+ * @returns Transformer factory function
21
+ *
22
+ * @example
23
+ * ```typescript
24
+ * // Use with ts-patch in tsconfig.json:
25
+ * {
26
+ * "compilerOptions": {
27
+ * "plugins": [
28
+ * {
29
+ * "transform": "@vibe-agent-toolkit/resource-compiler/transformer",
30
+ * "afterDeclarations": true
31
+ * }
32
+ * ]
33
+ * }
34
+ * }
35
+ * ```
36
+ */
37
+ export declare function createTransformer(_program?: ts.Program, options?: TransformerOptions): ts.TransformerFactory<ts.SourceFile>;
38
+ /**
39
+ * Default transformer export for ts-patch
40
+ * Can be used directly in tsconfig.json plugins
41
+ *
42
+ * @param program - The TypeScript program
43
+ * @returns Transformer factory
44
+ */
45
+ export default function transformerFactory(program: ts.Program): ts.TransformerFactory<ts.SourceFile>;
46
+ //# sourceMappingURL=transformer.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"transformer.d.ts","sourceRoot":"","sources":["../../src/transformer/transformer.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAIH,OAAO,EAAE,MAAM,YAAY,CAAC;AAM5B;;GAEG;AACH,MAAM,WAAW,kBAAkB;IACjC,wDAAwD;IACxD,eAAe,CAAC,EAAE,EAAE,CAAC,eAAe,CAAC;IACrC,6BAA6B;IAC7B,OAAO,CAAC,EAAE,OAAO,CAAC;CACnB;AAED;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,wBAAgB,iBAAiB,CAC/B,QAAQ,CAAC,EAAE,EAAE,CAAC,OAAO,EACrB,OAAO,CAAC,EAAE,kBAAkB,GAC3B,EAAE,CAAC,kBAAkB,CAAC,EAAE,CAAC,UAAU,CAAC,CAmEtC;AAED;;;;;;GAMG;AACH,MAAM,CAAC,OAAO,UAAU,kBAAkB,CAAC,OAAO,EAAE,EAAE,CAAC,OAAO,GAAG,EAAE,CAAC,kBAAkB,CAAC,EAAE,CAAC,UAAU,CAAC,CAEpG"}
@@ -0,0 +1,89 @@
1
+ /**
2
+ * TypeScript transformer for markdown imports
3
+ * Converts: import * as X from './foo.md' → const X = { meta, text, fragments }
4
+ */
5
+ /* eslint-disable sonarjs/no-nested-functions -- TypeScript transformer factory pattern requires 4 levels of nesting */
6
+ import ts from 'typescript';
7
+ import { findMarkdownImports } from './import-detector.js';
8
+ import { generateModuleReplacement, replaceImportWithConst } from './module-generator.js';
9
+ import { resolveMarkdownPath, createDefaultCompilerOptions } from './path-resolver.js';
10
+ /**
11
+ * Create a TypeScript transformer that converts markdown imports to const declarations
12
+ *
13
+ * @param program - The TypeScript program (optional, for better module resolution)
14
+ * @param options - Transformer options
15
+ * @returns Transformer factory function
16
+ *
17
+ * @example
18
+ * ```typescript
19
+ * // Use with ts-patch in tsconfig.json:
20
+ * {
21
+ * "compilerOptions": {
22
+ * "plugins": [
23
+ * {
24
+ * "transform": "@vibe-agent-toolkit/resource-compiler/transformer",
25
+ * "afterDeclarations": true
26
+ * }
27
+ * ]
28
+ * }
29
+ * }
30
+ * ```
31
+ */
32
+ export function createTransformer(_program, options) {
33
+ const compilerOptions = options?.compilerOptions ?? createDefaultCompilerOptions();
34
+ const verbose = options?.verbose ?? false;
35
+ return (context) => {
36
+ return (sourceFile) => {
37
+ // Find all markdown imports in the file
38
+ const markdownImports = findMarkdownImports(sourceFile);
39
+ if (markdownImports.length === 0) {
40
+ // No markdown imports, return unchanged
41
+ return sourceFile;
42
+ }
43
+ if (verbose) {
44
+ console.log(`[markdown-transformer] Found ${markdownImports.length} markdown import(s) in ${sourceFile.fileName}`);
45
+ }
46
+ // Create a visitor to transform the AST
47
+ const visitor = (node) => {
48
+ // Check if this is an import declaration
49
+ if (ts.isImportDeclaration(node)) {
50
+ // Check if it's one of our markdown imports
51
+ const importInfo = markdownImports.find((info) => info.node === node);
52
+ if (importInfo) {
53
+ // Resolve the markdown file path
54
+ const resolvedPath = resolveMarkdownPath(importInfo.modulePath, sourceFile.fileName, compilerOptions);
55
+ if (!resolvedPath) {
56
+ // File not found - log error and preserve original import
57
+ if (verbose) {
58
+ console.error(`[markdown-transformer] Error: Cannot find markdown file: ${importInfo.modulePath}`);
59
+ }
60
+ // Return the original node (transformation failed)
61
+ return node;
62
+ }
63
+ if (verbose) {
64
+ console.log(`[markdown-transformer] Transforming: ${importInfo.modulePath} → ${resolvedPath}`);
65
+ }
66
+ // Generate the replacement const declaration
67
+ const replacement = generateModuleReplacement(importInfo, resolvedPath);
68
+ return replaceImportWithConst(node, replacement);
69
+ }
70
+ }
71
+ // Visit children
72
+ return ts.visitEachChild(node, visitor, context);
73
+ };
74
+ // Transform the source file
75
+ return ts.visitNode(sourceFile, visitor);
76
+ };
77
+ };
78
+ }
79
+ /**
80
+ * Default transformer export for ts-patch
81
+ * Can be used directly in tsconfig.json plugins
82
+ *
83
+ * @param program - The TypeScript program
84
+ * @returns Transformer factory
85
+ */
86
+ export default function transformerFactory(program) {
87
+ return createTransformer(program);
88
+ }
89
+ //# sourceMappingURL=transformer.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"transformer.js","sourceRoot":"","sources":["../../src/transformer/transformer.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,uHAAuH;AAEvH,OAAO,EAAE,MAAM,YAAY,CAAC;AAE5B,OAAO,EAAE,mBAA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,CAAC,YAAY,EAAE,CAAC;4BAClB,0DAA0D;4BAC1D,IAAI,OAAO,EAAE,CAAC;gCACZ,OAAO,CAAC,KAAK,CACX,4DAA4D,UAAU,CAAC,UAAU,EAAE,CACpF,CAAC;4BACJ,CAAC;4BAED,mDAAmD;4BACnD,OAAO,IAAI,CAAC;wBACd,CAAC;wBAED,IAAI,OAAO,EAAE,CAAC;4BACZ,OAAO,CAAC,GAAG,CACT,wCAAwC,UAAU,CAAC,UAAU,MAAM,YAAY,EAAE,CAClF,CAAC;wBACJ,CAAC;wBAED,6CAA6C;wBAC7C,MAAM,WAAW,GAAG,yBAAyB,CAAC,UAAU,EAAE,YAAY,CAAC,CAAC;wBACxE,OAAO,sBAAsB,CAAC,IAAI,EAAE,WAAW,CAAC,CAAC;oBACnD,CAAC;gBACH,CAAC;gBAED,iBAAiB;gBACjB,OAAO,EAAE,CAAC,cAAc,CAAC,IAAI,EAAE,OAAO,EAAE,OAAO,CAAC,CAAC;YACnD,CAAC,CAAC;YAEF,4BAA4B;YAC5B,OAAO,EAAE,CAAC,SAAS,CAAC,UAAU,EAAE,OAAO,CAAkB,CAAC;QAC5D,CAAC,CAAC;IACJ,CAAC,CAAC;AACJ,CAAC;AAED;;;;;;GAMG;AACH,MAAM,CAAC,OAAO,UAAU,kBAAkB,CAAC,OAAmB;IAC5D,OAAO,iBAAiB,CAAC,OAAO,CAAC,CAAC;AACpC,CAAC"}
@@ -0,0 +1,54 @@
1
+ /**
2
+ * Copy Resources Utility
3
+ * Cross-platform utility for copying generated resources to dist directory
4
+ */
5
+ export interface CopyResourcesOptions {
6
+ /**
7
+ * Source directory containing generated resources
8
+ * Example: 'generated' or 'generated/resources'
9
+ */
10
+ sourceDir: string;
11
+ /**
12
+ * Target directory in dist
13
+ * Example: 'dist/generated' or 'dist'
14
+ */
15
+ targetDir: string;
16
+ /**
17
+ * Enable verbose logging
18
+ */
19
+ verbose?: boolean;
20
+ }
21
+ /**
22
+ * Copy generated resources to dist directory (cross-platform)
23
+ *
24
+ * @example
25
+ * ```typescript
26
+ * import { copyResources } from '@vibe-agent-toolkit/resource-compiler/utils';
27
+ *
28
+ * copyResources({
29
+ * sourceDir: 'generated',
30
+ * targetDir: 'dist/generated',
31
+ * });
32
+ * ```
33
+ */
34
+ export declare function copyResources(options: CopyResourcesOptions): void;
35
+ /**
36
+ * Create a post-build script that copies resources
37
+ *
38
+ * @example
39
+ * ```typescript
40
+ * // scripts/post-build.ts
41
+ * import { createPostBuildScript } from '@vibe-agent-toolkit/resource-compiler/utils';
42
+ *
43
+ * createPostBuildScript({
44
+ * generatedDir: 'generated',
45
+ * distDir: 'dist',
46
+ * });
47
+ * ```
48
+ */
49
+ export declare function createPostBuildScript(options: {
50
+ generatedDir: string;
51
+ distDir: string;
52
+ verbose?: boolean;
53
+ }): void;
54
+ //# sourceMappingURL=copy-resources.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"copy-resources.d.ts","sourceRoot":"","sources":["../../src/utils/copy-resources.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAOH,MAAM,WAAW,oBAAoB;IACnC;;;OAGG;IACH,SAAS,EAAE,MAAM,CAAC;IAElB;;;OAGG;IACH,SAAS,EAAE,MAAM,CAAC;IAElB;;OAEG;IACH,OAAO,CAAC,EAAE,OAAO,CAAC;CACnB;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,aAAa,CAAC,OAAO,EAAE,oBAAoB,GAAG,IAAI,CA+BjE;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAgB,qBAAqB,CAAC,OAAO,EAAE;IAC7C,YAAY,EAAE,MAAM,CAAC;IACrB,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,CAAC,EAAE,OAAO,CAAC;CACnB,GAAG,IAAI,CAaP"}
@@ -0,0 +1,77 @@
1
+ /**
2
+ * Copy Resources Utility
3
+ * Cross-platform utility for copying generated resources to dist directory
4
+ */
5
+ import { cpSync, existsSync } from 'node:fs';
6
+ import { dirname, join } from 'node:path';
7
+ import { mkdirSyncReal } from '@vibe-agent-toolkit/utils';
8
+ /**
9
+ * Copy generated resources to dist directory (cross-platform)
10
+ *
11
+ * @example
12
+ * ```typescript
13
+ * import { copyResources } from '@vibe-agent-toolkit/resource-compiler/utils';
14
+ *
15
+ * copyResources({
16
+ * sourceDir: 'generated',
17
+ * targetDir: 'dist/generated',
18
+ * });
19
+ * ```
20
+ */
21
+ export function copyResources(options) {
22
+ const { sourceDir, targetDir, verbose = false } = options;
23
+ if (verbose) {
24
+ console.log(`Copying resources: ${sourceDir} → ${targetDir}`);
25
+ }
26
+ // Validate source exists
27
+ // eslint-disable-next-line security/detect-non-literal-fs-filename -- sourceDir is from build config, not user input
28
+ if (!existsSync(sourceDir)) {
29
+ throw new Error(`Source directory does not exist: ${sourceDir}`);
30
+ }
31
+ // Ensure target parent directory exists
32
+ const targetParent = dirname(targetDir);
33
+ // eslint-disable-next-line security/detect-non-literal-fs-filename -- targetDir is from build config, not user input
34
+ if (!existsSync(targetParent)) {
35
+ mkdirSyncReal(targetParent, { recursive: true });
36
+ }
37
+ try {
38
+ // Copy recursively using Node's built-in cpSync (cross-platform)
39
+ cpSync(sourceDir, targetDir, { recursive: true });
40
+ if (verbose) {
41
+ console.log(`✓ Copied resources to ${targetDir}`);
42
+ }
43
+ }
44
+ catch (error) {
45
+ const message = error instanceof Error ? error.message : String(error);
46
+ throw new Error(`Failed to copy resources: ${message}`);
47
+ }
48
+ }
49
+ /**
50
+ * Create a post-build script that copies resources
51
+ *
52
+ * @example
53
+ * ```typescript
54
+ * // scripts/post-build.ts
55
+ * import { createPostBuildScript } from '@vibe-agent-toolkit/resource-compiler/utils';
56
+ *
57
+ * createPostBuildScript({
58
+ * generatedDir: 'generated',
59
+ * distDir: 'dist',
60
+ * });
61
+ * ```
62
+ */
63
+ export function createPostBuildScript(options) {
64
+ const { generatedDir, distDir, verbose = false } = options;
65
+ try {
66
+ copyResources({
67
+ sourceDir: generatedDir,
68
+ targetDir: join(distDir, generatedDir),
69
+ verbose,
70
+ });
71
+ }
72
+ catch (error) {
73
+ console.error(`Error in post-build script:`, error);
74
+ process.exit(1);
75
+ }
76
+ }
77
+ //# sourceMappingURL=copy-resources.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"copy-resources.js","sourceRoot":"","sources":["../../src/utils/copy-resources.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AAC7C,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAE1C,OAAO,EAAE,aAAa,EAAE,MAAM,2BAA2B,CAAC;AAqB1D;;;;;;;;;;;;GAYG;AACH,MAAM,UAAU,aAAa,CAAC,OAA6B;IACzD,MAAM,EAAE,SAAS,EAAE,SAAS,EAAE,OAAO,GAAG,KAAK,EAAE,GAAG,OAAO,CAAC;IAE1D,IAAI,OAAO,EAAE,CAAC;QACZ,OAAO,CAAC,GAAG,CAAC,sBAAsB,SAAS,MAAM,SAAS,EAAE,CAAC,CAAC;IAChE,CAAC;IAED,yBAAyB;IACzB,qHAAqH;IACrH,IAAI,CAAC,UAAU,CAAC,SAAS,CAAC,EAAE,CAAC;QAC3B,MAAM,IAAI,KAAK,CAAC,oCAAoC,SAAS,EAAE,CAAC,CAAC;IACnE,CAAC;IAED,wCAAwC;IACxC,MAAM,YAAY,GAAG,OAAO,CAAC,SAAS,CAAC,CAAC;IACxC,qHAAqH;IACrH,IAAI,CAAC,UAAU,CAAC,YAAY,CAAC,EAAE,CAAC;QAC9B,aAAa,CAAC,YAAY,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;IACnD,CAAC;IAED,IAAI,CAAC;QACH,iEAAiE;QACjE,MAAM,CAAC,SAAS,EAAE,SAAS,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;QAElD,IAAI,OAAO,EAAE,CAAC;YACZ,OAAO,CAAC,GAAG,CAAC,yBAAyB,SAAS,EAAE,CAAC,CAAC;QACpD,CAAC;IACH,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,MAAM,OAAO,GAAG,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;QACvE,MAAM,IAAI,KAAK,CAAC,6BAA6B,OAAO,EAAE,CAAC,CAAC;IAC1D,CAAC;AACH,CAAC;AAED;;;;;;;;;;;;;GAaG;AACH,MAAM,UAAU,qBAAqB,CAAC,OAIrC;IACC,MAAM,EAAE,YAAY,EAAE,OAAO,EAAE,OAAO,GAAG,KAAK,EAAE,GAAG,OAAO,CAAC;IAE3D,IAAI,CAAC;QACH,aAAa,CAAC;YACZ,SAAS,EAAE,YAAY;YACvB,SAAS,EAAE,IAAI,CAAC,OAAO,EAAE,YAAY,CAAC;YACtC,OAAO;SACR,CAAC,CAAC;IACL,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,OAAO,CAAC,KAAK,CAAC,6BAA6B,EAAE,KAAK,CAAC,CAAC;QACpD,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IAClB,CAAC;AACH,CAAC"}
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Resource Compiler Utilities
3
+ */
4
+ export { copyResources, createPostBuildScript } from './copy-resources.js';
5
+ export type { CopyResourcesOptions } from './copy-resources.js';
6
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,aAAa,EAAE,qBAAqB,EAAE,MAAM,qBAAqB,CAAC;AAC3E,YAAY,EAAE,oBAAoB,EAAE,MAAM,qBAAqB,CAAC"}
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Resource Compiler Utilities
3
+ */
4
+ export { copyResources, createPostBuildScript } from './copy-resources.js';
5
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,aAAa,EAAE,qBAAqB,EAAE,MAAM,qBAAqB,CAAC"}
package/package.json ADDED
@@ -0,0 +1,84 @@
1
+ {
2
+ "name": "@vibe-agent-toolkit/resource-compiler",
3
+ "version": "0.1.11",
4
+ "description": "Compile markdown resources to TypeScript with full IDE support",
5
+ "type": "module",
6
+ "main": "./dist/index.js",
7
+ "types": "./dist/index.d.ts",
8
+ "bin": {
9
+ "vat-compile-resources": "./bin/vat-compile-resources"
10
+ },
11
+ "exports": {
12
+ ".": {
13
+ "types": "./dist/index.d.ts",
14
+ "default": "./dist/index.js"
15
+ },
16
+ "./compiler": {
17
+ "types": "./dist/compiler/index.d.ts",
18
+ "default": "./dist/compiler/index.js"
19
+ },
20
+ "./transformer": {
21
+ "types": "./dist/transformer/index.d.ts",
22
+ "default": "./dist/transformer/index.js"
23
+ },
24
+ "./language-service": {
25
+ "types": "./dist/language-service/index.d.ts",
26
+ "default": "./dist/language-service/index.js"
27
+ },
28
+ "./utils": {
29
+ "types": "./dist/utils/index.d.ts",
30
+ "default": "./dist/utils/index.js"
31
+ }
32
+ },
33
+ "scripts": {
34
+ "build": "tsc --build",
35
+ "build:clean": "tsc --build --clean && tsc --build",
36
+ "test": "vitest run",
37
+ "test:unit": "vitest run test/**/*.test.ts",
38
+ "test:integration": "vitest run test/**/*.integration.test.ts",
39
+ "test:watch": "vitest",
40
+ "test:coverage": "vitest run --coverage",
41
+ "lint": "eslint src/ test/",
42
+ "typecheck": "tsc --build --dry --force"
43
+ },
44
+ "dependencies": {
45
+ "gray-matter": "^4.0.3",
46
+ "unified": "^11.0.5",
47
+ "remark-parse": "^11.0.0",
48
+ "remark-stringify": "^11.0.0",
49
+ "@kayvan/markdown-tree-parser": "^1.0.0",
50
+ "slugify": "^1.6.6",
51
+ "glob": "^10.3.10",
52
+ "chokidar": "^3.6.0",
53
+ "commander": "^11.1.0",
54
+ "@vibe-agent-toolkit/utils": "0.1.11"
55
+ },
56
+ "devDependencies": {
57
+ "@types/node": "^20.11.5",
58
+ "typescript": "^5.3.3",
59
+ "vitest": "^1.2.0",
60
+ "eslint": "^8.56.0"
61
+ },
62
+ "files": [
63
+ "dist",
64
+ "bin",
65
+ "README.md"
66
+ ],
67
+ "keywords": [
68
+ "markdown",
69
+ "typescript",
70
+ "compiler",
71
+ "resources",
72
+ "prompts",
73
+ "agents",
74
+ "vat",
75
+ "vibe-agent-toolkit"
76
+ ],
77
+ "author": "Jeff Dutton",
78
+ "license": "MIT",
79
+ "repository": {
80
+ "type": "git",
81
+ "url": "https://github.com/jdutton/vibe-agent-toolkit.git",
82
+ "directory": "packages/resource-compiler"
83
+ }
84
+ }