@vocoder/cli 0.1.3 → 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,127 +1,130 @@
1
1
  # @vocoder/cli
2
2
 
3
- CLI for Vocoder translation workflows.
3
+ Command-line tool for Vocoder. Handles project setup, string extraction from source code, and translation synchronization.
4
4
 
5
- Commands:
6
-
7
- - `vocoder init`
8
- - `vocoder sync`
9
- - `vocoder wrap`
10
-
11
- ## Install
5
+ ## Installation
12
6
 
13
7
  ```bash
14
- pnpm add -D @vocoder/cli
8
+ npm install -g @vocoder/cli
15
9
  ```
16
10
 
17
- ## `vocoder sync`
18
-
19
- Extracts translatable strings, sends them to Vocoder, then generates runtime artifacts for `@vocoder/react`.
11
+ Or use directly with npx:
20
12
 
21
- Generated output:
22
-
23
- `node_modules/@vocoder/generated`
13
+ ```bash
14
+ npx vocoder <command>
15
+ ```
24
16
 
25
- Includes:
17
+ ## Commands
26
18
 
27
- - `manifest.mjs`
28
- - `manifest.cjs`
29
- - `<locale>.js` files
30
- - `package.json` exports map
19
+ ### `vocoder init`
31
20
 
32
- ### Typical usage
21
+ Connect your repository to Vocoder.
33
22
 
34
23
  ```bash
35
- pnpm exec vocoder sync
24
+ vocoder init
36
25
  ```
37
26
 
38
- Add to build pipeline:
39
-
40
- ```json
41
- {
42
- "scripts": {
43
- "prebuild": "pnpm exec vocoder sync",
44
- "build": "next build"
45
- }
46
- }
47
- ```
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.
48
28
 
49
- ### Options
29
+ **Options:**
50
30
 
51
- - `--include <pattern>` (repeatable)
52
- - `--exclude <pattern>` (repeatable)
53
- - `--branch <name>`
54
- - `--force`
55
- - `--dry-run`
56
- - `--verbose`
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`) |
57
38
 
58
- ## `vocoder wrap`
39
+ ### `vocoder sync`
59
40
 
60
- Scans source files and wraps likely user-facing strings with `<T>` / `t()` patterns.
41
+ Extract translatable strings from your source code and push them to Vocoder for translation.
61
42
 
62
43
  ```bash
63
- pnpm exec vocoder wrap
44
+ vocoder sync
64
45
  ```
65
46
 
66
- Options:
47
+ This command:
48
+
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)
67
54
 
68
- - `--include <pattern>` (repeatable)
69
- - `--exclude <pattern>` (repeatable)
70
- - `--dry-run`
71
- - `--interactive`
72
- - `--confidence <high|medium|low>`
73
- - `--verbose`
55
+ **Options:**
74
56
 
75
- ## Configuration
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 |
76
68
 
77
- Config priority:
69
+ #### Sync Modes
78
70
 
79
- 1. CLI flags
80
- 2. environment variables
81
- 3. defaults
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.
82
74
 
83
- ### Environment variables
75
+ ### `vocoder wrap`
76
+
77
+ Automatically wrap string literals in your source code with `<T>` and `t()`.
84
78
 
85
79
  ```bash
86
- VOCODER_API_KEY=vc_xxx
87
- VOCODER_API_URL=https://vocoder.app
88
- VOCODER_EXTRACTION_PATTERN=src/**/*.{tsx,jsx,ts,js}
80
+ vocoder wrap
89
81
  ```
90
82
 
91
- `VOCODER_API_KEY` must come from the environment.
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).
92
84
 
93
- ## `vocoder init`
85
+ **Options:**
94
86
 
95
- Bootstraps a project by opening a browser authorization flow, then provisioning
96
- a workspace/project API key.
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 |
97
95
 
98
- During browser completion, you can paste a DeepL API key (BYOK) or reuse an
99
- existing org-level DeepL key.
96
+ ## Environment Variables
100
97
 
101
- ```bash
102
- pnpm exec vocoder init
103
- ```
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`) |
104
102
 
105
- ## Troubleshooting
103
+ The CLI reads `.env` files in the project root automatically.
106
104
 
107
- ### `VOCODER_API_KEY is required`
105
+ ## String Extraction
108
106
 
109
- Set `VOCODER_API_KEY` in `.env` or your environment.
107
+ The CLI uses Babel to parse JSX/TSX files and extract strings from:
110
108
 
111
- ### No strings found
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!')`
112
112
 
113
- Use `<T>` (from `@vocoder/react`) around translatable JSX text.
113
+ It tracks imports from `@vocoder/react` to ensure only Vocoder components are extracted (not unrelated components that happen to be named `T`).
114
114
 
115
- ### Wrong branch / skipped sync
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
116
119
 
117
- Use:
120
+ ## Git Integration
118
121
 
119
- ```bash
120
- pnpm exec vocoder sync --branch main
121
- ```
122
+ The CLI auto-detects the repository and branch:
122
123
 
123
- or force:
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
124
127
 
125
- ```bash
126
- pnpm exec vocoder sync --force
127
- ```
128
+ ## License
129
+
130
+ MIT