@lang-tag/cli 0.15.0 → 0.17.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 (30) hide show
  1. package/README.md +23 -14
  2. package/algorithms/case-utils.d.ts +12 -0
  3. package/algorithms/collector/dictionary-collector.d.ts +2 -2
  4. package/algorithms/collector/index.d.ts +3 -3
  5. package/algorithms/collector/namespace-collector.d.ts +2 -2
  6. package/algorithms/collector/type.d.ts +2 -2
  7. package/algorithms/config-generation/config-keeper.d.ts +1 -1
  8. package/algorithms/config-generation/index.d.ts +3 -3
  9. package/algorithms/config-generation/path-based-config-generator.d.ts +4 -3
  10. package/algorithms/config-generation/prepend-namespace-to-path.d.ts +1 -1
  11. package/algorithms/import/flexible-import-algorithm.d.ts +232 -0
  12. package/algorithms/import/index.d.ts +2 -1
  13. package/algorithms/import/simple-mapping-import-algorithm.d.ts +120 -0
  14. package/algorithms/index.cjs +418 -26
  15. package/algorithms/index.d.ts +6 -3
  16. package/algorithms/index.js +420 -28
  17. package/chunks/namespace-collector.cjs +75 -0
  18. package/chunks/namespace-collector.js +76 -0
  19. package/index.cjs +1156 -743
  20. package/index.js +1316 -903
  21. package/logger.d.ts +1 -1
  22. package/package.json +1 -1
  23. package/templates/config/init-config.mustache +1 -0
  24. package/templates/import/imported-tag.mustache +14 -0
  25. package/{config.d.ts → type.d.ts} +41 -32
  26. package/namespace-collector-DCruv_PK.js +0 -95
  27. package/namespace-collector-DRnZvkDR.cjs +0 -94
  28. /package/{template → templates/tag}/base-app.mustache +0 -0
  29. /package/{template → templates/tag}/base-library.mustache +0 -0
  30. /package/{template → templates/tag}/placeholder.mustache +0 -0
package/README.md CHANGED
@@ -1,6 +1,5 @@
1
1
  # Lang-tag CLI
2
2
 
3
-
4
3
  A professional solution for managing translations in modern JavaScript/TypeScript projects, especially those using component-based architectures. `lang-tag` simplifies internationalization by allowing you to define translation keys directly within the components where they are used. Translations become local, callable function objects with full TypeScript support, IntelliSense, and compile-time safety.
5
4
 
6
5
  ## Key Benefits
@@ -15,7 +14,7 @@ The core is optimized for performance, with a bundle size of just **~1KB** ([che
15
14
 
16
15
  ### Effortless translation structure
17
16
 
18
- Instead of manually managing centralized translation files, `lang-tag` lets you colocate keys within components and automatically organizes them into namespaces based on your project structure. For example, all components in `components/orders` or pages in `pages/order` share the `orders` namespace. You define a simple directory-to-namespace mapping once, and `lang-tag` handles merging and file organization—while you retain full control over how namespaces are merged.
17
+ Instead of manually managing centralized translation files, `lang-tag` lets you colocate keys within components and automatically organizes them into namespaces based on your project structure. For example, all components in `components/orders` or pages in `pages/order` share the `orders` namespace. You define a simple directory-to-namespace mapping once, and `lang-tag` handles merging and file organization—while you retain full control over how namespaces are merged.
19
18
 
20
19
  > Set your rules, then let `lang-tag` do the rest.
21
20
 
@@ -31,6 +30,7 @@ Full functionality is available through an advanced CLI that keeps your applicat
31
30
  ### Practical and Flexible Architecture
32
31
 
33
32
  The solution provides:
33
+
34
34
  - **Framework agnostic** – works with any JavaScript/TypeScript project and integrates easily with libraries like react-i18next
35
35
  - **Library ecosystem support** - create reusable component libraries with embedded lang-tag translations that consuming lang-tag applications can easily import/integrate and override
36
36
  - **Full TypeScript support** - complete type safety with IntelliSense for all translation keys and interpolation parameters
@@ -49,21 +49,24 @@ Instead of maintaining separate translation files and complex key mappings, tran
49
49
  // Component with colocated translations using custom i18n tag
50
50
  import { i18n } from '../utils/i18n';
51
51
 
52
- const translations = i18n({
53
- greeting: 'Welcome {{name}} to our store!',
54
- orderSummary: 'You have {{count}} items in your cart.',
55
- actions: {
56
- proceed: 'Proceed to Payment',
57
- cancel: 'Cancel Order'
52
+ const translations = i18n(
53
+ {
54
+ greeting: 'Welcome {{name}} to our store!',
55
+ orderSummary: 'You have {{count}} items in your cart.',
56
+ actions: {
57
+ proceed: 'Proceed to Payment',
58
+ cancel: 'Cancel Order',
59
+ },
60
+ },
61
+ {
62
+ namespace: 'orders',
63
+ path: 'components.checkout',
58
64
  }
59
- }, {
60
- namespace: 'orders',
61
- path: 'components.checkout'
62
- });
65
+ );
63
66
 
64
67
  function CheckoutComponent({ name, count }) {
65
68
  const t = translations.useT();
66
-
69
+
67
70
  return (
68
71
  <div>
69
72
  <h2>{t.greeting({ name })}</h2>
@@ -82,16 +85,19 @@ function CheckoutComponent({ name, count }) {
82
85
  The `lang-tag` ecosystem provides tooling to transform colocated definitions into production-ready translation files:
83
86
 
84
87
  **Collection & Organization**
88
+
85
89
  - The `lang-tag collect` command discovers translation tags throughout your codebase
86
90
  - Translations are organized into namespace-based JSON files (e.g., `public/locales/en/orders.json`)
87
91
  - Hierarchical key structures can be automatically generated based on configuration rules (eg.: based on component paths)
88
92
 
89
93
  **Dynamic Configuration Management**
94
+
90
95
  - Configuration parameters can be automatically generated using `onConfigGeneration` rules
91
96
  - Namespace and path assignments can be derived from custom logic (eg.: by file structure, component location)
92
97
  - The `lang-tag regenerate-tags` command updates source code configurations dynamically
93
98
 
94
99
  **Development-Time Optimization**
100
+
95
101
  - Watch mode (`lang-tag watch`) provides real-time translation collection during development
96
102
  - Changes to translation definitions trigger automatic regeneration of translation files
97
103
  - Full TypeScript integration ensures compile-time validation of translation keys and parameters
@@ -99,16 +105,19 @@ The `lang-tag` ecosystem provides tooling to transform colocated definitions int
99
105
  ### Enterprise Integration Capabilities
100
106
 
101
107
  **Framework Agnostic Architecture**
108
+
102
109
  - Core library provides building blocks (like `createCallableTranslations`) for creating custom tag functions
103
110
  - Seamless integration with existing i18n libraries (i18next, react-i18next, etc.)
104
111
  - Maintains compatibility with current translation workflows while enhancing developer experience
105
112
 
106
113
  **Library Ecosystem Support**
114
+
107
115
  - Component libraries can embed translations using `.lang-tag.exports.json` manifests
108
116
  - The `lang-tag import` command automatically discovers and integrates library translations
109
117
  - Consuming applications maintain full control over translation overrides and customization
110
118
 
111
119
  **Type-Safe Translation Experience**
120
+
112
121
  - Complete TypeScript support with IntelliSense for all translation keys
113
122
  - Compile-time validation of interpolation parameters
114
123
  - Callable translation objects provide intuitive API with full type inference
@@ -134,4 +143,4 @@ For detailed setup, usage, and advanced features, please refer to the documentat
134
143
  - [React-i18next Example](docs/react-i18n-example.md)
135
144
  - [Library Support](docs/library-support.md)
136
145
  - [API Reference](docs/api-reference.md)
137
- - [Flexible Translation Definitions](docs/flexible-translations.md)
146
+ - [Flexible Translation Definitions](docs/flexible-translations.md)
@@ -0,0 +1,12 @@
1
+ /**
2
+ * Available case transformation types supported by the case library.
3
+ */
4
+ export type CaseType = 'no' | 'camel' | 'capital' | 'constant' | 'dot' | 'header' | 'kebab' | 'lower' | 'param' | 'pascal' | 'path' | 'sentence' | 'snake' | 'swap' | 'title' | 'upper';
5
+ /**
6
+ * Applies case transformation to a string using the case library.
7
+ *
8
+ * @param str - The string to transform
9
+ * @param caseType - The case transformation type
10
+ * @returns The transformed string
11
+ */
12
+ export declare function applyCaseTransform(str: string, caseType: CaseType): string;
@@ -1,5 +1,5 @@
1
- import { TranslationsCollector } from './type.ts';
2
- import { LangTagCLIProcessedTag } from '../../config.ts';
1
+ import { TranslationsCollector } from './type';
2
+ import { LangTagCLIProcessedTag } from '../../type';
3
3
  interface Options {
4
4
  appendNamespaceToPath: boolean;
5
5
  }
@@ -5,6 +5,6 @@
5
5
  * during the collection process. Each collector implements a different strategy
6
6
  * for organizing translations (e.g., single dictionary vs. namespace-based files).
7
7
  */
8
- export { DictionaryCollector } from './dictionary-collector.ts';
9
- export { NamespaceCollector } from './namespace-collector.ts';
10
- export { type TranslationsCollector } from './type.ts';
8
+ export { DictionaryCollector } from './dictionary-collector';
9
+ export { NamespaceCollector } from './namespace-collector';
10
+ export { type TranslationsCollector } from './type';
@@ -1,5 +1,5 @@
1
- import { TranslationsCollector } from './type.ts';
2
- import { LangTagCLIProcessedTag } from '../../config.ts';
1
+ import { TranslationsCollector } from './type';
2
+ import { LangTagCLIProcessedTag } from '../../type';
3
3
  export declare class NamespaceCollector extends TranslationsCollector {
4
4
  private clean;
5
5
  private languageDirectory;
@@ -1,5 +1,5 @@
1
- import { LangTagCLIConfig, LangTagCLIProcessedTag } from '../../config.ts';
2
- import { LangTagCLILogger } from '../../logger.ts';
1
+ import { LangTagCLILogger } from '../../logger';
2
+ import { LangTagCLIConfig, LangTagCLIProcessedTag } from '../../type';
3
3
  export declare abstract class TranslationsCollector {
4
4
  config: LangTagCLIConfig;
5
5
  logger: LangTagCLILogger;
@@ -1,4 +1,4 @@
1
- import { LangTagCLIConfigGenerationEvent } from '../../config.ts';
1
+ import { LangTagCLIConfigGenerationEvent } from '../../type';
2
2
  export type ConfigKeeperMode = 'namespace' | 'path' | 'both';
3
3
  export interface ConfigKeeperOptions {
4
4
  /**
@@ -4,6 +4,6 @@
4
4
  * These algorithms customize how translation tag configurations are generated
5
5
  * during collection and regeneration.
6
6
  */
7
- export { pathBasedConfigGenerator, type PathBasedConfigGeneratorOptions } from './path-based-config-generator.ts';
8
- export { configKeeper, type ConfigKeeperOptions, type ConfigKeeperMode } from './config-keeper.ts';
9
- export { prependNamespaceToPath, type PrependNamespaceToPathOptions } from './prepend-namespace-to-path.ts';
7
+ export { pathBasedConfigGenerator, type PathBasedConfigGeneratorOptions, } from './path-based-config-generator';
8
+ export { configKeeper, type ConfigKeeperOptions, type ConfigKeeperMode, } from './config-keeper';
9
+ export { prependNamespaceToPath, type PrependNamespaceToPathOptions, } from './prepend-namespace-to-path';
@@ -1,4 +1,5 @@
1
- import { LangTagCLIConfigGenerationEvent } from '../../config.ts';
1
+ import { LangTagCLIConfigGenerationEvent } from '../../type';
2
+ import { CaseType } from '../case-utils';
2
3
  export interface PathBasedConfigGeneratorOptions {
3
4
  /**
4
5
  * Whether to include the filename (without extension) as part of the path segments.
@@ -120,14 +121,14 @@ export interface PathBasedConfigGeneratorOptions {
120
121
  * 'lower', 'no', 'param', 'pascal', 'path', 'sentence', 'snake', 'swap', 'title', 'upper'
121
122
  * @default undefined (no transformation)
122
123
  */
123
- namespaceCase?: 'camel' | 'capital' | 'constant' | 'dot' | 'header' | 'kebab' | 'lower' | 'no' | 'param' | 'pascal' | 'path' | 'sentence' | 'snake' | 'swap' | 'title' | 'upper';
124
+ namespaceCase?: CaseType;
124
125
  /**
125
126
  * Case transformation to apply to the path segments.
126
127
  * Available options: 'camel', 'capital', 'constant', 'dot', 'header', 'kebab',
127
128
  * 'lower', 'no', 'param', 'pascal', 'path', 'sentence', 'snake', 'swap', 'title', 'upper'
128
129
  * @default undefined (no transformation)
129
130
  */
130
- pathCase?: 'camel' | 'capital' | 'constant' | 'dot' | 'header' | 'kebab' | 'lower' | 'no' | 'param' | 'pascal' | 'path' | 'sentence' | 'snake' | 'swap' | 'title' | 'upper';
131
+ pathCase?: CaseType;
131
132
  /**
132
133
  * Fallback namespace to use when no segments remain after filtering.
133
134
  * Defaults to the defaultNamespace from langTagConfig.collect.defaultNamespace if not provided.
@@ -1,4 +1,4 @@
1
- import { LangTagCLIConfigGenerationEvent } from '../../config.ts';
1
+ import { LangTagCLIConfigGenerationEvent } from '../../type';
2
2
  /**
3
3
  * Options for the prependNamespaceToPath algorithm.
4
4
  */
@@ -0,0 +1,232 @@
1
+ import { LangTagCLIImportEvent } from '../../type';
2
+ import { CaseType } from '../case-utils';
3
+ /**
4
+ * Available case transformation options for variable names.
5
+ * Only includes transformations that produce valid JavaScript identifiers.
6
+ */
7
+ export type VariableNameCaseType = 'no' | 'camel' | 'capital' | 'constant' | 'lower' | 'pascal' | 'snake' | 'swap' | 'upper';
8
+ /**
9
+ * Case transformation configuration for file paths.
10
+ * Can be a string for uniform case transformation, or an object with separate
11
+ * case transformations for directories and files.
12
+ */
13
+ export type FilePathCaseType = CaseType | {
14
+ directories?: CaseType;
15
+ files?: CaseType;
16
+ };
17
+ export interface VariableNameOptions {
18
+ /**
19
+ * Whether to prefix variable names with package name to avoid conflicts.
20
+ * @default false
21
+ */
22
+ prefixWithPackageName?: boolean;
23
+ /**
24
+ * How to handle scoped package names (e.g., '@scope/package').
25
+ * - 'remove-scope': Remove @scope/ part, keep only package name
26
+ * - 'replace': Remove @ and replace / with underscores
27
+ * @default 'replace'
28
+ */
29
+ scopedPackageHandling?: 'remove-scope' | 'replace';
30
+ /**
31
+ * Case transformation to apply to variable names.
32
+ * Available options: 'camel', 'capital', 'constant', 'lower', 'no', 'pascal', 'snake', 'swap', 'upper'
33
+ * @default 'no'
34
+ */
35
+ case?: VariableNameCaseType;
36
+ /**
37
+ * Whether to sanitize variable names by replacing invalid characters with $.
38
+ * This ensures the final variable name is a valid JavaScript identifier.
39
+ * @default true
40
+ */
41
+ sanitizeVariableName?: boolean;
42
+ /**
43
+ * How to handle tags without variableName.
44
+ * - 'skip': Skip tags without variableName
45
+ * - 'auto-generate': Generate names like 'translations1', 'translations2', etc. (default)
46
+ * - Function: Custom function to generate variable names
47
+ * @default 'auto-generate'
48
+ */
49
+ handleMissingVariableName?: 'skip' | 'auto-generate' | ((tag: any, packageName: string, fileName: string, index: number) => string);
50
+ /**
51
+ * Custom function to generate variable names, completely overriding original names from export.
52
+ * When provided, this function will be used instead of the original variableName from the export.
53
+ *
54
+ * Note: The returned custom name will still be processed by all other transformations
55
+ * (case transformation, sanitization, prefixWithPackageName, etc.).
56
+ *
57
+ * @param context - Context information about the import
58
+ * @returns The custom variable name, or null to fall back to original naming logic
59
+ *
60
+ * @example
61
+ * ```typescript
62
+ * customVariableName: (context) => {
63
+ * // Generate names based on package and file structure
64
+ * const packagePrefix = context.packageName.replace('@company/', '').replace('-', '');
65
+ * const fileBase = context.fileName.split('/').pop()?.replace('.ts', '') || 'unknown';
66
+ * return `${packagePrefix}_${fileBase}_${context.tagIndex + 1}`;
67
+ * // This will still be processed by case transformation, sanitization, etc.
68
+ * }
69
+ * ```
70
+ */
71
+ customVariableName?: (context: {
72
+ packageName: string;
73
+ fileName: string;
74
+ originalVariableName: string | undefined;
75
+ tagIndex: number;
76
+ tag: any;
77
+ }) => string | null;
78
+ }
79
+ export interface FilePathOptions {
80
+ /**
81
+ * Whether to group all translations from each package into a single file.
82
+ * If false, preserves the original file structure from the library.
83
+ * @default false
84
+ */
85
+ groupByPackage?: boolean;
86
+ /**
87
+ * Whether to include package name in the file path.
88
+ * @default false
89
+ */
90
+ includePackageInPath?: boolean;
91
+ /**
92
+ * How to handle scoped package names in file paths (e.g., '@scope/package').
93
+ * - 'remove-scope': Remove @scope/ part, keep only package name
94
+ * - 'replace': Remove @ and replace / with dashes
95
+ * @default 'replace'
96
+ */
97
+ scopedPackageHandling?: 'remove-scope' | 'replace';
98
+ /**
99
+ * Case transformation to apply to file names and path segments.
100
+ * Can be a string for uniform case transformation, or an object with separate
101
+ * case transformations for directories and files.
102
+ * Available options: 'camel', 'capital', 'constant', 'dot', 'header', 'kebab',
103
+ * 'lower', 'no', 'param', 'pascal', 'path', 'sentence', 'snake', 'swap', 'title', 'upper'
104
+ * @default 'no'
105
+ */
106
+ case?: FilePathCaseType;
107
+ }
108
+ export interface FlexibleImportAlgorithmOptions {
109
+ /**
110
+ * Options for controlling variable name generation.
111
+ */
112
+ variableName?: VariableNameOptions;
113
+ /**
114
+ * Options for controlling file path generation.
115
+ */
116
+ filePath?: FilePathOptions;
117
+ /**
118
+ * Inclusion rules for filtering imports.
119
+ * If undefined, all packages and namespaces are processed.
120
+ * If defined, only matching packages and namespaces are processed.
121
+ */
122
+ include?: {
123
+ /**
124
+ * List of package name patterns to include from import.
125
+ * Supports wildcards with * (e.g., '@company/*', 'ui-*')
126
+ * @default undefined (include all)
127
+ */
128
+ packages?: string[];
129
+ /**
130
+ * List of namespace patterns to include from import.
131
+ * Supports wildcards with * (e.g., 'ui.*', '*.common')
132
+ * @default undefined (include all)
133
+ */
134
+ namespaces?: string[];
135
+ };
136
+ /**
137
+ * Exclusion rules for filtering imports.
138
+ * Applied after inclusion rules.
139
+ */
140
+ exclude?: {
141
+ /**
142
+ * List of package name patterns to exclude from import.
143
+ * Supports wildcards with * (e.g., '@company/*', 'ui-*')
144
+ * @default []
145
+ */
146
+ packages?: string[];
147
+ /**
148
+ * List of namespace patterns to exclude from import.
149
+ * Supports wildcards with * (e.g., 'admin.*', '*.internal')
150
+ * @default []
151
+ */
152
+ namespaces?: string[];
153
+ };
154
+ /**
155
+ * Function to remap/override configs before saving imported tags.
156
+ * Allows modification of namespace, path, and other config properties
157
+ * based on package name, file path, or other context.
158
+ *
159
+ * @param originalConfig - The original config from the imported tag
160
+ * @param context - Context information about the import
161
+ * @returns The modified config object, or null to remove the config from the tag
162
+ *
163
+ * @example
164
+ * ```typescript
165
+ * configRemap: (config, context) => {
166
+ * // Override namespace based on package name
167
+ * if (context.packageName === 'ui-components') {
168
+ * return { ...config, namespace: 'ui' };
169
+ * }
170
+ *
171
+ * // Remove config for certain packages (tag will be imported without config)
172
+ * if (context.packageName === 'no-config-package') {
173
+ * return null;
174
+ * }
175
+ *
176
+ * // Add prefix to all paths
177
+ * if (config.path) {
178
+ * return { ...config, path: `lib.${config.path}` };
179
+ * }
180
+ *
181
+ * return config;
182
+ * }
183
+ * ```
184
+ */
185
+ configRemap?: (originalConfig: any, context: {
186
+ packageName: string;
187
+ fileName: string;
188
+ variableName: string;
189
+ tagIndex: number;
190
+ }) => any | null;
191
+ }
192
+ /**
193
+ * Default import algorithm that imports translations from libraries.
194
+ *
195
+ * This algorithm provides flexible options for organizing imported translations
196
+ * while preserving the ability to customize the import process.
197
+ *
198
+ * @param options - Configuration options for the import algorithm
199
+ * @returns A function compatible with LangTagCLIConfig.import.onImport
200
+ *
201
+ * @example
202
+ * ```typescript
203
+ * import { flexibleImportAlgorithm } from '@lang-tag/cli/algorithms';
204
+ *
205
+ * export default {
206
+ * import: {
207
+ * onImport: flexibleImportAlgorithm({
208
+ * variableName: {
209
+ * prefixWithPackageName: true,
210
+ * scopedPackageHandling: 'replace', // '@scope/package' -> 'scope_package'
211
+ * case: 'camel', // 'scope_package_myVar' -> 'scopePackageMyVar'
212
+ * handleMissingVariableName: 'auto-generate' // Generate 'translations1', 'translations2', etc.
213
+ * },
214
+ * filePath: {
215
+ * groupByPackage: true,
216
+ * scopedPackageHandling: 'remove-scope', // '@scope/package' -> 'package'
217
+ * case: 'kebab' // 'package.ts' -> 'package.ts' (no change), 'my-file.ts' -> 'my-file.ts'
218
+ * },
219
+ * include: {
220
+ * packages: ['@company/*', 'ui-*'],
221
+ * namespaces: ['ui.*', '*.common']
222
+ * },
223
+ * exclude: {
224
+ * packages: ['@company/internal-*'],
225
+ * namespaces: ['admin.*', '*.internal']
226
+ * }
227
+ * })
228
+ * }
229
+ * };
230
+ * ```
231
+ */
232
+ export declare function flexibleImportAlgorithm(options?: FlexibleImportAlgorithmOptions): (event: LangTagCLIImportEvent) => void;
@@ -4,4 +4,5 @@
4
4
  * These algorithms customize how library translations are imported
5
5
  * and organized in your project.
6
6
  */
7
- export {};
7
+ export { flexibleImportAlgorithm, type FlexibleImportAlgorithmOptions, type FilePathCaseType, type VariableNameCaseType, } from './flexible-import-algorithm';
8
+ export { simpleMappingImportAlgorithm, type SimpleMappingImportAlgorithmOptions, type PackageMapping, type FileMapping, } from './simple-mapping-import-algorithm';
@@ -0,0 +1,120 @@
1
+ import { LangTagCLIImportEvent } from '../../type';
2
+ /**
3
+ * Mapping for a specific file within a package.
4
+ * Defines which variables to import and optionally rename them.
5
+ */
6
+ export interface FileMapping {
7
+ /**
8
+ * Source file path within the package
9
+ * @example 'components/button.ts'
10
+ */
11
+ sourceFile: string;
12
+ /**
13
+ * Target file path where variables should be imported
14
+ * @example 'ui/buttons.ts'
15
+ */
16
+ targetFile: string;
17
+ /**
18
+ * Map of variable names to import and their optional new names.
19
+ * If no new name is provided, the original name is used.
20
+ * @example { 'primaryButton': 'button', 'secondaryButton': 'secondary' }
21
+ */
22
+ variables: Record<string, string | undefined>;
23
+ }
24
+ /**
25
+ * Mapping for a specific package.
26
+ * Defines which files to import and how to map their variables.
27
+ */
28
+ export interface PackageMapping {
29
+ /**
30
+ * Package name to match
31
+ * @example '@company/ui-components'
32
+ */
33
+ packageName: string;
34
+ /**
35
+ * Array of file mappings for this package
36
+ */
37
+ files: FileMapping[];
38
+ }
39
+ /**
40
+ * Options for the simple mapping import algorithm.
41
+ */
42
+ export interface SimpleMappingImportAlgorithmOptions {
43
+ /**
44
+ * Array of package mappings defining how to import from each package
45
+ */
46
+ mappings: PackageMapping[];
47
+ /**
48
+ * Global config remapping function applied to all imported tags
49
+ */
50
+ configRemap?: (originalConfig: any, context: {
51
+ packageName: string;
52
+ sourceFile: string;
53
+ targetFile: string;
54
+ variableName: string;
55
+ originalVariableName: string;
56
+ }) => any | null;
57
+ }
58
+ /**
59
+ * Simple mapping import algorithm that provides straightforward control over
60
+ * how library translations are imported based on explicit package->file->variable mappings.
61
+ *
62
+ * This algorithm allows you to:
63
+ * - Specify exactly which packages to import from
64
+ * - Map specific files from packages to target files
65
+ * - Select which variables to import and optionally rename them
66
+ * - Skip packages/files/variables not explicitly mapped
67
+ *
68
+ * @param options - Configuration options for the simple mapping algorithm
69
+ * @returns A function compatible with LangTagCLIConfig.import.onImport
70
+ *
71
+ * @example
72
+ * ```typescript
73
+ * import { simpleMappingImportAlgorithm } from '@lang-tag/cli/algorithms';
74
+ *
75
+ * export default {
76
+ * import: {
77
+ * onImport: simpleMappingImportAlgorithm({
78
+ * mappings: [
79
+ * {
80
+ * packageName: '@company/ui-components',
81
+ * files: [
82
+ * {
83
+ * sourceFile: 'components/button.ts',
84
+ * targetFile: 'ui/buttons.ts',
85
+ * variables: {
86
+ * 'primaryButton': 'button',
87
+ * 'secondaryButton': 'secondary',
88
+ * 'tertiaryButton': undefined // keep original name
89
+ * }
90
+ * },
91
+ * {
92
+ * sourceFile: 'components/input.ts',
93
+ * targetFile: 'ui/inputs.ts',
94
+ * variables: {
95
+ * 'textInput': 'input',
96
+ * 'passwordInput': 'password'
97
+ * }
98
+ * }
99
+ * ]
100
+ * },
101
+ * {
102
+ * packageName: '@company/utils',
103
+ * files: [
104
+ * {
105
+ * sourceFile: 'helpers.ts',
106
+ * targetFile: 'utils/helpers.ts',
107
+ * variables: {
108
+ * 'formatDate': undefined,
109
+ * 'formatCurrency': 'currency'
110
+ * }
111
+ * }
112
+ * ]
113
+ * }
114
+ * ]
115
+ * })
116
+ * }
117
+ * };
118
+ * ```
119
+ */
120
+ export declare function simpleMappingImportAlgorithm(options: SimpleMappingImportAlgorithmOptions): (event: LangTagCLIImportEvent) => void;