@yuuvis/client-cli 19.3.2 → 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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@yuuvis/client-cli",
3
- "version": "19.3.2",
3
+ "version": "19.3.3",
4
4
  "main": "index.js",
5
5
  "schematics": "./schematics/factories/collection.json",
6
6
  "bin": {
@@ -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
- if (entry === 'i18n' && !excludeList.some((exclude) => entryPath.includes(exclude))) {
10
- i18nFolders.push(entryPath);
11
- } else {
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(directories, outputDir) {
38
- const files = directories.flatMap((dir) => fs.readdirSync(dir).map((file) => ({ dir, file })));
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
@@ -45,7 +47,8 @@ async function copyTo(directories, outputDir) {
45
47
  return { ...acc, ...data };
46
48
  }, {});
47
49
  const sortedMergedData = Object.keys(mergedData)
48
- .sort().reduce((sortedObj, key) => {
50
+ .sort()
51
+ .reduce((sortedObj, key) => {
49
52
  sortedObj[key] = mergedData[key];
50
53
  return sortedObj;
51
54
  }, {});
@@ -57,8 +60,8 @@ async function copyTo(directories, outputDir) {
57
60
  console.log(`Merged ${lang} files into ${outputFilePath}`);
58
61
  }
59
62
  }
60
- (() => {
61
- const externalFolders = findI18nFolders('./node_modules/@yuuvis', ['schematics',]);
63
+ function copyExternalLibs() {
64
+ const externalFolders = findI18nFolders('./node_modules/@yuuvis', ['schematics']);
62
65
  // copy external libs translations to i18n-external
63
66
  const externalOutputDir = path.join('.', 'i18n-external');
64
67
  copyTo(externalFolders, externalOutputDir).catch(console.error);
@@ -71,9 +74,11 @@ async function copyTo(directories, outputDir) {
71
74
  .filter((file) => file !== 'en.json')
72
75
  .forEach((file) => {
73
76
  const langFilePath = path.join(externalOutputDir, file);
74
- const srcLangfile = JSON.parse(fs.readFileSync(langFilePath, {
75
- encoding: 'utf-8',
76
- }));
77
+ const srcLangfile = JSON.parse(
78
+ fs.readFileSync(langFilePath, {
79
+ encoding: 'utf-8'
80
+ }
81
+ ));
77
82
  const targetLangFile = {};
78
83
  refKeys.forEach((k) => {
79
84
  targetLangFile[k] = srcLangfile[k] || '';
@@ -81,8 +86,12 @@ async function copyTo(directories, outputDir) {
81
86
  fs.writeFileSync(langFilePath, JSON.stringify(targetLangFile, null, 2));
82
87
  });
83
88
  }
89
+ return externalOutputDir;
90
+ }
91
+ (() => {
84
92
  const outputDir = path.join('.', 'src', 'assets', '_yuuvis', 'i18n');
85
- const localFolders = findI18nFolders('./projects', []);
93
+ const externalOutputDir = copyExternalLibs();
94
+ const localFolders = findI18nFolders('./projects');
86
95
  const clientFolders = findI18nFolders('./src', ['assets/_yuuvis']);
87
96
  copyTo([...localFolders, ...clientFolders, externalOutputDir], outputDir).catch(console.error);
88
97
  })();