@vocoder/cli 0.1.2 → 0.1.3
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 +69 -247
- package/dist/bin.mjs +2851 -5
- package/dist/bin.mjs.map +1 -1
- package/package.json +6 -9
- package/dist/chunk-N45Q4R6O.mjs +0 -635
- package/dist/chunk-N45Q4R6O.mjs.map +0 -1
- package/dist/index.d.mts +0 -97
- package/dist/index.mjs +0 -13
- package/dist/index.mjs.map +0 -1
package/README.md
CHANGED
|
@@ -1,305 +1,127 @@
|
|
|
1
1
|
# @vocoder/cli
|
|
2
2
|
|
|
3
|
-
CLI
|
|
3
|
+
CLI for Vocoder translation workflows.
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
Commands:
|
|
6
|
+
|
|
7
|
+
- `vocoder init`
|
|
8
|
+
- `vocoder sync`
|
|
9
|
+
- `vocoder wrap`
|
|
10
|
+
|
|
11
|
+
## Install
|
|
6
12
|
|
|
7
13
|
```bash
|
|
8
|
-
npm install -D @vocoder/cli
|
|
9
|
-
# or
|
|
10
14
|
pnpm add -D @vocoder/cli
|
|
11
|
-
# or
|
|
12
|
-
yarn add -D @vocoder/cli
|
|
13
15
|
```
|
|
14
16
|
|
|
15
|
-
##
|
|
17
|
+
## `vocoder sync`
|
|
18
|
+
|
|
19
|
+
Extracts translatable strings, sends them to Vocoder, then generates runtime artifacts for `@vocoder/react`.
|
|
20
|
+
|
|
21
|
+
Generated output:
|
|
22
|
+
|
|
23
|
+
`node_modules/@vocoder/generated`
|
|
16
24
|
|
|
17
|
-
|
|
25
|
+
Includes:
|
|
26
|
+
|
|
27
|
+
- `manifest.mjs`
|
|
28
|
+
- `manifest.cjs`
|
|
29
|
+
- `<locale>.js` files
|
|
30
|
+
- `package.json` exports map
|
|
31
|
+
|
|
32
|
+
### Typical usage
|
|
18
33
|
|
|
19
34
|
```bash
|
|
20
|
-
|
|
35
|
+
pnpm exec vocoder sync
|
|
21
36
|
```
|
|
22
37
|
|
|
23
|
-
|
|
38
|
+
Add to build pipeline:
|
|
24
39
|
|
|
25
40
|
```json
|
|
26
41
|
{
|
|
27
42
|
"scripts": {
|
|
28
|
-
"prebuild": "vocoder sync",
|
|
43
|
+
"prebuild": "pnpm exec vocoder sync",
|
|
29
44
|
"build": "next build"
|
|
30
45
|
}
|
|
31
46
|
}
|
|
32
47
|
```
|
|
33
48
|
|
|
34
|
-
|
|
49
|
+
### Options
|
|
35
50
|
|
|
36
|
-
|
|
37
|
-
|
|
51
|
+
- `--include <pattern>` (repeatable)
|
|
52
|
+
- `--exclude <pattern>` (repeatable)
|
|
53
|
+
- `--branch <name>`
|
|
54
|
+
- `--force`
|
|
55
|
+
- `--dry-run`
|
|
56
|
+
- `--verbose`
|
|
38
57
|
|
|
39
|
-
|
|
40
|
-
return (
|
|
41
|
-
<div>
|
|
42
|
-
<T>Welcome to our app!</T>
|
|
43
|
-
<T name={userName}>Hello, {name}!</T>
|
|
44
|
-
</div>
|
|
45
|
-
);
|
|
46
|
-
}
|
|
47
|
-
```
|
|
58
|
+
## `vocoder wrap`
|
|
48
59
|
|
|
49
|
-
|
|
60
|
+
Scans source files and wraps likely user-facing strings with `<T>` / `t()` patterns.
|
|
50
61
|
|
|
51
62
|
```bash
|
|
52
|
-
|
|
63
|
+
pnpm exec vocoder wrap
|
|
53
64
|
```
|
|
54
65
|
|
|
55
|
-
|
|
56
|
-
- Extract all `<T>` components from your code
|
|
57
|
-
- Submit them to Vocoder for translation
|
|
58
|
-
- Download translations to `.vocoder/locales/*.json`
|
|
59
|
-
- Only translate NEW strings (incremental updates are fast!)
|
|
60
|
-
|
|
61
|
-
## Configuration
|
|
62
|
-
|
|
63
|
-
The CLI uses environment variables for configuration:
|
|
64
|
-
|
|
65
|
-
### Required
|
|
66
|
-
|
|
67
|
-
- **`VOCODER_API_KEY`**: Your Vocoder API key (get from https://vocoder.dev)
|
|
68
|
-
|
|
69
|
-
### Optional (Development Only)
|
|
70
|
-
|
|
71
|
-
- **`VOCODER_API_URL`**: Override API endpoint (defaults to `https://api.vocoder.dev`)
|
|
72
|
-
|
|
73
|
-
### Defaults (Not Configurable)
|
|
74
|
-
|
|
75
|
-
- **Target locales**: `es`, `fr`, `de`
|
|
76
|
-
- **Extraction pattern**: `src/**/*.{tsx,jsx,ts,js}`
|
|
77
|
-
- **Output directory**: `.vocoder/locales`
|
|
78
|
-
- **Target branches**: `main`, `master`, `production`, `staging`
|
|
79
|
-
|
|
80
|
-
To customize these defaults, configure them in your Vocoder dashboard.
|
|
81
|
-
|
|
82
|
-
## Commands
|
|
66
|
+
Options:
|
|
83
67
|
|
|
84
|
-
|
|
68
|
+
- `--include <pattern>` (repeatable)
|
|
69
|
+
- `--exclude <pattern>` (repeatable)
|
|
70
|
+
- `--dry-run`
|
|
71
|
+
- `--interactive`
|
|
72
|
+
- `--confidence <high|medium|low>`
|
|
73
|
+
- `--verbose`
|
|
85
74
|
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
```bash
|
|
89
|
-
npx vocoder sync [options]
|
|
90
|
-
```
|
|
75
|
+
## Configuration
|
|
91
76
|
|
|
92
|
-
|
|
77
|
+
Config priority:
|
|
93
78
|
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
- `--verbose` - Show detailed output
|
|
79
|
+
1. CLI flags
|
|
80
|
+
2. environment variables
|
|
81
|
+
3. defaults
|
|
98
82
|
|
|
99
|
-
|
|
83
|
+
### Environment variables
|
|
100
84
|
|
|
101
85
|
```bash
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
# Specify branch manually
|
|
106
|
-
npx vocoder sync --branch feature/new-ui
|
|
107
|
-
|
|
108
|
-
# See what would be translated without making API calls
|
|
109
|
-
npx vocoder sync --dry-run
|
|
110
|
-
|
|
111
|
-
# Force translation even if not on a target branch
|
|
112
|
-
npx vocoder sync --force
|
|
113
|
-
|
|
114
|
-
# Verbose output for debugging
|
|
115
|
-
npx vocoder sync --verbose
|
|
86
|
+
VOCODER_API_KEY=vc_xxx
|
|
87
|
+
VOCODER_API_URL=https://vocoder.app
|
|
88
|
+
VOCODER_EXTRACTION_PATTERN=src/**/*.{tsx,jsx,ts,js}
|
|
116
89
|
```
|
|
117
90
|
|
|
118
|
-
|
|
91
|
+
`VOCODER_API_KEY` must come from the environment.
|
|
119
92
|
|
|
120
|
-
|
|
121
|
-
```bash
|
|
122
|
-
$ npx vocoder sync
|
|
123
|
-
✓ Detected branch: main
|
|
124
|
-
✓ Loaded config for project: abc123
|
|
125
|
-
✓ Extracted 100 strings from src/**/*.{tsx,jsx,ts,js}
|
|
126
|
-
✓ Submitted to API - Batch ID: batch-xyz
|
|
127
|
-
Found 100 new strings to translate
|
|
128
|
-
⏳ Translating to 3 locales (es, fr, de)
|
|
129
|
-
Estimated time: ~30 seconds
|
|
130
|
-
✓ Translations complete!
|
|
131
|
-
✓ Wrote 3 locale files
|
|
132
|
-
|
|
133
|
-
✅ Translation complete! (32.4s)
|
|
134
|
-
```
|
|
93
|
+
## `vocoder init`
|
|
135
94
|
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
$ npx vocoder sync
|
|
139
|
-
✓ Detected branch: main
|
|
140
|
-
✓ Loaded config for project: abc123
|
|
141
|
-
✓ Extracted 100 strings from src/**/*.{tsx,jsx,ts,js}
|
|
142
|
-
✓ Submitted to API - Batch ID: batch-abc
|
|
143
|
-
Found 0 new strings to translate
|
|
144
|
-
|
|
145
|
-
✅ No new strings - using existing translations
|
|
146
|
-
✓ Wrote 3 locale files
|
|
95
|
+
Bootstraps a project by opening a browser authorization flow, then provisioning
|
|
96
|
+
a workspace/project API key.
|
|
147
97
|
|
|
148
|
-
|
|
149
|
-
|
|
98
|
+
During browser completion, you can paste a DeepL API key (BYOK) or reuse an
|
|
99
|
+
existing org-level DeepL key.
|
|
150
100
|
|
|
151
|
-
### Incremental Run (1 new string)
|
|
152
101
|
```bash
|
|
153
|
-
|
|
154
|
-
✓ Detected branch: main
|
|
155
|
-
✓ Loaded config for project: abc123
|
|
156
|
-
✓ Extracted 101 strings from src/**/*.{tsx,jsx,ts,js}
|
|
157
|
-
✓ Submitted to API - Batch ID: batch-def
|
|
158
|
-
Found 1 new strings to translate
|
|
159
|
-
⏳ Translating to 3 locales (es, fr, de)
|
|
160
|
-
Estimated time: ~1 seconds
|
|
161
|
-
✓ Translations complete!
|
|
162
|
-
✓ Wrote 3 locale files
|
|
163
|
-
|
|
164
|
-
✅ Translation complete! (1.2s)
|
|
165
|
-
```
|
|
166
|
-
|
|
167
|
-
## Branch-Scoped Translations
|
|
168
|
-
|
|
169
|
-
Translations are isolated per git branch:
|
|
170
|
-
|
|
171
|
-
- **Main branch** translations are shared across the team
|
|
172
|
-
- **Feature branches** get their own translations
|
|
173
|
-
- Feature branches fall back to main branch translations
|
|
174
|
-
- Merge to main to promote feature translations
|
|
175
|
-
|
|
176
|
-
This allows you to:
|
|
177
|
-
- Test translations in feature branches
|
|
178
|
-
- Preview translations before merging
|
|
179
|
-
- Avoid conflicts between features
|
|
180
|
-
|
|
181
|
-
## Performance
|
|
182
|
-
|
|
183
|
-
The CLI is optimized for incremental updates:
|
|
184
|
-
|
|
185
|
-
| Scenario | Time | Cost |
|
|
186
|
-
|----------|------|------|
|
|
187
|
-
| 100 new strings | ~30s | 100 strings × 3 locales |
|
|
188
|
-
| 0 new strings | <1s | No API calls |
|
|
189
|
-
| 1 new string | ~1s | 1 string × 3 locales |
|
|
190
|
-
|
|
191
|
-
**Speedup: 30x faster** for incremental updates!
|
|
192
|
-
|
|
193
|
-
## Output
|
|
194
|
-
|
|
195
|
-
Translations are written to `.vocoder/locales/`:
|
|
196
|
-
|
|
197
|
-
```
|
|
198
|
-
.vocoder/
|
|
199
|
-
└── locales/
|
|
200
|
-
├── es.json
|
|
201
|
-
├── fr.json
|
|
202
|
-
└── de.json
|
|
203
|
-
```
|
|
204
|
-
|
|
205
|
-
Each file contains a flat key-value mapping:
|
|
206
|
-
|
|
207
|
-
```json
|
|
208
|
-
{
|
|
209
|
-
"Welcome to our app!": "¡Bienvenido a nuestra aplicación!",
|
|
210
|
-
"Hello, {name}!": "¡Hola, {name}!",
|
|
211
|
-
"You have {count} messages": "Tienes {count} mensajes"
|
|
212
|
-
}
|
|
213
|
-
```
|
|
214
|
-
|
|
215
|
-
**Add to `.gitignore`:**
|
|
216
|
-
|
|
217
|
-
```
|
|
218
|
-
.vocoder/
|
|
219
|
-
```
|
|
220
|
-
|
|
221
|
-
Translations are generated at build time, not checked into git.
|
|
222
|
-
|
|
223
|
-
## Integration with React
|
|
224
|
-
|
|
225
|
-
Use the generated locale files with `@vocoder/react`:
|
|
226
|
-
|
|
227
|
-
```tsx
|
|
228
|
-
import { VocoderProvider } from '@vocoder/react';
|
|
229
|
-
import en from './.vocoder/locales/en.json';
|
|
230
|
-
import es from './.vocoder/locales/es.json';
|
|
231
|
-
import fr from './.vocoder/locales/fr.json';
|
|
232
|
-
|
|
233
|
-
export default function App({ children }) {
|
|
234
|
-
return (
|
|
235
|
-
<VocoderProvider
|
|
236
|
-
translations={{ en, es, fr }}
|
|
237
|
-
defaultLocale="en"
|
|
238
|
-
>
|
|
239
|
-
{children}
|
|
240
|
-
</VocoderProvider>
|
|
241
|
-
);
|
|
242
|
-
}
|
|
102
|
+
pnpm exec vocoder init
|
|
243
103
|
```
|
|
244
104
|
|
|
245
105
|
## Troubleshooting
|
|
246
106
|
|
|
247
|
-
###
|
|
248
|
-
|
|
249
|
-
Create a `.env` file in your project root:
|
|
107
|
+
### `VOCODER_API_KEY is required`
|
|
250
108
|
|
|
251
|
-
|
|
252
|
-
VOCODER_API_KEY=your-api-key
|
|
253
|
-
```
|
|
109
|
+
Set `VOCODER_API_KEY` in `.env` or your environment.
|
|
254
110
|
|
|
255
|
-
###
|
|
111
|
+
### No strings found
|
|
256
112
|
|
|
257
|
-
|
|
113
|
+
Use `<T>` (from `@vocoder/react`) around translatable JSX text.
|
|
258
114
|
|
|
259
|
-
|
|
260
|
-
import { T } from '@vocoder/react';
|
|
115
|
+
### Wrong branch / skipped sync
|
|
261
116
|
|
|
262
|
-
|
|
263
|
-
<T>Welcome!</T>
|
|
117
|
+
Use:
|
|
264
118
|
|
|
265
|
-
|
|
266
|
-
|
|
119
|
+
```bash
|
|
120
|
+
pnpm exec vocoder sync --branch main
|
|
267
121
|
```
|
|
268
122
|
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
The CLI auto-detects the branch from git. Either:
|
|
272
|
-
- Initialize git: `git init`
|
|
273
|
-
- Specify branch manually: `vocoder sync --branch main`
|
|
274
|
-
|
|
275
|
-
### "Skipping translations (not a target branch)"
|
|
276
|
-
|
|
277
|
-
The CLI only runs on target branches (`main`, `master`, `production`, `staging`) by default. Either:
|
|
278
|
-
- Merge to a target branch
|
|
279
|
-
- Use `--force` flag: `vocoder sync --force`
|
|
280
|
-
|
|
281
|
-
## Development
|
|
123
|
+
or force:
|
|
282
124
|
|
|
283
125
|
```bash
|
|
284
|
-
|
|
285
|
-
pnpm install
|
|
286
|
-
|
|
287
|
-
# Build
|
|
288
|
-
pnpm build
|
|
289
|
-
|
|
290
|
-
# Run tests
|
|
291
|
-
pnpm test
|
|
292
|
-
|
|
293
|
-
# Run unit tests only (fast)
|
|
294
|
-
pnpm test:unit
|
|
295
|
-
|
|
296
|
-
# Run integration tests (requires API)
|
|
297
|
-
pnpm test:integration
|
|
298
|
-
|
|
299
|
-
# Watch mode
|
|
300
|
-
pnpm test:watch
|
|
126
|
+
pnpm exec vocoder sync --force
|
|
301
127
|
```
|
|
302
|
-
|
|
303
|
-
## License
|
|
304
|
-
|
|
305
|
-
MIT
|