|
| 1 | +# CLAUDE.md |
| 2 | + |
| 3 | +This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository. |
| 4 | + |
| 5 | +## Project Overview |
| 6 | + |
| 7 | +loco-cli is a Node.js CLI tool for syncing translation assets between a project and Loco (localise.biz). Three main commands: `pull` (download translations), `push` (upload translations), `status` (show diff). |
| 8 | + |
| 9 | +## Common Commands |
| 10 | + |
| 11 | +```bash |
| 12 | +yarn build # TypeScript compilation to dist/ |
| 13 | +yarn test # Run all tests with vitest |
| 14 | +yarn lint # ESLint |
| 15 | +yarn format # Prettier write |
| 16 | +yarn format:check # Prettier check |
| 17 | +yarn loco-cli # Build and run the CLI locally for testing |
| 18 | +``` |
| 19 | + |
| 20 | +## Architecture |
| 21 | + |
| 22 | +``` |
| 23 | +cli.ts # Entry point, defines commands with commander |
| 24 | + ↓ |
| 25 | +src/commands/ # Command implementations (pull, push, status) |
| 26 | + ↓ |
| 27 | +src/lib/ # Core business logic |
| 28 | + ├── api.ts # Loco API interaction (fetch wrapper) |
| 29 | + ├── readFiles.ts # Read local JSON translation files |
| 30 | + ├── writeFiles.ts # Write local JSON translation files |
| 31 | + ├── diff.ts # Compare local vs remote translations |
| 32 | + └── dotObject.ts # Convert nested objects to dot-notation for API |
| 33 | + ↓ |
| 34 | +src/util/ # Helper utilities |
| 35 | + ├── config.ts # Load config via cosmiconfig |
| 36 | + ├── options.ts # Merge CLI options with config file |
| 37 | + ├── logger.ts # Colorized console output |
| 38 | + ├── print.ts # Format diff output |
| 39 | + ├── namespaces.ts # Split dot-notation back to nested objects |
| 40 | + └── handleAsyncErrors.ts # Error handling wrapper for commands |
| 41 | +``` |
| 42 | + |
| 43 | +## Key Data Flow |
| 44 | + |
| 45 | +All three commands follow similar pattern: |
| 46 | +1. `readFiles()` loads local JSON translations |
| 47 | +2. `apiPull()` fetches remote translations from Loco |
| 48 | +3. `diff()` compares the two sets |
| 49 | +4. Command-specific action (write files, push to API, or just print) |
| 50 | + |
| 51 | +## Translation File Formats |
| 52 | + |
| 53 | +**Without namespaces** (flat): |
| 54 | +``` |
| 55 | +locales/en.json, locales/es.json |
| 56 | +``` |
| 57 | + |
| 58 | +**With namespaces** (nested folders): |
| 59 | +``` |
| 60 | +locales/en/common.json, locales/en/home.json |
| 61 | +``` |
| 62 | + |
| 63 | +Nested JSON is flattened to dot-notation when communicating with Loco API. |
| 64 | + |
| 65 | +## Code Style |
| 66 | + |
| 67 | +- 2-space indent, 100 char width, single quotes, semicolons required |
| 68 | +- Arrow parens avoided (`x => x` not `(x) => x`) |
| 69 | +- No trailing commas |
| 70 | +- Prefer typed code over `any` |
| 71 | +- No barrel exports; use explicit imports from specific files |
0 commit comments