ai-localize-codemods 1.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.
@@ -0,0 +1,105 @@
1
+ import { DetectedText, CloudFrontAsset, LegacyCdnUrl, LocalizationConfig } from '@ai-localize/shared';
2
+
3
+ interface CodemodResult {
4
+ filePath: string;
5
+ originalContent: string;
6
+ transformedContent: string;
7
+ changed: boolean;
8
+ injectedImport: boolean;
9
+ injectedHook: boolean;
10
+ replacedTexts: number;
11
+ }
12
+ /**
13
+ * React i18n codemod: wraps hardcoded JSX text / string literals with t() calls.
14
+ * Preserves formatting, comments, and import order.
15
+ */
16
+ declare class ReactCodemod {
17
+ private filePath;
18
+ private content;
19
+ private texts;
20
+ constructor(filePath: string, content: string, texts: DetectedText[]);
21
+ transform(): CodemodResult;
22
+ private injectUseTranslationHook;
23
+ }
24
+ /**
25
+ * Applies the React codemod to a file in-place.
26
+ */
27
+ declare function applyReactCodemod(filePath: string, texts: DetectedText[], dryRun?: boolean): CodemodResult;
28
+
29
+ /**
30
+ * Vue i18n codemod: wraps hardcoded text with $t() calls in Vue SFCs.
31
+ * Handles both Options API and Composition API.
32
+ */
33
+ declare class VueCodemod {
34
+ private filePath;
35
+ private content;
36
+ private texts;
37
+ constructor(filePath: string, content: string, texts: DetectedText[]);
38
+ transform(): CodemodResult;
39
+ private unchanged;
40
+ }
41
+ declare function applyVueCodemod(filePath: string, texts: DetectedText[], dryRun?: boolean): CodemodResult;
42
+
43
+ /**
44
+ * Angular ngx-translate codemod:
45
+ * - In templates: wraps text with {{ 'key' | translate }}
46
+ * - In TS: replaces string literals with this.translateService.instant('key')
47
+ */
48
+ declare class AngularCodemod {
49
+ private filePath;
50
+ private content;
51
+ private texts;
52
+ constructor(filePath: string, content: string, texts: DetectedText[]);
53
+ transform(): CodemodResult;
54
+ private unchanged;
55
+ }
56
+ declare function applyAngularCodemod(filePath: string, texts: DetectedText[], dryRun?: boolean): CodemodResult;
57
+
58
+ interface CdnReplacementResult {
59
+ filePath: string;
60
+ replacedCount: number;
61
+ changed: boolean;
62
+ originalContent: string;
63
+ transformedContent: string;
64
+ }
65
+ /**
66
+ * Replaces legacy CDN URLs with CloudFront URLs in source files.
67
+ * Supports: TS/JS/JSX/TSX/CSS/HTML/Vue
68
+ */
69
+ declare class CdnReplacer {
70
+ private assetMap;
71
+ constructor(assets: CloudFrontAsset[]);
72
+ replaceInFile(filePath: string, legacyUrls: LegacyCdnUrl[], dryRun?: boolean): CdnReplacementResult;
73
+ private findAsset;
74
+ }
75
+ /**
76
+ * Batch replace CDN URLs across multiple files.
77
+ */
78
+ declare function batchReplaceCdnUrls(fileUrlMap: Map<string, LegacyCdnUrl[]>, assets: CloudFrontAsset[], dryRun?: boolean): Promise<CdnReplacementResult[]>;
79
+
80
+ interface CodemodRunOptions {
81
+ dryRun?: boolean;
82
+ onProgress?: (filePath: string, result: CodemodResult) => void;
83
+ }
84
+ interface CodemodRunSummary {
85
+ totalFiles: number;
86
+ changedFiles: number;
87
+ totalReplacements: number;
88
+ importInjections: number;
89
+ hookInjections: number;
90
+ results: CodemodResult[];
91
+ duration: number;
92
+ }
93
+ /**
94
+ * Orchestrates codemods across all detected files.
95
+ * Groups detected texts by file and applies the appropriate codemod
96
+ * based on the project framework.
97
+ */
98
+ declare class CodemodRunner {
99
+ private config;
100
+ constructor(config: LocalizationConfig);
101
+ run(detectedTexts: DetectedText[], options?: CodemodRunOptions): Promise<CodemodRunSummary>;
102
+ private applyCodemod;
103
+ }
104
+
105
+ export { AngularCodemod, type CdnReplacementResult, CdnReplacer, type CodemodResult, type CodemodRunOptions, type CodemodRunSummary, CodemodRunner, ReactCodemod, VueCodemod, applyAngularCodemod, applyReactCodemod, applyVueCodemod, batchReplaceCdnUrls };
@@ -0,0 +1,105 @@
1
+ import { DetectedText, CloudFrontAsset, LegacyCdnUrl, LocalizationConfig } from '@ai-localize/shared';
2
+
3
+ interface CodemodResult {
4
+ filePath: string;
5
+ originalContent: string;
6
+ transformedContent: string;
7
+ changed: boolean;
8
+ injectedImport: boolean;
9
+ injectedHook: boolean;
10
+ replacedTexts: number;
11
+ }
12
+ /**
13
+ * React i18n codemod: wraps hardcoded JSX text / string literals with t() calls.
14
+ * Preserves formatting, comments, and import order.
15
+ */
16
+ declare class ReactCodemod {
17
+ private filePath;
18
+ private content;
19
+ private texts;
20
+ constructor(filePath: string, content: string, texts: DetectedText[]);
21
+ transform(): CodemodResult;
22
+ private injectUseTranslationHook;
23
+ }
24
+ /**
25
+ * Applies the React codemod to a file in-place.
26
+ */
27
+ declare function applyReactCodemod(filePath: string, texts: DetectedText[], dryRun?: boolean): CodemodResult;
28
+
29
+ /**
30
+ * Vue i18n codemod: wraps hardcoded text with $t() calls in Vue SFCs.
31
+ * Handles both Options API and Composition API.
32
+ */
33
+ declare class VueCodemod {
34
+ private filePath;
35
+ private content;
36
+ private texts;
37
+ constructor(filePath: string, content: string, texts: DetectedText[]);
38
+ transform(): CodemodResult;
39
+ private unchanged;
40
+ }
41
+ declare function applyVueCodemod(filePath: string, texts: DetectedText[], dryRun?: boolean): CodemodResult;
42
+
43
+ /**
44
+ * Angular ngx-translate codemod:
45
+ * - In templates: wraps text with {{ 'key' | translate }}
46
+ * - In TS: replaces string literals with this.translateService.instant('key')
47
+ */
48
+ declare class AngularCodemod {
49
+ private filePath;
50
+ private content;
51
+ private texts;
52
+ constructor(filePath: string, content: string, texts: DetectedText[]);
53
+ transform(): CodemodResult;
54
+ private unchanged;
55
+ }
56
+ declare function applyAngularCodemod(filePath: string, texts: DetectedText[], dryRun?: boolean): CodemodResult;
57
+
58
+ interface CdnReplacementResult {
59
+ filePath: string;
60
+ replacedCount: number;
61
+ changed: boolean;
62
+ originalContent: string;
63
+ transformedContent: string;
64
+ }
65
+ /**
66
+ * Replaces legacy CDN URLs with CloudFront URLs in source files.
67
+ * Supports: TS/JS/JSX/TSX/CSS/HTML/Vue
68
+ */
69
+ declare class CdnReplacer {
70
+ private assetMap;
71
+ constructor(assets: CloudFrontAsset[]);
72
+ replaceInFile(filePath: string, legacyUrls: LegacyCdnUrl[], dryRun?: boolean): CdnReplacementResult;
73
+ private findAsset;
74
+ }
75
+ /**
76
+ * Batch replace CDN URLs across multiple files.
77
+ */
78
+ declare function batchReplaceCdnUrls(fileUrlMap: Map<string, LegacyCdnUrl[]>, assets: CloudFrontAsset[], dryRun?: boolean): Promise<CdnReplacementResult[]>;
79
+
80
+ interface CodemodRunOptions {
81
+ dryRun?: boolean;
82
+ onProgress?: (filePath: string, result: CodemodResult) => void;
83
+ }
84
+ interface CodemodRunSummary {
85
+ totalFiles: number;
86
+ changedFiles: number;
87
+ totalReplacements: number;
88
+ importInjections: number;
89
+ hookInjections: number;
90
+ results: CodemodResult[];
91
+ duration: number;
92
+ }
93
+ /**
94
+ * Orchestrates codemods across all detected files.
95
+ * Groups detected texts by file and applies the appropriate codemod
96
+ * based on the project framework.
97
+ */
98
+ declare class CodemodRunner {
99
+ private config;
100
+ constructor(config: LocalizationConfig);
101
+ run(detectedTexts: DetectedText[], options?: CodemodRunOptions): Promise<CodemodRunSummary>;
102
+ private applyCodemod;
103
+ }
104
+
105
+ export { AngularCodemod, type CdnReplacementResult, CdnReplacer, type CodemodResult, type CodemodRunOptions, type CodemodRunSummary, CodemodRunner, ReactCodemod, VueCodemod, applyAngularCodemod, applyReactCodemod, applyVueCodemod, batchReplaceCdnUrls };