@claudiv/vite-sdk 0.1.0 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +41 -405
- package/bin/dev.js +27 -0
- package/bin/gen.js +38 -0
- package/bin/init.js +31 -0
- package/bin/mode.js +12 -0
- package/bin/postinstall.js +31 -0
- package/dist/cache.d.ts +12 -0
- package/dist/cache.d.ts.map +1 -0
- package/dist/cache.js +22 -0
- package/dist/cache.js.map +1 -0
- package/dist/detector.d.ts +13 -0
- package/dist/detector.d.ts.map +1 -0
- package/dist/detector.js +68 -0
- package/dist/detector.js.map +1 -0
- package/dist/dev-runner.d.ts +8 -0
- package/dist/dev-runner.d.ts.map +1 -0
- package/dist/dev-runner.js +102 -0
- package/dist/dev-runner.js.map +1 -0
- package/dist/gen-runner.d.ts +6 -0
- package/dist/gen-runner.d.ts.map +1 -0
- package/dist/gen-runner.js +67 -0
- package/dist/gen-runner.js.map +1 -0
- package/dist/index.d.ts +11 -5
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +11 -6
- package/dist/index.js.map +1 -1
- package/dist/init.d.ts +9 -0
- package/dist/init.d.ts.map +1 -0
- package/dist/init.js +72 -0
- package/dist/init.js.map +1 -0
- package/dist/mode-selector.d.ts +6 -0
- package/dist/mode-selector.d.ts.map +1 -0
- package/dist/mode-selector.js +40 -0
- package/dist/mode-selector.js.map +1 -0
- package/dist/package-json.d.ts +6 -0
- package/dist/package-json.d.ts.map +1 -0
- package/dist/package-json.js +25 -0
- package/dist/package-json.js.map +1 -0
- package/dist/plugin.d.ts +10 -11
- package/dist/plugin.d.ts.map +1 -1
- package/dist/plugin.js +25 -45
- package/dist/plugin.js.map +1 -1
- package/dist/sdk.d.ts +6 -0
- package/dist/sdk.d.ts.map +1 -0
- package/dist/sdk.js +6 -0
- package/dist/sdk.js.map +1 -0
- package/dist/types.d.ts +4 -30
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js +3 -1
- package/dist/types.js.map +1 -1
- package/dist/watcher.d.ts +3 -10
- package/dist/watcher.d.ts.map +1 -1
- package/dist/watcher.js +3 -34
- package/dist/watcher.js.map +1 -1
- package/package.json +20 -12
package/README.md
CHANGED
|
@@ -1,20 +1,10 @@
|
|
|
1
1
|
# @claudiv/vite-sdk
|
|
2
2
|
|
|
3
|
-
> Vite
|
|
4
|
-
|
|
5
|
-
[](https://www.npmjs.com/package/@claudiv/vite-sdk)
|
|
6
|
-
[](https://opensource.org/licenses/MIT)
|
|
3
|
+
> Vite framework SDK for the Claudiv declarative AI interaction platform
|
|
7
4
|
|
|
8
5
|
## Overview
|
|
9
6
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
**Features:**
|
|
13
|
-
- 🔥 **Hot Module Replacement** - Changes to .cdml files trigger instant reloads
|
|
14
|
-
- 📁 **Automatic File Watching** - Watches `claudiv/**/*.cdml` by default
|
|
15
|
-
- ⚡ **Vite-Optimized** - Leverages Vite's fast build pipeline
|
|
16
|
-
- 🔄 **Auto-Regeneration** - Code regenerates on .cdml file changes
|
|
17
|
-
- 🎯 **Type-Safe** - Full TypeScript support
|
|
7
|
+
@claudiv/vite-sdk integrates Claudiv into Vite projects as an add-on package. It provides `claudiv:*` npm scripts for initializing, watching, and generating from `.cdml` files.
|
|
18
8
|
|
|
19
9
|
## Installation
|
|
20
10
|
|
|
@@ -22,416 +12,62 @@
|
|
|
22
12
|
npm install --save-dev @claudiv/vite-sdk
|
|
23
13
|
```
|
|
24
14
|
|
|
25
|
-
|
|
26
|
-
- `vite` ^6.0.0
|
|
27
|
-
|
|
28
|
-
## Quick Start
|
|
29
|
-
|
|
30
|
-
### 1. Add Plugin to Vite Config
|
|
15
|
+
On install, `claudiv:init` script is added to your `package.json`.
|
|
31
16
|
|
|
32
|
-
|
|
33
|
-
// vite.config.ts
|
|
34
|
-
import { defineConfig } from 'vite';
|
|
35
|
-
import { claudiv } from '@claudiv/vite-sdk';
|
|
36
|
-
|
|
37
|
-
export default defineConfig({
|
|
38
|
-
plugins: [
|
|
39
|
-
claudiv({
|
|
40
|
-
specFile: 'claudiv/app.cdml',
|
|
41
|
-
outputDir: 'src/generated'
|
|
42
|
-
})
|
|
43
|
-
]
|
|
44
|
-
});
|
|
45
|
-
```
|
|
17
|
+
## npm Scripts
|
|
46
18
|
|
|
47
|
-
|
|
19
|
+
After `npm run claudiv:init`, these scripts are available:
|
|
48
20
|
|
|
49
21
|
```bash
|
|
50
|
-
|
|
22
|
+
npm run claudiv:init # Scan project, generate .cdml + context
|
|
23
|
+
npm run claudiv:dev # Watch .cdml files, diff and process
|
|
24
|
+
npm run claudiv:gen # One-shot generation
|
|
25
|
+
npm run claudiv:mode # Switch between cli/api mode
|
|
51
26
|
```
|
|
52
27
|
|
|
53
|
-
|
|
54
|
-
<!-- claudiv/app.cdml -->
|
|
55
|
-
<app target="html">
|
|
56
|
-
<dashboard gen>
|
|
57
|
-
Create an analytics dashboard with charts and stats
|
|
58
|
-
</dashboard>
|
|
59
|
-
</app>
|
|
60
|
-
```
|
|
28
|
+
## How It Works
|
|
61
29
|
|
|
62
|
-
###
|
|
30
|
+
### Init
|
|
31
|
+
1. Detects Vite project (vite.config.* or vite in package.json)
|
|
32
|
+
2. Scans source directories (src/, lib/, app/, etc.)
|
|
33
|
+
3. Generates component `.cdml` skeleton
|
|
34
|
+
4. Generates `.claudiv/context.cdml` with scope-to-file mappings
|
|
35
|
+
5. Generates `claudiv.project.cdml` manifest
|
|
36
|
+
6. Adds remaining `claudiv:*` scripts to package.json
|
|
63
37
|
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
38
|
+
### Dev Mode
|
|
39
|
+
Watches `*.cdml` files with chokidar. On change:
|
|
40
|
+
1. Diffs against cached state
|
|
41
|
+
2. Processes changes through context engine
|
|
42
|
+
3. Executes headless Claude for each changed scope
|
|
67
43
|
|
|
68
|
-
|
|
44
|
+
### Gen Mode
|
|
45
|
+
One-shot processing. Supports `--scope` filter and `--dry-run`.
|
|
69
46
|
|
|
70
|
-
##
|
|
47
|
+
## SDK Interface
|
|
71
48
|
|
|
72
|
-
|
|
49
|
+
Implements `ClaudivSDK` from `@claudiv/core`:
|
|
73
50
|
|
|
74
51
|
```typescript
|
|
75
|
-
interface
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
/**
|
|
83
|
-
* Directory for generated code output
|
|
84
|
-
* @default 'src/generated'
|
|
85
|
-
*/
|
|
86
|
-
outputDir?: string;
|
|
87
|
-
|
|
88
|
-
/**
|
|
89
|
-
* Generation mode
|
|
90
|
-
* - 'cli': Use Claude Code CLI (requires subscription)
|
|
91
|
-
* - 'api': Use Anthropic API (pay-per-use)
|
|
92
|
-
* @default 'cli'
|
|
93
|
-
*/
|
|
94
|
-
mode?: 'cli' | 'api';
|
|
95
|
-
|
|
96
|
-
/**
|
|
97
|
-
* Default target language
|
|
98
|
-
* @default 'html'
|
|
99
|
-
*/
|
|
100
|
-
target?: 'html' | 'react' | 'vue' | 'python' | 'bash';
|
|
101
|
-
|
|
102
|
-
/**
|
|
103
|
-
* Enable/disable file watching
|
|
104
|
-
* @default true
|
|
105
|
-
*/
|
|
106
|
-
watch?: boolean;
|
|
52
|
+
interface ClaudivSDK {
|
|
53
|
+
name: string;
|
|
54
|
+
frameworkDetector: FrameworkDetector;
|
|
55
|
+
init(projectRoot: string): Promise<InitResult>;
|
|
56
|
+
dev(projectRoot: string, opts: DevOptions): Promise<void>;
|
|
57
|
+
gen(projectRoot: string, opts: GenOptions): Promise<void>;
|
|
58
|
+
getScripts(): Record<string, string>;
|
|
107
59
|
}
|
|
108
60
|
```
|
|
109
61
|
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
```typescript
|
|
113
|
-
// vite.config.ts
|
|
114
|
-
import { defineConfig } from 'vite';
|
|
115
|
-
import { claudiv } from '@claudiv/vite-sdk';
|
|
116
|
-
|
|
117
|
-
export default defineConfig({
|
|
118
|
-
plugins: [
|
|
119
|
-
claudiv({
|
|
120
|
-
specFile: 'claudiv/app.cdml',
|
|
121
|
-
outputDir: 'src/generated',
|
|
122
|
-
mode: 'api', // Use Anthropic API
|
|
123
|
-
target: 'react', // Generate React components
|
|
124
|
-
watch: true // Enable HMR (default)
|
|
125
|
-
})
|
|
126
|
-
]
|
|
127
|
-
});
|
|
128
|
-
```
|
|
129
|
-
|
|
130
|
-
## Project Structure
|
|
131
|
-
|
|
132
|
-
### Recommended Folder Layout
|
|
133
|
-
|
|
134
|
-
```
|
|
135
|
-
my-vite-app/
|
|
136
|
-
├── claudiv/ # CDML source files (version controlled)
|
|
137
|
-
│ ├── app.cdml # Main spec
|
|
138
|
-
│ ├── components/ # Component specs
|
|
139
|
-
│ │ ├── header.cdml
|
|
140
|
-
│ │ └── footer.cdml
|
|
141
|
-
│ └── pages/ # Page specs
|
|
142
|
-
│ ├── home.cdml
|
|
143
|
-
│ └── about.cdml
|
|
144
|
-
│
|
|
145
|
-
├── src/
|
|
146
|
-
│ ├── generated/ # Generated code (gitignored)
|
|
147
|
-
│ │ ├── app.html
|
|
148
|
-
│ │ └── components/
|
|
149
|
-
│ └── main.ts # Your entry point
|
|
150
|
-
│
|
|
151
|
-
├── .gitignore # Ignore src/generated/
|
|
152
|
-
├── claudiv.json # Claudiv config (optional)
|
|
153
|
-
├── package.json
|
|
154
|
-
└── vite.config.ts
|
|
155
|
-
```
|
|
156
|
-
|
|
157
|
-
### .gitignore
|
|
158
|
-
|
|
159
|
-
```gitignore
|
|
160
|
-
# Claudiv generated files
|
|
161
|
-
src/generated/
|
|
162
|
-
|
|
163
|
-
# Claudiv metadata
|
|
164
|
-
.claudiv/
|
|
165
|
-
```
|
|
166
|
-
|
|
167
|
-
## Usage Patterns
|
|
168
|
-
|
|
169
|
-
### Basic HTML Generation
|
|
170
|
-
|
|
171
|
-
```typescript
|
|
172
|
-
// vite.config.ts
|
|
173
|
-
export default defineConfig({
|
|
174
|
-
plugins: [
|
|
175
|
-
claudiv({
|
|
176
|
-
specFile: 'claudiv/app.cdml',
|
|
177
|
-
target: 'html'
|
|
178
|
-
})
|
|
179
|
-
]
|
|
180
|
-
});
|
|
181
|
-
```
|
|
182
|
-
|
|
183
|
-
```xml
|
|
184
|
-
<!-- claudiv/app.cdml -->
|
|
185
|
-
<app target="html">
|
|
186
|
-
<landing-page gen>
|
|
187
|
-
Hero section with gradient background,
|
|
188
|
-
feature cards, and call-to-action buttons
|
|
189
|
-
</landing-page>
|
|
190
|
-
</app>
|
|
191
|
-
```
|
|
192
|
-
|
|
193
|
-
Generated: `src/generated/app.html`
|
|
194
|
-
|
|
195
|
-
### React Components
|
|
196
|
-
|
|
197
|
-
```typescript
|
|
198
|
-
// vite.config.ts
|
|
199
|
-
import react from '@vitejs/plugin-react';
|
|
200
|
-
import { claudiv } from '@claudiv/vite-sdk';
|
|
201
|
-
|
|
202
|
-
export default defineConfig({
|
|
203
|
-
plugins: [
|
|
204
|
-
react(),
|
|
205
|
-
claudiv({
|
|
206
|
-
specFile: 'claudiv/app.cdml',
|
|
207
|
-
target: 'react',
|
|
208
|
-
outputDir: 'src/components'
|
|
209
|
-
})
|
|
210
|
-
]
|
|
211
|
-
});
|
|
212
|
-
```
|
|
213
|
-
|
|
214
|
-
```xml
|
|
215
|
-
<!-- claudiv/app.cdml -->
|
|
216
|
-
<app target="react">
|
|
217
|
-
<Dashboard gen>
|
|
218
|
-
Analytics dashboard with charts using recharts
|
|
219
|
-
</Dashboard>
|
|
220
|
-
</app>
|
|
221
|
-
```
|
|
222
|
-
|
|
223
|
-
Generated: `src/components/Dashboard.tsx`
|
|
224
|
-
|
|
225
|
-
### Multi-File Setup
|
|
226
|
-
|
|
227
|
-
```typescript
|
|
228
|
-
// vite.config.ts
|
|
229
|
-
export default defineConfig({
|
|
230
|
-
plugins: [
|
|
231
|
-
claudiv({
|
|
232
|
-
specFile: 'claudiv/**/*.cdml', // Watch all .cdml files
|
|
233
|
-
outputDir: 'src/generated'
|
|
234
|
-
})
|
|
235
|
-
]
|
|
236
|
-
});
|
|
237
|
-
```
|
|
238
|
-
|
|
239
|
-
## API Mode Setup
|
|
240
|
-
|
|
241
|
-
### Using Anthropic API
|
|
242
|
-
|
|
243
|
-
1. Install @anthropic-ai/sdk:
|
|
244
|
-
```bash
|
|
245
|
-
npm install @anthropic-ai/sdk
|
|
246
|
-
```
|
|
247
|
-
|
|
248
|
-
2. Create `.env` file:
|
|
249
|
-
```env
|
|
250
|
-
ANTHROPIC_API_KEY=sk-ant-api03-...
|
|
251
|
-
```
|
|
252
|
-
|
|
253
|
-
3. Configure plugin:
|
|
254
|
-
```typescript
|
|
255
|
-
export default defineConfig({
|
|
256
|
-
plugins: [
|
|
257
|
-
claudiv({
|
|
258
|
-
mode: 'api',
|
|
259
|
-
specFile: 'claudiv/app.cdml'
|
|
260
|
-
})
|
|
261
|
-
]
|
|
262
|
-
});
|
|
263
|
-
```
|
|
264
|
-
|
|
265
|
-
## CLI Mode Setup
|
|
266
|
-
|
|
267
|
-
### Using Claude Code Subscription
|
|
268
|
-
|
|
269
|
-
1. Install Claude Code:
|
|
270
|
-
```bash
|
|
271
|
-
# Follow installation at https://claude.ai/code
|
|
272
|
-
```
|
|
273
|
-
|
|
274
|
-
2. Configure plugin:
|
|
275
|
-
```typescript
|
|
276
|
-
export default defineConfig({
|
|
277
|
-
plugins: [
|
|
278
|
-
claudiv({
|
|
279
|
-
mode: 'cli', // Default mode
|
|
280
|
-
specFile: 'claudiv/app.cdml'
|
|
281
|
-
})
|
|
282
|
-
]
|
|
283
|
-
});
|
|
284
|
-
```
|
|
285
|
-
|
|
286
|
-
## Hot Module Replacement (HMR)
|
|
287
|
-
|
|
288
|
-
The plugin automatically enables HMR for .cdml files:
|
|
289
|
-
|
|
290
|
-
1. Edit your CDML file:
|
|
291
|
-
```xml
|
|
292
|
-
<!-- claudiv/app.cdml -->
|
|
293
|
-
<button gen>Make it blue</button>
|
|
294
|
-
```
|
|
295
|
-
|
|
296
|
-
2. Save the file
|
|
297
|
-
3. Browser automatically reloads with updated code
|
|
298
|
-
4. No manual refresh needed!
|
|
299
|
-
|
|
300
|
-
### HMR Behavior
|
|
301
|
-
|
|
302
|
-
- **Full Reload:** Changes to .cdml files trigger full page reload
|
|
303
|
-
- **Instant:** Vite's dev server provides sub-second feedback
|
|
304
|
-
- **Automatic:** No configuration needed - works out of the box
|
|
305
|
-
|
|
306
|
-
## Build-Time Generation
|
|
307
|
-
|
|
308
|
-
During production builds, Claudiv generates code before bundling:
|
|
309
|
-
|
|
310
|
-
```bash
|
|
311
|
-
npm run build
|
|
312
|
-
```
|
|
313
|
-
|
|
314
|
-
**Build Process:**
|
|
315
|
-
1. Parse all .cdml files
|
|
316
|
-
2. Generate code to `outputDir`
|
|
317
|
-
3. Vite bundles generated code
|
|
318
|
-
4. Outputs production-ready assets
|
|
319
|
-
|
|
320
|
-
## Advanced Usage
|
|
321
|
-
|
|
322
|
-
### Custom Watcher
|
|
323
|
-
|
|
324
|
-
```typescript
|
|
325
|
-
import { ClaudivViteWatcher } from '@claudiv/vite-sdk';
|
|
326
|
-
|
|
327
|
-
const watcher = new ClaudivViteWatcher({
|
|
328
|
-
specFile: 'custom-path/**/*.cdml'
|
|
329
|
-
});
|
|
330
|
-
|
|
331
|
-
watcher.on('change', (file) => {
|
|
332
|
-
console.log('CDML file changed:', file);
|
|
333
|
-
});
|
|
334
|
-
|
|
335
|
-
watcher.start();
|
|
336
|
-
```
|
|
337
|
-
|
|
338
|
-
### Programmatic Generation
|
|
339
|
-
|
|
340
|
-
```typescript
|
|
341
|
-
import { claudiv } from '@claudiv/vite-sdk';
|
|
342
|
-
import { generateCode } from '@claudiv/core';
|
|
343
|
-
|
|
344
|
-
// Use core package for custom logic
|
|
345
|
-
const generated = await generateCode(response, pattern, context);
|
|
346
|
-
```
|
|
347
|
-
|
|
348
|
-
## Troubleshooting
|
|
349
|
-
|
|
350
|
-
### Plugin Not Watching Files
|
|
351
|
-
|
|
352
|
-
**Issue:** Changes to .cdml files don't trigger reloads
|
|
353
|
-
|
|
354
|
-
**Solution:**
|
|
355
|
-
```typescript
|
|
356
|
-
// Ensure watch is enabled (default)
|
|
357
|
-
claudiv({
|
|
358
|
-
watch: true,
|
|
359
|
-
specFile: 'claudiv/**/*.cdml' // Correct glob pattern
|
|
360
|
-
})
|
|
361
|
-
```
|
|
362
|
-
|
|
363
|
-
### Generated Files Not Found
|
|
364
|
-
|
|
365
|
-
**Issue:** Import errors for generated files
|
|
366
|
-
|
|
367
|
-
**Solution:**
|
|
368
|
-
1. Check `outputDir` matches import paths
|
|
369
|
-
2. Verify .cdml files have `gen` attributes
|
|
370
|
-
3. Check Vite dev server logs for generation errors
|
|
371
|
-
|
|
372
|
-
### API Key Not Found
|
|
373
|
-
|
|
374
|
-
**Issue:** `ANTHROPIC_API_KEY` not detected
|
|
375
|
-
|
|
376
|
-
**Solution:**
|
|
377
|
-
```bash
|
|
378
|
-
# Create .env file in project root
|
|
379
|
-
echo "ANTHROPIC_API_KEY=sk-ant-..." > .env
|
|
380
|
-
```
|
|
381
|
-
|
|
382
|
-
## Status
|
|
383
|
-
|
|
384
|
-
⚠️ **Alpha Release** - Core functionality implemented, active development ongoing
|
|
385
|
-
|
|
386
|
-
**Current Features:**
|
|
387
|
-
- ✅ File watching with HMR
|
|
388
|
-
- ✅ Basic code generation
|
|
389
|
-
- ✅ Vite dev server integration
|
|
390
|
-
|
|
391
|
-
**Planned Features:**
|
|
392
|
-
- 🚧 Build-time generation optimization
|
|
393
|
-
- 🚧 Source maps for debugging
|
|
394
|
-
- 🚧 Multi-target support in single project
|
|
395
|
-
- 🚧 Plugin hooks for customization
|
|
62
|
+
## Bin Scripts
|
|
396
63
|
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
# Build
|
|
404
|
-
npm run build
|
|
405
|
-
|
|
406
|
-
# Watch mode
|
|
407
|
-
npm run dev
|
|
408
|
-
|
|
409
|
-
# Clean dist
|
|
410
|
-
npm run clean
|
|
411
|
-
```
|
|
412
|
-
|
|
413
|
-
## Contributing
|
|
414
|
-
|
|
415
|
-
Contributions are welcome! Please see [CONTRIBUTING.md](../../CONTRIBUTING.md) for guidelines.
|
|
64
|
+
| Script | Purpose |
|
|
65
|
+
|--------|---------|
|
|
66
|
+
| `claudiv-vite-init` | Project initialization |
|
|
67
|
+
| `claudiv-vite-dev` | Dev mode watcher |
|
|
68
|
+
| `claudiv-vite-gen` | One-shot generation |
|
|
69
|
+
| `claudiv-vite-mode` | Mode selection prompt |
|
|
416
70
|
|
|
417
71
|
## License
|
|
418
72
|
|
|
419
|
-
MIT
|
|
420
|
-
|
|
421
|
-
See [LICENSE](./LICENSE) for details.
|
|
422
|
-
|
|
423
|
-
## Links
|
|
424
|
-
|
|
425
|
-
- **Homepage:** [https://claudiv.org](https://claudiv.org)
|
|
426
|
-
- **GitHub:** [https://github.com/claudiv-ai/vite-sdk](https://github.com/claudiv-ai/vite-sdk)
|
|
427
|
-
- **npm:** [https://npmjs.com/package/@claudiv/vite-sdk](https://npmjs.com/package/@claudiv/vite-sdk)
|
|
428
|
-
- **Documentation:** [https://docs.claudiv.org/vite-sdk](https://docs.claudiv.org/vite-sdk)
|
|
429
|
-
|
|
430
|
-
## Related Packages
|
|
431
|
-
|
|
432
|
-
- [@claudiv/core](https://npmjs.com/package/@claudiv/core) - Core generation engine
|
|
433
|
-
- [@claudiv/cli](https://npmjs.com/package/@claudiv/cli) - CLI tool for CDML generation
|
|
434
|
-
|
|
435
|
-
---
|
|
436
|
-
|
|
437
|
-
**Add declarative AI-powered generation to your Vite projects!**
|
|
73
|
+
MIT
|
package/bin/dev.js
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* claudiv-vite-dev — Watch .cdml files and process changes.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import { runDev } from '../dist/dev-runner.js';
|
|
8
|
+
import { readFile } from 'fs/promises';
|
|
9
|
+
import { join, existsSync } from 'path';
|
|
10
|
+
|
|
11
|
+
const projectRoot = process.cwd();
|
|
12
|
+
|
|
13
|
+
// Load config
|
|
14
|
+
let opts = {};
|
|
15
|
+
const configPath = join(projectRoot, '.claudiv', 'config.json');
|
|
16
|
+
try {
|
|
17
|
+
if (existsSync(configPath)) {
|
|
18
|
+
opts = JSON.parse(await readFile(configPath, 'utf-8'));
|
|
19
|
+
}
|
|
20
|
+
} catch {
|
|
21
|
+
// Use defaults
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
runDev(projectRoot, opts).catch((err) => {
|
|
25
|
+
console.error(`[claudiv:dev] Fatal: ${err.message}`);
|
|
26
|
+
process.exit(1);
|
|
27
|
+
});
|
package/bin/gen.js
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* claudiv-vite-gen — One-shot generation from .cdml files.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import { runGen } from '../dist/gen-runner.js';
|
|
8
|
+
import { readFile } from 'fs/promises';
|
|
9
|
+
import { join, existsSync } from 'path';
|
|
10
|
+
|
|
11
|
+
const projectRoot = process.cwd();
|
|
12
|
+
|
|
13
|
+
// Load config
|
|
14
|
+
let opts = {};
|
|
15
|
+
const configPath = join(projectRoot, '.claudiv', 'config.json');
|
|
16
|
+
try {
|
|
17
|
+
if (existsSync(configPath)) {
|
|
18
|
+
opts = JSON.parse(await readFile(configPath, 'utf-8'));
|
|
19
|
+
}
|
|
20
|
+
} catch {
|
|
21
|
+
// Use defaults
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
// Check for --dry-run flag
|
|
25
|
+
if (process.argv.includes('--dry-run')) {
|
|
26
|
+
opts.dryRun = true;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
// Check for --scope flag
|
|
30
|
+
const scopeIdx = process.argv.indexOf('--scope');
|
|
31
|
+
if (scopeIdx !== -1 && process.argv[scopeIdx + 1]) {
|
|
32
|
+
opts.scope = process.argv[scopeIdx + 1];
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
runGen(projectRoot, opts).catch((err) => {
|
|
36
|
+
console.error(`[claudiv:gen] Fatal: ${err.message}`);
|
|
37
|
+
process.exit(1);
|
|
38
|
+
});
|
package/bin/init.js
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* claudiv-vite-init — Initialize a Vite project for Claudiv.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import { ViteSdk } from '../dist/index.js';
|
|
8
|
+
|
|
9
|
+
const sdk = new ViteSdk();
|
|
10
|
+
const projectRoot = process.cwd();
|
|
11
|
+
|
|
12
|
+
const result = await sdk.init(projectRoot);
|
|
13
|
+
|
|
14
|
+
if (result.success) {
|
|
15
|
+
console.log('Claudiv initialized successfully!');
|
|
16
|
+
console.log('Files created:');
|
|
17
|
+
for (const file of result.filesCreated) {
|
|
18
|
+
console.log(` + ${file}`);
|
|
19
|
+
}
|
|
20
|
+
console.log('');
|
|
21
|
+
console.log('Next steps:');
|
|
22
|
+
console.log(' npm run claudiv:dev — watch & generate');
|
|
23
|
+
console.log(' npm run claudiv:gen — one-shot generation');
|
|
24
|
+
console.log(' npm run claudiv:mode — switch CLI/API mode');
|
|
25
|
+
} else {
|
|
26
|
+
console.error('Initialization failed:');
|
|
27
|
+
for (const w of result.warnings || []) {
|
|
28
|
+
console.error(` ${w}`);
|
|
29
|
+
}
|
|
30
|
+
process.exit(1);
|
|
31
|
+
}
|
package/bin/mode.js
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Postinstall hook: adds only claudiv:init to user's package.json.
|
|
5
|
+
* Other scripts are added during init.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import { readFile, writeFile } from 'fs/promises';
|
|
9
|
+
import { join } from 'path';
|
|
10
|
+
|
|
11
|
+
const projectRoot = process.env.INIT_CWD || process.cwd();
|
|
12
|
+
|
|
13
|
+
async function main() {
|
|
14
|
+
try {
|
|
15
|
+
const pkgPath = join(projectRoot, 'package.json');
|
|
16
|
+
const pkg = JSON.parse(await readFile(pkgPath, 'utf-8'));
|
|
17
|
+
|
|
18
|
+
if (!pkg.scripts) pkg.scripts = {};
|
|
19
|
+
|
|
20
|
+
// Only add init script on postinstall
|
|
21
|
+
if (!pkg.scripts['claudiv:init']) {
|
|
22
|
+
pkg.scripts['claudiv:init'] = 'claudiv-vite-init';
|
|
23
|
+
await writeFile(pkgPath, JSON.stringify(pkg, null, 2) + '\n', 'utf-8');
|
|
24
|
+
console.log('[claudiv] Added claudiv:init script. Run: npm run claudiv:init');
|
|
25
|
+
}
|
|
26
|
+
} catch {
|
|
27
|
+
// Silently skip if package.json can't be modified
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
main();
|
package/dist/cache.d.ts
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* In-memory CDML content cache for diff-based change detection.
|
|
3
|
+
*/
|
|
4
|
+
export declare class CdmlCache {
|
|
5
|
+
private entries;
|
|
6
|
+
get(key: string): string | undefined;
|
|
7
|
+
set(key: string, content: string): void;
|
|
8
|
+
has(key: string): boolean;
|
|
9
|
+
delete(key: string): boolean;
|
|
10
|
+
clear(): void;
|
|
11
|
+
}
|
|
12
|
+
//# sourceMappingURL=cache.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cache.d.ts","sourceRoot":"","sources":["../src/cache.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,qBAAa,SAAS;IACpB,OAAO,CAAC,OAAO,CAA6B;IAE5C,GAAG,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS;IAIpC,GAAG,CAAC,GAAG,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,IAAI;IAIvC,GAAG,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO;IAIzB,MAAM,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO;IAI5B,KAAK,IAAI,IAAI;CAGd"}
|
package/dist/cache.js
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* In-memory CDML content cache for diff-based change detection.
|
|
3
|
+
*/
|
|
4
|
+
export class CdmlCache {
|
|
5
|
+
entries = new Map();
|
|
6
|
+
get(key) {
|
|
7
|
+
return this.entries.get(key);
|
|
8
|
+
}
|
|
9
|
+
set(key, content) {
|
|
10
|
+
this.entries.set(key, content);
|
|
11
|
+
}
|
|
12
|
+
has(key) {
|
|
13
|
+
return this.entries.has(key);
|
|
14
|
+
}
|
|
15
|
+
delete(key) {
|
|
16
|
+
return this.entries.delete(key);
|
|
17
|
+
}
|
|
18
|
+
clear() {
|
|
19
|
+
this.entries.clear();
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
//# sourceMappingURL=cache.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cache.js","sourceRoot":"","sources":["../src/cache.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,MAAM,OAAO,SAAS;IACZ,OAAO,GAAG,IAAI,GAAG,EAAkB,CAAC;IAE5C,GAAG,CAAC,GAAW;QACb,OAAO,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;IAC/B,CAAC;IAED,GAAG,CAAC,GAAW,EAAE,OAAe;QAC9B,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,GAAG,EAAE,OAAO,CAAC,CAAC;IACjC,CAAC;IAED,GAAG,CAAC,GAAW;QACb,OAAO,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;IAC/B,CAAC;IAED,MAAM,CAAC,GAAW;QAChB,OAAO,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;IAClC,CAAC;IAED,KAAK;QACH,IAAI,CAAC,OAAO,CAAC,KAAK,EAAE,CAAC;IACvB,CAAC;CACF"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Vite framework detector.
|
|
3
|
+
*
|
|
4
|
+
* Checks if a project uses Vite and extracts project metadata.
|
|
5
|
+
*/
|
|
6
|
+
import type { FrameworkDetector } from '@claudiv/core';
|
|
7
|
+
export declare class ViteDetector implements FrameworkDetector {
|
|
8
|
+
detect(projectRoot: string): Promise<boolean>;
|
|
9
|
+
getAppName(projectRoot: string): Promise<string>;
|
|
10
|
+
getSourcePaths(projectRoot: string): Promise<string[]>;
|
|
11
|
+
getIgnorePatterns(): string[];
|
|
12
|
+
}
|
|
13
|
+
//# sourceMappingURL=detector.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"detector.d.ts","sourceRoot":"","sources":["../src/detector.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAKH,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAC;AAEvD,qBAAa,YAAa,YAAW,iBAAiB;IAC9C,MAAM,CAAC,WAAW,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;IA4B7C,UAAU,CAAC,WAAW,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IAahD,cAAc,CAAC,WAAW,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC;IAa5D,iBAAiB,IAAI,MAAM,EAAE;CAQ9B"}
|