@kopynator/cli 1.5.1 → 1.6.1
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/.ai-metrics/accumulated.master.jsonl +1 -0
- package/README.md +187 -13
- package/dist/index.js +322 -101
- package/package.json +1 -1
- package/src/commands/check.ts +118 -10
- package/src/commands/limits.ts +1 -1
- package/src/commands/sync.ts +4 -51
- package/src/commands/upload.ts +1 -1
- package/src/index.ts +6 -3
- package/src/lib/i18n-guardian.ts +190 -0
- package/src/lib/project.ts +60 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"ts":"2026-07-08T18:08:50.183Z","session":"ea6cfebf-3920-4f0f-b274-376907231052","source":"claude-code","branch":"master","model":"claude-opus-4-8","category":"chat","tokens_in":564,"tokens_out":6806,"cache_read_delta":1318530,"cache_creation_delta":159049,"lines_added":0,"lines_removed":0,"cost_input":0.001692,"cost_output":0.10209,"cost_cache_read":0.395559,"cost_cache_write":0.596434}
|
package/README.md
CHANGED
|
@@ -3,7 +3,13 @@
|
|
|
3
3
|
The official Command Line Interface for [Kopynator](https://kopynator.com).
|
|
4
4
|
Manage your internationalization workflow directly from your terminal.
|
|
5
5
|
|
|
6
|
-
|
|
6
|
+
**Languages / Idiomas:** [English](#english) · [Español](#español)
|
|
7
|
+
|
|
8
|
+
---
|
|
9
|
+
|
|
10
|
+
## English
|
|
11
|
+
|
|
12
|
+
### Installation
|
|
7
13
|
|
|
8
14
|
You don't need to install it globally! We recommend using `npx` for the latest version:
|
|
9
15
|
|
|
@@ -17,33 +23,67 @@ If you prefer a global installation:
|
|
|
17
23
|
npm install -g @kopynator/cli
|
|
18
24
|
```
|
|
19
25
|
|
|
20
|
-
|
|
26
|
+
### Commands
|
|
21
27
|
|
|
22
|
-
|
|
23
|
-
|
|
28
|
+
| Command | What it does |
|
|
29
|
+
| --- | --- |
|
|
30
|
+
| [`init`](#1-init) | Sets up Kopynator in your project (framework detection, config injection). |
|
|
31
|
+
| [`check`](#2-check) | Validates local translation files: JSON syntax, broken references, duplicate global keys. |
|
|
32
|
+
| [`sync`](#3-sync) | Downloads translations from Kopynator Cloud into local JSON files. |
|
|
33
|
+
| [`upload`](#4-upload) | Uploads a local JSON file to Kopynator Cloud. |
|
|
34
|
+
| [`limits`](#5-limits) | Shows your plan's limits and current usage. |
|
|
35
|
+
| [`help`](#6-help) | Prints help for all commands. |
|
|
36
|
+
|
|
37
|
+
#### 1. `init`
|
|
38
|
+
Sets up Kopynator in your project. Auto-detects your framework (Angular, React, Vue, React Native, Ionic) and either injects `provideKopynator(...)` directly into your app config, or falls back to creating a `kopynator.config.json` file. Interactively asks for your default locale and supported languages.
|
|
24
39
|
|
|
25
40
|
```bash
|
|
26
41
|
npx -y @kopynator/cli init
|
|
27
42
|
```
|
|
28
43
|
|
|
29
|
-
|
|
30
|
-
Validates your local
|
|
44
|
+
#### 2. `check`
|
|
45
|
+
Validates your local translation files. Three things, in order:
|
|
46
|
+
|
|
47
|
+
1. **JSON syntax** — every locale file must parse.
|
|
48
|
+
2. **Broken references** — translation keys used in your source code (`| kopy`, `[kopy]="'...'"`, `.translate()`/`.t()`) that don't exist in *any* locale file.
|
|
49
|
+
3. **Duplicate global keys** — keys whose value duplicates an existing `global.*` key, so your team converges on one canonical key instead of silently drifting into copies.
|
|
50
|
+
|
|
51
|
+
Useful for CI/CD pipelines and pre-commit hooks — it exits with a non-zero code on failure.
|
|
31
52
|
|
|
32
53
|
```bash
|
|
33
54
|
npx -y @kopynator/cli check
|
|
34
55
|
```
|
|
35
56
|
|
|
36
|
-
|
|
37
|
-
|
|
57
|
+
Flags:
|
|
58
|
+
- `--base-ref <ref>` — git ref to diff against when deciding which duplicate keys are *new* (default: `master`). Duplicates that already existed at that ref aren't re-flagged, so adopting `check` doesn't force you to clean up all pre-existing debt at once.
|
|
59
|
+
- `--update-baseline` — accepts every currently-missing key as backlog, writing `kopynator.i18n-baseline.json`. From then on, `check` only fails on keys that go missing *after* that point.
|
|
60
|
+
- `--all` — lists every missing key (baseline + new), tagging which ones are already accepted.
|
|
61
|
+
|
|
62
|
+
Two optional project-root config files:
|
|
63
|
+
- `kopynator.i18n-baseline.json` — `{ "keys": [...] }`, written automatically by `--update-baseline`.
|
|
64
|
+
- `kopynator.i18n-safelist.json` — `{ "dynamicPrefixes": ["status."] }`. Protects key families built dynamically at runtime (e.g. `` `status.${s}` ``) from being flagged as missing. You can also declare a prefix inline, right next to the code that uses it, with a comment: `// kopynator-keys: status.*`.
|
|
65
|
+
|
|
66
|
+
Set `KOPYNATOR_I18N_SKIP=1` to bypass the check entirely (e.g. an emergency commit).
|
|
67
|
+
|
|
68
|
+
```bash
|
|
69
|
+
# CI example: only fail on regressions since main
|
|
70
|
+
npx -y @kopynator/cli check --base-ref origin/main
|
|
71
|
+
|
|
72
|
+
# Adopt the check on a legacy project without a big-bang cleanup
|
|
73
|
+
npx -y @kopynator/cli check --update-baseline
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
#### 3. `sync`
|
|
77
|
+
Downloads translations from the Kopynator Cloud and saves them as local JSON files (e.g. `src/assets/i18n/en.json`). On first run it asks how you want the output formatted (nested vs. flat keys, pretty-print, indentation) and remembers your choice in `kopynator.sync.config.json`.
|
|
38
78
|
|
|
39
79
|
```bash
|
|
40
80
|
npx -y @kopynator/cli sync
|
|
41
81
|
```
|
|
42
82
|
|
|
43
|
-
|
|
44
|
-
Uploads a JSON translation file to the Kopynator Cloud. Keys are merged/updated for the given language.
|
|
83
|
+
#### 4. `upload`
|
|
84
|
+
Uploads a JSON translation file to the Kopynator Cloud. Keys are merged/updated for the given language. Uses the same API key (token) as your app or `kopynator.config.json`.
|
|
45
85
|
|
|
46
|
-
**Project:**
|
|
86
|
+
**Project:** the target project is determined by the token. Each token is linked to one project when created in [Dashboard → Settings → Tokens](https://www.kopynator.com/dashboard/settings/tokens). To upload to a different project, use that project's token.
|
|
47
87
|
|
|
48
88
|
```bash
|
|
49
89
|
# Language inferred from filename (es.json → es)
|
|
@@ -55,8 +95,140 @@ npx -y @kopynator/cli upload --file=locales/en.json --lang=en
|
|
|
55
95
|
|
|
56
96
|
After uploading, run `sync` to download the latest state from the cloud if needed.
|
|
57
97
|
|
|
58
|
-
|
|
59
|
-
|
|
98
|
+
#### 5. `limits`
|
|
99
|
+
Shows your current plan, and per-organization limits and usage (projects, translation keys, members). Reads the same API key resolution as `sync`/`upload` (`kopynator.config.json`, `app.config.ts`/`app.module.ts`, or `KOPYNATOR_API_KEY`).
|
|
100
|
+
|
|
101
|
+
```bash
|
|
102
|
+
npx -y @kopynator/cli limits
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
#### 6. `help`
|
|
106
|
+
Prints help for every command.
|
|
107
|
+
|
|
108
|
+
```bash
|
|
109
|
+
npx -y @kopynator/cli help
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
### Configuration
|
|
113
|
+
The `init` command creates a `kopynator.config.json` file in your root (used as a fallback when it can't inject config directly into your app):
|
|
114
|
+
|
|
115
|
+
```json
|
|
116
|
+
{
|
|
117
|
+
"apiKey": "YOUR_API_KEY",
|
|
118
|
+
"defaultLocale": "en",
|
|
119
|
+
"languages": ["en", "es"],
|
|
120
|
+
"mode": "local"
|
|
121
|
+
}
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
For CI environments without a config file, set `KOPYNATOR_API_KEY` (and optionally `KOPYNATOR_BASE_URL`) instead.
|
|
125
|
+
|
|
126
|
+
---
|
|
127
|
+
|
|
128
|
+
## Español
|
|
129
|
+
|
|
130
|
+
### Instalación
|
|
131
|
+
|
|
132
|
+
No hace falta instalarlo globalmente. Recomendamos usar `npx` para tener siempre la última versión:
|
|
133
|
+
|
|
134
|
+
```bash
|
|
135
|
+
npx -y @kopynator/cli <comando>
|
|
136
|
+
```
|
|
137
|
+
|
|
138
|
+
Si prefieres instalarlo de forma global:
|
|
139
|
+
|
|
140
|
+
```bash
|
|
141
|
+
npm install -g @kopynator/cli
|
|
142
|
+
```
|
|
143
|
+
|
|
144
|
+
### Comandos
|
|
145
|
+
|
|
146
|
+
| Comando | Qué hace |
|
|
147
|
+
| --- | --- |
|
|
148
|
+
| [`init`](#1-init-1) | Configura Kopynator en tu proyecto (detecta el framework e inyecta la configuración). |
|
|
149
|
+
| [`check`](#2-check-1) | Valida los ficheros de traducción locales: sintaxis JSON, referencias rotas, claves globales duplicadas. |
|
|
150
|
+
| [`sync`](#3-sync-1) | Descarga las traducciones de Kopynator Cloud a ficheros JSON locales. |
|
|
151
|
+
| [`upload`](#4-upload-1) | Sube un fichero JSON local a Kopynator Cloud. |
|
|
152
|
+
| [`limits`](#5-limits-1) | Muestra los límites de tu plan y el uso actual. |
|
|
153
|
+
| [`help`](#6-help-1) | Muestra la ayuda de todos los comandos. |
|
|
154
|
+
|
|
155
|
+
#### 1. `init`
|
|
156
|
+
Configura Kopynator en tu proyecto. Detecta automáticamente el framework (Angular, React, Vue, React Native, Ionic) e inyecta `provideKopynator(...)` directamente en la configuración de tu app, o crea un `kopynator.config.json` si no puede hacerlo. Te pregunta interactivamente el idioma por defecto y los idiomas que quieres soportar.
|
|
157
|
+
|
|
158
|
+
```bash
|
|
159
|
+
npx -y @kopynator/cli init
|
|
160
|
+
```
|
|
161
|
+
|
|
162
|
+
#### 2. `check`
|
|
163
|
+
Valida tus ficheros de traducción locales. Comprueba tres cosas, en este orden:
|
|
164
|
+
|
|
165
|
+
1. **Sintaxis JSON** — todos los ficheros de idioma deben parsear correctamente.
|
|
166
|
+
2. **Referencias rotas** — claves de traducción usadas en tu código (`| kopy`, `[kopy]="'...'"`, `.translate()`/`.t()`) que no existen en *ningún* fichero de idioma.
|
|
167
|
+
3. **Claves globales duplicadas** — claves cuyo valor duplica el de una clave `global.*` ya existente, para que el equipo converja en una única clave canónica en vez de ir creando copias sin darse cuenta.
|
|
168
|
+
|
|
169
|
+
Útil en pipelines de CI/CD y hooks de pre-commit — termina con código de salida distinto de cero si falla.
|
|
170
|
+
|
|
171
|
+
```bash
|
|
172
|
+
npx -y @kopynator/cli check
|
|
173
|
+
```
|
|
174
|
+
|
|
175
|
+
Flags:
|
|
176
|
+
- `--base-ref <ref>` — referencia git contra la que comparar para decidir qué claves duplicadas son *nuevas* (por defecto: `master`). Los duplicados que ya existían en esa referencia no se vuelven a marcar, así que adoptar `check` no obliga a limpiar toda la deuda existente de golpe.
|
|
177
|
+
- `--update-baseline` — acepta todas las claves actualmente rotas como deuda pendiente, escribiendo `kopynator.i18n-baseline.json`. A partir de ahí, `check` solo falla con claves que se rompan *después* de ese punto.
|
|
178
|
+
- `--all` — lista todas las claves rotas (aceptadas + nuevas), indicando cuáles ya están aceptadas.
|
|
179
|
+
|
|
180
|
+
Dos ficheros de configuración opcionales en la raíz del proyecto:
|
|
181
|
+
- `kopynator.i18n-baseline.json` — `{ "keys": [...] }`, se escribe automáticamente con `--update-baseline`.
|
|
182
|
+
- `kopynator.i18n-safelist.json` — `{ "dynamicPrefixes": ["status."] }`. Protege familias de claves construidas dinámicamente en tiempo de ejecución (p. ej. `` `status.${s}` ``) para que no se marquen como rotas. También puedes declarar un prefijo en línea, junto al código que lo usa, con un comentario: `// kopynator-keys: status.*`.
|
|
183
|
+
|
|
184
|
+
Define `KOPYNATOR_I18N_SKIP=1` para saltarte el check por completo (p. ej. un commit de emergencia).
|
|
185
|
+
|
|
186
|
+
```bash
|
|
187
|
+
# Ejemplo de CI: solo falla con regresiones desde main
|
|
188
|
+
npx -y @kopynator/cli check --base-ref origin/main
|
|
189
|
+
|
|
190
|
+
# Adoptar el check en un proyecto legacy sin limpieza masiva previa
|
|
191
|
+
npx -y @kopynator/cli check --update-baseline
|
|
192
|
+
```
|
|
193
|
+
|
|
194
|
+
#### 3. `sync`
|
|
195
|
+
Descarga las traducciones de Kopynator Cloud y las guarda como ficheros JSON locales (p. ej. `src/assets/i18n/en.json`). La primera vez te pregunta cómo quieres el formato de salida (claves anidadas o planas, formato legible, indentación) y recuerda tu elección en `kopynator.sync.config.json`.
|
|
196
|
+
|
|
197
|
+
```bash
|
|
198
|
+
npx -y @kopynator/cli sync
|
|
199
|
+
```
|
|
200
|
+
|
|
201
|
+
#### 4. `upload`
|
|
202
|
+
Sube un fichero JSON de traducción a Kopynator Cloud. Las claves se fusionan/actualizan para el idioma indicado. Usa la misma API key (token) que tu app o `kopynator.config.json`.
|
|
203
|
+
|
|
204
|
+
**Proyecto:** el proyecto de destino lo determina el token. Cada token está vinculado a un proyecto al crearse en [Dashboard → Settings → Tokens](https://www.kopynator.com/dashboard/settings/tokens). Para subir a otro proyecto, usa el token de ese proyecto.
|
|
205
|
+
|
|
206
|
+
```bash
|
|
207
|
+
# Idioma inferido del nombre del fichero (es.json → es)
|
|
208
|
+
npx -y @kopynator/cli upload --file=src/assets/i18n/es.json
|
|
209
|
+
|
|
210
|
+
# Idioma explícito
|
|
211
|
+
npx -y @kopynator/cli upload --file=locales/en.json --lang=en
|
|
212
|
+
```
|
|
213
|
+
|
|
214
|
+
Después de subir, ejecuta `sync` si necesitas descargar el estado más reciente de la nube.
|
|
215
|
+
|
|
216
|
+
#### 5. `limits`
|
|
217
|
+
Muestra tu plan actual y los límites y uso por organización (proyectos, claves de traducción, miembros). Resuelve la API key igual que `sync`/`upload` (`kopynator.config.json`, `app.config.ts`/`app.module.ts`, o `KOPYNATOR_API_KEY`).
|
|
218
|
+
|
|
219
|
+
```bash
|
|
220
|
+
npx -y @kopynator/cli limits
|
|
221
|
+
```
|
|
222
|
+
|
|
223
|
+
#### 6. `help`
|
|
224
|
+
Muestra la ayuda de todos los comandos.
|
|
225
|
+
|
|
226
|
+
```bash
|
|
227
|
+
npx -y @kopynator/cli help
|
|
228
|
+
```
|
|
229
|
+
|
|
230
|
+
### Configuración
|
|
231
|
+
El comando `init` crea un fichero `kopynator.config.json` en la raíz (se usa como alternativa cuando no puede inyectar la configuración directamente en tu app):
|
|
60
232
|
|
|
61
233
|
```json
|
|
62
234
|
{
|
|
@@ -66,3 +238,5 @@ The `init` command creates a `kopynator.config.json` file in your root:
|
|
|
66
238
|
"mode": "local"
|
|
67
239
|
}
|
|
68
240
|
```
|
|
241
|
+
|
|
242
|
+
Para entornos de CI sin fichero de configuración, define `KOPYNATOR_API_KEY` (y opcionalmente `KOPYNATOR_BASE_URL`).
|