@vocoder/cli 0.1.2 → 0.1.4

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 CHANGED
@@ -1,304 +1,129 @@
1
1
  # @vocoder/cli
2
2
 
3
- CLI tool for the Vocoder translation workflow. Extract translatable strings from your React code and get them translated automatically.
3
+ Command-line tool for Vocoder. Handles project setup, string extraction from source code, and translation synchronization.
4
4
 
5
5
  ## Installation
6
6
 
7
7
  ```bash
8
- npm install -D @vocoder/cli
9
- # or
10
- pnpm add -D @vocoder/cli
11
- # or
12
- yarn add -D @vocoder/cli
8
+ npm install -g @vocoder/cli
13
9
  ```
14
10
 
15
- ## Quick Start
16
-
17
- 1. **Set up environment variables** (create `.env` in your project root):
11
+ Or use directly with npx:
18
12
 
19
13
  ```bash
20
- VOCODER_API_KEY=your-api-key-here
14
+ npx vocoder <command>
21
15
  ```
22
16
 
23
- 2. **Add to your build script**:
24
-
25
- ```json
26
- {
27
- "scripts": {
28
- "prebuild": "vocoder sync",
29
- "build": "next build"
30
- }
31
- }
32
- ```
33
-
34
- 3. **Use `<T>` components in your code**:
35
-
36
- ```tsx
37
- import { T } from '@vocoder/react';
38
-
39
- function MyComponent() {
40
- return (
41
- <div>
42
- <T>Welcome to our app!</T>
43
- <T name={userName}>Hello, {name}!</T>
44
- </div>
45
- );
46
- }
47
- ```
48
-
49
- 4. **Run the CLI**:
50
-
51
- ```bash
52
- npx vocoder sync
53
- ```
54
-
55
- This will:
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
17
  ## Commands
83
18
 
84
- ### `vocoder sync`
19
+ ### `vocoder init`
85
20
 
86
- Extract and translate strings.
21
+ Connect your repository to Vocoder.
87
22
 
88
23
  ```bash
89
- npx vocoder sync [options]
90
- ```
91
-
92
- **Options:**
93
-
94
- - `--branch <name>` - Specify branch name (auto-detected from git)
95
- - `--force` - Translate even if not on a target branch
96
- - `--dry-run` - Show what would be translated without making API calls
97
- - `--verbose` - Show detailed output
98
-
99
- **Examples:**
100
-
101
- ```bash
102
- # Normal usage (auto-detects branch from git)
103
- npx vocoder sync
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
24
+ vocoder init
116
25
  ```
117
26
 
118
- ## Workflow
27
+ The command detects your git remote and checks if a Vocoder project already exists for the repository. If found, it confirms the connection and prints next steps. If not, it opens a browser-based setup flow to create a new project.
119
28
 
120
- ### First Run (100 strings)
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
- ```
29
+ **Options:**
135
30
 
136
- ### Second Run (Same strings, 0 new)
137
- ```bash
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
31
+ | Flag | Description |
32
+ |---|---|
33
+ | `--api-url <url>` | Override Vocoder API URL |
34
+ | `--yes` | Skip confirmation prompts |
35
+ | `--project-name <name>` | Pre-fill project name |
36
+ | `--source-locale <locale>` | Pre-fill source locale |
37
+ | `--target-locales <list>` | Comma-separated target locales (e.g., `es,fr,de`) |
144
38
 
145
- No new strings - using existing translations
146
- ✓ Wrote 3 locale files
39
+ ### `vocoder sync`
147
40
 
148
- Translation complete! (0.8s)
149
- ```
41
+ Extract translatable strings from your source code and push them to Vocoder for translation.
150
42
 
151
- ### Incremental Run (1 new string)
152
43
  ```bash
153
- $ npx vocoder sync
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/
44
+ vocoder sync
219
45
  ```
220
46
 
221
- Translations are generated at build time, not checked into git.
47
+ This command:
222
48
 
223
- ## Integration with React
49
+ 1. Detects the current git branch and repository
50
+ 2. Scans your source files for `<T>` components and `t()` calls
51
+ 3. Extracts the source text, file location, and any context/formality hints
52
+ 4. Sends the extracted strings to the Vocoder API
53
+ 5. Optionally waits for translations to complete (based on sync mode)
224
54
 
225
- Use the generated locale files with `@vocoder/react`:
55
+ **Options:**
226
56
 
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';
57
+ | Flag | Description |
58
+ |---|---|
59
+ | `--branch <name>` | Override branch detection |
60
+ | `--include <pattern>` | Glob pattern(s) to include (repeatable) |
61
+ | `--exclude <pattern>` | Glob pattern(s) to exclude (repeatable) |
62
+ | `--force` | Sync even if not on a target branch |
63
+ | `--mode <mode>` | Sync mode: `auto`, `required`, or `best-effort` |
64
+ | `--max-wait-ms <ms>` | Max wait time before fallback (milliseconds) |
65
+ | `--no-fallback` | Fail instead of falling back to cached translations |
66
+ | `--dry-run` | Show what would be synced without sending |
67
+ | `--verbose` | Show detailed progress |
232
68
 
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
- }
243
- ```
69
+ #### Sync Modes
244
70
 
245
- ## Troubleshooting
71
+ - **`auto`** (default) -- Checks the project's sync policy. Blocking branches (e.g., `main`, `production`) use `required` mode; other branches use `best-effort`.
72
+ - **`required`** -- Waits for translations to complete before finishing. Fails if translations can't be completed within the timeout.
73
+ - **`best-effort`** -- Sends strings for translation but doesn't wait. Falls back to the latest available translations.
246
74
 
247
- ### "VOCODER_API_KEY is required"
75
+ ### `vocoder wrap`
248
76
 
249
- Create a `.env` file in your project root:
77
+ Automatically wrap string literals in your source code with `<T>` and `t()`.
250
78
 
251
79
  ```bash
252
- VOCODER_API_KEY=your-api-key
80
+ vocoder wrap
253
81
  ```
254
82
 
255
- ### "No translatable strings found"
256
-
257
- Make sure you're using `<T>` components from `@vocoder/react`:
258
-
259
- ```tsx
260
- import { T } from '@vocoder/react';
83
+ Scans your JSX/TSX files for user-facing string literals and wraps them with the appropriate Vocoder translation markers. Uses AST analysis to detect strings that are likely user-facing (not keys, classnames, or internal identifiers).
261
84
 
262
- // ✅ Good
263
- <T>Welcome!</T>
85
+ **Options:**
264
86
 
265
- // Bad (not detected)
266
- <span>Welcome!</span>
267
- ```
87
+ | Flag | Description |
88
+ |---|---|
89
+ | `--include <pattern>` | Glob pattern(s) to include (repeatable) |
90
+ | `--exclude <pattern>` | Glob pattern(s) to exclude (repeatable) |
91
+ | `--dry-run` | Preview changes without modifying files |
92
+ | `--interactive` | Confirm each string interactively |
93
+ | `--confidence <level>` | Minimum confidence: `high`, `medium`, `low` (default: `high`) |
94
+ | `--verbose` | Detailed output |
268
95
 
269
- ### "Not a git repository"
96
+ ## Environment Variables
270
97
 
271
- The CLI auto-detects the branch from git. Either:
272
- - Initialize git: `git init`
273
- - Specify branch manually: `vocoder sync --branch main`
98
+ | Variable | Required | Description |
99
+ |---|---|---|
100
+ | `VOCODER_API_KEY` | Yes (for `sync`) | API key for authenticating with the Vocoder API |
101
+ | `VOCODER_API_URL` | No | Override API URL (default: `https://vocoder.app`) |
274
102
 
275
- ### "Skipping translations (not a target branch)"
103
+ The CLI reads `.env` files in the project root automatically.
276
104
 
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`
105
+ ## String Extraction
280
106
 
281
- ## Development
107
+ The CLI uses Babel to parse JSX/TSX files and extract strings from:
282
108
 
283
- ```bash
284
- # Install dependencies
285
- pnpm install
109
+ - `<T>` component children: `<T>Hello, world!</T>`
110
+ - `<T>` component `msg` prop: `<T msg="{count, plural, one {# item} other {# items}}" />`
111
+ - `t()` function calls: `t('Hello, world!')`
286
112
 
287
- # Build
288
- pnpm build
113
+ It tracks imports from `@vocoder/react` to ensure only Vocoder components are extracted (not unrelated components that happen to be named `T`).
289
114
 
290
- # Run tests
291
- pnpm test
115
+ Each extracted string includes:
116
+ - The source text (used as the translation key)
117
+ - File path and line number
118
+ - Optional `context` and `formality` props
292
119
 
293
- # Run unit tests only (fast)
294
- pnpm test:unit
120
+ ## Git Integration
295
121
 
296
- # Run integration tests (requires API)
297
- pnpm test:integration
122
+ The CLI auto-detects the repository and branch:
298
123
 
299
- # Watch mode
300
- pnpm test:watch
301
- ```
124
+ - **Repository:** Reads the git remote URL and normalizes it to a canonical format (`github:owner/repo`)
125
+ - **Branch:** Checks CI environment variables first (GitHub Actions, Vercel, Netlify, etc.), then falls back to reading `.git/HEAD`
126
+ - **Scope path:** For monorepos, computes the relative path from the git root to the working directory
302
127
 
303
128
  ## License
304
129