melaka 0.0.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.
Files changed (49) hide show
  1. package/CONTRIBUTING.md +347 -0
  2. package/LICENSE +21 -0
  3. package/README.md +57 -0
  4. package/docs/AI_PROVIDERS.md +343 -0
  5. package/docs/ARCHITECTURE.md +512 -0
  6. package/docs/CLI.md +438 -0
  7. package/docs/CONFIGURATION.md +453 -0
  8. package/docs/INTEGRATION.md +477 -0
  9. package/docs/ROADMAP.md +248 -0
  10. package/package.json +46 -0
  11. package/packages/ai/README.md +43 -0
  12. package/packages/ai/package.json +42 -0
  13. package/packages/ai/src/facade.ts +120 -0
  14. package/packages/ai/src/index.ts +34 -0
  15. package/packages/ai/src/prompt.ts +117 -0
  16. package/packages/ai/src/providers/gemini.ts +185 -0
  17. package/packages/ai/src/providers/index.ts +9 -0
  18. package/packages/ai/src/types.ts +134 -0
  19. package/packages/ai/tsconfig.json +19 -0
  20. package/packages/cli/README.md +70 -0
  21. package/packages/cli/package.json +44 -0
  22. package/packages/cli/src/cli.ts +30 -0
  23. package/packages/cli/src/commands/deploy.ts +115 -0
  24. package/packages/cli/src/commands/index.ts +9 -0
  25. package/packages/cli/src/commands/init.ts +107 -0
  26. package/packages/cli/src/commands/status.ts +73 -0
  27. package/packages/cli/src/commands/translate.ts +92 -0
  28. package/packages/cli/src/commands/validate.ts +69 -0
  29. package/packages/cli/tsconfig.json +19 -0
  30. package/packages/core/README.md +46 -0
  31. package/packages/core/package.json +50 -0
  32. package/packages/core/src/config.ts +241 -0
  33. package/packages/core/src/index.ts +111 -0
  34. package/packages/core/src/schema-generator.ts +263 -0
  35. package/packages/core/src/schemas.ts +126 -0
  36. package/packages/core/src/types.ts +481 -0
  37. package/packages/core/src/utils.ts +343 -0
  38. package/packages/core/tsconfig.json +19 -0
  39. package/packages/firestore/README.md +60 -0
  40. package/packages/firestore/package.json +48 -0
  41. package/packages/firestore/src/generator.ts +270 -0
  42. package/packages/firestore/src/i18n.ts +262 -0
  43. package/packages/firestore/src/index.ts +54 -0
  44. package/packages/firestore/src/processor.ts +245 -0
  45. package/packages/firestore/src/queue.ts +202 -0
  46. package/packages/firestore/src/task-handler.ts +164 -0
  47. package/packages/firestore/tsconfig.json +19 -0
  48. package/pnpm-workspace.yaml +2 -0
  49. package/turbo.json +31 -0
package/docs/CLI.md ADDED
@@ -0,0 +1,438 @@
1
+ # CLI Reference
2
+
3
+ Melaka provides a command-line interface for managing translations.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ # Global installation (recommended)
9
+ npm install -g melaka
10
+
11
+ # Or use npx
12
+ npx melaka <command>
13
+ ```
14
+
15
+ ---
16
+
17
+ ## Commands
18
+
19
+ ### `melaka init`
20
+
21
+ Initialize Melaka in your Firebase project.
22
+
23
+ ```bash
24
+ melaka init [options]
25
+ ```
26
+
27
+ **Options:**
28
+ | Option | Description |
29
+ |--------|-------------|
30
+ | `--typescript` | Generate TypeScript config (default) |
31
+ | `--javascript` | Generate JavaScript config |
32
+ | `--provider <name>` | AI provider: gemini, openai, claude |
33
+
34
+ **Example:**
35
+ ```bash
36
+ cd my-firebase-project
37
+ melaka init --provider gemini
38
+ ```
39
+
40
+ **Creates:**
41
+ - `melaka.config.ts` — Configuration file with example collections
42
+
43
+ ---
44
+
45
+ ### `melaka deploy`
46
+
47
+ Generate and deploy Firestore triggers for automatic translation.
48
+
49
+ ```bash
50
+ melaka deploy [options]
51
+ ```
52
+
53
+ **Options:**
54
+ | Option | Description |
55
+ |--------|-------------|
56
+ | `--dry-run` | Preview generated code without deploying |
57
+ | `--only <collections>` | Deploy triggers for specific collections |
58
+ | `--region <region>` | Override Firebase region |
59
+
60
+ **Example:**
61
+ ```bash
62
+ # Deploy all triggers
63
+ melaka deploy
64
+
65
+ # Preview without deploying
66
+ melaka deploy --dry-run
67
+
68
+ # Deploy specific collections
69
+ melaka deploy --only articles,products
70
+ ```
71
+
72
+ **Generated:**
73
+ - Firestore `onDocumentWritten` triggers for each collection
74
+ - Cloud Task handler for async translation processing
75
+
76
+ ---
77
+
78
+ ### `melaka translate`
79
+
80
+ Manually translate documents in a collection.
81
+
82
+ ```bash
83
+ melaka translate <collection> [options]
84
+ ```
85
+
86
+ **Arguments:**
87
+ | Argument | Description |
88
+ |----------|-------------|
89
+ | `collection` | Collection path to translate |
90
+
91
+ **Options:**
92
+ | Option | Description |
93
+ |--------|-------------|
94
+ | `--language <code>` | Target language (translates to all if omitted) |
95
+ | `--force` | Re-translate even if unchanged |
96
+ | `--batch-size <n>` | Documents per batch |
97
+ | `--dry-run` | Preview without translating |
98
+ | `--document <id>` | Translate single document |
99
+
100
+ **Examples:**
101
+ ```bash
102
+ # Translate all articles to all configured languages
103
+ melaka translate articles
104
+
105
+ # Translate to specific language
106
+ melaka translate articles --language ms-MY
107
+
108
+ # Force re-translation
109
+ melaka translate articles --force
110
+
111
+ # Translate single document
112
+ melaka translate articles --document article-123
113
+
114
+ # Preview translation
115
+ melaka translate articles --dry-run
116
+ ```
117
+
118
+ ---
119
+
120
+ ### `melaka status`
121
+
122
+ Check translation progress for collections.
123
+
124
+ ```bash
125
+ melaka status [collection] [options]
126
+ ```
127
+
128
+ **Arguments:**
129
+ | Argument | Description |
130
+ |----------|-------------|
131
+ | `collection` | Collection path (shows all if omitted) |
132
+
133
+ **Options:**
134
+ | Option | Description |
135
+ |--------|-------------|
136
+ | `--language <code>` | Filter by language |
137
+ | `--json` | Output as JSON |
138
+
139
+ **Examples:**
140
+ ```bash
141
+ # Status of all collections
142
+ melaka status
143
+
144
+ # Status of specific collection
145
+ melaka status articles
146
+
147
+ # Filter by language
148
+ melaka status articles --language ms-MY
149
+ ```
150
+
151
+ **Output:**
152
+ ```
153
+ Collection: articles
154
+ Language: ms-MY
155
+
156
+ Total Documents: 150
157
+ ├─ Completed: 142 (94.7%)
158
+ ├─ Failed: 3 (2.0%)
159
+ └─ Pending: 5 (3.3%)
160
+
161
+ Last Translation: 2 hours ago
162
+ ```
163
+
164
+ ---
165
+
166
+ ### `melaka retry`
167
+
168
+ Retry failed translations.
169
+
170
+ ```bash
171
+ melaka retry [collection] [options]
172
+ ```
173
+
174
+ **Arguments:**
175
+ | Argument | Description |
176
+ |----------|-------------|
177
+ | `collection` | Collection path (retries all if omitted) |
178
+
179
+ **Options:**
180
+ | Option | Description |
181
+ |--------|-------------|
182
+ | `--language <code>` | Filter by language |
183
+ | `--limit <n>` | Maximum documents to retry |
184
+
185
+ **Examples:**
186
+ ```bash
187
+ # Retry all failed translations
188
+ melaka retry
189
+
190
+ # Retry specific collection
191
+ melaka retry articles
192
+
193
+ # Retry with limit
194
+ melaka retry articles --limit 10
195
+ ```
196
+
197
+ ---
198
+
199
+ ### `melaka validate`
200
+
201
+ Validate your configuration file.
202
+
203
+ ```bash
204
+ melaka validate [options]
205
+ ```
206
+
207
+ **Options:**
208
+ | Option | Description |
209
+ |--------|-------------|
210
+ | `--config <path>` | Path to config file |
211
+
212
+ **Example:**
213
+ ```bash
214
+ melaka validate
215
+ ```
216
+
217
+ **Output:**
218
+ ```
219
+ ✓ Config file found: melaka.config.ts
220
+ ✓ Languages valid: ms-MY, zh-CN
221
+ ✓ AI provider configured: gemini
222
+ ✓ Collections configured: 3
223
+ ✓ Glossary entries: 15
224
+
225
+ Config is valid!
226
+ ```
227
+
228
+ ---
229
+
230
+ ### `melaka cleanup`
231
+
232
+ Remove old or outdated translations.
233
+
234
+ ```bash
235
+ melaka cleanup [collection] [options]
236
+ ```
237
+
238
+ **Arguments:**
239
+ | Argument | Description |
240
+ |----------|-------------|
241
+ | `collection` | Collection path (cleans all if omitted) |
242
+
243
+ **Options:**
244
+ | Option | Description |
245
+ |--------|-------------|
246
+ | `--days <n>` | Remove translations older than N days |
247
+ | `--failed-only` | Remove only failed translations |
248
+ | `--orphaned` | Remove translations for deleted source docs |
249
+ | `--dry-run` | Preview without deleting |
250
+
251
+ **Examples:**
252
+ ```bash
253
+ # Remove translations older than 30 days
254
+ melaka cleanup --days 30
255
+
256
+ # Remove failed translations only
257
+ melaka cleanup articles --failed-only
258
+
259
+ # Preview cleanup
260
+ melaka cleanup --orphaned --dry-run
261
+ ```
262
+
263
+ ---
264
+
265
+ ### `melaka export`
266
+
267
+ Export translations to files.
268
+
269
+ ```bash
270
+ melaka export <collection> [options]
271
+ ```
272
+
273
+ **Arguments:**
274
+ | Argument | Description |
275
+ |----------|-------------|
276
+ | `collection` | Collection path to export |
277
+
278
+ **Options:**
279
+ | Option | Description |
280
+ |--------|-------------|
281
+ | `--language <code>` | Language to export |
282
+ | `--format <type>` | Output format: json, csv |
283
+ | `--output <path>` | Output file path |
284
+
285
+ **Examples:**
286
+ ```bash
287
+ # Export to JSON
288
+ melaka export articles --language ms-MY --output translations.json
289
+
290
+ # Export to CSV
291
+ melaka export articles --format csv --output translations.csv
292
+ ```
293
+
294
+ ---
295
+
296
+ ### `melaka import`
297
+
298
+ Import translations from files (for human-reviewed content).
299
+
300
+ ```bash
301
+ melaka import <collection> <file> [options]
302
+ ```
303
+
304
+ **Arguments:**
305
+ | Argument | Description |
306
+ |----------|-------------|
307
+ | `collection` | Collection path to import into |
308
+ | `file` | Input file path |
309
+
310
+ **Options:**
311
+ | Option | Description |
312
+ |--------|-------------|
313
+ | `--language <code>` | Target language |
314
+ | `--mark-reviewed` | Mark imported as reviewed |
315
+ | `--dry-run` | Preview without importing |
316
+
317
+ **Examples:**
318
+ ```bash
319
+ # Import reviewed translations
320
+ melaka import articles translations.json --language ms-MY --mark-reviewed
321
+
322
+ # Preview import
323
+ melaka import articles translations.json --dry-run
324
+ ```
325
+
326
+ ---
327
+
328
+ ## Global Options
329
+
330
+ These options work with any command:
331
+
332
+ | Option | Description |
333
+ |--------|-------------|
334
+ | `--config <path>` | Path to config file |
335
+ | `--project <id>` | Firebase project ID |
336
+ | `--help` | Show help |
337
+ | `--version` | Show version |
338
+ | `--verbose` | Verbose output |
339
+ | `--quiet` | Minimal output |
340
+
341
+ ---
342
+
343
+ ## Environment Variables
344
+
345
+ | Variable | Description |
346
+ |----------|-------------|
347
+ | `MELAKA_CONFIG` | Path to config file |
348
+ | `FIREBASE_PROJECT` | Firebase project ID |
349
+ | `GEMINI_API_KEY` | Gemini API key |
350
+ | `OPENAI_API_KEY` | OpenAI API key |
351
+ | `ANTHROPIC_API_KEY` | Anthropic API key |
352
+
353
+ ---
354
+
355
+ ## Exit Codes
356
+
357
+ | Code | Description |
358
+ |------|-------------|
359
+ | `0` | Success |
360
+ | `1` | General error |
361
+ | `2` | Config error |
362
+ | `3` | Firebase error |
363
+ | `4` | Translation error |
364
+
365
+ ---
366
+
367
+ ## Examples
368
+
369
+ ### Complete Workflow
370
+
371
+ ```bash
372
+ # 1. Initialize project
373
+ cd my-firebase-project
374
+ melaka init --provider gemini
375
+
376
+ # 2. Edit configuration
377
+ vim melaka.config.ts
378
+
379
+ # 3. Validate config
380
+ melaka validate
381
+
382
+ # 4. Deploy triggers
383
+ melaka deploy
384
+
385
+ # 5. Run initial translation
386
+ melaka translate --all
387
+
388
+ # 6. Check progress
389
+ melaka status
390
+
391
+ # 7. Retry any failures
392
+ melaka retry
393
+ ```
394
+
395
+ ### CI/CD Integration
396
+
397
+ ```yaml
398
+ # .github/workflows/deploy.yml
399
+ name: Deploy Translations
400
+
401
+ on:
402
+ push:
403
+ branches: [main]
404
+
405
+ jobs:
406
+ deploy:
407
+ runs-on: ubuntu-latest
408
+ steps:
409
+ - uses: actions/checkout@v3
410
+
411
+ - name: Setup Node
412
+ uses: actions/setup-node@v3
413
+ with:
414
+ node-version: '18'
415
+
416
+ - name: Install dependencies
417
+ run: npm ci
418
+
419
+ - name: Install Melaka
420
+ run: npm install -g melaka
421
+
422
+ - name: Validate config
423
+ run: melaka validate
424
+
425
+ - name: Deploy triggers
426
+ run: melaka deploy
427
+ env:
428
+ FIREBASE_PROJECT: ${{ secrets.FIREBASE_PROJECT }}
429
+ GOOGLE_APPLICATION_CREDENTIALS: ${{ secrets.GCP_SA_KEY }}
430
+ ```
431
+
432
+ ---
433
+
434
+ ## Next Steps
435
+
436
+ - [Configuration](./CONFIGURATION.md) — Config file reference
437
+ - [AI Providers](./AI_PROVIDERS.md) — Provider-specific setup
438
+ - [Architecture](./ARCHITECTURE.md) — System design