i18nsmith 0.4.3 → 0.6.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.
- package/README.md +126 -0
- package/build.mjs +5 -0
- package/dist/commands/backup.d.ts.map +1 -1
- package/dist/commands/check.d.ts.map +1 -1
- package/dist/commands/config.d.ts.map +1 -1
- package/dist/commands/coverage.d.ts.map +1 -1
- package/dist/commands/detect.d.ts.map +1 -1
- package/dist/commands/diagnose.d.ts.map +1 -1
- package/dist/commands/init.d.ts.map +1 -1
- package/dist/commands/rename.d.ts.map +1 -1
- package/dist/commands/review.d.ts.map +1 -1
- package/dist/commands/scaffold-adapter.d.ts.map +1 -1
- package/dist/commands/scan.d.ts.map +1 -1
- package/dist/commands/sync.d.ts.map +1 -1
- package/dist/commands/transform.d.ts.map +1 -1
- package/dist/index.cjs +13069 -6794
- package/dist/services/index.d.ts +12 -0
- package/dist/services/index.d.ts.map +1 -0
- package/dist/services/transform-service.d.ts +64 -0
- package/dist/services/transform-service.d.ts.map +1 -0
- package/dist/utils/bootstrap.d.ts +83 -0
- package/dist/utils/bootstrap.d.ts.map +1 -0
- package/package.json +1 -1
- package/src/commands/backup.ts +28 -10
- package/src/commands/check.ts +16 -4
- package/src/commands/config.ts +126 -0
- package/src/commands/coverage.ts +11 -4
- package/src/commands/detect.ts +11 -4
- package/src/commands/diagnose.ts +12 -2
- package/src/commands/init.test.ts +80 -0
- package/src/commands/init.ts +92 -49
- package/src/commands/rename.ts +24 -5
- package/src/commands/review.ts +10 -3
- package/src/commands/scaffold-adapter.ts +11 -2
- package/src/commands/scan.ts +20 -7
- package/src/commands/sync.ts +91 -23
- package/src/commands/transform.ts +8 -1
- package/src/index.ts +1 -1
- package/src/integration.test.ts +145 -12
- package/src/services/index.ts +12 -0
- package/src/services/transform-service.ts +203 -0
- package/src/utils/bootstrap.ts +221 -0
package/README.md
ADDED
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
# i18nsmith CLI
|
|
2
|
+
|
|
3
|
+
Command-line interface for i18nsmith - universal automated i18n.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install -g i18nsmith
|
|
9
|
+
# or
|
|
10
|
+
pnpm add -g i18nsmith
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## Quick Start
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
# Initialize project
|
|
17
|
+
i18nsmith init
|
|
18
|
+
|
|
19
|
+
# Scan for translation candidates
|
|
20
|
+
i18nsmith scan
|
|
21
|
+
|
|
22
|
+
# Sync locale files with code
|
|
23
|
+
i18nsmith sync
|
|
24
|
+
|
|
25
|
+
# Run health checks
|
|
26
|
+
i18nsmith check
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
## Commands
|
|
30
|
+
|
|
31
|
+
| Command | Description |
|
|
32
|
+
|---------|-------------|
|
|
33
|
+
| `init` | Initialize i18n configuration |
|
|
34
|
+
| `scan` | Scan source files for hardcoded text |
|
|
35
|
+
| `sync` | Synchronize locale files with code references |
|
|
36
|
+
| `check` | Run validation checks on locales |
|
|
37
|
+
| `transform` | Transform hardcoded strings to i18n calls |
|
|
38
|
+
| `rename` | Rename translation keys |
|
|
39
|
+
| `diagnose` | Generate diagnostic report |
|
|
40
|
+
| `backup` | Backup/restore locale files |
|
|
41
|
+
| `detect` | Auto-detect project configuration |
|
|
42
|
+
| `review` | Review borderline candidates interactively |
|
|
43
|
+
| `translate` | Translate using external services |
|
|
44
|
+
| `coverage` | Show translation coverage stats |
|
|
45
|
+
| `preflight` | Validate setup before operations |
|
|
46
|
+
| `scaffold-adapter` | Scaffold translation adapter files |
|
|
47
|
+
|
|
48
|
+
## Architecture
|
|
49
|
+
|
|
50
|
+
The CLI follows **Hexagonal Architecture** principles. Commands use `ServiceContainer` for dependency injection:
|
|
51
|
+
|
|
52
|
+
```typescript
|
|
53
|
+
import { getServiceContainer } from '../utils/bootstrap.js';
|
|
54
|
+
import { CliError, withErrorHandling } from '../utils/errors.js';
|
|
55
|
+
|
|
56
|
+
export function registerMyCommand(program: Command) {
|
|
57
|
+
program
|
|
58
|
+
.command('my-command')
|
|
59
|
+
.action(withErrorHandling(async (options) => {
|
|
60
|
+
const { config, projectRoot } = await loadConfigWithMeta(options.config);
|
|
61
|
+
const container = getServiceContainer({ workspaceRoot: projectRoot });
|
|
62
|
+
|
|
63
|
+
const result = await container.scanner.scan(config);
|
|
64
|
+
if (!result.success) {
|
|
65
|
+
throw new CliError(result.error.message);
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
// Use result.data
|
|
69
|
+
}));
|
|
70
|
+
}
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
### Service Container
|
|
74
|
+
|
|
75
|
+
The CLI bootstrap (`src/utils/bootstrap.ts`) configures:
|
|
76
|
+
|
|
77
|
+
- `NodeFileSystem` - Node.js file operations
|
|
78
|
+
- `CliLoggerFactory` - Console logging with chalk formatting
|
|
79
|
+
|
|
80
|
+
### Commands Using ServiceContainer
|
|
81
|
+
|
|
82
|
+
| Command | Services Used |
|
|
83
|
+
|---------|--------------|
|
|
84
|
+
| `scan` | `scanner` |
|
|
85
|
+
| `sync` | `keyRenamer` |
|
|
86
|
+
| `check` | `check` |
|
|
87
|
+
| `diagnose` | `diagnostics` |
|
|
88
|
+
| `detect` | `projectIntelligence` |
|
|
89
|
+
| `backup` | `backup` |
|
|
90
|
+
| `rename` | `keyRenamer` |
|
|
91
|
+
| `coverage` | `diagnostics` |
|
|
92
|
+
| `init` | `scanner`, `keyGenerator`, `projectIntelligence` |
|
|
93
|
+
| `review` | `scanner` |
|
|
94
|
+
| `scaffold-adapter` | `diagnostics` |
|
|
95
|
+
|
|
96
|
+
## Development
|
|
97
|
+
|
|
98
|
+
```bash
|
|
99
|
+
# Build
|
|
100
|
+
pnpm build
|
|
101
|
+
|
|
102
|
+
# Test
|
|
103
|
+
pnpm test
|
|
104
|
+
|
|
105
|
+
# Run locally
|
|
106
|
+
node dist/index.js <command>
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
## Adding New Commands
|
|
110
|
+
|
|
111
|
+
1. Create command in `src/commands/my-command.ts`
|
|
112
|
+
2. Use `getServiceContainer()` for service access
|
|
113
|
+
3. Handle `Result<T>` pattern for error handling
|
|
114
|
+
4. Register in `src/index.ts`
|
|
115
|
+
|
|
116
|
+
See [CONTRIBUTING.md](../../CONTRIBUTING.md) for detailed patterns.
|
|
117
|
+
|
|
118
|
+
## Related Documentation
|
|
119
|
+
|
|
120
|
+
| Document | Purpose |
|
|
121
|
+
|----------|---------|
|
|
122
|
+
| [ARCHITECTURE.md](../../ARCHITECTURE.md) | System architecture, Hexagonal pattern |
|
|
123
|
+
| [CONTRIBUTING.md](../../CONTRIBUTING.md) | Contribution guidelines |
|
|
124
|
+
| [docs/schema.md](../../docs/schema.md) | Configuration schema reference |
|
|
125
|
+
| [docs/best-practices.md](../../docs/best-practices.md) | Usage best practices |
|
|
126
|
+
| [@i18nsmith/core README](../core/README.md) | Core library documentation |
|
package/build.mjs
CHANGED
|
@@ -17,6 +17,11 @@ console.log('Bundling CLI as a single, self-contained CommonJS file (no external
|
|
|
17
17
|
|
|
18
18
|
// Produce a single CommonJS bundle so `npx`/npm-installed binaries run consistently
|
|
19
19
|
// (some deps perform dynamic require() calls which fail under ESM bundles).
|
|
20
|
+
// Run a static check to prevent accidentally introducing top-level await in
|
|
21
|
+
// packages that are bundled into the CJS CLI. Top-level await breaks esbuild
|
|
22
|
+
// when producing `format: 'cjs'` bundles.
|
|
23
|
+
await import('../../scripts/check-no-top-level-await.mjs').then((m) => m.default());
|
|
24
|
+
|
|
20
25
|
await esbuild.build({
|
|
21
26
|
entryPoints: ['src/index.ts'],
|
|
22
27
|
bundle: true,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"backup.d.ts","sourceRoot":"","sources":["../../src/commands/backup.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAMpC;;GAEG;AACH,wBAAgB,cAAc,CAAC,OAAO,EAAE,OAAO,GAAG,IAAI,
|
|
1
|
+
{"version":3,"file":"backup.d.ts","sourceRoot":"","sources":["../../src/commands/backup.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAMpC;;GAEG;AACH,wBAAgB,cAAc,CAAC,OAAO,EAAE,OAAO,GAAG,IAAI,CA4GrD"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"check.d.ts","sourceRoot":"","sources":["../../src/commands/check.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;
|
|
1
|
+
{"version":3,"file":"check.d.ts","sourceRoot":"","sources":["../../src/commands/check.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAezC,UAAU,mBAAmB;IAC3B,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,IAAI,CAAC,EAAE,OAAO,CAAC;IACf,MAAM,CAAC,EAAE,MAAM,EAAE,CAAC;IAClB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,OAAO,CAAC,EAAE,MAAM,EAAE,CAAC;IACnB,OAAO,CAAC,EAAE,MAAM,EAAE,CAAC;IACnB,MAAM,CAAC,EAAE,MAAM,GAAG,WAAW,GAAG,UAAU,CAAC;IAC3C,MAAM,CAAC,EAAE,MAAM,EAAE,CAAC;IAClB,WAAW,CAAC,EAAE,MAAM,EAAE,CAAC;IACvB,sBAAsB,CAAC,EAAE,OAAO,CAAC;IACjC,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB,IAAI,CAAC,EAAE,OAAO,CAAC;IACf,eAAe,CAAC,EAAE,OAAO,CAAC;IAC1B,qBAAqB,CAAC,EAAE,OAAO,CAAC;IAChC,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB,YAAY,CAAC,EAAE,MAAM,EAAE,CAAC;IACxB,eAAe,CAAC,EAAE,OAAO,CAAC;IAC1B,iBAAiB,CAAC,EAAE,OAAO,CAAC;IAC5B,aAAa,CAAC,EAAE,OAAO,CAAC;CACzB;AA0HD,wBAAgB,aAAa,CAAC,OAAO,EAAE,OAAO,QAuB7C;AAED,wBAAsB,QAAQ,CAAC,OAAO,EAAE,mBAAmB,GAAG,OAAO,CAAC,IAAI,CAAC,CAwI1E"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../src/commands/config.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AA8GzC,wBAAgB,cAAc,CAAC,OAAO,EAAE,OAAO,
|
|
1
|
+
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../src/commands/config.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AA8GzC,wBAAgB,cAAc,CAAC,OAAO,EAAE,OAAO,QAyS9C"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"coverage.d.ts","sourceRoot":"","sources":["../../src/commands/coverage.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;
|
|
1
|
+
{"version":3,"file":"coverage.d.ts","sourceRoot":"","sources":["../../src/commands/coverage.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAMzC,UAAU,sBAAsB;IAC9B,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,IAAI,CAAC,EAAE,OAAO,CAAC;IACf,MAAM,CAAC,EAAE,MAAM,EAAE,CAAC;IAClB,eAAe,CAAC,EAAE,OAAO,CAAC;CAC3B;AA2CD,wBAAgB,gBAAgB,CAAC,OAAO,EAAE,OAAO,QAUhD;AAED,wBAAsB,WAAW,CAAC,OAAO,EAAE,sBAAsB,GAAG,OAAO,CAAC,IAAI,CAAC,CAiChF"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"detect.d.ts","sourceRoot":"","sources":["../../src/commands/detect.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAgSzC,wBAAgB,cAAc,CAAC,OAAO,EAAE,OAAO,
|
|
1
|
+
{"version":3,"file":"detect.d.ts","sourceRoot":"","sources":["../../src/commands/detect.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAgSzC,wBAAgB,cAAc,CAAC,OAAO,EAAE,OAAO,QAyD9C"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"diagnose.d.ts","sourceRoot":"","sources":["../../src/commands/diagnose.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;
|
|
1
|
+
{"version":3,"file":"diagnose.d.ts","sourceRoot":"","sources":["../../src/commands/diagnose.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAiGzC,wBAAgB,gBAAgB,CAAC,OAAO,EAAE,OAAO,QAgDhD"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"init.d.ts","sourceRoot":"","sources":["../../src/commands/init.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;
|
|
1
|
+
{"version":3,"file":"init.d.ts","sourceRoot":"","sources":["../../src/commands/init.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAYpC;;;GAGG;AACH,wBAAgB,aAAa,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,EAAE,CAwBrD;AAsVD,wBAAgB,YAAY,CAAC,OAAO,EAAE,OAAO,QA6Z5C"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"rename.d.ts","sourceRoot":"","sources":["../../src/commands/rename.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;
|
|
1
|
+
{"version":3,"file":"rename.d.ts","sourceRoot":"","sources":["../../src/commands/rename.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AA6BpC;;GAEG;AACH,wBAAgB,cAAc,CAAC,OAAO,EAAE,OAAO,GAAG,IAAI,CAwJrD"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"review.d.ts","sourceRoot":"","sources":["../../src/commands/review.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;
|
|
1
|
+
{"version":3,"file":"review.d.ts","sourceRoot":"","sources":["../../src/commands/review.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAiBzC,wBAAgB,qBAAqB,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAG3D;AAyGD,wBAAgB,cAAc,CAAC,OAAO,EAAE,OAAO,QAwG9C"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"scaffold-adapter.d.ts","sourceRoot":"","sources":["../../src/commands/scaffold-adapter.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;
|
|
1
|
+
{"version":3,"file":"scaffold-adapter.d.ts","sourceRoot":"","sources":["../../src/commands/scaffold-adapter.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAkCpC,wBAAgB,uBAAuB,CAAC,OAAO,EAAE,OAAO,QAqMvD"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"scan.d.ts","sourceRoot":"","sources":["../../src/commands/scan.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;
|
|
1
|
+
{"version":3,"file":"scan.d.ts","sourceRoot":"","sources":["../../src/commands/scan.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AA6CzC,wBAAgB,YAAY,CAAC,OAAO,EAAE,OAAO,QA+F5C"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sync.d.ts","sourceRoot":"","sources":["../../src/commands/sync.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;
|
|
1
|
+
{"version":3,"file":"sync.d.ts","sourceRoot":"","sources":["../../src/commands/sync.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AA0FpC,wBAAgB,YAAY,CAAC,OAAO,EAAE,OAAO,QA8oB5C"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"transform.d.ts","sourceRoot":"","sources":["../../src/commands/transform.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AA2LzC,wBAAgB,iBAAiB,CAAC,OAAO,EAAE,OAAO,
|
|
1
|
+
{"version":3,"file":"transform.d.ts","sourceRoot":"","sources":["../../src/commands/transform.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AA2LzC,wBAAgB,iBAAiB,CAAC,OAAO,EAAE,OAAO,QAuJjD"}
|