@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.
- package/README.md +449 -0
- package/bin/vat-compile-resources +8 -0
- package/dist/cli/compile-command.d.ts +11 -0
- package/dist/cli/compile-command.d.ts.map +1 -0
- package/dist/cli/compile-command.js +34 -0
- package/dist/cli/compile-command.js.map +1 -0
- package/dist/cli/compile-utils.d.ts +41 -0
- package/dist/cli/compile-utils.d.ts.map +1 -0
- package/dist/cli/compile-utils.js +51 -0
- package/dist/cli/compile-utils.js.map +1 -0
- package/dist/cli/generate-types-command.d.ts +11 -0
- package/dist/cli/generate-types-command.d.ts.map +1 -0
- package/dist/cli/generate-types-command.js +107 -0
- package/dist/cli/generate-types-command.js.map +1 -0
- package/dist/cli/index.d.ts +17 -0
- package/dist/cli/index.d.ts.map +1 -0
- package/dist/cli/index.js +34 -0
- package/dist/cli/index.js.map +1 -0
- package/dist/cli/watch-command.d.ts +11 -0
- package/dist/cli/watch-command.d.ts.map +1 -0
- package/dist/cli/watch-command.js +88 -0
- package/dist/cli/watch-command.js.map +1 -0
- package/dist/compiler/dts-generator.d.ts +29 -0
- package/dist/compiler/dts-generator.d.ts.map +1 -0
- package/dist/compiler/dts-generator.js +133 -0
- package/dist/compiler/dts-generator.js.map +1 -0
- package/dist/compiler/index.d.ts +9 -0
- package/dist/compiler/index.d.ts.map +1 -0
- package/dist/compiler/index.js +9 -0
- package/dist/compiler/index.js.map +1 -0
- package/dist/compiler/javascript-generator.d.ts +22 -0
- package/dist/compiler/javascript-generator.d.ts.map +1 -0
- package/dist/compiler/javascript-generator.js +106 -0
- package/dist/compiler/javascript-generator.js.map +1 -0
- package/dist/compiler/markdown-compiler.d.ts +30 -0
- package/dist/compiler/markdown-compiler.d.ts.map +1 -0
- package/dist/compiler/markdown-compiler.js +125 -0
- package/dist/compiler/markdown-compiler.js.map +1 -0
- package/dist/compiler/markdown-parser.d.ts +32 -0
- package/dist/compiler/markdown-parser.d.ts.map +1 -0
- package/dist/compiler/markdown-parser.js +126 -0
- package/dist/compiler/markdown-parser.js.map +1 -0
- package/dist/compiler/types.d.ts +71 -0
- package/dist/compiler/types.d.ts.map +1 -0
- package/dist/compiler/types.js +5 -0
- package/dist/compiler/types.js.map +1 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +7 -0
- package/dist/index.js.map +1 -0
- package/dist/language-service/completions.d.ts +27 -0
- package/dist/language-service/completions.d.ts.map +1 -0
- package/dist/language-service/completions.js +147 -0
- package/dist/language-service/completions.js.map +1 -0
- package/dist/language-service/definitions.d.ts +14 -0
- package/dist/language-service/definitions.d.ts.map +1 -0
- package/dist/language-service/definitions.js +140 -0
- package/dist/language-service/definitions.js.map +1 -0
- package/dist/language-service/diagnostics.d.ts +13 -0
- package/dist/language-service/diagnostics.d.ts.map +1 -0
- package/dist/language-service/diagnostics.js +169 -0
- package/dist/language-service/diagnostics.js.map +1 -0
- package/dist/language-service/hover.d.ts +15 -0
- package/dist/language-service/hover.d.ts.map +1 -0
- package/dist/language-service/hover.js +125 -0
- package/dist/language-service/hover.js.map +1 -0
- package/dist/language-service/index.d.ts +26 -0
- package/dist/language-service/index.d.ts.map +1 -0
- package/dist/language-service/index.js +30 -0
- package/dist/language-service/index.js.map +1 -0
- package/dist/language-service/markdown-cache.d.ts +44 -0
- package/dist/language-service/markdown-cache.d.ts.map +1 -0
- package/dist/language-service/markdown-cache.js +77 -0
- package/dist/language-service/markdown-cache.js.map +1 -0
- package/dist/language-service/plugin.d.ts +15 -0
- package/dist/language-service/plugin.d.ts.map +1 -0
- package/dist/language-service/plugin.js +51 -0
- package/dist/language-service/plugin.js.map +1 -0
- package/dist/language-service/utils.d.ts +173 -0
- package/dist/language-service/utils.d.ts.map +1 -0
- package/dist/language-service/utils.js +341 -0
- package/dist/language-service/utils.js.map +1 -0
- package/dist/transformer/ast-helpers.d.ts +35 -0
- package/dist/transformer/ast-helpers.d.ts.map +1 -0
- package/dist/transformer/ast-helpers.js +153 -0
- package/dist/transformer/ast-helpers.js.map +1 -0
- package/dist/transformer/declaration-generator.d.ts +47 -0
- package/dist/transformer/declaration-generator.d.ts.map +1 -0
- package/dist/transformer/declaration-generator.js +53 -0
- package/dist/transformer/declaration-generator.js.map +1 -0
- package/dist/transformer/import-detector.d.ts +62 -0
- package/dist/transformer/import-detector.d.ts.map +1 -0
- package/dist/transformer/import-detector.js +115 -0
- package/dist/transformer/import-detector.js.map +1 -0
- package/dist/transformer/index.d.ts +11 -0
- package/dist/transformer/index.d.ts.map +1 -0
- package/dist/transformer/index.js +11 -0
- package/dist/transformer/index.js.map +1 -0
- package/dist/transformer/module-generator.d.ts +29 -0
- package/dist/transformer/module-generator.d.ts.map +1 -0
- package/dist/transformer/module-generator.js +48 -0
- package/dist/transformer/module-generator.js.map +1 -0
- package/dist/transformer/path-resolver.d.ts +32 -0
- package/dist/transformer/path-resolver.d.ts.map +1 -0
- package/dist/transformer/path-resolver.js +112 -0
- package/dist/transformer/path-resolver.js.map +1 -0
- package/dist/transformer/transformer.d.ts +46 -0
- package/dist/transformer/transformer.d.ts.map +1 -0
- package/dist/transformer/transformer.js +89 -0
- package/dist/transformer/transformer.js.map +1 -0
- package/dist/utils/copy-resources.d.ts +54 -0
- package/dist/utils/copy-resources.d.ts.map +1 -0
- package/dist/utils/copy-resources.js +77 -0
- package/dist/utils/copy-resources.js.map +1 -0
- package/dist/utils/index.d.ts +6 -0
- package/dist/utils/index.d.ts.map +1 -0
- package/dist/utils/index.js +5 -0
- package/dist/utils/index.js.map +1 -0
- package/package.json +84 -0
package/README.md
ADDED
|
@@ -0,0 +1,449 @@
|
|
|
1
|
+
# @vibe-agent-toolkit/resource-compiler
|
|
2
|
+
|
|
3
|
+
> Compile markdown resources to TypeScript with full IDE support
|
|
4
|
+
|
|
5
|
+
## Status
|
|
6
|
+
|
|
7
|
+
🚧 **Under Development** - Phase 1: Core Compiler (v0.2.0)
|
|
8
|
+
|
|
9
|
+
## Overview
|
|
10
|
+
|
|
11
|
+
The resource compiler transforms markdown files into TypeScript modules with:
|
|
12
|
+
|
|
13
|
+
- **Type-safe imports**: Import `.md` files directly in TypeScript
|
|
14
|
+
- **Fragment extraction**: H2 headings become typed properties
|
|
15
|
+
- **IDE support**: Autocomplete, go-to-definition, hover tooltips
|
|
16
|
+
- **Frontmatter parsing**: YAML metadata becomes typed objects
|
|
17
|
+
|
|
18
|
+
## Installation
|
|
19
|
+
|
|
20
|
+
```bash
|
|
21
|
+
npm install -D @vibe-agent-toolkit/resource-compiler
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
## Quick Start
|
|
25
|
+
|
|
26
|
+
### 1. Create a Markdown File
|
|
27
|
+
|
|
28
|
+
```markdown
|
|
29
|
+
<!-- src/prompts/system.md -->
|
|
30
|
+
---
|
|
31
|
+
title: System Prompts
|
|
32
|
+
version: 1.0
|
|
33
|
+
---
|
|
34
|
+
|
|
35
|
+
# System Prompts
|
|
36
|
+
|
|
37
|
+
## Welcome
|
|
38
|
+
|
|
39
|
+
You are a helpful AI assistant.
|
|
40
|
+
|
|
41
|
+
## Farewell
|
|
42
|
+
|
|
43
|
+
Thank you for using our system.
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
### 2. Compile to TypeScript
|
|
47
|
+
|
|
48
|
+
```bash
|
|
49
|
+
# Compile markdown files
|
|
50
|
+
npx vat-compile-resources compile src/prompts dist/prompts
|
|
51
|
+
|
|
52
|
+
# Or generate type declarations only
|
|
53
|
+
npx vat-compile-resources generate-types src/prompts
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
### 3. Import in TypeScript
|
|
57
|
+
|
|
58
|
+
```typescript
|
|
59
|
+
import prompts from './prompts/system.md';
|
|
60
|
+
|
|
61
|
+
// Type-safe access to frontmatter
|
|
62
|
+
console.log(prompts.meta.title); // "System Prompts"
|
|
63
|
+
console.log(prompts.meta.version); // 1.0
|
|
64
|
+
|
|
65
|
+
// Access full markdown text
|
|
66
|
+
console.log(prompts.text);
|
|
67
|
+
|
|
68
|
+
// Access specific fragments (H2 sections)
|
|
69
|
+
console.log(prompts.fragments.welcome.text);
|
|
70
|
+
console.log(prompts.fragments.farewell.body);
|
|
71
|
+
|
|
72
|
+
// Get all fragment names (type-safe)
|
|
73
|
+
const names: ('welcome' | 'farewell')[] = ['welcome', 'farewell'];
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
## Build Integration
|
|
77
|
+
|
|
78
|
+
When using the `compile` command, you generate JavaScript modules in a separate `generated/` directory. To ensure these modules are available at runtime, you need to copy them to your build output directory.
|
|
79
|
+
|
|
80
|
+
### Why Copy Generated Resources?
|
|
81
|
+
|
|
82
|
+
TypeScript's type-checker needs to resolve imports **during compilation**. Your source files import from the `generated/` directory:
|
|
83
|
+
|
|
84
|
+
```typescript
|
|
85
|
+
// src/agent.ts
|
|
86
|
+
import * as Core from '../generated/resources/core.js';
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
When TypeScript compiles to `dist/`, it only copies compiled TypeScript files - not the generated JavaScript resources. You must copy `generated/` to `dist/` separately.
|
|
90
|
+
|
|
91
|
+
### Recommended Pattern
|
|
92
|
+
|
|
93
|
+
**Directory structure:**
|
|
94
|
+
```
|
|
95
|
+
your-package/
|
|
96
|
+
├── resources/ # Source markdown (author these)
|
|
97
|
+
│ └── prompts/
|
|
98
|
+
│ └── core.md
|
|
99
|
+
├── generated/ # Generated JS/TS (from compile command)
|
|
100
|
+
│ └── resources/
|
|
101
|
+
│ └── prompts/
|
|
102
|
+
│ ├── core.js
|
|
103
|
+
│ └── core.d.ts
|
|
104
|
+
├── src/ # Your TypeScript source
|
|
105
|
+
│ └── agent.ts
|
|
106
|
+
└── dist/ # Build output
|
|
107
|
+
├── src/ # Compiled TypeScript
|
|
108
|
+
│ └── agent.js
|
|
109
|
+
└── generated/ # Copied resources (post-build step)
|
|
110
|
+
└── resources/
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
**Build flow:**
|
|
114
|
+
1. `compile` resources → `generated/`
|
|
115
|
+
2. TypeScript compilation → `dist/src/`
|
|
116
|
+
3. Copy `generated/` → `dist/generated/`
|
|
117
|
+
|
|
118
|
+
### Method 1: Using the Provided Utility (Recommended)
|
|
119
|
+
|
|
120
|
+
Create a post-build script using the provided cross-platform utility:
|
|
121
|
+
|
|
122
|
+
```typescript
|
|
123
|
+
// scripts/post-build.ts
|
|
124
|
+
import { createPostBuildScript } from '@vibe-agent-toolkit/resource-compiler/utils';
|
|
125
|
+
|
|
126
|
+
createPostBuildScript({
|
|
127
|
+
generatedDir: 'generated',
|
|
128
|
+
distDir: 'dist',
|
|
129
|
+
verbose: true,
|
|
130
|
+
});
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
Update `package.json`:
|
|
134
|
+
|
|
135
|
+
```json
|
|
136
|
+
{
|
|
137
|
+
"scripts": {
|
|
138
|
+
"generate:resources": "vat-compile-resources compile resources/ generated/resources/",
|
|
139
|
+
"build": "npm run generate:resources && tsc && node scripts/post-build.js"
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
```
|
|
143
|
+
|
|
144
|
+
### Method 2: Manual Copy (Custom Logic)
|
|
145
|
+
|
|
146
|
+
For more control, use the `copyResources` utility directly:
|
|
147
|
+
|
|
148
|
+
```typescript
|
|
149
|
+
// scripts/post-build.ts
|
|
150
|
+
import { copyResources } from '@vibe-agent-toolkit/resource-compiler/utils';
|
|
151
|
+
|
|
152
|
+
copyResources({
|
|
153
|
+
sourceDir: 'generated',
|
|
154
|
+
targetDir: 'dist/generated',
|
|
155
|
+
verbose: true,
|
|
156
|
+
});
|
|
157
|
+
|
|
158
|
+
// Add custom logic here
|
|
159
|
+
console.log('Build complete!');
|
|
160
|
+
```
|
|
161
|
+
|
|
162
|
+
### Method 3: Build Tool Integration
|
|
163
|
+
|
|
164
|
+
Integrate with your build tool (Vite, Rollup, etc.):
|
|
165
|
+
|
|
166
|
+
```typescript
|
|
167
|
+
// vite.config.ts
|
|
168
|
+
import { copyResources } from '@vibe-agent-toolkit/resource-compiler/utils';
|
|
169
|
+
|
|
170
|
+
export default {
|
|
171
|
+
plugins: [
|
|
172
|
+
{
|
|
173
|
+
name: 'copy-resources',
|
|
174
|
+
closeBundle() {
|
|
175
|
+
copyResources({
|
|
176
|
+
sourceDir: 'generated',
|
|
177
|
+
targetDir: 'dist/generated',
|
|
178
|
+
});
|
|
179
|
+
},
|
|
180
|
+
},
|
|
181
|
+
],
|
|
182
|
+
};
|
|
183
|
+
```
|
|
184
|
+
|
|
185
|
+
### Cross-Platform Considerations
|
|
186
|
+
|
|
187
|
+
**❌ Don't use shell commands:**
|
|
188
|
+
```json
|
|
189
|
+
"build": "tsc && cp -r generated dist/" // Unix only!
|
|
190
|
+
```
|
|
191
|
+
|
|
192
|
+
**✅ Use Node.js APIs:**
|
|
193
|
+
```typescript
|
|
194
|
+
import { cpSync } from 'node:fs';
|
|
195
|
+
cpSync('generated', 'dist/generated', { recursive: true });
|
|
196
|
+
```
|
|
197
|
+
|
|
198
|
+
The provided utilities use Node's built-in `cpSync()` which works on Windows, macOS, and Linux.
|
|
199
|
+
|
|
200
|
+
### Alternative: Co-located Generation (Not Recommended)
|
|
201
|
+
|
|
202
|
+
You could generate `.md.js` files alongside `.md` files:
|
|
203
|
+
|
|
204
|
+
```
|
|
205
|
+
resources/
|
|
206
|
+
├── core.md
|
|
207
|
+
├── core.md.js # Generated - clutters source directory
|
|
208
|
+
└── core.md.d.ts # Generated - clutters source directory
|
|
209
|
+
```
|
|
210
|
+
|
|
211
|
+
**Why we don't recommend this:**
|
|
212
|
+
- ❌ Clutters your clean markdown directory with generated files
|
|
213
|
+
- ❌ Makes `.gitignore` patterns more complex
|
|
214
|
+
- ❌ Harder to clean generated files
|
|
215
|
+
|
|
216
|
+
**Use a separate `generated/` directory instead** - it keeps source files clean and makes the build process explicit.
|
|
217
|
+
|
|
218
|
+
## Documentation
|
|
219
|
+
|
|
220
|
+
### CLI Commands
|
|
221
|
+
|
|
222
|
+
#### `compile` - Compile Markdown to JavaScript/TypeScript
|
|
223
|
+
|
|
224
|
+
Compiles markdown files to JavaScript modules and TypeScript declarations.
|
|
225
|
+
|
|
226
|
+
```bash
|
|
227
|
+
npx vat-compile-resources compile <input> <output> [options]
|
|
228
|
+
```
|
|
229
|
+
|
|
230
|
+
**Arguments:**
|
|
231
|
+
- `<input>` - Input directory containing markdown files
|
|
232
|
+
- `<output>` - Output directory for compiled files
|
|
233
|
+
|
|
234
|
+
**Options:**
|
|
235
|
+
- `-p, --pattern <pattern>` - Glob pattern for markdown files (default: `**/*.md`)
|
|
236
|
+
- `-v, --verbose` - Enable verbose logging
|
|
237
|
+
- `-w, --watch` - Watch mode for automatic recompilation
|
|
238
|
+
|
|
239
|
+
**Example:**
|
|
240
|
+
|
|
241
|
+
```bash
|
|
242
|
+
# Compile all markdown files
|
|
243
|
+
npx vat-compile-resources compile src/prompts dist/prompts
|
|
244
|
+
|
|
245
|
+
# Compile with custom pattern
|
|
246
|
+
npx vat-compile-resources compile src docs --pattern "guides/**/*.md"
|
|
247
|
+
|
|
248
|
+
# Watch mode
|
|
249
|
+
npx vat-compile-resources compile src dist --watch
|
|
250
|
+
```
|
|
251
|
+
|
|
252
|
+
#### `generate-types` - Generate .md.d.ts Declaration Files
|
|
253
|
+
|
|
254
|
+
Generates TypeScript declaration files (`.md.d.ts`) alongside markdown files for use with the TypeScript transformer.
|
|
255
|
+
|
|
256
|
+
```bash
|
|
257
|
+
npx vat-compile-resources generate-types <input> [options]
|
|
258
|
+
```
|
|
259
|
+
|
|
260
|
+
**Arguments:**
|
|
261
|
+
- `<input>` - Input directory containing markdown files
|
|
262
|
+
|
|
263
|
+
**Options:**
|
|
264
|
+
- `-p, --pattern <pattern>` - Glob pattern for markdown files (default: `**/*.md`)
|
|
265
|
+
- `-v, --verbose` - Enable verbose logging
|
|
266
|
+
|
|
267
|
+
**Example:**
|
|
268
|
+
|
|
269
|
+
```bash
|
|
270
|
+
# Generate declarations for all markdown files
|
|
271
|
+
npx vat-compile-resources generate-types src/prompts
|
|
272
|
+
|
|
273
|
+
# Generate with custom pattern
|
|
274
|
+
npx vat-compile-resources generate-types docs --pattern "**/*.md"
|
|
275
|
+
```
|
|
276
|
+
|
|
277
|
+
### TypeScript Transformer
|
|
278
|
+
|
|
279
|
+
The TypeScript transformer enables direct `.md` imports in TypeScript without pre-compilation.
|
|
280
|
+
|
|
281
|
+
#### Setup with ts-patch
|
|
282
|
+
|
|
283
|
+
1. Install dependencies:
|
|
284
|
+
|
|
285
|
+
```bash
|
|
286
|
+
npm install -D @vibe-agent-toolkit/resource-compiler ts-patch typescript
|
|
287
|
+
```
|
|
288
|
+
|
|
289
|
+
2. Update `tsconfig.json`:
|
|
290
|
+
|
|
291
|
+
```json
|
|
292
|
+
{
|
|
293
|
+
"compilerOptions": {
|
|
294
|
+
"plugins": [
|
|
295
|
+
{
|
|
296
|
+
"transform": "@vibe-agent-toolkit/resource-compiler/transformer"
|
|
297
|
+
}
|
|
298
|
+
]
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
```
|
|
302
|
+
|
|
303
|
+
3. Patch TypeScript:
|
|
304
|
+
|
|
305
|
+
```bash
|
|
306
|
+
npx ts-patch install
|
|
307
|
+
```
|
|
308
|
+
|
|
309
|
+
4. Generate type declarations:
|
|
310
|
+
|
|
311
|
+
```bash
|
|
312
|
+
npx vat-compile-resources generate-types src/
|
|
313
|
+
```
|
|
314
|
+
|
|
315
|
+
5. Import markdown files:
|
|
316
|
+
|
|
317
|
+
```typescript
|
|
318
|
+
import prompts from './prompts/system.md';
|
|
319
|
+
|
|
320
|
+
console.log(prompts.text);
|
|
321
|
+
console.log(prompts.fragments.welcome.text);
|
|
322
|
+
```
|
|
323
|
+
|
|
324
|
+
#### How It Works
|
|
325
|
+
|
|
326
|
+
1. **Generate Declarations**: `generate-types` creates `.md.d.ts` files alongside your markdown files
|
|
327
|
+
2. **Transform Imports**: The transformer detects `.md` imports and inlines the compiled resource
|
|
328
|
+
3. **Type Safety**: TypeScript uses `.md.d.ts` files to provide autocomplete and type checking
|
|
329
|
+
|
|
330
|
+
#### Import Styles
|
|
331
|
+
|
|
332
|
+
The transformer supports all TypeScript import styles:
|
|
333
|
+
|
|
334
|
+
```typescript
|
|
335
|
+
// Default import
|
|
336
|
+
import doc from './doc.md';
|
|
337
|
+
|
|
338
|
+
// Namespace import
|
|
339
|
+
import * as doc from './doc.md';
|
|
340
|
+
|
|
341
|
+
// Named imports
|
|
342
|
+
import { text, fragments, meta } from './doc.md';
|
|
343
|
+
```
|
|
344
|
+
|
|
345
|
+
### API Reference
|
|
346
|
+
|
|
347
|
+
#### Exported Types
|
|
348
|
+
|
|
349
|
+
```typescript
|
|
350
|
+
// From compiled markdown
|
|
351
|
+
export interface Fragment {
|
|
352
|
+
readonly header: string; // H2 heading with ##
|
|
353
|
+
readonly body: string; // Content below heading
|
|
354
|
+
readonly text: string; // header + body
|
|
355
|
+
}
|
|
356
|
+
|
|
357
|
+
export const meta: Record<string, unknown>; // Frontmatter
|
|
358
|
+
export const text: string; // Full markdown text
|
|
359
|
+
export const fragments: Record<string, Fragment>; // H2 sections
|
|
360
|
+
export type FragmentName = keyof typeof fragments;
|
|
361
|
+
```
|
|
362
|
+
|
|
363
|
+
#### Compiler API
|
|
364
|
+
|
|
365
|
+
```typescript
|
|
366
|
+
import { compileMarkdownResources } from '@vibe-agent-toolkit/resource-compiler/compiler';
|
|
367
|
+
|
|
368
|
+
const results = await compileMarkdownResources({
|
|
369
|
+
inputDir: 'src/prompts',
|
|
370
|
+
outputDir: 'dist/prompts',
|
|
371
|
+
pattern: '**/*.md',
|
|
372
|
+
verbose: true,
|
|
373
|
+
});
|
|
374
|
+
|
|
375
|
+
// Each result contains:
|
|
376
|
+
interface CompileResult {
|
|
377
|
+
sourcePath: string;
|
|
378
|
+
jsPath: string;
|
|
379
|
+
dtsPath: string;
|
|
380
|
+
success: boolean;
|
|
381
|
+
error?: string;
|
|
382
|
+
}
|
|
383
|
+
```
|
|
384
|
+
|
|
385
|
+
#### Transformer API
|
|
386
|
+
|
|
387
|
+
```typescript
|
|
388
|
+
import { createTransformer } from '@vibe-agent-toolkit/resource-compiler/transformer';
|
|
389
|
+
import ts from 'typescript';
|
|
390
|
+
|
|
391
|
+
const transformer = createTransformer({
|
|
392
|
+
verbose: true,
|
|
393
|
+
});
|
|
394
|
+
|
|
395
|
+
// Use with TypeScript compiler API
|
|
396
|
+
const result = program.emit(
|
|
397
|
+
undefined,
|
|
398
|
+
undefined,
|
|
399
|
+
undefined,
|
|
400
|
+
undefined,
|
|
401
|
+
{ before: [transformer] }
|
|
402
|
+
);
|
|
403
|
+
```
|
|
404
|
+
|
|
405
|
+
#### Build Utilities API
|
|
406
|
+
|
|
407
|
+
```typescript
|
|
408
|
+
import { copyResources, createPostBuildScript } from '@vibe-agent-toolkit/resource-compiler/utils';
|
|
409
|
+
|
|
410
|
+
// Copy resources with options
|
|
411
|
+
copyResources({
|
|
412
|
+
sourceDir: 'generated',
|
|
413
|
+
targetDir: 'dist/generated',
|
|
414
|
+
verbose: true,
|
|
415
|
+
});
|
|
416
|
+
|
|
417
|
+
// Create a complete post-build script
|
|
418
|
+
createPostBuildScript({
|
|
419
|
+
generatedDir: 'generated',
|
|
420
|
+
distDir: 'dist',
|
|
421
|
+
verbose: true,
|
|
422
|
+
});
|
|
423
|
+
```
|
|
424
|
+
|
|
425
|
+
**Options:**
|
|
426
|
+
|
|
427
|
+
```typescript
|
|
428
|
+
interface CopyResourcesOptions {
|
|
429
|
+
sourceDir: string; // Source directory with generated files
|
|
430
|
+
targetDir: string; // Target directory in dist
|
|
431
|
+
verbose?: boolean; // Enable logging (default: false)
|
|
432
|
+
}
|
|
433
|
+
```
|
|
434
|
+
|
|
435
|
+
**Throws:**
|
|
436
|
+
- Error if source directory doesn't exist
|
|
437
|
+
- Error if copy operation fails
|
|
438
|
+
|
|
439
|
+
### Language Service Plugin
|
|
440
|
+
|
|
441
|
+
Coming soon - TypeScript language service plugin for enhanced IDE support.
|
|
442
|
+
|
|
443
|
+
## Development
|
|
444
|
+
|
|
445
|
+
See the implementation plan for development details.
|
|
446
|
+
|
|
447
|
+
## License
|
|
448
|
+
|
|
449
|
+
MIT
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* CLI compile command implementation
|
|
3
|
+
*/
|
|
4
|
+
import type { Command } from 'commander';
|
|
5
|
+
/**
|
|
6
|
+
* Register the compile command with Commander
|
|
7
|
+
*
|
|
8
|
+
* @param program - Commander program instance
|
|
9
|
+
*/
|
|
10
|
+
export declare function registerCompileCommand(program: Command): void;
|
|
11
|
+
//# sourceMappingURL=compile-command.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"compile-command.d.ts","sourceRoot":"","sources":["../../src/cli/compile-command.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAMzC;;;;GAIG;AACH,wBAAgB,sBAAsB,CAAC,OAAO,EAAE,OAAO,GAAG,IAAI,CAyB7D"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* CLI compile command implementation
|
|
3
|
+
*/
|
|
4
|
+
import { compileMarkdownResources } from '../compiler/markdown-compiler.js';
|
|
5
|
+
import { addCompileOptions, printCompilationSummary, exitWithResults } from './compile-utils.js';
|
|
6
|
+
/**
|
|
7
|
+
* Register the compile command with Commander
|
|
8
|
+
*
|
|
9
|
+
* @param program - Commander program instance
|
|
10
|
+
*/
|
|
11
|
+
export function registerCompileCommand(program) {
|
|
12
|
+
addCompileOptions(program
|
|
13
|
+
.command('compile')
|
|
14
|
+
.description('Compile markdown resources to JavaScript and TypeScript')).action(async (input, output, options) => {
|
|
15
|
+
try {
|
|
16
|
+
const results = await compileMarkdownResources({
|
|
17
|
+
inputDir: input,
|
|
18
|
+
outputDir: output,
|
|
19
|
+
pattern: options.pattern,
|
|
20
|
+
verbose: options.verbose,
|
|
21
|
+
});
|
|
22
|
+
// Summary
|
|
23
|
+
console.log('');
|
|
24
|
+
console.log('Compilation complete:');
|
|
25
|
+
printCompilationSummary(results);
|
|
26
|
+
exitWithResults(results);
|
|
27
|
+
}
|
|
28
|
+
catch (error) {
|
|
29
|
+
console.error('Compilation error:', error instanceof Error ? error.message : String(error));
|
|
30
|
+
process.exit(1);
|
|
31
|
+
}
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
//# sourceMappingURL=compile-command.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"compile-command.js","sourceRoot":"","sources":["../../src/cli/compile-command.ts"],"names":[],"mappings":"AAAA;;GAEG;AAIH,OAAO,EAAE,wBAAwB,EAAE,MAAM,kCAAkC,CAAC;AAE5E,OAAO,EAAE,iBAAiB,EAAE,uBAAuB,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AAEjG;;;;GAIG;AACH,MAAM,UAAU,sBAAsB,CAAC,OAAgB;IACrD,iBAAiB,CACf,OAAO;SACJ,OAAO,CAAC,SAAS,CAAC;SAClB,WAAW,CAAC,yDAAyD,CAAC,CAC1E,CAAC,MAAM,CAAC,KAAK,EAAE,KAAa,EAAE,MAAc,EAAE,OAA8C,EAAE,EAAE;QAC7F,IAAI,CAAC;YACH,MAAM,OAAO,GAAG,MAAM,wBAAwB,CAAC;gBAC7C,QAAQ,EAAE,KAAK;gBACf,SAAS,EAAE,MAAM;gBACjB,OAAO,EAAE,OAAO,CAAC,OAAO;gBACxB,OAAO,EAAE,OAAO,CAAC,OAAO;aACzB,CAAC,CAAC;YAEH,UAAU;YACV,OAAO,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;YAChB,OAAO,CAAC,GAAG,CAAC,uBAAuB,CAAC,CAAC;YACrC,uBAAuB,CAAC,OAAO,CAAC,CAAC;YAEjC,eAAe,CAAC,OAAO,CAAC,CAAC;QAC3B,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,OAAO,CAAC,KAAK,CAAC,oBAAoB,EAAE,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC;YAC5F,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;QAClB,CAAC;IACH,CAAC,CAAC,CAAC;AACP,CAAC"}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared utilities for CLI commands
|
|
3
|
+
*/
|
|
4
|
+
import type { Command } from 'commander';
|
|
5
|
+
import type { CompileResult } from '../compiler/types.js';
|
|
6
|
+
/**
|
|
7
|
+
* Generic result type for CLI operations
|
|
8
|
+
*/
|
|
9
|
+
interface OperationResult {
|
|
10
|
+
sourcePath: string;
|
|
11
|
+
success: boolean;
|
|
12
|
+
error?: string;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Print operation summary (generic)
|
|
16
|
+
*
|
|
17
|
+
* @param results - Operation results
|
|
18
|
+
* @param operationName - Name of the operation (e.g., "Recompiled", "Generated")
|
|
19
|
+
*/
|
|
20
|
+
export declare function printOperationSummary(results: OperationResult[], operationName: string): void;
|
|
21
|
+
/**
|
|
22
|
+
* Print compilation summary
|
|
23
|
+
*
|
|
24
|
+
* @param results - Compilation results
|
|
25
|
+
*/
|
|
26
|
+
export declare function printCompilationSummary(results: CompileResult[]): void;
|
|
27
|
+
/**
|
|
28
|
+
* Exit with appropriate code based on results
|
|
29
|
+
*
|
|
30
|
+
* @param results - Operation results
|
|
31
|
+
*/
|
|
32
|
+
export declare function exitWithResults(results: OperationResult[]): never;
|
|
33
|
+
/**
|
|
34
|
+
* Add common compile/watch options to a command
|
|
35
|
+
*
|
|
36
|
+
* @param command - Commander command instance
|
|
37
|
+
* @returns Command with options added
|
|
38
|
+
*/
|
|
39
|
+
export declare function addCompileOptions(command: Command): Command;
|
|
40
|
+
export {};
|
|
41
|
+
//# sourceMappingURL=compile-utils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"compile-utils.d.ts","sourceRoot":"","sources":["../../src/cli/compile-utils.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAEzC,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AAE1D;;GAEG;AACH,UAAU,eAAe;IACvB,UAAU,EAAE,MAAM,CAAC;IACnB,OAAO,EAAE,OAAO,CAAC;IACjB,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAED;;;;;GAKG;AACH,wBAAgB,qBAAqB,CAAC,OAAO,EAAE,eAAe,EAAE,EAAE,aAAa,EAAE,MAAM,GAAG,IAAI,CAY7F;AAED;;;;GAIG;AACH,wBAAgB,uBAAuB,CAAC,OAAO,EAAE,aAAa,EAAE,GAAG,IAAI,CAEtE;AAED;;;;GAIG;AACH,wBAAgB,eAAe,CAAC,OAAO,EAAE,eAAe,EAAE,GAAG,KAAK,CAGjE;AAED;;;;;GAKG;AACH,wBAAgB,iBAAiB,CAAC,OAAO,EAAE,OAAO,GAAG,OAAO,CAM3D"}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared utilities for CLI commands
|
|
3
|
+
*/
|
|
4
|
+
/**
|
|
5
|
+
* Print operation summary (generic)
|
|
6
|
+
*
|
|
7
|
+
* @param results - Operation results
|
|
8
|
+
* @param operationName - Name of the operation (e.g., "Recompiled", "Generated")
|
|
9
|
+
*/
|
|
10
|
+
export function printOperationSummary(results, operationName) {
|
|
11
|
+
const successCount = results.filter((r) => r.success).length;
|
|
12
|
+
const failureCount = results.filter((r) => !r.success).length;
|
|
13
|
+
console.log(` ${operationName}: ${successCount} succeeded, ${failureCount} failed`);
|
|
14
|
+
if (failureCount > 0) {
|
|
15
|
+
const failures = results.filter((r) => !r.success);
|
|
16
|
+
for (const failure of failures) {
|
|
17
|
+
console.error(` Error: ${failure.sourcePath}: ${failure.error ?? 'Unknown error'}`);
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Print compilation summary
|
|
23
|
+
*
|
|
24
|
+
* @param results - Compilation results
|
|
25
|
+
*/
|
|
26
|
+
export function printCompilationSummary(results) {
|
|
27
|
+
printOperationSummary(results, 'Recompiled');
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Exit with appropriate code based on results
|
|
31
|
+
*
|
|
32
|
+
* @param results - Operation results
|
|
33
|
+
*/
|
|
34
|
+
export function exitWithResults(results) {
|
|
35
|
+
const failureCount = results.filter((r) => !r.success).length;
|
|
36
|
+
process.exit(failureCount > 0 ? 1 : 0);
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Add common compile/watch options to a command
|
|
40
|
+
*
|
|
41
|
+
* @param command - Commander command instance
|
|
42
|
+
* @returns Command with options added
|
|
43
|
+
*/
|
|
44
|
+
export function addCompileOptions(command) {
|
|
45
|
+
return command
|
|
46
|
+
.argument('<input>', 'Input directory containing markdown files')
|
|
47
|
+
.argument('<output>', 'Output directory for compiled files')
|
|
48
|
+
.option('-p, --pattern <pattern>', 'Glob pattern for markdown files', '**/*.md')
|
|
49
|
+
.option('-v, --verbose', 'Enable verbose logging', false);
|
|
50
|
+
}
|
|
51
|
+
//# sourceMappingURL=compile-utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"compile-utils.js","sourceRoot":"","sources":["../../src/cli/compile-utils.ts"],"names":[],"mappings":"AAAA;;GAEG;AAeH;;;;;GAKG;AACH,MAAM,UAAU,qBAAqB,CAAC,OAA0B,EAAE,aAAqB;IACrF,MAAM,YAAY,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,MAAM,CAAC;IAC7D,MAAM,YAAY,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,MAAM,CAAC;IAE9D,OAAO,CAAC,GAAG,CAAC,KAAK,aAAa,KAAK,YAAY,eAAe,YAAY,SAAS,CAAC,CAAC;IAErF,IAAI,YAAY,GAAG,CAAC,EAAE,CAAC;QACrB,MAAM,QAAQ,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC;QACnD,KAAK,MAAM,OAAO,IAAI,QAAQ,EAAE,CAAC;YAC/B,OAAO,CAAC,KAAK,CAAC,YAAY,OAAO,CAAC,UAAU,KAAK,OAAO,CAAC,KAAK,IAAI,eAAe,EAAE,CAAC,CAAC;QACvF,CAAC;IACH,CAAC;AACH,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,uBAAuB,CAAC,OAAwB;IAC9D,qBAAqB,CAAC,OAAO,EAAE,YAAY,CAAC,CAAC;AAC/C,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,eAAe,CAAC,OAA0B;IACxD,MAAM,YAAY,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,MAAM,CAAC;IAC9D,OAAO,CAAC,IAAI,CAAC,YAAY,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;AACzC,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,iBAAiB,CAAC,OAAgB;IAChD,OAAO,OAAO;SACX,QAAQ,CAAC,SAAS,EAAE,2CAA2C,CAAC;SAChE,QAAQ,CAAC,UAAU,EAAE,qCAAqC,CAAC;SAC3D,MAAM,CAAC,yBAAyB,EAAE,iCAAiC,EAAE,SAAS,CAAC;SAC/E,MAAM,CAAC,eAAe,EAAE,wBAAwB,EAAE,KAAK,CAAC,CAAC;AAC9D,CAAC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* CLI generate-types command implementation
|
|
3
|
+
*/
|
|
4
|
+
import type { Command } from 'commander';
|
|
5
|
+
/**
|
|
6
|
+
* Register the generate-types command with Commander
|
|
7
|
+
*
|
|
8
|
+
* @param program - Commander program instance
|
|
9
|
+
*/
|
|
10
|
+
export declare function registerGenerateTypesCommand(program: Command): void;
|
|
11
|
+
//# sourceMappingURL=generate-types-command.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"generate-types-command.d.ts","sourceRoot":"","sources":["../../src/cli/generate-types-command.ts"],"names":[],"mappings":"AAAA;;GAEG;AAOH,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAyGzC;;;;GAIG;AACH,wBAAgB,4BAA4B,CAAC,OAAO,EAAE,OAAO,GAAG,IAAI,CA2BnE"}
|