@lang-tag/cli 0.14.0 → 0.16.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/algorithms/case-utils.d.ts +12 -0
- package/algorithms/collector/dictionary-collector.d.ts +17 -0
- package/algorithms/collector/index.d.ts +10 -0
- package/algorithms/collector/namespace-collector.d.ts +12 -0
- package/algorithms/collector/type.d.ts +12 -0
- package/algorithms/config-generation/index.d.ts +1 -0
- package/algorithms/config-generation/path-based-config-generator.d.ts +3 -2
- package/algorithms/config-generation/prepend-namespace-to-path.d.ts +28 -0
- package/algorithms/import/flexible-import-algorithm.d.ts +232 -0
- package/algorithms/import/index.d.ts +2 -1
- package/algorithms/import/simple-mapping-import-algorithm.d.ts +120 -0
- package/algorithms/index.cjs +161 -28
- package/algorithms/index.d.ts +9 -3
- package/algorithms/index.js +177 -26
- package/config.d.ts +95 -75
- package/flexible-import-algorithm-C-S1c742.js +311 -0
- package/flexible-import-algorithm-Fa-l4jWj.cjs +327 -0
- package/index.cjs +236 -203
- package/index.js +233 -200
- package/package.json +1 -1
- package/templates/config/init-config.mustache +1 -0
- package/templates/import/imported-tag.mustache +14 -0
- /package/{template → templates/tag}/base-app.mustache +0 -0
- /package/{template → templates/tag}/base-library.mustache +0 -0
- /package/{template → templates/tag}/placeholder.mustache +0 -0
package/algorithms/index.cjs
CHANGED
|
@@ -1,25 +1,76 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
+
const flexibleImportAlgorithm = require("../flexible-import-algorithm-Fa-l4jWj.cjs");
|
|
3
4
|
const path = require("pathe");
|
|
4
|
-
const
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
5
|
+
const process = require("node:process");
|
|
6
|
+
class DictionaryCollector extends flexibleImportAlgorithm.TranslationsCollector {
|
|
7
|
+
constructor(options = {
|
|
8
|
+
appendNamespaceToPath: false
|
|
9
|
+
}) {
|
|
10
|
+
super();
|
|
11
|
+
this.options = options;
|
|
12
|
+
}
|
|
13
|
+
clean;
|
|
14
|
+
aggregateCollection(namespace) {
|
|
15
|
+
return this.config.baseLanguageCode;
|
|
16
|
+
}
|
|
17
|
+
transformTag(tag) {
|
|
18
|
+
const originalPath = tag.parameterConfig.path;
|
|
19
|
+
let path2 = originalPath;
|
|
20
|
+
if (this.options.appendNamespaceToPath) {
|
|
21
|
+
path2 = tag.parameterConfig.namespace;
|
|
22
|
+
if (originalPath) {
|
|
23
|
+
path2 += ".";
|
|
24
|
+
path2 += originalPath;
|
|
15
25
|
}
|
|
26
|
+
return {
|
|
27
|
+
...tag,
|
|
28
|
+
parameterConfig: {
|
|
29
|
+
...tag.parameterConfig,
|
|
30
|
+
namespace: void 0,
|
|
31
|
+
path: path2
|
|
32
|
+
}
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
return tag;
|
|
36
|
+
}
|
|
37
|
+
async preWrite(clean) {
|
|
38
|
+
this.clean = clean;
|
|
39
|
+
const baseDictionaryFile = path.join(this.config.localesDirectory, `${this.config.baseLanguageCode}.json`);
|
|
40
|
+
if (clean) {
|
|
41
|
+
this.logger.info("Removing {file}", { file: baseDictionaryFile });
|
|
42
|
+
await flexibleImportAlgorithm.$LT_RemoveFile(baseDictionaryFile);
|
|
43
|
+
}
|
|
44
|
+
await flexibleImportAlgorithm.$LT_EnsureDirectoryExists(this.config.localesDirectory);
|
|
45
|
+
}
|
|
46
|
+
async resolveCollectionFilePath(baseLanguageCode) {
|
|
47
|
+
return path.resolve(
|
|
48
|
+
process.cwd(),
|
|
49
|
+
this.config.localesDirectory,
|
|
50
|
+
baseLanguageCode + ".json"
|
|
51
|
+
);
|
|
52
|
+
}
|
|
53
|
+
async onMissingCollection(baseLanguageCode) {
|
|
54
|
+
if (!this.clean) {
|
|
55
|
+
this.logger.warn(`Original dictionary file "{namespace}.json" not found. A new one will be created.`, { namespace: baseLanguageCode });
|
|
16
56
|
}
|
|
17
57
|
}
|
|
18
|
-
|
|
19
|
-
|
|
58
|
+
async postWrite(changedCollections) {
|
|
59
|
+
if (!changedCollections?.length) {
|
|
60
|
+
this.logger.info("No changes were made based on the current configuration and files");
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
63
|
+
if (changedCollections.length > 1) {
|
|
64
|
+
throw new Error("Should not write more than 1 collection! Only 1 base language dictionary expected!");
|
|
65
|
+
}
|
|
66
|
+
const dict = path.resolve(
|
|
67
|
+
this.config.localesDirectory,
|
|
68
|
+
this.config.baseLanguageCode + ".json"
|
|
69
|
+
);
|
|
70
|
+
this.logger.success("Updated dictionary {dict}", { dict });
|
|
71
|
+
}
|
|
20
72
|
}
|
|
21
|
-
const
|
|
22
|
-
const TRIGGER_NAME$1 = "path-based-config-generator";
|
|
73
|
+
const TRIGGER_NAME$2 = "path-based-config-generator";
|
|
23
74
|
function pathBasedConfigGenerator(options = {}) {
|
|
24
75
|
const {
|
|
25
76
|
includeFileName = false,
|
|
@@ -91,12 +142,12 @@ function pathBasedConfigGenerator(options = {}) {
|
|
|
91
142
|
namespace = namespace.toLowerCase();
|
|
92
143
|
}
|
|
93
144
|
if (namespaceCase) {
|
|
94
|
-
namespace = applyCaseTransform(namespace, namespaceCase);
|
|
145
|
+
namespace = flexibleImportAlgorithm.applyCaseTransform(namespace, namespaceCase);
|
|
95
146
|
}
|
|
96
147
|
}
|
|
97
148
|
if (path$1 && pathCase) {
|
|
98
149
|
const pathParts = path$1.split(".");
|
|
99
|
-
const transformedParts = pathParts.map((part) => applyCaseTransform(part, pathCase));
|
|
150
|
+
const transformedParts = pathParts.map((part) => flexibleImportAlgorithm.applyCaseTransform(part, pathCase));
|
|
100
151
|
path$1 = transformedParts.join(".");
|
|
101
152
|
}
|
|
102
153
|
const newConfig = event.config ? { ...event.config } : {};
|
|
@@ -109,7 +160,7 @@ function pathBasedConfigGenerator(options = {}) {
|
|
|
109
160
|
(key) => key !== "namespace" && key !== "path"
|
|
110
161
|
);
|
|
111
162
|
if (!hasOtherProperties) {
|
|
112
|
-
event.save(null, TRIGGER_NAME$
|
|
163
|
+
event.save(null, TRIGGER_NAME$2);
|
|
113
164
|
return;
|
|
114
165
|
} else {
|
|
115
166
|
delete newConfig.namespace;
|
|
@@ -127,7 +178,7 @@ function pathBasedConfigGenerator(options = {}) {
|
|
|
127
178
|
}
|
|
128
179
|
}
|
|
129
180
|
if (Object.keys(newConfig).length > 0) {
|
|
130
|
-
event.save(newConfig, TRIGGER_NAME$
|
|
181
|
+
event.save(newConfig, TRIGGER_NAME$2);
|
|
131
182
|
}
|
|
132
183
|
};
|
|
133
184
|
}
|
|
@@ -289,13 +340,6 @@ function applyPathRules(segments, structure) {
|
|
|
289
340
|
}
|
|
290
341
|
return result;
|
|
291
342
|
}
|
|
292
|
-
function applyCaseTransform(str, caseType) {
|
|
293
|
-
const caseFunction = caseLib__namespace[caseType];
|
|
294
|
-
if (typeof caseFunction === "function") {
|
|
295
|
-
return caseFunction(str);
|
|
296
|
-
}
|
|
297
|
-
return str;
|
|
298
|
-
}
|
|
299
343
|
function extractRootDirectoriesFromIncludes(includes) {
|
|
300
344
|
const directories = /* @__PURE__ */ new Set();
|
|
301
345
|
for (const pattern of includes) {
|
|
@@ -313,7 +357,7 @@ function extractRootDirectoriesFromIncludes(includes) {
|
|
|
313
357
|
}
|
|
314
358
|
return Array.from(directories);
|
|
315
359
|
}
|
|
316
|
-
const TRIGGER_NAME = "config-keeper";
|
|
360
|
+
const TRIGGER_NAME$1 = "config-keeper";
|
|
317
361
|
function configKeeper(options = {}) {
|
|
318
362
|
const propertyName = options.propertyName ?? "keep";
|
|
319
363
|
const keepPropertyAtEnd = options.keepPropertyAtEnd ?? true;
|
|
@@ -370,8 +414,97 @@ function configKeeper(options = {}) {
|
|
|
370
414
|
delete finalConfig[propertyName];
|
|
371
415
|
}
|
|
372
416
|
finalConfig[propertyName] = keepMode;
|
|
373
|
-
event.save(finalConfig, TRIGGER_NAME);
|
|
417
|
+
event.save(finalConfig, TRIGGER_NAME$1);
|
|
418
|
+
};
|
|
419
|
+
}
|
|
420
|
+
const TRIGGER_NAME = "prepend-namespace-to-path";
|
|
421
|
+
function prependNamespaceToPath(options = {}) {
|
|
422
|
+
return async (event) => {
|
|
423
|
+
const currentConfig = event.savedConfig;
|
|
424
|
+
const { namespace, path: path2 } = currentConfig || {};
|
|
425
|
+
const actualNamespace = namespace || event.langTagConfig.collect?.defaultNamespace;
|
|
426
|
+
if (!actualNamespace) {
|
|
427
|
+
return;
|
|
428
|
+
}
|
|
429
|
+
let newPath;
|
|
430
|
+
if (path2) {
|
|
431
|
+
newPath = `${actualNamespace}.${path2}`;
|
|
432
|
+
} else {
|
|
433
|
+
newPath = actualNamespace;
|
|
434
|
+
}
|
|
435
|
+
event.save({
|
|
436
|
+
...currentConfig || {},
|
|
437
|
+
path: newPath,
|
|
438
|
+
namespace: void 0
|
|
439
|
+
}, TRIGGER_NAME);
|
|
440
|
+
};
|
|
441
|
+
}
|
|
442
|
+
function simpleMappingImportAlgorithm(options) {
|
|
443
|
+
const { mappings, configRemap } = options;
|
|
444
|
+
const packageMap = /* @__PURE__ */ new Map();
|
|
445
|
+
const fileMap = /* @__PURE__ */ new Map();
|
|
446
|
+
for (const mapping of mappings) {
|
|
447
|
+
packageMap.set(mapping.packageName, mapping);
|
|
448
|
+
const files = /* @__PURE__ */ new Map();
|
|
449
|
+
for (const file of mapping.files) {
|
|
450
|
+
files.set(file.sourceFile, file);
|
|
451
|
+
}
|
|
452
|
+
fileMap.set(mapping.packageName, files);
|
|
453
|
+
}
|
|
454
|
+
return (event) => {
|
|
455
|
+
const { exports: exports2, importManager, logger } = event;
|
|
456
|
+
for (const { packageJSON, exportData } of exports2) {
|
|
457
|
+
const packageName = packageJSON.name || "unknown-package";
|
|
458
|
+
const packageMapping = packageMap.get(packageName);
|
|
459
|
+
if (!packageMapping) {
|
|
460
|
+
logger.debug(`Skipping unmapped package: ${packageName}`);
|
|
461
|
+
continue;
|
|
462
|
+
}
|
|
463
|
+
logger.debug(`Processing mapped package: ${packageName}`);
|
|
464
|
+
for (const file of exportData.files) {
|
|
465
|
+
const sourceFile = file.relativeFilePath;
|
|
466
|
+
const packageFiles = fileMap.get(packageName);
|
|
467
|
+
if (!packageFiles) continue;
|
|
468
|
+
const fileMapping = packageFiles.get(sourceFile);
|
|
469
|
+
if (!fileMapping) {
|
|
470
|
+
logger.debug(`Skipping unmapped file: ${packageName}/${sourceFile}`);
|
|
471
|
+
continue;
|
|
472
|
+
}
|
|
473
|
+
logger.debug(`Processing mapped file: ${packageName}/${sourceFile} -> ${fileMapping.targetFile}`);
|
|
474
|
+
for (const tag of file.tags) {
|
|
475
|
+
const originalVariableName = tag.variableName;
|
|
476
|
+
if (!originalVariableName || !(originalVariableName in fileMapping.variables)) {
|
|
477
|
+
logger.debug(`Skipping unmapped variable: ${originalVariableName} in ${packageName}/${sourceFile}`);
|
|
478
|
+
continue;
|
|
479
|
+
}
|
|
480
|
+
const newVariableName = fileMapping.variables[originalVariableName] || originalVariableName;
|
|
481
|
+
const targetFilePath = fileMapping.targetFile;
|
|
482
|
+
let finalConfig = tag.config;
|
|
483
|
+
if (configRemap) {
|
|
484
|
+
finalConfig = configRemap(tag.config, {
|
|
485
|
+
packageName,
|
|
486
|
+
sourceFile,
|
|
487
|
+
targetFile: targetFilePath,
|
|
488
|
+
variableName: newVariableName,
|
|
489
|
+
originalVariableName
|
|
490
|
+
});
|
|
491
|
+
}
|
|
492
|
+
importManager.importTag(targetFilePath, {
|
|
493
|
+
variableName: newVariableName,
|
|
494
|
+
translations: tag.translations,
|
|
495
|
+
config: finalConfig
|
|
496
|
+
});
|
|
497
|
+
logger.debug(`Imported: ${originalVariableName} -> ${newVariableName} in ${targetFilePath}`);
|
|
498
|
+
}
|
|
499
|
+
}
|
|
500
|
+
}
|
|
374
501
|
};
|
|
375
502
|
}
|
|
503
|
+
exports.NamespaceCollector = flexibleImportAlgorithm.NamespaceCollector;
|
|
504
|
+
exports.applyCaseTransform = flexibleImportAlgorithm.applyCaseTransform;
|
|
505
|
+
exports.flexibleImportAlgorithm = flexibleImportAlgorithm.flexibleImportAlgorithm;
|
|
506
|
+
exports.DictionaryCollector = DictionaryCollector;
|
|
376
507
|
exports.configKeeper = configKeeper;
|
|
377
508
|
exports.pathBasedConfigGenerator = pathBasedConfigGenerator;
|
|
509
|
+
exports.prependNamespaceToPath = prependNamespaceToPath;
|
|
510
|
+
exports.simpleMappingImportAlgorithm = simpleMappingImportAlgorithm;
|
package/algorithms/index.d.ts
CHANGED
|
@@ -1,7 +1,13 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* Algorithm modules for lang-tag-cli.
|
|
3
3
|
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
4
|
+
* This module provides access to all available algorithms organized by category:
|
|
5
|
+
* - Collectors: Define how translation tags are organized into output files
|
|
6
|
+
* - Config Generation: Customize tag configuration generation
|
|
7
|
+
* - Import: Handle importing translation libraries
|
|
8
|
+
* - Case Utils: Common case transformation utilities
|
|
6
9
|
*/
|
|
10
|
+
export * from './case-utils';
|
|
11
|
+
export * from './collector/index.ts';
|
|
7
12
|
export * from './config-generation/index.ts';
|
|
13
|
+
export * from './import/index.ts';
|
package/algorithms/index.js
CHANGED
|
@@ -1,6 +1,75 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import
|
|
3
|
-
|
|
1
|
+
import { T as TranslationsCollector, e as $LT_RemoveFile, c as $LT_EnsureDirectoryExists, g as applyCaseTransform } from "../flexible-import-algorithm-C-S1c742.js";
|
|
2
|
+
import { N, f } from "../flexible-import-algorithm-C-S1c742.js";
|
|
3
|
+
import path, { resolve, sep } from "pathe";
|
|
4
|
+
import process__default from "node:process";
|
|
5
|
+
class DictionaryCollector extends TranslationsCollector {
|
|
6
|
+
constructor(options = {
|
|
7
|
+
appendNamespaceToPath: false
|
|
8
|
+
}) {
|
|
9
|
+
super();
|
|
10
|
+
this.options = options;
|
|
11
|
+
}
|
|
12
|
+
clean;
|
|
13
|
+
aggregateCollection(namespace) {
|
|
14
|
+
return this.config.baseLanguageCode;
|
|
15
|
+
}
|
|
16
|
+
transformTag(tag) {
|
|
17
|
+
const originalPath = tag.parameterConfig.path;
|
|
18
|
+
let path2 = originalPath;
|
|
19
|
+
if (this.options.appendNamespaceToPath) {
|
|
20
|
+
path2 = tag.parameterConfig.namespace;
|
|
21
|
+
if (originalPath) {
|
|
22
|
+
path2 += ".";
|
|
23
|
+
path2 += originalPath;
|
|
24
|
+
}
|
|
25
|
+
return {
|
|
26
|
+
...tag,
|
|
27
|
+
parameterConfig: {
|
|
28
|
+
...tag.parameterConfig,
|
|
29
|
+
namespace: void 0,
|
|
30
|
+
path: path2
|
|
31
|
+
}
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
return tag;
|
|
35
|
+
}
|
|
36
|
+
async preWrite(clean) {
|
|
37
|
+
this.clean = clean;
|
|
38
|
+
const baseDictionaryFile = path.join(this.config.localesDirectory, `${this.config.baseLanguageCode}.json`);
|
|
39
|
+
if (clean) {
|
|
40
|
+
this.logger.info("Removing {file}", { file: baseDictionaryFile });
|
|
41
|
+
await $LT_RemoveFile(baseDictionaryFile);
|
|
42
|
+
}
|
|
43
|
+
await $LT_EnsureDirectoryExists(this.config.localesDirectory);
|
|
44
|
+
}
|
|
45
|
+
async resolveCollectionFilePath(baseLanguageCode) {
|
|
46
|
+
return resolve(
|
|
47
|
+
process__default.cwd(),
|
|
48
|
+
this.config.localesDirectory,
|
|
49
|
+
baseLanguageCode + ".json"
|
|
50
|
+
);
|
|
51
|
+
}
|
|
52
|
+
async onMissingCollection(baseLanguageCode) {
|
|
53
|
+
if (!this.clean) {
|
|
54
|
+
this.logger.warn(`Original dictionary file "{namespace}.json" not found. A new one will be created.`, { namespace: baseLanguageCode });
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
async postWrite(changedCollections) {
|
|
58
|
+
if (!changedCollections?.length) {
|
|
59
|
+
this.logger.info("No changes were made based on the current configuration and files");
|
|
60
|
+
return;
|
|
61
|
+
}
|
|
62
|
+
if (changedCollections.length > 1) {
|
|
63
|
+
throw new Error("Should not write more than 1 collection! Only 1 base language dictionary expected!");
|
|
64
|
+
}
|
|
65
|
+
const dict = resolve(
|
|
66
|
+
this.config.localesDirectory,
|
|
67
|
+
this.config.baseLanguageCode + ".json"
|
|
68
|
+
);
|
|
69
|
+
this.logger.success("Updated dictionary {dict}", { dict });
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
const TRIGGER_NAME$2 = "path-based-config-generator";
|
|
4
73
|
function pathBasedConfigGenerator(options = {}) {
|
|
5
74
|
const {
|
|
6
75
|
includeFileName = false,
|
|
@@ -56,13 +125,13 @@ function pathBasedConfigGenerator(options = {}) {
|
|
|
56
125
|
}
|
|
57
126
|
pathSegments = pathSegments.filter((seg) => !ignoreDirectories.includes(seg));
|
|
58
127
|
let namespace;
|
|
59
|
-
let
|
|
128
|
+
let path2;
|
|
60
129
|
if (pathSegments.length >= 1) {
|
|
61
130
|
namespace = pathSegments[0];
|
|
62
131
|
if (pathSegments.length > 1) {
|
|
63
|
-
|
|
132
|
+
path2 = pathSegments.slice(1).join(".");
|
|
64
133
|
} else {
|
|
65
|
-
|
|
134
|
+
path2 = "";
|
|
66
135
|
}
|
|
67
136
|
} else {
|
|
68
137
|
namespace = actualFallbackNamespace;
|
|
@@ -75,22 +144,22 @@ function pathBasedConfigGenerator(options = {}) {
|
|
|
75
144
|
namespace = applyCaseTransform(namespace, namespaceCase);
|
|
76
145
|
}
|
|
77
146
|
}
|
|
78
|
-
if (
|
|
79
|
-
const pathParts =
|
|
147
|
+
if (path2 && pathCase) {
|
|
148
|
+
const pathParts = path2.split(".");
|
|
80
149
|
const transformedParts = pathParts.map((part) => applyCaseTransform(part, pathCase));
|
|
81
|
-
|
|
150
|
+
path2 = transformedParts.join(".");
|
|
82
151
|
}
|
|
83
152
|
const newConfig = event.config ? { ...event.config } : {};
|
|
84
153
|
if (clearOnDefaultNamespace && namespace === actualFallbackNamespace) {
|
|
85
|
-
if (
|
|
86
|
-
newConfig.path =
|
|
154
|
+
if (path2) {
|
|
155
|
+
newConfig.path = path2;
|
|
87
156
|
delete newConfig.namespace;
|
|
88
157
|
} else {
|
|
89
158
|
const hasOtherProperties = event.config && Object.keys(event.config).some(
|
|
90
159
|
(key) => key !== "namespace" && key !== "path"
|
|
91
160
|
);
|
|
92
161
|
if (!hasOtherProperties) {
|
|
93
|
-
event.save(null, TRIGGER_NAME$
|
|
162
|
+
event.save(null, TRIGGER_NAME$2);
|
|
94
163
|
return;
|
|
95
164
|
} else {
|
|
96
165
|
delete newConfig.namespace;
|
|
@@ -101,14 +170,14 @@ function pathBasedConfigGenerator(options = {}) {
|
|
|
101
170
|
if (namespace) {
|
|
102
171
|
newConfig.namespace = namespace;
|
|
103
172
|
}
|
|
104
|
-
if (
|
|
105
|
-
newConfig.path =
|
|
173
|
+
if (path2) {
|
|
174
|
+
newConfig.path = path2;
|
|
106
175
|
} else {
|
|
107
176
|
delete newConfig.path;
|
|
108
177
|
}
|
|
109
178
|
}
|
|
110
179
|
if (Object.keys(newConfig).length > 0) {
|
|
111
|
-
event.save(newConfig, TRIGGER_NAME$
|
|
180
|
+
event.save(newConfig, TRIGGER_NAME$2);
|
|
112
181
|
}
|
|
113
182
|
};
|
|
114
183
|
}
|
|
@@ -270,13 +339,6 @@ function applyPathRules(segments, structure) {
|
|
|
270
339
|
}
|
|
271
340
|
return result;
|
|
272
341
|
}
|
|
273
|
-
function applyCaseTransform(str, caseType) {
|
|
274
|
-
const caseFunction = caseLib[caseType];
|
|
275
|
-
if (typeof caseFunction === "function") {
|
|
276
|
-
return caseFunction(str);
|
|
277
|
-
}
|
|
278
|
-
return str;
|
|
279
|
-
}
|
|
280
342
|
function extractRootDirectoriesFromIncludes(includes) {
|
|
281
343
|
const directories = /* @__PURE__ */ new Set();
|
|
282
344
|
for (const pattern of includes) {
|
|
@@ -286,7 +348,7 @@ function extractRootDirectoriesFromIncludes(includes) {
|
|
|
286
348
|
const firstSegment = match[1];
|
|
287
349
|
const groupMatch = firstSegment.match(/^[\(\[]([^\)\]]+)[\)\]]$/);
|
|
288
350
|
if (groupMatch) {
|
|
289
|
-
const groupDirectories = groupMatch[1].split("|").map((
|
|
351
|
+
const groupDirectories = groupMatch[1].split("|").map((f2) => f2.trim());
|
|
290
352
|
groupDirectories.forEach((directory) => directories.add(directory));
|
|
291
353
|
} else {
|
|
292
354
|
directories.add(firstSegment);
|
|
@@ -294,7 +356,7 @@ function extractRootDirectoriesFromIncludes(includes) {
|
|
|
294
356
|
}
|
|
295
357
|
return Array.from(directories);
|
|
296
358
|
}
|
|
297
|
-
const TRIGGER_NAME = "config-keeper";
|
|
359
|
+
const TRIGGER_NAME$1 = "config-keeper";
|
|
298
360
|
function configKeeper(options = {}) {
|
|
299
361
|
const propertyName = options.propertyName ?? "keep";
|
|
300
362
|
const keepPropertyAtEnd = options.keepPropertyAtEnd ?? true;
|
|
@@ -351,10 +413,99 @@ function configKeeper(options = {}) {
|
|
|
351
413
|
delete finalConfig[propertyName];
|
|
352
414
|
}
|
|
353
415
|
finalConfig[propertyName] = keepMode;
|
|
354
|
-
event.save(finalConfig, TRIGGER_NAME);
|
|
416
|
+
event.save(finalConfig, TRIGGER_NAME$1);
|
|
417
|
+
};
|
|
418
|
+
}
|
|
419
|
+
const TRIGGER_NAME = "prepend-namespace-to-path";
|
|
420
|
+
function prependNamespaceToPath(options = {}) {
|
|
421
|
+
return async (event) => {
|
|
422
|
+
const currentConfig = event.savedConfig;
|
|
423
|
+
const { namespace, path: path2 } = currentConfig || {};
|
|
424
|
+
const actualNamespace = namespace || event.langTagConfig.collect?.defaultNamespace;
|
|
425
|
+
if (!actualNamespace) {
|
|
426
|
+
return;
|
|
427
|
+
}
|
|
428
|
+
let newPath;
|
|
429
|
+
if (path2) {
|
|
430
|
+
newPath = `${actualNamespace}.${path2}`;
|
|
431
|
+
} else {
|
|
432
|
+
newPath = actualNamespace;
|
|
433
|
+
}
|
|
434
|
+
event.save({
|
|
435
|
+
...currentConfig || {},
|
|
436
|
+
path: newPath,
|
|
437
|
+
namespace: void 0
|
|
438
|
+
}, TRIGGER_NAME);
|
|
439
|
+
};
|
|
440
|
+
}
|
|
441
|
+
function simpleMappingImportAlgorithm(options) {
|
|
442
|
+
const { mappings, configRemap } = options;
|
|
443
|
+
const packageMap = /* @__PURE__ */ new Map();
|
|
444
|
+
const fileMap = /* @__PURE__ */ new Map();
|
|
445
|
+
for (const mapping of mappings) {
|
|
446
|
+
packageMap.set(mapping.packageName, mapping);
|
|
447
|
+
const files = /* @__PURE__ */ new Map();
|
|
448
|
+
for (const file of mapping.files) {
|
|
449
|
+
files.set(file.sourceFile, file);
|
|
450
|
+
}
|
|
451
|
+
fileMap.set(mapping.packageName, files);
|
|
452
|
+
}
|
|
453
|
+
return (event) => {
|
|
454
|
+
const { exports, importManager, logger } = event;
|
|
455
|
+
for (const { packageJSON, exportData } of exports) {
|
|
456
|
+
const packageName = packageJSON.name || "unknown-package";
|
|
457
|
+
const packageMapping = packageMap.get(packageName);
|
|
458
|
+
if (!packageMapping) {
|
|
459
|
+
logger.debug(`Skipping unmapped package: ${packageName}`);
|
|
460
|
+
continue;
|
|
461
|
+
}
|
|
462
|
+
logger.debug(`Processing mapped package: ${packageName}`);
|
|
463
|
+
for (const file of exportData.files) {
|
|
464
|
+
const sourceFile = file.relativeFilePath;
|
|
465
|
+
const packageFiles = fileMap.get(packageName);
|
|
466
|
+
if (!packageFiles) continue;
|
|
467
|
+
const fileMapping = packageFiles.get(sourceFile);
|
|
468
|
+
if (!fileMapping) {
|
|
469
|
+
logger.debug(`Skipping unmapped file: ${packageName}/${sourceFile}`);
|
|
470
|
+
continue;
|
|
471
|
+
}
|
|
472
|
+
logger.debug(`Processing mapped file: ${packageName}/${sourceFile} -> ${fileMapping.targetFile}`);
|
|
473
|
+
for (const tag of file.tags) {
|
|
474
|
+
const originalVariableName = tag.variableName;
|
|
475
|
+
if (!originalVariableName || !(originalVariableName in fileMapping.variables)) {
|
|
476
|
+
logger.debug(`Skipping unmapped variable: ${originalVariableName} in ${packageName}/${sourceFile}`);
|
|
477
|
+
continue;
|
|
478
|
+
}
|
|
479
|
+
const newVariableName = fileMapping.variables[originalVariableName] || originalVariableName;
|
|
480
|
+
const targetFilePath = fileMapping.targetFile;
|
|
481
|
+
let finalConfig = tag.config;
|
|
482
|
+
if (configRemap) {
|
|
483
|
+
finalConfig = configRemap(tag.config, {
|
|
484
|
+
packageName,
|
|
485
|
+
sourceFile,
|
|
486
|
+
targetFile: targetFilePath,
|
|
487
|
+
variableName: newVariableName,
|
|
488
|
+
originalVariableName
|
|
489
|
+
});
|
|
490
|
+
}
|
|
491
|
+
importManager.importTag(targetFilePath, {
|
|
492
|
+
variableName: newVariableName,
|
|
493
|
+
translations: tag.translations,
|
|
494
|
+
config: finalConfig
|
|
495
|
+
});
|
|
496
|
+
logger.debug(`Imported: ${originalVariableName} -> ${newVariableName} in ${targetFilePath}`);
|
|
497
|
+
}
|
|
498
|
+
}
|
|
499
|
+
}
|
|
355
500
|
};
|
|
356
501
|
}
|
|
357
502
|
export {
|
|
503
|
+
DictionaryCollector,
|
|
504
|
+
N as NamespaceCollector,
|
|
505
|
+
applyCaseTransform,
|
|
358
506
|
configKeeper,
|
|
359
|
-
|
|
507
|
+
f as flexibleImportAlgorithm,
|
|
508
|
+
pathBasedConfigGenerator,
|
|
509
|
+
prependNamespaceToPath,
|
|
510
|
+
simpleMappingImportAlgorithm
|
|
360
511
|
};
|