@yuuvis/client-cli 19.3.1 → 19.3.3
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/package.json
CHANGED
|
@@ -6,16 +6,19 @@ function traverseDirectory(currentPath, i18nFolders, excludeList) {
|
|
|
6
6
|
const entryPath = path.join(currentPath, entry);
|
|
7
7
|
const isDirectory = fs.statSync(entryPath).isDirectory();
|
|
8
8
|
if (isDirectory) {
|
|
9
|
-
|
|
10
|
-
i18nFolders.push(entryPath)
|
|
11
|
-
|
|
12
|
-
traverseDirectory(entryPath, i18nFolders, excludeList);
|
|
13
|
-
}
|
|
9
|
+
entry === 'i18n' && !excludeList.some((exclude) => entryPath.includes(exclude))
|
|
10
|
+
? i18nFolders.push(entryPath)
|
|
11
|
+
: traverseDirectory(entryPath, i18nFolders, excludeList);
|
|
14
12
|
}
|
|
15
13
|
});
|
|
16
14
|
return i18nFolders;
|
|
17
15
|
}
|
|
18
|
-
function findI18nFolders(base, excludeList) {
|
|
16
|
+
function findI18nFolders(base, excludeList = []) {
|
|
17
|
+
// Normalize base to absolute paths for comparison
|
|
18
|
+
base = base.split('/').reduce((acc, part) => path.join(acc, part), '');
|
|
19
|
+
// Normalize excludeList entries to absolute paths for comparison
|
|
20
|
+
excludeList = excludeList.map((exclude) => exclude.split('/').reduce((acc, part) => path.join(acc, part), ''));
|
|
21
|
+
|
|
19
22
|
let i18nFolders = [];
|
|
20
23
|
if (fs.existsSync(base)) {
|
|
21
24
|
i18nFolders = traverseDirectory(base, i18nFolders, excludeList);
|
|
@@ -27,15 +30,14 @@ function groupFilesByLanguageCode(files) {
|
|
|
27
30
|
const match = file.match(/^([a-z]{2})\.json$/);
|
|
28
31
|
if (match) {
|
|
29
32
|
const lang = match[1];
|
|
30
|
-
if (!acc[lang])
|
|
31
|
-
acc[lang] = [];
|
|
33
|
+
if (!acc[lang]) acc[lang] = [];
|
|
32
34
|
acc[lang].push(path.join(dir, file));
|
|
33
35
|
}
|
|
34
36
|
return acc;
|
|
35
37
|
}, {});
|
|
36
38
|
}
|
|
37
|
-
async function copyTo(
|
|
38
|
-
const files =
|
|
39
|
+
async function copyTo(srcDirectories, outputDir) {
|
|
40
|
+
const files = srcDirectories.flatMap((dir) => fs.readdirSync(dir).map((file) => ({ dir, file })));
|
|
39
41
|
// Group files by language code
|
|
40
42
|
const languageFiles = groupFilesByLanguageCode(files);
|
|
41
43
|
// Merge files for each language
|
|
@@ -44,16 +46,22 @@ async function copyTo(directories, outputDir) {
|
|
|
44
46
|
const data = fs.existsSync(filePath) ? JSON.parse(fs.readFileSync(filePath, 'utf-8')) : {};
|
|
45
47
|
return { ...acc, ...data };
|
|
46
48
|
}, {});
|
|
49
|
+
const sortedMergedData = Object.keys(mergedData)
|
|
50
|
+
.sort()
|
|
51
|
+
.reduce((sortedObj, key) => {
|
|
52
|
+
sortedObj[key] = mergedData[key];
|
|
53
|
+
return sortedObj;
|
|
54
|
+
}, {});
|
|
47
55
|
if (!fs.existsSync(outputDir)) {
|
|
48
56
|
fs.mkdirSync(outputDir, { recursive: true });
|
|
49
57
|
}
|
|
50
58
|
const outputFilePath = path.join(outputDir, `${lang}.json`);
|
|
51
|
-
fs.writeFileSync(outputFilePath, JSON.stringify(
|
|
59
|
+
fs.writeFileSync(outputFilePath, JSON.stringify(sortedMergedData, null, 2), 'utf-8');
|
|
52
60
|
console.log(`Merged ${lang} files into ${outputFilePath}`);
|
|
53
61
|
}
|
|
54
62
|
}
|
|
55
|
-
(
|
|
56
|
-
const externalFolders = findI18nFolders('./node_modules/@yuuvis', ['schematics'
|
|
63
|
+
function copyExternalLibs() {
|
|
64
|
+
const externalFolders = findI18nFolders('./node_modules/@yuuvis', ['schematics']);
|
|
57
65
|
// copy external libs translations to i18n-external
|
|
58
66
|
const externalOutputDir = path.join('.', 'i18n-external');
|
|
59
67
|
copyTo(externalFolders, externalOutputDir).catch(console.error);
|
|
@@ -66,9 +74,11 @@ async function copyTo(directories, outputDir) {
|
|
|
66
74
|
.filter((file) => file !== 'en.json')
|
|
67
75
|
.forEach((file) => {
|
|
68
76
|
const langFilePath = path.join(externalOutputDir, file);
|
|
69
|
-
const srcLangfile = JSON.parse(
|
|
70
|
-
|
|
71
|
-
|
|
77
|
+
const srcLangfile = JSON.parse(
|
|
78
|
+
fs.readFileSync(langFilePath, {
|
|
79
|
+
encoding: 'utf-8'
|
|
80
|
+
}
|
|
81
|
+
));
|
|
72
82
|
const targetLangFile = {};
|
|
73
83
|
refKeys.forEach((k) => {
|
|
74
84
|
targetLangFile[k] = srcLangfile[k] || '';
|
|
@@ -76,8 +86,12 @@ async function copyTo(directories, outputDir) {
|
|
|
76
86
|
fs.writeFileSync(langFilePath, JSON.stringify(targetLangFile, null, 2));
|
|
77
87
|
});
|
|
78
88
|
}
|
|
89
|
+
return externalOutputDir;
|
|
90
|
+
}
|
|
91
|
+
(() => {
|
|
79
92
|
const outputDir = path.join('.', 'src', 'assets', '_yuuvis', 'i18n');
|
|
80
|
-
const
|
|
93
|
+
const externalOutputDir = copyExternalLibs();
|
|
94
|
+
const localFolders = findI18nFolders('./projects');
|
|
81
95
|
const clientFolders = findI18nFolders('./src', ['assets/_yuuvis']);
|
|
82
96
|
copyTo([...localFolders, ...clientFolders, externalOutputDir], outputDir).catch(console.error);
|
|
83
97
|
})();
|