i18nsmith 0.1.8 → 0.2.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/build.mjs +16 -10
- package/dist/commands/audit.d.ts +3 -0
- package/dist/commands/audit.d.ts.map +1 -0
- package/dist/commands/backup.d.ts +6 -0
- package/dist/commands/backup.d.ts.map +1 -0
- package/dist/commands/check.d.ts +3 -0
- package/dist/commands/check.d.ts.map +1 -0
- package/dist/commands/config.d.ts +3 -0
- package/dist/commands/config.d.ts.map +1 -0
- package/dist/commands/debug-patterns.d.ts +3 -0
- package/dist/commands/debug-patterns.d.ts.map +1 -0
- package/dist/commands/debug-patterns.test.d.ts +2 -0
- package/dist/commands/debug-patterns.test.d.ts.map +1 -0
- package/dist/commands/diagnose.d.ts +3 -0
- package/dist/commands/diagnose.d.ts.map +1 -0
- package/dist/commands/init.d.ts +8 -0
- package/dist/commands/init.d.ts.map +1 -0
- package/dist/commands/init.test.d.ts +2 -0
- package/dist/commands/init.test.d.ts.map +1 -0
- package/dist/commands/install-hooks.d.ts +3 -0
- package/dist/commands/install-hooks.d.ts.map +1 -0
- package/dist/commands/preflight.d.ts +7 -0
- package/dist/commands/preflight.d.ts.map +1 -0
- package/dist/commands/preflight.test.d.ts +5 -0
- package/dist/commands/preflight.test.d.ts.map +1 -0
- package/dist/commands/rename.d.ts +6 -0
- package/dist/commands/rename.d.ts.map +1 -0
- package/dist/commands/review.d.ts +4 -0
- package/dist/commands/review.d.ts.map +1 -0
- package/dist/commands/review.test.d.ts +2 -0
- package/dist/commands/review.test.d.ts.map +1 -0
- package/dist/commands/scaffold-adapter.d.ts +3 -0
- package/dist/commands/scaffold-adapter.d.ts.map +1 -0
- package/dist/commands/scaffold-adapter.test.d.ts +2 -0
- package/dist/commands/scaffold-adapter.test.d.ts.map +1 -0
- package/dist/commands/scan.d.ts +3 -0
- package/dist/commands/scan.d.ts.map +1 -0
- package/dist/commands/sync-seed.test.d.ts +2 -0
- package/dist/commands/sync-seed.test.d.ts.map +1 -0
- package/dist/commands/sync.d.ts +3 -0
- package/dist/commands/sync.d.ts.map +1 -0
- package/dist/commands/transform.d.ts +3 -0
- package/dist/commands/transform.d.ts.map +1 -0
- package/dist/commands/translate/csv-handler.d.ts +21 -0
- package/dist/commands/translate/csv-handler.d.ts.map +1 -0
- package/dist/commands/translate/executor.d.ts +31 -0
- package/dist/commands/translate/executor.d.ts.map +1 -0
- package/dist/commands/translate/index.d.ts +10 -0
- package/dist/commands/translate/index.d.ts.map +1 -0
- package/dist/commands/translate/reporter.d.ts +29 -0
- package/dist/commands/translate/reporter.d.ts.map +1 -0
- package/dist/commands/translate/types.d.ts +52 -0
- package/dist/commands/translate/types.d.ts.map +1 -0
- package/dist/commands/translate.d.ts +7 -0
- package/dist/commands/translate.d.ts.map +1 -0
- package/dist/commands/translate.test.d.ts +2 -0
- package/dist/commands/translate.test.d.ts.map +1 -0
- package/dist/e2e.test.d.ts +6 -0
- package/dist/e2e.test.d.ts.map +1 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +1121 -387
- package/dist/integration.test.d.ts +6 -0
- package/dist/integration.test.d.ts.map +1 -0
- package/dist/test-helpers/ensure-cli-built.d.ts +2 -0
- package/dist/test-helpers/ensure-cli-built.d.ts.map +1 -0
- package/dist/utils/diagnostics-exit.d.ts +12 -0
- package/dist/utils/diagnostics-exit.d.ts.map +1 -0
- package/dist/utils/diagnostics-exit.test.d.ts +2 -0
- package/dist/utils/diagnostics-exit.test.d.ts.map +1 -0
- package/dist/utils/diff-utils.d.ts +4 -0
- package/dist/utils/diff-utils.d.ts.map +1 -0
- package/dist/utils/diff-utils.test.d.ts +2 -0
- package/dist/utils/diff-utils.test.d.ts.map +1 -0
- package/dist/utils/exit-codes.d.ts +142 -0
- package/dist/utils/exit-codes.d.ts.map +1 -0
- package/dist/utils/package-manager.d.ts +4 -0
- package/dist/utils/package-manager.d.ts.map +1 -0
- package/dist/utils/pkg.d.ts +3 -0
- package/dist/utils/pkg.d.ts.map +1 -0
- package/dist/utils/preview.d.ts +13 -0
- package/dist/utils/preview.d.ts.map +1 -0
- package/dist/utils/provider-injector.d.ts +36 -0
- package/dist/utils/provider-injector.d.ts.map +1 -0
- package/dist/utils/provider-injector.test.d.ts +2 -0
- package/dist/utils/provider-injector.test.d.ts.map +1 -0
- package/dist/utils/scaffold.d.ts +20 -0
- package/dist/utils/scaffold.d.ts.map +1 -0
- package/package.json +3 -2
- package/src/commands/debug-patterns.test.ts +6 -1
- package/src/commands/rename.ts +35 -3
- package/src/commands/review.test.ts +12 -0
- package/src/commands/review.ts +228 -0
- package/src/commands/sync-seed.test.ts +9 -3
- package/src/commands/sync.ts +104 -10
- package/src/commands/transform.ts +31 -4
- package/src/commands/translate/index.ts +23 -3
- package/src/commands/translate/types.ts +2 -0
- package/src/commands/translate.test.ts +9 -3
- package/src/e2e.test.ts +3 -11
- package/src/index.ts +2 -0
- package/src/integration.test.ts +12 -1
- package/src/test-helpers/ensure-cli-built.ts +32 -0
- package/src/utils/preview.ts +126 -0
- package/dist/index.js.map +0 -7
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"integration.test.d.ts","sourceRoot":"","sources":["../src/integration.test.ts"],"names":[],"mappings":"AAAA;;;GAGG"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ensure-cli-built.d.ts","sourceRoot":"","sources":["../../src/test-helpers/ensure-cli-built.ts"],"names":[],"mappings":"AAUA,wBAAsB,cAAc,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAqBnE"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { DiagnoseConflict, DiagnosisReport } from '@i18nsmith/core';
|
|
2
|
+
export interface DiagnosisExitSignal {
|
|
3
|
+
code: number;
|
|
4
|
+
reason: string;
|
|
5
|
+
}
|
|
6
|
+
export declare function getDiagnosisExitSignal(report: Pick<DiagnosisReport, 'conflicts'>): DiagnosisExitSignal | null;
|
|
7
|
+
export declare function selectExitSignal(conflicts: DiagnoseConflict[]): DiagnosisExitSignal | null;
|
|
8
|
+
export declare function describeDiagnosisExitCodes(): Array<{
|
|
9
|
+
code: number;
|
|
10
|
+
reason: string;
|
|
11
|
+
}>;
|
|
12
|
+
//# sourceMappingURL=diagnostics-exit.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"diagnostics-exit.d.ts","sourceRoot":"","sources":["../../src/utils/diagnostics-exit.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC;AAGzE,MAAM,WAAW,mBAAmB;IAClC,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,MAAM,CAAC;CAChB;AAiBD,wBAAgB,sBAAsB,CAAC,MAAM,EAAE,IAAI,CAAC,eAAe,EAAE,WAAW,CAAC,GAAG,mBAAmB,GAAG,IAAI,CAE7G;AAED,wBAAgB,gBAAgB,CAAC,SAAS,EAAE,gBAAgB,EAAE,GAAG,mBAAmB,GAAG,IAAI,CA2B1F;AAED,wBAAgB,0BAA0B,IAAI,KAAK,CAAC;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,CAAC,CAMpF"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"diagnostics-exit.test.d.ts","sourceRoot":"","sources":["../../src/utils/diagnostics-exit.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { SyncSummary } from '@i18nsmith/core';
|
|
2
|
+
export declare function printLocaleDiffs(diffs: SyncSummary['diffs']): void;
|
|
3
|
+
export declare function writeLocaleDiffPatches(diffs: SyncSummary['diffs'], directory: string): Promise<void>;
|
|
4
|
+
//# sourceMappingURL=diff-utils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"diff-utils.d.ts","sourceRoot":"","sources":["../../src/utils/diff-utils.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAEnD,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,WAAW,CAAC,OAAO,CAAC,QAW3D;AAED,wBAAsB,sBAAsB,CAAC,KAAK,EAAE,WAAW,CAAC,OAAO,CAAC,EAAE,SAAS,EAAE,MAAM,iBAuB1F"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"diff-utils.test.d.ts","sourceRoot":"","sources":["../../src/utils/diff-utils.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Exit Code Reference for i18nsmith CLI
|
|
3
|
+
*
|
|
4
|
+
* This module centralizes all exit codes used by the CLI for consistent
|
|
5
|
+
* behavior across commands and improved CI/CD integration.
|
|
6
|
+
*
|
|
7
|
+
* ## Exit Code Ranges
|
|
8
|
+
*
|
|
9
|
+
* | Range | Category | Description |
|
|
10
|
+
* |--------|-----------------------|---------------------------------------|
|
|
11
|
+
* | 0 | Success | Command completed successfully |
|
|
12
|
+
* | 1 | General Error | Unspecified error or crash |
|
|
13
|
+
* | 2-5 | Diagnostics | Workspace diagnostic conflicts |
|
|
14
|
+
* | 10-19 | Check Command | Health check warnings/conflicts |
|
|
15
|
+
* | 1-4 | Sync Command | Sync drift/validation issues |
|
|
16
|
+
*
|
|
17
|
+
* Note: Sync exit codes overlap with diagnostics for backward compatibility.
|
|
18
|
+
* Use `--prefer-diagnostics-exit` in `check` command to disambiguate.
|
|
19
|
+
*
|
|
20
|
+
* ## Usage in CI/CD
|
|
21
|
+
*
|
|
22
|
+
* ```bash
|
|
23
|
+
* # Basic CI check
|
|
24
|
+
* npx i18nsmith check --fail-on conflicts
|
|
25
|
+
* if [ $? -eq 11 ]; then
|
|
26
|
+
* echo "Blocking conflicts found"
|
|
27
|
+
* fi
|
|
28
|
+
*
|
|
29
|
+
* # Strict sync check
|
|
30
|
+
* npx i18nsmith sync --check --strict
|
|
31
|
+
* case $? in
|
|
32
|
+
* 0) echo "All clear" ;;
|
|
33
|
+
* 1) echo "Locale drift detected" ;;
|
|
34
|
+
* 2) echo "Placeholder mismatch" ;;
|
|
35
|
+
* 4) echo "Suspicious keys found" ;;
|
|
36
|
+
* esac
|
|
37
|
+
* ```
|
|
38
|
+
*/
|
|
39
|
+
/**
|
|
40
|
+
* Exit codes for the `sync` command.
|
|
41
|
+
*
|
|
42
|
+
* Used when running `i18nsmith sync --check` or `--strict` mode.
|
|
43
|
+
*/
|
|
44
|
+
export declare const SYNC_EXIT_CODES: {
|
|
45
|
+
/** Locale drift detected (missing or unused keys) */
|
|
46
|
+
readonly DRIFT: 1;
|
|
47
|
+
/** Placeholder/interpolation mismatch between locales */
|
|
48
|
+
readonly PLACEHOLDER_MISMATCH: 2;
|
|
49
|
+
/** Empty or placeholder values in locale files */
|
|
50
|
+
readonly EMPTY_VALUES: 3;
|
|
51
|
+
/** Suspicious key patterns detected (e.g., key=value, raw text keys) */
|
|
52
|
+
readonly SUSPICIOUS_KEYS: 4;
|
|
53
|
+
};
|
|
54
|
+
/**
|
|
55
|
+
* Exit codes for the `check` command.
|
|
56
|
+
*
|
|
57
|
+
* Used when running `i18nsmith check --fail-on <level>`.
|
|
58
|
+
*/
|
|
59
|
+
export declare const CHECK_EXIT_CODES: {
|
|
60
|
+
/** Warnings detected (when --fail-on warnings) */
|
|
61
|
+
readonly WARNINGS: 10;
|
|
62
|
+
/** Blocking conflicts detected (when --fail-on conflicts) */
|
|
63
|
+
readonly CONFLICTS: 11;
|
|
64
|
+
};
|
|
65
|
+
/**
|
|
66
|
+
* Exit codes for the `diagnose` command and diagnostic conflicts.
|
|
67
|
+
*
|
|
68
|
+
* These are also used by `check` when `--prefer-diagnostics-exit` is set.
|
|
69
|
+
*/
|
|
70
|
+
export declare const DIAGNOSTICS_EXIT_CODES: {
|
|
71
|
+
/** Missing source locale file */
|
|
72
|
+
readonly MISSING_SOURCE_LOCALE: 2;
|
|
73
|
+
/** Invalid JSON in locale file */
|
|
74
|
+
readonly INVALID_LOCALE_JSON: 3;
|
|
75
|
+
/** Provider/adapter clash detected */
|
|
76
|
+
readonly UNSAFE_PROVIDER_CLASH: 4;
|
|
77
|
+
/** General diagnostics conflict (fallback) */
|
|
78
|
+
readonly GENERAL_CONFLICT: 5;
|
|
79
|
+
};
|
|
80
|
+
/**
|
|
81
|
+
* General exit codes used across all commands.
|
|
82
|
+
*/
|
|
83
|
+
export declare const GENERAL_EXIT_CODES: {
|
|
84
|
+
/** Success - no issues found */
|
|
85
|
+
readonly SUCCESS: 0;
|
|
86
|
+
/** General error (catch-all for exceptions) */
|
|
87
|
+
readonly ERROR: 1;
|
|
88
|
+
};
|
|
89
|
+
/**
|
|
90
|
+
* Type for all sync exit codes
|
|
91
|
+
*/
|
|
92
|
+
export type SyncExitCode = (typeof SYNC_EXIT_CODES)[keyof typeof SYNC_EXIT_CODES];
|
|
93
|
+
/**
|
|
94
|
+
* Type for all check exit codes
|
|
95
|
+
*/
|
|
96
|
+
export type CheckExitCode = (typeof CHECK_EXIT_CODES)[keyof typeof CHECK_EXIT_CODES];
|
|
97
|
+
/**
|
|
98
|
+
* Type for all diagnostics exit codes
|
|
99
|
+
*/
|
|
100
|
+
export type DiagnosticsExitCode = (typeof DIAGNOSTICS_EXIT_CODES)[keyof typeof DIAGNOSTICS_EXIT_CODES];
|
|
101
|
+
/**
|
|
102
|
+
* Human-readable descriptions for sync exit codes.
|
|
103
|
+
*/
|
|
104
|
+
export declare const SYNC_EXIT_DESCRIPTIONS: Record<number, string>;
|
|
105
|
+
/**
|
|
106
|
+
* Human-readable descriptions for check exit codes.
|
|
107
|
+
*/
|
|
108
|
+
export declare const CHECK_EXIT_DESCRIPTIONS: Record<number, string>;
|
|
109
|
+
/**
|
|
110
|
+
* Human-readable descriptions for diagnostics exit codes.
|
|
111
|
+
*/
|
|
112
|
+
export declare const DIAGNOSTICS_EXIT_DESCRIPTIONS: Record<number, string>;
|
|
113
|
+
/**
|
|
114
|
+
* All exit code descriptions by command context.
|
|
115
|
+
*/
|
|
116
|
+
export declare const EXIT_CODE_DESCRIPTIONS: {
|
|
117
|
+
readonly general: {
|
|
118
|
+
readonly 0: "Success - no issues found";
|
|
119
|
+
readonly 1: "General error";
|
|
120
|
+
};
|
|
121
|
+
readonly sync: Record<number, string>;
|
|
122
|
+
readonly check: Record<number, string>;
|
|
123
|
+
readonly diagnostics: Record<number, string>;
|
|
124
|
+
};
|
|
125
|
+
/**
|
|
126
|
+
* Get a human-readable description for an exit code.
|
|
127
|
+
*
|
|
128
|
+
* @param code - The exit code
|
|
129
|
+
* @param context - Optional context to disambiguate overlapping codes
|
|
130
|
+
* @returns Description string, or 'Unknown exit code' if not recognized
|
|
131
|
+
*/
|
|
132
|
+
export declare function getExitCodeDescription(code: number, context?: 'sync' | 'check' | 'diagnostics'): string;
|
|
133
|
+
/**
|
|
134
|
+
* Helper to set process exit code with optional logging.
|
|
135
|
+
*
|
|
136
|
+
* @param code - The exit code to set
|
|
137
|
+
* @param options - Optional configuration
|
|
138
|
+
*/
|
|
139
|
+
export declare function setExitCode(code: number, options?: {
|
|
140
|
+
silent?: boolean;
|
|
141
|
+
}): void;
|
|
142
|
+
//# sourceMappingURL=exit-codes.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"exit-codes.d.ts","sourceRoot":"","sources":["../../src/utils/exit-codes.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAqCG;AAEH;;;;GAIG;AACH,eAAO,MAAM,eAAe;IAC1B,qDAAqD;;IAErD,yDAAyD;;IAEzD,kDAAkD;;IAElD,wEAAwE;;CAEhE,CAAC;AAEX;;;;GAIG;AACH,eAAO,MAAM,gBAAgB;IAC3B,kDAAkD;;IAElD,6DAA6D;;CAErD,CAAC;AAEX;;;;GAIG;AACH,eAAO,MAAM,sBAAsB;IACjC,iCAAiC;;IAEjC,kCAAkC;;IAElC,sCAAsC;;IAEtC,8CAA8C;;CAEtC,CAAC;AAEX;;GAEG;AACH,eAAO,MAAM,kBAAkB;IAC7B,gCAAgC;;IAEhC,+CAA+C;;CAEvC,CAAC;AAEX;;GAEG;AACH,MAAM,MAAM,YAAY,GAAG,CAAC,OAAO,eAAe,CAAC,CAAC,MAAM,OAAO,eAAe,CAAC,CAAC;AAElF;;GAEG;AACH,MAAM,MAAM,aAAa,GAAG,CAAC,OAAO,gBAAgB,CAAC,CAAC,MAAM,OAAO,gBAAgB,CAAC,CAAC;AAErF;;GAEG;AACH,MAAM,MAAM,mBAAmB,GAAG,CAAC,OAAO,sBAAsB,CAAC,CAAC,MAAM,OAAO,sBAAsB,CAAC,CAAC;AAEvG;;GAEG;AACH,eAAO,MAAM,sBAAsB,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAKzD,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,uBAAuB,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAG1D,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,6BAA6B,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAKhE,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,sBAAsB;;;;;;;;CAQzB,CAAC;AAEX;;;;;;GAMG;AACH,wBAAgB,sBAAsB,CACpC,IAAI,EAAE,MAAM,EACZ,OAAO,CAAC,EAAE,MAAM,GAAG,OAAO,GAAG,aAAa,GACzC,MAAM,CAsBR;AAED;;;;;GAKG;AACH,wBAAgB,WAAW,CACzB,IAAI,EAAE,MAAM,EACZ,OAAO,CAAC,EAAE;IAAE,MAAM,CAAC,EAAE,OAAO,CAAA;CAAE,GAC7B,IAAI,CAQN"}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export type PackageManager = 'pnpm' | 'yarn' | 'npm';
|
|
2
|
+
export declare function detectPackageManager(workspaceRoot?: string): Promise<PackageManager>;
|
|
3
|
+
export declare function installDependencies(manager: PackageManager, deps: string[], workspaceRoot?: string): Promise<void>;
|
|
4
|
+
//# sourceMappingURL=package-manager.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"package-manager.d.ts","sourceRoot":"","sources":["../../src/utils/package-manager.ts"],"names":[],"mappings":"AAIA,MAAM,MAAM,cAAc,GAAG,MAAM,GAAG,MAAM,GAAG,KAAK,CAAC;AAErD,wBAAsB,oBAAoB,CAAC,aAAa,SAAgB,GAAG,OAAO,CAAC,cAAc,CAAC,CAQjG;AAED,wBAAsB,mBAAmB,CAAC,OAAO,EAAE,cAAc,EAAE,IAAI,EAAE,MAAM,EAAE,EAAE,aAAa,SAAgB,iBAkB/G"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pkg.d.ts","sourceRoot":"","sources":["../../src/utils/pkg.ts"],"names":[],"mappings":"AAGA,wBAAsB,eAAe,CAAC,GAAG,CAAC,EAAE,MAAM,gDAYjD;AAED,wBAAgB,aAAa,CAAC,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,SAAS,EAAE,GAAG,EAAE,MAAM,WAKlF"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export interface PreviewPayload<TSummary> {
|
|
2
|
+
type: string;
|
|
3
|
+
version: number;
|
|
4
|
+
command: string;
|
|
5
|
+
args: string[];
|
|
6
|
+
timestamp: string;
|
|
7
|
+
summary: TSummary;
|
|
8
|
+
}
|
|
9
|
+
export type PreviewKind = 'sync' | 'transform' | 'rename-key' | 'translate';
|
|
10
|
+
export declare function writePreviewFile<TSummary>(kind: PreviewKind, summary: TSummary, outputPath: string): Promise<string>;
|
|
11
|
+
export declare function readPreviewFile<TSummary>(expectedKind: PreviewKind, previewPath: string): Promise<PreviewPayload<TSummary>>;
|
|
12
|
+
export declare function applyPreviewFile(expectedKind: PreviewKind, previewPath: string, extraArgs?: string[]): Promise<void>;
|
|
13
|
+
//# sourceMappingURL=preview.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"preview.d.ts","sourceRoot":"","sources":["../../src/utils/preview.ts"],"names":[],"mappings":"AAIA,MAAM,WAAW,cAAc,CAAC,QAAQ;IACtC,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,EAAE,MAAM,EAAE,CAAC;IACf,SAAS,EAAE,MAAM,CAAC;IAClB,OAAO,EAAE,QAAQ,CAAC;CACnB;AAED,MAAM,MAAM,WAAW,GAAG,MAAM,GAAG,WAAW,GAAG,YAAY,GAAG,WAAW,CAAC;AAE5E,wBAAsB,gBAAgB,CAAC,QAAQ,EAC7C,IAAI,EAAE,WAAW,EACjB,OAAO,EAAE,QAAQ,EACjB,UAAU,EAAE,MAAM,GACjB,OAAO,CAAC,MAAM,CAAC,CAcjB;AAED,wBAAsB,eAAe,CAAC,QAAQ,EAC5C,YAAY,EAAE,WAAW,EACzB,WAAW,EAAE,MAAM,GAClB,OAAO,CAAC,cAAc,CAAC,QAAQ,CAAC,CAAC,CAWnC;AAED,wBAAsB,gBAAgB,CACpC,YAAY,EAAE,WAAW,EACzB,WAAW,EAAE,MAAM,EACnB,SAAS,GAAE,MAAM,EAAO,GACvB,OAAO,CAAC,IAAI,CAAC,CAuBf"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
export type ProviderInjectionResult = {
|
|
2
|
+
status: 'injected';
|
|
3
|
+
file: string;
|
|
4
|
+
diff?: string;
|
|
5
|
+
} | {
|
|
6
|
+
status: 'preview';
|
|
7
|
+
file: string;
|
|
8
|
+
diff: string;
|
|
9
|
+
} | {
|
|
10
|
+
status: 'skipped';
|
|
11
|
+
file: string;
|
|
12
|
+
existingProvider?: string;
|
|
13
|
+
} | {
|
|
14
|
+
status: 'failed';
|
|
15
|
+
file: string;
|
|
16
|
+
reason: string;
|
|
17
|
+
} | {
|
|
18
|
+
status: 'not-found';
|
|
19
|
+
};
|
|
20
|
+
export interface ProviderDetectionResult {
|
|
21
|
+
found: boolean;
|
|
22
|
+
file?: string;
|
|
23
|
+
provider?: string;
|
|
24
|
+
candidates: string[];
|
|
25
|
+
}
|
|
26
|
+
export interface ProviderInjectionOptions {
|
|
27
|
+
providerComponentPath: string;
|
|
28
|
+
candidates?: string[];
|
|
29
|
+
dryRun?: boolean;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Detect if any provider file exists and whether an i18n provider is already wired.
|
|
33
|
+
*/
|
|
34
|
+
export declare function detectExistingProvider(candidates?: string[]): Promise<ProviderDetectionResult>;
|
|
35
|
+
export declare function maybeInjectProvider(options: ProviderInjectionOptions): Promise<ProviderInjectionResult>;
|
|
36
|
+
//# sourceMappingURL=provider-injector.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"provider-injector.d.ts","sourceRoot":"","sources":["../../src/utils/provider-injector.ts"],"names":[],"mappings":"AAeA,MAAM,MAAM,uBAAuB,GAC/B;IAAE,MAAM,EAAE,UAAU,CAAC;IAAC,IAAI,EAAE,MAAM,CAAC;IAAC,IAAI,CAAC,EAAE,MAAM,CAAA;CAAE,GACnD;IAAE,MAAM,EAAE,SAAS,CAAC;IAAC,IAAI,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,GACjD;IAAE,MAAM,EAAE,SAAS,CAAC;IAAC,IAAI,EAAE,MAAM,CAAC;IAAC,gBAAgB,CAAC,EAAE,MAAM,CAAA;CAAE,GAC9D;IAAE,MAAM,EAAE,QAAQ,CAAC;IAAC,IAAI,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,GAClD;IAAE,MAAM,EAAE,WAAW,CAAA;CAAE,CAAC;AAE5B,MAAM,WAAW,uBAAuB;IACtC,KAAK,EAAE,OAAO,CAAC;IACf,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,UAAU,EAAE,MAAM,EAAE,CAAC;CACtB;AAED,MAAM,WAAW,wBAAwB;IACvC,qBAAqB,EAAE,MAAM,CAAC;IAC9B,UAAU,CAAC,EAAE,MAAM,EAAE,CAAC;IACtB,MAAM,CAAC,EAAE,OAAO,CAAC;CAClB;AAuCD;;GAEG;AACH,wBAAsB,sBAAsB,CAC1C,UAAU,GAAE,MAAM,EAAgC,GACjD,OAAO,CAAC,uBAAuB,CAAC,CAwClC;AAuBD,wBAAsB,mBAAmB,CACvC,OAAO,EAAE,wBAAwB,GAChC,OAAO,CAAC,uBAAuB,CAAC,CA2BlC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"provider-injector.test.d.ts","sourceRoot":"","sources":["../../src/utils/provider-injector.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
interface ScaffoldOptions {
|
|
2
|
+
localesDir?: string;
|
|
3
|
+
workspaceRoot?: string;
|
|
4
|
+
force?: boolean;
|
|
5
|
+
dryRun?: boolean;
|
|
6
|
+
}
|
|
7
|
+
export interface ScaffoldResult {
|
|
8
|
+
path: string;
|
|
9
|
+
content: string;
|
|
10
|
+
written: boolean;
|
|
11
|
+
}
|
|
12
|
+
export declare function scaffoldTranslationContext(filePath: string, sourceLanguage: string, options?: ScaffoldOptions): Promise<ScaffoldResult>;
|
|
13
|
+
export declare function scaffoldI18next(i18nPath: string, providerPath: string, sourceLanguage: string, localesDir?: string, options?: ScaffoldOptions): Promise<{
|
|
14
|
+
i18nPath: string;
|
|
15
|
+
providerPath: string;
|
|
16
|
+
i18nResult: ScaffoldResult;
|
|
17
|
+
providerResult: ScaffoldResult;
|
|
18
|
+
}>;
|
|
19
|
+
export {};
|
|
20
|
+
//# sourceMappingURL=scaffold.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"scaffold.d.ts","sourceRoot":"","sources":["../../src/utils/scaffold.ts"],"names":[],"mappings":"AAGA,UAAU,eAAe;IACvB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,MAAM,CAAC,EAAE,OAAO,CAAC;CAClB;AAED,MAAM,WAAW,cAAc;IAC7B,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,EAAE,OAAO,CAAC;CAClB;AA2CD,wBAAsB,0BAA0B,CAC9C,QAAQ,EAAE,MAAM,EAChB,cAAc,EAAE,MAAM,EACtB,OAAO,GAAE,eAAoB,GAC5B,OAAO,CAAC,cAAc,CAAC,CA0DzB;AAED,wBAAsB,eAAe,CACnC,QAAQ,EAAE,MAAM,EAChB,YAAY,EAAE,MAAM,EACpB,cAAc,EAAE,MAAM,EACtB,UAAU,SAAY,EACtB,OAAO,GAAE,eAAoB,GAC5B,OAAO,CAAC;IAAE,QAAQ,EAAE,MAAM,CAAC;IAAC,YAAY,EAAE,MAAM,CAAC;IAAC,UAAU,EAAE,cAAc,CAAC;IAAC,cAAc,EAAE,cAAc,CAAA;CAAE,CAAC,CAgHjH"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "i18nsmith",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"description": "CLI for i18nsmith",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -11,7 +11,8 @@
|
|
|
11
11
|
"exports": {
|
|
12
12
|
".": {
|
|
13
13
|
"types": "./dist/index.d.ts",
|
|
14
|
-
"import": "./dist/index.js"
|
|
14
|
+
"import": "./dist/index.js",
|
|
15
|
+
"default": "./dist/index.js"
|
|
15
16
|
}
|
|
16
17
|
},
|
|
17
18
|
"scripts": {
|
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
import { describe, it, expect, beforeEach, afterEach } from 'vitest';
|
|
1
|
+
import { describe, it, expect, beforeEach, afterEach, beforeAll } from 'vitest';
|
|
2
2
|
import fs from 'fs/promises';
|
|
3
3
|
import path from 'path';
|
|
4
4
|
import os from 'os';
|
|
5
5
|
import { spawnSync } from 'child_process';
|
|
6
6
|
import { fileURLToPath } from 'url';
|
|
7
|
+
import { ensureCliBuilt } from '../test-helpers/ensure-cli-built';
|
|
7
8
|
|
|
8
9
|
const __filename = fileURLToPath(import.meta.url);
|
|
9
10
|
const __dirname = path.dirname(__filename);
|
|
@@ -33,6 +34,10 @@ function runCli(args: string[], options: { cwd?: string } = {}) {
|
|
|
33
34
|
describe('debug-patterns command', () => {
|
|
34
35
|
let tmpDir: string;
|
|
35
36
|
|
|
37
|
+
beforeAll(async () => {
|
|
38
|
+
await ensureCliBuilt(CLI_PATH);
|
|
39
|
+
});
|
|
40
|
+
|
|
36
41
|
beforeEach(async () => {
|
|
37
42
|
tmpDir = await fs.mkdtemp(path.join(os.tmpdir(), 'i18nsmith-debug-patterns-'));
|
|
38
43
|
|
package/src/commands/rename.ts
CHANGED
|
@@ -3,6 +3,7 @@ import chalk from 'chalk';
|
|
|
3
3
|
import path from 'node:path';
|
|
4
4
|
import { promises as fs } from 'node:fs';
|
|
5
5
|
import { loadConfig, KeyRenamer, type KeyRenameSummary, type KeyRenameBatchSummary, type KeyRenameMapping } from '@i18nsmith/core';
|
|
6
|
+
import { applyPreviewFile, writePreviewFile } from '../utils/preview.js';
|
|
6
7
|
|
|
7
8
|
interface ScanOptions {
|
|
8
9
|
config: string;
|
|
@@ -10,6 +11,13 @@ interface ScanOptions {
|
|
|
10
11
|
report?: string;
|
|
11
12
|
}
|
|
12
13
|
|
|
14
|
+
interface RenameKeyOptions extends ScanOptions {
|
|
15
|
+
write?: boolean;
|
|
16
|
+
diff?: boolean;
|
|
17
|
+
previewOutput?: string;
|
|
18
|
+
applyPreview?: string;
|
|
19
|
+
}
|
|
20
|
+
|
|
13
21
|
interface RenameMapOptions extends ScanOptions {
|
|
14
22
|
map: string;
|
|
15
23
|
write?: boolean;
|
|
@@ -29,13 +37,37 @@ export function registerRename(program: Command): void {
|
|
|
29
37
|
.option('--json', 'Print raw JSON results', false)
|
|
30
38
|
.option('--report <path>', 'Write JSON summary to a file (for CI or editors)')
|
|
31
39
|
.option('--write', 'Write changes to disk (defaults to dry-run)', false)
|
|
32
|
-
.
|
|
33
|
-
|
|
40
|
+
.option('--diff', 'Display unified diffs for files that would change', false)
|
|
41
|
+
.option('--preview-output <path>', 'Write preview summary (JSON) to a file (implies dry-run)')
|
|
42
|
+
.option('--apply-preview <path>', 'Apply a previously saved rename preview JSON file safely')
|
|
43
|
+
.action(async (oldKey: string, newKey: string, options: RenameKeyOptions) => {
|
|
44
|
+
if (options.applyPreview) {
|
|
45
|
+
await applyPreviewFile('rename-key', options.applyPreview);
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
const previewMode = Boolean(options.previewOutput);
|
|
50
|
+
const writeEnabled = Boolean(options.write) && !previewMode;
|
|
51
|
+
if (previewMode && options.write) {
|
|
52
|
+
console.log(chalk.yellow('Preview requested; ignoring --write and running in dry-run mode.'));
|
|
53
|
+
}
|
|
54
|
+
options.write = writeEnabled;
|
|
55
|
+
|
|
56
|
+
console.log(chalk.blue(writeEnabled ? 'Renaming translation key...' : 'Planning key rename (dry-run)...'));
|
|
34
57
|
|
|
35
58
|
try {
|
|
36
59
|
const config = await loadConfig(options.config);
|
|
37
60
|
const renamer = new KeyRenamer(config);
|
|
38
|
-
const summary = await renamer.rename(oldKey, newKey, {
|
|
61
|
+
const summary = await renamer.rename(oldKey, newKey, {
|
|
62
|
+
write: options.write,
|
|
63
|
+
diff: options.diff || previewMode,
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
if (previewMode && options.previewOutput) {
|
|
67
|
+
const savedPath = await writePreviewFile('rename-key', summary, options.previewOutput);
|
|
68
|
+
console.log(chalk.green(`Preview written to ${path.relative(process.cwd(), savedPath)}`));
|
|
69
|
+
return;
|
|
70
|
+
}
|
|
39
71
|
|
|
40
72
|
if (options.report) {
|
|
41
73
|
const outputPath = path.resolve(process.cwd(), options.report);
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { describe, it, expect } from 'vitest';
|
|
2
|
+
import { literalToRegexPattern } from './review.js';
|
|
3
|
+
|
|
4
|
+
describe('literalToRegexPattern', () => {
|
|
5
|
+
it('anchors the value and escapes regex metacharacters', () => {
|
|
6
|
+
expect(literalToRegexPattern('Price (USD)+?')).toBe('^Price \\(USD\\)\\+\\?$');
|
|
7
|
+
});
|
|
8
|
+
|
|
9
|
+
it('preserves whitespace and newline characters', () => {
|
|
10
|
+
expect(literalToRegexPattern('Multi\nLine')).toBe('^Multi\nLine$');
|
|
11
|
+
});
|
|
12
|
+
});
|