@intlayer/chokidar 3.2.1 → 3.3.2

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 (45) hide show
  1. package/dist/cjs/chokidar/watcher.cjs +14 -9
  2. package/dist/cjs/chokidar/watcher.cjs.map +1 -1
  3. package/dist/cjs/cleanOutputDir.cjs +38 -0
  4. package/dist/cjs/cleanOutputDir.cjs.map +1 -0
  5. package/dist/cjs/fetchDistantDictionaries.cjs +5 -5
  6. package/dist/cjs/fetchDistantDictionaries.cjs.map +1 -1
  7. package/dist/cjs/fetchDistantDictionaryKeys.cjs +5 -5
  8. package/dist/cjs/fetchDistantDictionaryKeys.cjs.map +1 -1
  9. package/dist/cjs/loadDictionaries/loadDictionaries.cjs +5 -6
  10. package/dist/cjs/loadDictionaries/loadDictionaries.cjs.map +1 -1
  11. package/dist/cjs/log.cjs +20 -30
  12. package/dist/cjs/log.cjs.map +1 -1
  13. package/dist/cjs/transpiler/dictionary_to_main/createDictionaryList.cjs +12 -2
  14. package/dist/cjs/transpiler/dictionary_to_main/createDictionaryList.cjs.map +1 -1
  15. package/dist/cjs/transpiler/dictionary_to_type/createModuleAugmentation.cjs +12 -2
  16. package/dist/cjs/transpiler/dictionary_to_type/createModuleAugmentation.cjs.map +1 -1
  17. package/dist/cjs/utils.cjs +3 -0
  18. package/dist/cjs/utils.cjs.map +1 -1
  19. package/dist/esm/chokidar/watcher.mjs +4 -9
  20. package/dist/esm/chokidar/watcher.mjs.map +1 -1
  21. package/dist/esm/cleanOutputDir.mjs +14 -0
  22. package/dist/esm/cleanOutputDir.mjs.map +1 -0
  23. package/dist/esm/fetchDistantDictionaries.mjs +4 -4
  24. package/dist/esm/fetchDistantDictionaries.mjs.map +1 -1
  25. package/dist/esm/fetchDistantDictionaryKeys.mjs +4 -4
  26. package/dist/esm/fetchDistantDictionaryKeys.mjs.map +1 -1
  27. package/dist/esm/loadDictionaries/loadDictionaries.mjs +5 -6
  28. package/dist/esm/loadDictionaries/loadDictionaries.mjs.map +1 -1
  29. package/dist/esm/log.mjs +20 -30
  30. package/dist/esm/log.mjs.map +1 -1
  31. package/dist/esm/transpiler/dictionary_to_main/createDictionaryList.mjs +2 -2
  32. package/dist/esm/transpiler/dictionary_to_main/createDictionaryList.mjs.map +1 -1
  33. package/dist/esm/transpiler/dictionary_to_type/createModuleAugmentation.mjs +2 -2
  34. package/dist/esm/transpiler/dictionary_to_type/createModuleAugmentation.mjs.map +1 -1
  35. package/dist/esm/utils.mjs +2 -0
  36. package/dist/esm/utils.mjs.map +1 -1
  37. package/dist/types/chokidar/watcher.d.ts.map +1 -1
  38. package/dist/types/cleanOutputDir.d.ts +2 -0
  39. package/dist/types/cleanOutputDir.d.ts.map +1 -0
  40. package/dist/types/fetchDistantDictionaryKeys.d.ts.map +1 -1
  41. package/dist/types/loadDictionaries/loadDictionaries.d.ts.map +1 -1
  42. package/dist/types/log.d.ts.map +1 -1
  43. package/dist/types/utils.d.ts +1 -0
  44. package/dist/types/utils.d.ts.map +1 -1
  45. package/package.json +13 -12
@@ -29,6 +29,7 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
29
29
  var utils_exports = {};
30
30
  __export(utils_exports, {
31
31
  getFileHash: () => getFileHash,
32
+ sortAlphabetically: () => sortAlphabetically,
32
33
  transformToCamelCase: () => transformToCamelCase
33
34
  });
34
35
  module.exports = __toCommonJS(utils_exports);
@@ -47,9 +48,11 @@ const transformToCamelCase = (string) => {
47
48
  });
48
49
  return camelCasedWords.join("");
49
50
  };
51
+ const sortAlphabetically = (a, b) => a.localeCompare(b);
50
52
  // Annotate the CommonJS export names for ESM import in node:
51
53
  0 && (module.exports = {
52
54
  getFileHash,
55
+ sortAlphabetically,
53
56
  transformToCamelCase
54
57
  });
55
58
  //# sourceMappingURL=utils.cjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/utils.ts"],"sourcesContent":["import crypto from 'crypto-js';\n\nexport const getFileHash = (filePath: string) => {\n const hash = crypto.SHA3(filePath);\n\n return hash\n .toString(crypto.enc.Base64)\n .replace(/[^A-Z\\d]/gi, '')\n .substring(0, 20);\n};\n\nexport const transformToCamelCase = (string: string): string => {\n // Split the string into words using a regex that finds spaces, hyphens, and underscores\n const words = string.split(/[\\s\\-_]+/);\n\n // Transform each word except the first to have its first letter uppercase\n const camelCasedWords = words.map((word, index) => {\n if (index === 0) {\n return word[0].toUpperCase() + word.slice(1);\n }\n return word.charAt(0).toUpperCase() + word.slice(1);\n });\n\n // Join the words back together\n return camelCasedWords.join('');\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,uBAAmB;AAEZ,MAAM,cAAc,CAAC,aAAqB;AAC/C,QAAM,OAAO,iBAAAA,QAAO,KAAK,QAAQ;AAEjC,SAAO,KACJ,SAAS,iBAAAA,QAAO,IAAI,MAAM,EAC1B,QAAQ,cAAc,EAAE,EACxB,UAAU,GAAG,EAAE;AACpB;AAEO,MAAM,uBAAuB,CAAC,WAA2B;AAE9D,QAAM,QAAQ,OAAO,MAAM,UAAU;AAGrC,QAAM,kBAAkB,MAAM,IAAI,CAAC,MAAM,UAAU;AACjD,QAAI,UAAU,GAAG;AACf,aAAO,KAAK,CAAC,EAAE,YAAY,IAAI,KAAK,MAAM,CAAC;AAAA,IAC7C;AACA,WAAO,KAAK,OAAO,CAAC,EAAE,YAAY,IAAI,KAAK,MAAM,CAAC;AAAA,EACpD,CAAC;AAGD,SAAO,gBAAgB,KAAK,EAAE;AAChC;","names":["crypto"]}
1
+ {"version":3,"sources":["../../src/utils.ts"],"sourcesContent":["import crypto from 'crypto-js';\n\nexport const getFileHash = (filePath: string) => {\n const hash = crypto.SHA3(filePath);\n\n return hash\n .toString(crypto.enc.Base64)\n .replace(/[^A-Z\\d]/gi, '')\n .substring(0, 20);\n};\n\nexport const transformToCamelCase = (string: string): string => {\n // Split the string into words using a regex that finds spaces, hyphens, and underscores\n const words = string.split(/[\\s\\-_]+/);\n\n // Transform each word except the first to have its first letter uppercase\n const camelCasedWords = words.map((word, index) => {\n if (index === 0) {\n return word[0].toUpperCase() + word.slice(1);\n }\n return word.charAt(0).toUpperCase() + word.slice(1);\n });\n\n // Join the words back together\n return camelCasedWords.join('');\n};\n\nexport const sortAlphabetically = (a: string, b: string) => a.localeCompare(b);\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,uBAAmB;AAEZ,MAAM,cAAc,CAAC,aAAqB;AAC/C,QAAM,OAAO,iBAAAA,QAAO,KAAK,QAAQ;AAEjC,SAAO,KACJ,SAAS,iBAAAA,QAAO,IAAI,MAAM,EAC1B,QAAQ,cAAc,EAAE,EACxB,UAAU,GAAG,EAAE;AACpB;AAEO,MAAM,uBAAuB,CAAC,WAA2B;AAE9D,QAAM,QAAQ,OAAO,MAAM,UAAU;AAGrC,QAAM,kBAAkB,MAAM,IAAI,CAAC,MAAM,UAAU;AACjD,QAAI,UAAU,GAAG;AACf,aAAO,KAAK,CAAC,EAAE,YAAY,IAAI,KAAK,MAAM,CAAC;AAAA,IAC7C;AACA,WAAO,KAAK,OAAO,CAAC,EAAE,YAAY,IAAI,KAAK,MAAM,CAAC;AAAA,EACpD,CAAC;AAGD,SAAO,gBAAgB,KAAK,EAAE;AAChC;AAEO,MAAM,qBAAqB,CAAC,GAAW,MAAc,EAAE,cAAc,CAAC;","names":["crypto"]}
@@ -1,7 +1,8 @@
1
1
  import { relative } from "path";
2
2
  import { getConfiguration } from "@intlayer/config";
3
3
  import { watch as chokidarWatch } from "chokidar";
4
- import { sync } from "glob";
4
+ import fg from "fast-glob";
5
+ import { cleanOutputDir } from '../cleanOutputDir.mjs';
5
6
  import { loadDictionaries } from '../loadDictionaries/loadDictionaries.mjs';
6
7
  import { loadLocalDictionaries } from '../loadDictionaries/loadLocalDictionaries.mjs';
7
8
  import { buildDictionary } from '../transpiler/declaration_file_to_dictionary/index.mjs';
@@ -16,7 +17,8 @@ const watch = (options) => {
16
17
  verbose: true
17
18
  });
18
19
  const { watchedFilesPatternWithPath, baseDir } = content;
19
- const files = sync(watchedFilesPatternWithPath);
20
+ cleanOutputDir();
21
+ const files = fg.sync(watchedFilesPatternWithPath);
20
22
  return chokidarWatch(watchedFilesPatternWithPath, {
21
23
  persistent: true,
22
24
  // Make the watcher persistent
@@ -27,13 +29,8 @@ const watch = (options) => {
27
29
  const dictionaries = await loadDictionaries(files);
28
30
  const dictionariesPaths = await buildDictionary(dictionaries);
29
31
  await createTypes(dictionariesPaths);
30
- console.info(`${LOG_PREFIX}TypeScript types built`);
31
32
  createModuleAugmentation();
32
- console.info(`${LOG_PREFIX}Intlayer module augmentation built`);
33
33
  createDictionaryList();
34
- console.info(`${LOG_PREFIX}Intlayer dictionary list built`);
35
- }).on("unlink", (filePath) => {
36
- console.info("Removed file detected: ", relative(baseDir, filePath));
37
34
  }).on("add", async (filePath) => {
38
35
  console.info(
39
36
  `${LOG_PREFIX}Additional file detected: `,
@@ -42,9 +39,7 @@ const watch = (options) => {
42
39
  const localeDictionaries = await loadLocalDictionaries(filePath);
43
40
  const dictionaries = await buildDictionary(localeDictionaries);
44
41
  await createTypes(dictionaries);
45
- console.info(`${LOG_PREFIX}TypeScript types built`);
46
42
  createModuleAugmentation();
47
- console.info(`${LOG_PREFIX}Intlayer module augmentation built`);
48
43
  createDictionaryList();
49
44
  }).on("change", async (filePath) => {
50
45
  console.info("Change detected: ", relative(baseDir, filePath));
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/chokidar/watcher.ts"],"sourcesContent":["import { relative } from 'path';\nimport { getConfiguration } from '@intlayer/config';\n/** @ts-ignore remove error Module '\"chokidar\"' has no exported member 'ChokidarOptions' */\nimport { type ChokidarOptions, watch as chokidarWatch } from 'chokidar';\nimport { sync } from 'glob';\nimport { loadDictionaries } from '../loadDictionaries/loadDictionaries';\nimport { loadLocalDictionaries } from '../loadDictionaries/loadLocalDictionaries';\nimport { buildDictionary } from '../transpiler/declaration_file_to_dictionary/index';\nimport { createDictionaryList } from '../transpiler/dictionary_to_main/createDictionaryList';\nimport {\n createTypes,\n createModuleAugmentation,\n} from '../transpiler/dictionary_to_type/index';\n\nconst LOG_PREFIX = '[intlayer] ';\n\n// Initialize chokidar watcher (non-persistent)\nexport const watch = (options?: ChokidarOptions) => {\n const { content } = getConfiguration({\n verbose: true,\n });\n\n const { watchedFilesPatternWithPath, baseDir } = content;\n\n const files: string[] = sync(watchedFilesPatternWithPath);\n\n /** @ts-ignore remove error Expected 0-1 arguments, but got 2. */\n return chokidarWatch(watchedFilesPatternWithPath, {\n persistent: true, // Make the watcher persistent\n ignoreInitial: true, // Process existing files\n ...options,\n })\n .on('ready', async () => {\n const dictionaries = await loadDictionaries(files);\n\n // Build locale dictionaries\n const dictionariesPaths = await buildDictionary(dictionaries);\n\n await createTypes(dictionariesPaths);\n console.info(`${LOG_PREFIX}TypeScript types built`);\n\n createModuleAugmentation();\n console.info(`${LOG_PREFIX}Intlayer module augmentation built`);\n\n createDictionaryList();\n console.info(`${LOG_PREFIX}Intlayer dictionary list built`);\n })\n .on('unlink', (filePath) => {\n // Process the file with the functionToRun\n console.info('Removed file detected: ', relative(baseDir, filePath));\n })\n .on('add', async (filePath) => {\n // Process the file with the functionToRun\n console.info(\n `${LOG_PREFIX}Additional file detected: `,\n relative(baseDir, filePath)\n );\n\n const localeDictionaries = await loadLocalDictionaries(filePath);\n const dictionaries = await buildDictionary(localeDictionaries);\n\n await createTypes(dictionaries);\n console.info(`${LOG_PREFIX}TypeScript types built`);\n\n createModuleAugmentation();\n console.info(`${LOG_PREFIX}Intlayer module augmentation built`);\n\n createDictionaryList();\n })\n .on('change', async (filePath) => {\n // Process the file with the functionToRun\n console.info('Change detected: ', relative(baseDir, filePath));\n\n const localeDictionaries = await loadLocalDictionaries(filePath);\n const dictionaries = await buildDictionary(localeDictionaries);\n\n await createTypes(dictionaries);\n console.info(`${LOG_PREFIX}TypeScript types built`);\n })\n .on('error', (error) => {\n console.error('Watcher error:', error);\n });\n};\n"],"mappings":"AAAA,SAAS,gBAAgB;AACzB,SAAS,wBAAwB;AAEjC,SAA+B,SAAS,qBAAqB;AAC7D,SAAS,YAAY;AACrB,SAAS,wBAAwB;AACjC,SAAS,6BAA6B;AACtC,SAAS,uBAAuB;AAChC,SAAS,4BAA4B;AACrC;AAAA,EACE;AAAA,EACA;AAAA,OACK;AAEP,MAAM,aAAa;AAGZ,MAAM,QAAQ,CAAC,YAA8B;AAClD,QAAM,EAAE,QAAQ,IAAI,iBAAiB;AAAA,IACnC,SAAS;AAAA,EACX,CAAC;AAED,QAAM,EAAE,6BAA6B,QAAQ,IAAI;AAEjD,QAAM,QAAkB,KAAK,2BAA2B;AAGxD,SAAO,cAAc,6BAA6B;AAAA,IAChD,YAAY;AAAA;AAAA,IACZ,eAAe;AAAA;AAAA,IACf,GAAG;AAAA,EACL,CAAC,EACE,GAAG,SAAS,YAAY;AACvB,UAAM,eAAe,MAAM,iBAAiB,KAAK;AAGjD,UAAM,oBAAoB,MAAM,gBAAgB,YAAY;AAE5D,UAAM,YAAY,iBAAiB;AACnC,YAAQ,KAAK,GAAG,UAAU,wBAAwB;AAElD,6BAAyB;AACzB,YAAQ,KAAK,GAAG,UAAU,oCAAoC;AAE9D,yBAAqB;AACrB,YAAQ,KAAK,GAAG,UAAU,gCAAgC;AAAA,EAC5D,CAAC,EACA,GAAG,UAAU,CAAC,aAAa;AAE1B,YAAQ,KAAK,2BAA2B,SAAS,SAAS,QAAQ,CAAC;AAAA,EACrE,CAAC,EACA,GAAG,OAAO,OAAO,aAAa;AAE7B,YAAQ;AAAA,MACN,GAAG,UAAU;AAAA,MACb,SAAS,SAAS,QAAQ;AAAA,IAC5B;AAEA,UAAM,qBAAqB,MAAM,sBAAsB,QAAQ;AAC/D,UAAM,eAAe,MAAM,gBAAgB,kBAAkB;AAE7D,UAAM,YAAY,YAAY;AAC9B,YAAQ,KAAK,GAAG,UAAU,wBAAwB;AAElD,6BAAyB;AACzB,YAAQ,KAAK,GAAG,UAAU,oCAAoC;AAE9D,yBAAqB;AAAA,EACvB,CAAC,EACA,GAAG,UAAU,OAAO,aAAa;AAEhC,YAAQ,KAAK,qBAAqB,SAAS,SAAS,QAAQ,CAAC;AAE7D,UAAM,qBAAqB,MAAM,sBAAsB,QAAQ;AAC/D,UAAM,eAAe,MAAM,gBAAgB,kBAAkB;AAE7D,UAAM,YAAY,YAAY;AAC9B,YAAQ,KAAK,GAAG,UAAU,wBAAwB;AAAA,EACpD,CAAC,EACA,GAAG,SAAS,CAAC,UAAU;AACtB,YAAQ,MAAM,kBAAkB,KAAK;AAAA,EACvC,CAAC;AACL;","names":[]}
1
+ {"version":3,"sources":["../../../src/chokidar/watcher.ts"],"sourcesContent":["import { relative } from 'path';\nimport { getConfiguration } from '@intlayer/config';\n/** @ts-ignore remove error Module '\"chokidar\"' has no exported member 'ChokidarOptions' */\nimport { type ChokidarOptions, watch as chokidarWatch } from 'chokidar';\nimport fg from 'fast-glob';\nimport { cleanOutputDir } from '../cleanOutputDir';\nimport { loadDictionaries } from '../loadDictionaries/loadDictionaries';\nimport { loadLocalDictionaries } from '../loadDictionaries/loadLocalDictionaries';\nimport { buildDictionary } from '../transpiler/declaration_file_to_dictionary/index';\nimport { createDictionaryList } from '../transpiler/dictionary_to_main/createDictionaryList';\nimport {\n createTypes,\n createModuleAugmentation,\n} from '../transpiler/dictionary_to_type/index';\n\nconst LOG_PREFIX = '[intlayer] ';\n\n// Initialize chokidar watcher (non-persistent)\nexport const watch = (options?: ChokidarOptions) => {\n const { content } = getConfiguration({\n verbose: true,\n });\n\n const { watchedFilesPatternWithPath, baseDir } = content;\n\n cleanOutputDir();\n\n const files: string[] = fg.sync(watchedFilesPatternWithPath);\n\n /** @ts-ignore remove error Expected 0-1 arguments, but got 2. */\n return chokidarWatch(watchedFilesPatternWithPath, {\n persistent: true, // Make the watcher persistent\n ignoreInitial: true, // Process existing files\n ...options,\n })\n .on('ready', async () => {\n const dictionaries = await loadDictionaries(files);\n\n // Build locale dictionaries\n const dictionariesPaths = await buildDictionary(dictionaries);\n\n await createTypes(dictionariesPaths);\n\n createModuleAugmentation();\n\n createDictionaryList();\n })\n .on('add', async (filePath) => {\n // Process the file with the functionToRun\n console.info(\n `${LOG_PREFIX}Additional file detected: `,\n relative(baseDir, filePath)\n );\n\n const localeDictionaries = await loadLocalDictionaries(filePath);\n\n const dictionaries = await buildDictionary(localeDictionaries);\n\n await createTypes(dictionaries);\n\n createModuleAugmentation();\n\n createDictionaryList();\n })\n .on('change', async (filePath) => {\n // Process the file with the functionToRun\n console.info('Change detected: ', relative(baseDir, filePath));\n\n const localeDictionaries = await loadLocalDictionaries(filePath);\n const dictionaries = await buildDictionary(localeDictionaries);\n\n await createTypes(dictionaries);\n console.info(`${LOG_PREFIX}TypeScript types built`);\n })\n .on('error', (error) => {\n console.error('Watcher error:', error);\n });\n};\n"],"mappings":"AAAA,SAAS,gBAAgB;AACzB,SAAS,wBAAwB;AAEjC,SAA+B,SAAS,qBAAqB;AAC7D,OAAO,QAAQ;AACf,SAAS,sBAAsB;AAC/B,SAAS,wBAAwB;AACjC,SAAS,6BAA6B;AACtC,SAAS,uBAAuB;AAChC,SAAS,4BAA4B;AACrC;AAAA,EACE;AAAA,EACA;AAAA,OACK;AAEP,MAAM,aAAa;AAGZ,MAAM,QAAQ,CAAC,YAA8B;AAClD,QAAM,EAAE,QAAQ,IAAI,iBAAiB;AAAA,IACnC,SAAS;AAAA,EACX,CAAC;AAED,QAAM,EAAE,6BAA6B,QAAQ,IAAI;AAEjD,iBAAe;AAEf,QAAM,QAAkB,GAAG,KAAK,2BAA2B;AAG3D,SAAO,cAAc,6BAA6B;AAAA,IAChD,YAAY;AAAA;AAAA,IACZ,eAAe;AAAA;AAAA,IACf,GAAG;AAAA,EACL,CAAC,EACE,GAAG,SAAS,YAAY;AACvB,UAAM,eAAe,MAAM,iBAAiB,KAAK;AAGjD,UAAM,oBAAoB,MAAM,gBAAgB,YAAY;AAE5D,UAAM,YAAY,iBAAiB;AAEnC,6BAAyB;AAEzB,yBAAqB;AAAA,EACvB,CAAC,EACA,GAAG,OAAO,OAAO,aAAa;AAE7B,YAAQ;AAAA,MACN,GAAG,UAAU;AAAA,MACb,SAAS,SAAS,QAAQ;AAAA,IAC5B;AAEA,UAAM,qBAAqB,MAAM,sBAAsB,QAAQ;AAE/D,UAAM,eAAe,MAAM,gBAAgB,kBAAkB;AAE7D,UAAM,YAAY,YAAY;AAE9B,6BAAyB;AAEzB,yBAAqB;AAAA,EACvB,CAAC,EACA,GAAG,UAAU,OAAO,aAAa;AAEhC,YAAQ,KAAK,qBAAqB,SAAS,SAAS,QAAQ,CAAC;AAE7D,UAAM,qBAAqB,MAAM,sBAAsB,QAAQ;AAC/D,UAAM,eAAe,MAAM,gBAAgB,kBAAkB;AAE7D,UAAM,YAAY,YAAY;AAC9B,YAAQ,KAAK,GAAG,UAAU,wBAAwB;AAAA,EACpD,CAAC,EACA,GAAG,SAAS,CAAC,UAAU;AACtB,YAAQ,MAAM,kBAAkB,KAAK;AAAA,EACvC,CAAC;AACL;","names":[]}
@@ -0,0 +1,14 @@
1
+ import { existsSync, rmSync, mkdirSync } from "fs";
2
+ import { getConfiguration } from "@intlayer/config";
3
+ const cleanOutputDir = () => {
4
+ const { content } = getConfiguration();
5
+ const { resultDir } = content;
6
+ if (existsSync(resultDir)) {
7
+ rmSync(resultDir, { recursive: true });
8
+ }
9
+ mkdirSync(resultDir);
10
+ };
11
+ export {
12
+ cleanOutputDir
13
+ };
14
+ //# sourceMappingURL=cleanOutputDir.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/cleanOutputDir.ts"],"sourcesContent":["import { existsSync, rmSync, mkdirSync } from 'fs';\nimport { getConfiguration } from '@intlayer/config';\n\nexport const cleanOutputDir = () => {\n const { content } = getConfiguration();\n\n const { resultDir } = content;\n\n // Delete the dictionary directory dictionariesDir\n if (existsSync(resultDir)) {\n rmSync(resultDir, { recursive: true });\n }\n\n // Create the dictionary directory dictionariesDir\n mkdirSync(resultDir);\n};\n"],"mappings":"AAAA,SAAS,YAAY,QAAQ,iBAAiB;AAC9C,SAAS,wBAAwB;AAE1B,MAAM,iBAAiB,MAAM;AAClC,QAAM,EAAE,QAAQ,IAAI,iBAAiB;AAErC,QAAM,EAAE,UAAU,IAAI;AAGtB,MAAI,WAAW,SAAS,GAAG;AACzB,WAAO,WAAW,EAAE,WAAW,KAAK,CAAC;AAAA,EACvC;AAGA,YAAU,SAAS;AACrB;","names":[]}
@@ -1,12 +1,12 @@
1
1
  import { getConfiguration } from "@intlayer/config";
2
- import { intlayerAPI } from "@intlayer/design-system/libs";
2
+ import { getIntlayerAPI } from "@intlayer/design-system/libs";
3
3
  import pLimit from "p-limit";
4
4
  import { logger } from './log.mjs';
5
5
  const fetchDistantDictionaries = async (options) => {
6
6
  try {
7
- const {
8
- editor: { clientId, clientSecret }
9
- } = getConfiguration();
7
+ const config = getConfiguration();
8
+ const { clientId, clientSecret } = config.editor;
9
+ const intlayerAPI = getIntlayerAPI(void 0, config);
10
10
  if (!clientId || !clientSecret) {
11
11
  throw new Error(
12
12
  "Missing OAuth2 client ID or client secret. To get access token go to https://intlayer.org/dashboard/project."
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/fetchDistantDictionaries.ts"],"sourcesContent":["// @ts-ignore @intlayer/backend not build yet\nimport { type DictionaryAPI } from '@intlayer/backend';\nimport { getConfiguration } from '@intlayer/config';\n// @ts-ignore @intlayer/design-system not build yet\nimport { intlayerAPI } from '@intlayer/design-system/libs';\nimport pLimit from 'p-limit';\nimport { logger } from './log';\n\ntype FetchDistantDictionariesOptions = {\n dictionaryKeys: string[];\n newDictionariesPath?: string;\n logPrefix?: string;\n};\n\n/**\n * Fetch distant dictionaries and update the logger with their statuses.\n */\nexport const fetchDistantDictionaries = async (\n options: FetchDistantDictionariesOptions\n): Promise<DictionaryAPI[]> => {\n try {\n const {\n editor: { clientId, clientSecret },\n } = getConfiguration();\n\n if (!clientId || !clientSecret) {\n throw new Error(\n 'Missing OAuth2 client ID or client secret. To get access token go to https://intlayer.org/dashboard/project.'\n );\n }\n\n const oAuth2TokenResult = await intlayerAPI.auth.getOAuth2AccessToken();\n\n const oAuth2AccessToken = oAuth2TokenResult.data?.accessToken;\n\n const distantDictionariesKeys = options.dictionaryKeys;\n\n // Process dictionaries in parallel with a concurrency limit\n const limit = pLimit(5); // Adjust the limit as needed\n\n const processDictionary = async (\n dictionaryKey: string\n ): Promise<DictionaryAPI | undefined> => {\n logger.updateStatus(dictionaryKey, 'distant', { status: 'fetching' });\n\n try {\n // Fetch the dictionary\n const getDictionaryResult = await intlayerAPI.dictionary.getDictionary(\n dictionaryKey,\n undefined,\n {\n headers: { Authorization: `Bearer ${oAuth2AccessToken}` },\n }\n );\n\n const distantDictionary = getDictionaryResult.data;\n\n if (!distantDictionary) {\n throw new Error(`Dictionary ${dictionaryKey} not found on remote`);\n }\n\n logger.updateStatus(dictionaryKey, 'distant', { status: 'imported' });\n\n return distantDictionary;\n } catch (error) {\n logger.updateStatus(dictionaryKey, 'distant', {\n status: 'error',\n error: error as Error,\n errorMessage: `${options?.logPrefix ?? ''}Error fetching dictionary ${dictionaryKey}: ${error}`,\n });\n return undefined;\n }\n };\n\n const fetchPromises = distantDictionariesKeys.map((dictionaryKey) =>\n limit(() => processDictionary(dictionaryKey))\n );\n\n const result = await Promise.all(fetchPromises);\n\n // Output any error messages\n const statuses = logger.getStatuses();\n for (const statusObj of statuses) {\n const currentState = statusObj.state.find((s) => s.type === 'distant');\n if (currentState && currentState.errorMessage) {\n console.error(currentState.errorMessage);\n }\n }\n\n // Remove undefined values\n const filteredResult = result.filter(\n (dict): dict is DictionaryAPI => dict !== undefined\n );\n\n return filteredResult;\n } catch (error) {\n console.error(error);\n return [];\n }\n};\n"],"mappings":"AAEA,SAAS,wBAAwB;AAEjC,SAAS,mBAAm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YAAM,eAAe,UAAU,MAAM,KAAK,CAAC,MAAM,EAAE,SAAS,SAAS;AACrE,UAAI,gBAAgB,aAAa,cAAc;AAC7C,gBAAQ,MAAM,aAAa,YAAY;AAAA,MACzC;AAAA,IACF;AAGA,UAAM,iBAAiB,OAAO;AAAA,MAC5B,CAAC,SAAgC,SAAS;AAAA,IAC5C;AAEA,WAAO;AAAA,EACT,SAAS,OAAO;AACd,YAAQ,MAAM,KAAK;AACnB,WAAO,CAAC;AAAA,EACV;AACF;","names":[]}
1
+ {"version":3,"sources":["../../src/fetchDistantDictionaries.ts"],"sourcesContent":["// @ts-ignore @intlayer/backend not build yet\nimport { type DictionaryAPI } from '@intlayer/backend';\nimport { getConfiguration } from '@intlayer/config';\n// @ts-ignore @intlayer/design-system not build yet\nimport { getIntlayerAPI } from '@intlayer/design-system/libs';\nimport pLimit from 'p-limit';\nimport { logger } from './log';\n\ntype FetchDistantDictionariesOptions = {\n dictionaryKeys: string[];\n newDictionariesPath?: string;\n logPrefix?: string;\n};\n\n/**\n * Fetch distant dictionaries and update the logger with their statuses.\n */\nexport const fetchDistantDictionaries = async (\n options: FetchDistantDictionariesOptions\n): Promise<DictionaryAPI[]> => {\n try {\n const config = getConfiguration();\n const { clientId, clientSecret } = config.editor;\n const intlayerAPI = getIntlayerAPI(undefined, config);\n\n if (!clientId || !clientSecret) {\n throw new Error(\n 'Missing OAuth2 client ID or client secret. To get access token go to https://intlayer.org/dashboard/project.'\n );\n }\n\n const oAuth2TokenResult = await intlayerAPI.auth.getOAuth2AccessToken();\n\n const oAuth2AccessToken = oAuth2TokenResult.data?.accessToken;\n\n const distantDictionariesKeys = options.dictionaryKeys;\n\n // Process dictionaries in parallel with a concurrency limit\n const limit = pLimit(5); // Adjust the limit as needed\n\n const processDictionary = async (\n dictionaryKey: string\n ): Promise<DictionaryAPI | undefined> => {\n logger.updateStatus(dictionaryKey, 'distant', { status: 'fetching' });\n\n try {\n // Fetch the dictionary\n const getDictionaryResult = await intlayerAPI.dictionary.getDictionary(\n dictionaryKey,\n undefined,\n {\n headers: { Authorization: `Bearer ${oAuth2AccessToken}` },\n }\n );\n\n const distantDictionary = getDictionaryResult.data;\n\n if (!distantDictionary) {\n throw new Error(`Dictionary ${dictionaryKey} not found on remote`);\n }\n\n logger.updateStatus(dictionaryKey, 'distant', { status: 'imported' });\n\n return distantDictionary;\n } catch (error) {\n logger.updateStatus(dictionaryKey, 'distant', {\n status: 'error',\n error: error as Error,\n errorMessage: `${options?.logPrefix ?? ''}Error fetching dictionary ${dictionaryKey}: ${error}`,\n });\n return undefined;\n }\n };\n\n const fetchPromises = distantDictionariesKeys.map((dictionaryKey) =>\n limit(() => processDictionary(dictionaryKey))\n );\n\n const result = await Promise.all(fetchPromises);\n\n // Output any error messages\n const statuses = logger.getStatuses();\n for (const statusObj of statuses) {\n const currentState = statusObj.state.find((s) => s.type === 'distant');\n if (currentState && currentState.errorMessage) {\n console.error(currentState.errorMessage);\n }\n }\n\n // Remove undefined values\n const filteredResult = result.filter(\n (dict): dict is DictionaryAPI => dict !== undefined\n );\n\n return filteredResult;\n } catch (error) {\n console.error(error);\n return [];\n }\n};\n"],"mappings":"AAEA,SAAS,wBAAwB;AAEjC,SAAS,sBAAsB;AAC/B,OAAO,YAAY;AACnB,SAAS,cAAc;AAWhB,MAAM,2BAA2B,OACtC,YAC6B;AAC7B,MAAI;AACF,UAAM,SAAS,iBAAiB;AAChC,UAAM,EAAE,UAAU,aAAa,IAAI,OAAO;AAC1C,UAAM,cAAc,eAAe,QAAW,MAAM;AAEpD,QAAI,CAAC,YAAY,CAAC,cAAc;AAC9B,YAAM,IAAI;AAAA,QACR;AAAA,MACF;AAAA,IACF;AAEA,UAAM,oBAAoB,MAAM,YAAY,KAAK,qBAAqB;AAEtE,UAAM,oBAAoB,kBAAkB,MAAM;AAElD,UAAM,0BAA0B,QAAQ;AAGxC,UAAM,QAAQ,OAAO,CAAC;AAEtB,UAAM,oBAAoB,OACxB,kBACuC;AACvC,aAAO,aAAa,eAAe,WAAW,EAAE,QAAQ,WAAW,CAAC;AAEpE,UAAI;AAEF,cAAM,sBAAsB,MAAM,YAAY,WAAW;AAAA,UACvD;AAAA,UACA;AAAA,UACA;AAAA,YACE,SAAS,EAAE,eAAe,UAAU,iBAAiB,GAAG;AAAA,UAC1D;AAAA,QACF;AAEA,cAAM,oBAAoB,oBAAoB;AAE9C,YAAI,CAAC,mBAAmB;AACtB,gBAAM,IAAI,MAAM,cAAc,aAAa,sBAAsB;AAAA,QACnE;AAEA,eAAO,aAAa,eAAe,WAAW,EAAE,QAAQ,WAAW,CAAC;AAEpE,eAAO;AAAA,MACT,SAAS,OAAO;AACd,eAAO,aAAa,eAAe,WAAW;AAAA,UAC5C,QAAQ;AAAA,UACR;AAAA,UACA,cAAc,GAAG,SAAS,aAAa,EAAE,6BAA6B,aAAa,KAAK,KAAK;AAAA,QAC/F,CAAC;AACD,eAAO;AAAA,MACT;AAAA,IACF;AAEA,UAAM,gBAAgB,wBAAwB;AAAA,MAAI,CAAC,kBACjD,MAAM,MAAM,kBAAkB,aAAa,CAAC;AAAA,IAC9C;AAEA,UAAM,SAAS,MAAM,QAAQ,IAAI,aAAa;AAG9C,UAAM,WAAW,OAAO,YAAY;AACpC,eAAW,aAAa,UAAU;AAChC,YAAM,eAAe,UAAU,MAAM,KAAK,CAAC,MAAM,EAAE,SAAS,SAAS;AACrE,UAAI,gBAAgB,aAAa,cAAc;AAC7C,gBAAQ,MAAM,aAAa,YAAY;AAAA,MACzC;AAAA,IACF;AAGA,UAAM,iBAAiB,OAAO;AAAA,MAC5B,CAAC,SAAgC,SAAS;AAAA,IAC5C;AAEA,WAAO;AAAA,EACT,SAAS,OAAO;AACd,YAAQ,MAAM,KAAK;AACnB,WAAO,CAAC;AAAA,EACV;AACF;","names":[]}
@@ -1,14 +1,14 @@
1
1
  import { getConfiguration } from "@intlayer/config";
2
- import { intlayerAPI } from "@intlayer/design-system/libs";
2
+ import { getIntlayerAPI } from "@intlayer/design-system/libs";
3
3
  const fetchDistantDictionaryKeys = async () => {
4
- const {
5
- editor: { clientId, clientSecret }
6
- } = getConfiguration();
4
+ const config = getConfiguration();
5
+ const { clientId, clientSecret } = config.editor;
7
6
  if (!clientId || !clientSecret) {
8
7
  throw new Error(
9
8
  "Missing OAuth2 client ID or client secret. To get access token go to https://intlayer.org/dashboard/project."
10
9
  );
11
10
  }
11
+ const intlayerAPI = getIntlayerAPI(void 0, config);
12
12
  const oAuth2TokenResult = await intlayerAPI.auth.getOAuth2AccessToken();
13
13
  const oAuth2AccessToken = oAuth2TokenResult.data?.accessToken;
14
14
  const getDictionariesKeysResult = await intlayerAPI.dictionary.getDictionariesKeys({
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/fetchDistantDictionaryKeys.ts"],"sourcesContent":["import { getConfiguration } from '@intlayer/config';\n// @ts-ignore @intlayer/design-system not build yet\nimport { intlayerAPI } from '@intlayer/design-system/libs';\n\nexport const fetchDistantDictionaryKeys = async (): Promise<string[]> => {\n const {\n editor: { clientId, clientSecret },\n } = getConfiguration();\n\n if (!clientId || !clientSecret) {\n throw new Error(\n 'Missing OAuth2 client ID or client secret. To get access token go to https://intlayer.org/dashboard/project.'\n );\n }\n\n const oAuth2TokenResult = await intlayerAPI.auth.getOAuth2AccessToken();\n\n const oAuth2AccessToken = oAuth2TokenResult.data?.accessToken;\n\n // Get the list of dictionary keys\n const getDictionariesKeysResult =\n await intlayerAPI.dictionary.getDictionariesKeys({\n headers: { Authorization: `Bearer ${oAuth2AccessToken}` },\n });\n\n if (!getDictionariesKeysResult.data) {\n throw new Error('No distant dictionaries found');\n }\n\n const distantDictionariesKeys: string[] = getDictionariesKeysResult.data;\n\n // Apply any filtering if needed\n return distantDictionariesKeys;\n};\n"],"mappings":"AAAA,SAAS,wBAAwB;AAEjC,SAAS,mBAAmB;AAErB,MAAM,6BAA6B,YAA+B;AACvE,QAAM;AAAA,IACJ,QAAQ,EAAE,UAAU,aAAa;AAAA,EACnC,IAAI,iBAAiB;AAErB,MAAI,CAAC,YAAY,CAAC,cAAc;AAC9B,UAAM,IAAI;AAAA,MACR;AAAA,IACF;AAAA,EACF;AAEA,QAAM,oBAAoB,MAAM,YAAY,KAAK,qBAAqB;AAEtE,QAAM,oBAAoB,kBAAkB,MAAM;AAGlD,QAAM,4BACJ,MAAM,YAAY,WAAW,oBAAoB;AAAA,IAC/C,SAAS,EAAE,eAAe,UAAU,iBAAiB,GAAG;AAAA,EAC1D,CAAC;AAEH,MAAI,CAAC,0BAA0B,MAAM;AACnC,UAAM,IAAI,MAAM,+BAA+B;AAAA,EACjD;AAEA,QAAM,0BAAoC,0BAA0B;AAGpE,SAAO;AACT;","names":[]}
1
+ {"version":3,"sources":["../../src/fetchDistantDictionaryKeys.ts"],"sourcesContent":["import { getConfiguration } from '@intlayer/config';\n// @ts-ignore @intlayer/design-system not build yet\nimport { getIntlayerAPI } from '@intlayer/design-system/libs';\n\nexport const fetchDistantDictionaryKeys = async (): Promise<string[]> => {\n const config = getConfiguration();\n const { clientId, clientSecret } = config.editor;\n\n if (!clientId || !clientSecret) {\n throw new Error(\n 'Missing OAuth2 client ID or client secret. To get access token go to https://intlayer.org/dashboard/project.'\n );\n }\n\n const intlayerAPI = getIntlayerAPI(undefined, config);\n\n const oAuth2TokenResult = await intlayerAPI.auth.getOAuth2AccessToken();\n\n const oAuth2AccessToken = oAuth2TokenResult.data?.accessToken;\n\n // Get the list of dictionary keys\n const getDictionariesKeysResult =\n await intlayerAPI.dictionary.getDictionariesKeys({\n headers: { Authorization: `Bearer ${oAuth2AccessToken}` },\n });\n\n if (!getDictionariesKeysResult.data) {\n throw new Error('No distant dictionaries found');\n }\n\n const distantDictionariesKeys: string[] = getDictionariesKeysResult.data;\n\n // Apply any filtering if needed\n return distantDictionariesKeys;\n};\n"],"mappings":"AAAA,SAAS,wBAAwB;AAEjC,SAAS,sBAAsB;AAExB,MAAM,6BAA6B,YAA+B;AACvE,QAAM,SAAS,iBAAiB;AAChC,QAAM,EAAE,UAAU,aAAa,IAAI,OAAO;AAE1C,MAAI,CAAC,YAAY,CAAC,cAAc;AAC9B,UAAM,IAAI;AAAA,MACR;AAAA,IACF;AAAA,EACF;AAEA,QAAM,cAAc,eAAe,QAAW,MAAM;AAEpD,QAAM,oBAAoB,MAAM,YAAY,KAAK,qBAAqB;AAEtE,QAAM,oBAAoB,kBAAkB,MAAM;AAGlD,QAAM,4BACJ,MAAM,YAAY,WAAW,oBAAoB;AAAA,IAC/C,SAAS,EAAE,eAAe,UAAU,iBAAiB,GAAG;AAAA,EAC1D,CAAC;AAEH,MAAI,CAAC,0BAA0B,MAAM;AACnC,UAAM,IAAI,MAAM,+BAA+B;AAAA,EACjD;AAEA,QAAM,0BAAoC,0BAA0B;AAGpE,SAAO;AACT;","names":[]}
@@ -3,14 +3,13 @@ import merge from "deepmerge";
3
3
  import { fetchDistantDictionaryKeys } from '../fetchDistantDictionaryKeys.mjs';
4
4
  import { logger } from '../log.mjs';
5
5
  import { mergeByKey } from '../mergeDictionaries.mjs';
6
+ import { sortAlphabetically } from '../utils.mjs';
6
7
  import { loadContentDeclarations } from './loadContentDeclaration.mjs';
7
8
  import { loadDistantDictionaries } from './loadDistantDictionaries.mjs';
8
9
  const LOG_PREFIX = "[intlayer] ";
9
10
  const loadDictionaries = async (contentDeclarationsPaths) => {
10
11
  try {
11
- const { editor } = getConfiguration({
12
- verbose: true
13
- });
12
+ const { editor } = getConfiguration();
14
13
  console.info(`${LOG_PREFIX}Dictionaries:`);
15
14
  const files = Array.isArray(contentDeclarationsPaths) ? contentDeclarationsPaths : [contentDeclarationsPaths];
16
15
  const localDictionaries = await loadContentDeclarations(files);
@@ -24,9 +23,10 @@ const loadDictionaries = async (contentDeclarationsPaths) => {
24
23
  let mergedDictionaries = localDictionaries;
25
24
  if (editor.clientId && editor.clientSecret) {
26
25
  distantDictionaryKeys = await fetchDistantDictionaryKeys();
27
- logger.addDictionaryKeys("distant", distantDictionaryKeys);
26
+ const orderedDistantDictionaryKeys = distantDictionaryKeys.sort(sortAlphabetically);
27
+ logger.addDictionaryKeys("distant", orderedDistantDictionaryKeys);
28
28
  distantDictionaries = await loadDistantDictionaries({
29
- dictionaryKeys: distantDictionaryKeys
29
+ dictionaryKeys: orderedDistantDictionaryKeys
30
30
  });
31
31
  if (editor.dictionaryPriorityStrategy === "distant_first") {
32
32
  mergedDictionaries = merge(localDictionaries, distantDictionaries, {
@@ -41,7 +41,6 @@ const loadDictionaries = async (contentDeclarationsPaths) => {
41
41
  logger.stop();
42
42
  return mergedDictionaries;
43
43
  } catch (error) {
44
- console.error(error);
45
44
  logger.stop();
46
45
  throw error;
47
46
  }
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/loadDictionaries/loadDictionaries.ts"],"sourcesContent":["// @ts-ignore @intlayer/backend not build yet\nimport { type DictionaryAPI } from '@intlayer/backend';\nimport { getConfiguration } from '@intlayer/config';\nimport { Dictionary } from '@intlayer/core';\nimport merge from 'deepmerge';\nimport { fetchDistantDictionaryKeys } from '../fetchDistantDictionaryKeys';\nimport { logger } from '../log';\nimport { mergeByKey } from '../mergeDictionaries';\nimport { loadContentDeclarations } from './loadContentDeclaration';\nimport { loadDistantDictionaries } from './loadDistantDictionaries';\n\nconst LOG_PREFIX = '[intlayer] ';\n\nexport const loadDictionaries = async (\n contentDeclarationsPaths: string[] | string\n): Promise<Dictionary[]> => {\n try {\n const { editor } = getConfiguration({\n verbose: true,\n });\n\n console.info(`${LOG_PREFIX}Dictionaries:`);\n\n const files = Array.isArray(contentDeclarationsPaths)\n ? contentDeclarationsPaths\n : [contentDeclarationsPaths];\n\n const localDictionaries: Dictionary[] =\n await loadContentDeclarations(files);\n const localDictionaryKeys = localDictionaries.map((dict) => dict.key);\n\n // Initialize the logger with both local and distant dictionaries\n logger.init(localDictionaryKeys, []);\n\n // Update logger statuses for local dictionaries\n for (const dict of localDictionaries) {\n logger.updateStatus(dict.key, 'local', { status: 'built' });\n }\n\n let distantDictionaries: DictionaryAPI[] = [];\n let distantDictionaryKeys: string[] = [];\n let mergedDictionaries = localDictionaries;\n\n if (editor.clientId && editor.clientSecret) {\n // Fetch distant dictionary keys\n distantDictionaryKeys = await fetchDistantDictionaryKeys();\n\n // Add distant dictionaries to the logger\n logger.addDictionaryKeys('distant', distantDictionaryKeys);\n\n // Fetch distant dictionaries\n distantDictionaries = await loadDistantDictionaries({\n dictionaryKeys: distantDictionaryKeys,\n });\n if (editor.dictionaryPriorityStrategy === 'distant_first') {\n // Merge the dictionaries\n mergedDictionaries = merge(localDictionaries, distantDictionaries, {\n arrayMerge: mergeByKey('key'),\n });\n } else {\n // Merge the dictionaries\n mergedDictionaries = merge(distantDictionaries, localDictionaries, {\n arrayMerge: mergeByKey('key'),\n });\n }\n }\n\n // Ensure the logger is stopped\n logger.stop();\n\n return mergedDictionaries;\n } catch (error) {\n console.error(error);\n // Ensure the logger is stopped\n logger.stop();\n throw error; // Re-throw the error after logging\n }\n};\n"],"mappings":"AAEA,SAAS,wBAAwB;AAEjC,OAAO,WAAW;AAClB,SAAS,kCAAkC;AAC3C,SAAS,cAAc;AACvB,SAAS,kBAAkB;AAC3B,SAAS,+BAA+B;AACxC,SAAS,+BAA+B;AAExC,MAAM,aAAa;AAEZ,MAAM,mBAAmB,OAC9B,6BAC0B;AAC1B,MAAI;AACF,UAAM,EAAE,OAAO,IAAI,iBAAiB;AAAA,MAClC,SAAS;AAAA,IACX,CAAC;AAED,YAAQ,KAAK,GAAG,UAAU,eAAe;AAEzC,UAAM,QAAQ,MAAM,QAAQ,wBAAwB,IAChD,2BACA,CAAC,wBAAwB;AAE7B,UAAM,oBACJ,MAAM,wBAAwB,KAAK;AACrC,UAAM,sBAAsB,kBAAkB,IAAI,CAAC,SAAS,KAAK,GAAG;AAGpE,WAAO,KAAK,qBAAqB,CAAC,CAAC;AAGnC,eAAW,QAAQ,mBAAmB;AACpC,aAAO,aAAa,KAAK,KAAK,SAAS,EAAE,QAAQ,QAAQ,CAAC;AAAA,IAC5D;AAEA,QAAI,sBAAuC,CAAC;AAC5C,QAAI,wBAAkC,CAAC;AACvC,QAAI,qBAAqB;AAEzB,QAAI,OAAO,YAAY,OAAO,cAAc;AAE1C,8BAAwB,MAAM,2BAA2B;AAGzD,aAAO,kBAAkB,WAAW,qBAAqB;AAGzD,4BAAsB,MAAM,wBAAwB;AAAA,QAClD,gBAAgB;AAAA,MAClB,CAAC;AACD,UAAI,OAAO,+BAA+B,iBAAiB;AAEzD,6BAAqB,MAAM,mBAAmB,qBAAqB;AAAA,UACjE,YAAY,WAAW,KAAK;AAAA,QAC9B,CAAC;AAAA,MACH,OAAO;AAEL,6BAAqB,MAAM,qBAAqB,mBAAmB;AAAA,UACjE,YAAY,WAAW,KAAK;AAAA,QAC9B,CAAC;AAAA,MACH;AAAA,IACF;AAGA,WAAO,KAAK;AAEZ,WAAO;AAAA,EACT,SAAS,OAAO;AACd,YAAQ,MAAM,KAAK;AAEnB,WAAO,KAAK;AACZ,UAAM;AAAA,EACR;AACF;","names":[]}
1
+ {"version":3,"sources":["../../../src/loadDictionaries/loadDictionaries.ts"],"sourcesContent":["// @ts-ignore @intlayer/backend not build yet\nimport { type DictionaryAPI } from '@intlayer/backend';\nimport { getConfiguration } from '@intlayer/config';\nimport { Dictionary } from '@intlayer/core';\nimport merge from 'deepmerge';\nimport { fetchDistantDictionaryKeys } from '../fetchDistantDictionaryKeys';\nimport { logger } from '../log';\nimport { mergeByKey } from '../mergeDictionaries';\nimport { sortAlphabetically } from '../utils';\nimport { loadContentDeclarations } from './loadContentDeclaration';\nimport { loadDistantDictionaries } from './loadDistantDictionaries';\n\nconst LOG_PREFIX = '[intlayer] ';\n\nexport const loadDictionaries = async (\n contentDeclarationsPaths: string[] | string\n): Promise<Dictionary[]> => {\n try {\n const { editor } = getConfiguration();\n\n console.info(`${LOG_PREFIX}Dictionaries:`);\n\n const files = Array.isArray(contentDeclarationsPaths)\n ? contentDeclarationsPaths\n : [contentDeclarationsPaths];\n\n const localDictionaries: Dictionary[] =\n await loadContentDeclarations(files);\n const localDictionaryKeys = localDictionaries.map((dict) => dict.key);\n\n // Initialize the logger with both local and distant dictionaries\n logger.init(localDictionaryKeys, []);\n\n // Update logger statuses for local dictionaries\n for (const dict of localDictionaries) {\n logger.updateStatus(dict.key, 'local', { status: 'built' });\n }\n\n let distantDictionaries: DictionaryAPI[] = [];\n let distantDictionaryKeys: string[] = [];\n let mergedDictionaries = localDictionaries;\n\n if (editor.clientId && editor.clientSecret) {\n // Fetch distant dictionary keys\n distantDictionaryKeys = await fetchDistantDictionaryKeys();\n\n const orderedDistantDictionaryKeys =\n distantDictionaryKeys.sort(sortAlphabetically);\n // Add distant dictionaries to the logger\n logger.addDictionaryKeys('distant', orderedDistantDictionaryKeys);\n\n // Fetch distant dictionaries\n distantDictionaries = await loadDistantDictionaries({\n dictionaryKeys: orderedDistantDictionaryKeys,\n });\n if (editor.dictionaryPriorityStrategy === 'distant_first') {\n // Merge the dictionaries\n mergedDictionaries = merge(localDictionaries, distantDictionaries, {\n arrayMerge: mergeByKey('key'),\n });\n } else {\n // Merge the dictionaries\n mergedDictionaries = merge(distantDictionaries, localDictionaries, {\n arrayMerge: mergeByKey('key'),\n });\n }\n }\n\n // Ensure the logger is stopped\n logger.stop();\n\n return mergedDictionaries;\n } catch (error) {\n // Ensure the logger is stopped\n logger.stop();\n\n throw error; // Re-throw the error after logging\n }\n};\n"],"mappings":"AAEA,SAAS,wBAAwB;AAEjC,OAAO,WAAW;AAClB,SAAS,kCAAkC;AAC3C,SAAS,cAAc;AACvB,SAAS,kBAAkB;AAC3B,SAAS,0BAA0B;AACnC,SAAS,+BAA+B;AACxC,SAAS,+BAA+B;AAExC,MAAM,aAAa;AAEZ,MAAM,mBAAmB,OAC9B,6BAC0B;AAC1B,MAAI;AACF,UAAM,EAAE,OAAO,IAAI,iBAAiB;AAEpC,YAAQ,KAAK,GAAG,UAAU,eAAe;AAEzC,UAAM,QAAQ,MAAM,QAAQ,wBAAwB,IAChD,2BACA,CAAC,wBAAwB;AAE7B,UAAM,oBACJ,MAAM,wBAAwB,KAAK;AACrC,UAAM,sBAAsB,kBAAkB,IAAI,CAAC,SAAS,KAAK,GAAG;AAGpE,WAAO,KAAK,qBAAqB,CAAC,CAAC;AAGnC,eAAW,QAAQ,mBAAmB;AACpC,aAAO,aAAa,KAAK,KAAK,SAAS,EAAE,QAAQ,QAAQ,CAAC;AAAA,IAC5D;AAEA,QAAI,sBAAuC,CAAC;AAC5C,QAAI,wBAAkC,CAAC;AACvC,QAAI,qBAAqB;AAEzB,QAAI,OAAO,YAAY,OAAO,cAAc;AAE1C,8BAAwB,MAAM,2BAA2B;AAEzD,YAAM,+BACJ,sBAAsB,KAAK,kBAAkB;AAE/C,aAAO,kBAAkB,WAAW,4BAA4B;AAGhE,4BAAsB,MAAM,wBAAwB;AAAA,QAClD,gBAAgB;AAAA,MAClB,CAAC;AACD,UAAI,OAAO,+BAA+B,iBAAiB;AAEzD,6BAAqB,MAAM,mBAAmB,qBAAqB;AAAA,UACjE,YAAY,WAAW,KAAK;AAAA,QAC9B,CAAC;AAAA,MACH,OAAO;AAEL,6BAAqB,MAAM,qBAAqB,mBAAmB;AAAA,UACjE,YAAY,WAAW,KAAK;AAAA,QAC9B,CAAC;AAAA,MACH;AAAA,IACF;AAGA,WAAO,KAAK;AAEZ,WAAO;AAAA,EACT,SAAS,OAAO;AAEd,WAAO,KAAK;AAEZ,UAAM;AAAA,EACR;AACF;","names":[]}
package/dist/esm/log.mjs CHANGED
@@ -1,4 +1,5 @@
1
- import * as readline from "readline";
1
+ import logUpdate from "log-update";
2
+ import { sortAlphabetically } from './utils.mjs';
2
3
  class Logger {
3
4
  dictionariesStatuses = [];
4
5
  spinnerFrames = ["\u280B", "\u2819", "\u2839", "\u2838", "\u283C", "\u2834", "\u2826", "\u2827", "\u2807", "\u280F"];
@@ -23,7 +24,11 @@ class Logger {
23
24
  }
24
25
  init(localDictionariesKeys, distantDictionariesKeys) {
25
26
  const allKeys = Array.from(
26
- /* @__PURE__ */ new Set([...localDictionariesKeys, ...distantDictionariesKeys])
27
+ new Set(
28
+ [...localDictionariesKeys, ...distantDictionariesKeys].sort(
29
+ sortAlphabetically
30
+ )
31
+ )
27
32
  );
28
33
  this.maxDictionaryKeyLength = allKeys.reduce(
29
34
  (max, key) => key.length > max ? key.length : max,
@@ -50,10 +55,8 @@ class Logger {
50
55
  state: states
51
56
  };
52
57
  });
53
- for (const statusObj of this.dictionariesStatuses) {
54
- process.stdout.write(this.getStatusLine(statusObj) + "\n");
55
- }
56
58
  this.startSpinner();
59
+ this.updateAllStatusLines();
57
60
  }
58
61
  // New method to add dictionary keys after initialization
59
62
  addDictionaryKeys(type, dictionaryKeys) {
@@ -76,7 +79,6 @@ class Logger {
76
79
  spinnerFrameIndex: 0
77
80
  };
78
81
  statusObj.state.push(newState);
79
- process.stdout.write(this.getStatusLine(statusObj) + "\n");
80
82
  } else {
81
83
  const existingState = statusObj.state.find((s) => s.type === type);
82
84
  if (!existingState) {
@@ -86,22 +88,10 @@ class Logger {
86
88
  spinnerFrameIndex: 0
87
89
  };
88
90
  statusObj.state.push(newState);
89
- const lineIndex = this.dictionariesStatuses.indexOf(statusObj);
90
- readline.moveCursor(
91
- process.stdout,
92
- 0,
93
- -(this.dictionariesStatuses.length - lineIndex)
94
- );
95
- readline.clearLine(process.stdout, 0);
96
- process.stdout.write(this.getStatusLine(statusObj) + "\n");
97
- readline.moveCursor(
98
- process.stdout,
99
- 0,
100
- this.dictionariesStatuses.length - lineIndex - 1
101
- );
102
91
  }
103
92
  }
104
93
  }
94
+ this.updateAllStatusLines();
105
95
  }
106
96
  startSpinner() {
107
97
  if (!this.spinnerTimer) {
@@ -118,7 +108,11 @@ class Logger {
118
108
  }
119
109
  stop() {
120
110
  this.stopSpinner();
121
- this.updateAllStatusLines();
111
+ logUpdate.clear();
112
+ const lines = this.dictionariesStatuses.map(
113
+ (statusObj) => this.getStatusLine(statusObj)
114
+ );
115
+ console.log(lines.join("\n"));
122
116
  }
123
117
  updateStatus(dictionaryKey, type, status) {
124
118
  const statusObj = this.dictionariesStatuses.find(
@@ -156,8 +150,8 @@ class Logger {
156
150
  state: [newState]
157
151
  });
158
152
  }
153
+ this.updateAllStatusLines();
159
154
  }
160
- // Rest of the Logger class remains the same...
161
155
  getStatusIcon(status) {
162
156
  const statusIcons = {
163
157
  pending: "\u23F2",
@@ -171,7 +165,7 @@ class Logger {
171
165
  }
172
166
  getStatusLine(statusObj) {
173
167
  const keyPadding = this.maxDictionaryKeyLength - statusObj.dictionaryKey.length;
174
- const paddedKey = statusObj.dictionaryKey + " ".repeat(keyPadding);
168
+ const paddedKey = `${statusObj.dictionaryKey}${" ".repeat(keyPadding)}`;
175
169
  const states = statusObj.state.map((state) => {
176
170
  let colorStart = "";
177
171
  let colorEnd = "";
@@ -196,19 +190,15 @@ class Logger {
196
190
  return `- ${paddedKey} ${states.join(" ")}`;
197
191
  }
198
192
  updateAllStatusLines() {
199
- readline.moveCursor(process.stdout, 0, -this.dictionariesStatuses.length);
200
- for (const statusObj of this.dictionariesStatuses) {
201
- readline.clearLine(process.stdout, 0);
202
- if (typeof statusObj?.state === "undefined") {
203
- return;
204
- }
193
+ const lines = this.dictionariesStatuses.map((statusObj) => {
205
194
  statusObj.state.forEach((state) => {
206
195
  if (state.status === "fetching") {
207
196
  state.spinnerFrameIndex = (state.spinnerFrameIndex + 1) % this.spinnerFrames.length;
208
197
  }
209
198
  });
210
- process.stdout.write(this.getStatusLine(statusObj) + "\n");
211
- }
199
+ return this.getStatusLine(statusObj);
200
+ });
201
+ logUpdate(lines.join("\n"));
212
202
  }
213
203
  getStatuses() {
214
204
  return this.dictionariesStatuses;
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/log.ts"],"sourcesContent":["import * as readline from 'readline';\n\nexport type State = {\n type: 'local' | 'distant';\n status: 'pending' | 'fetching' | 'fetched' | 'error' | 'imported' | 'built';\n icon?: string;\n error?: Error;\n errorMessage?: string;\n spinnerFrameIndex?: number;\n};\n\nexport type DictionariesStatus = {\n dictionaryKey: string;\n state: State[];\n};\n\nclass Logger {\n private dictionariesStatuses: DictionariesStatus[] = [];\n private spinnerFrames = ['⠋', '⠙', '⠹', '⠸', '⠼', '⠴', '⠦', '⠧', '⠇', '⠏'];\n private spinnerTimer: NodeJS.Timeout | null = null;\n private maxDictionaryKeyLength: number = 0;\n\n // ANSI color codes\n private RESET = '\\x1b[0m';\n private GREEN = '\\x1b[32m';\n private RED = '\\x1b[31m';\n private BLUE = '\\x1b[34m';\n private GREY = '\\x1b[90m';\n private GREY_DARK = '\\x1b[90m';\n\n // Singleton instance\n private static instance: Logger;\n\n private constructor() {}\n\n public static getInstance(): Logger {\n if (!Logger.instance) {\n Logger.instance = new Logger();\n }\n return Logger.instance;\n }\n\n public init(\n localDictionariesKeys: string[],\n distantDictionariesKeys: string[]\n ) {\n const allKeys = Array.from(\n new Set([...localDictionariesKeys, ...distantDictionariesKeys])\n );\n\n this.maxDictionaryKeyLength = allKeys.reduce(\n (max, key) => (key.length > max ? key.length : max),\n 0\n );\n\n this.dictionariesStatuses = allKeys.map((dictionaryKey) => {\n const states: State[] = [];\n if (localDictionariesKeys.includes(dictionaryKey)) {\n states.push({\n type: 'local',\n status: 'pending',\n spinnerFrameIndex: 0,\n });\n }\n if (distantDictionariesKeys.includes(dictionaryKey)) {\n states.push({\n type: 'distant',\n status: 'pending',\n spinnerFrameIndex: 0,\n });\n }\n return {\n dictionaryKey,\n state: states,\n };\n });\n\n // Output initial statuses\n for (const statusObj of this.dictionariesStatuses) {\n process.stdout.write(this.getStatusLine(statusObj) + '\\n');\n }\n\n // Start spinner timer\n this.startSpinner();\n }\n\n // New method to add dictionary keys after initialization\n public addDictionaryKeys(\n type: 'local' | 'distant',\n dictionaryKeys: string[]\n ) {\n for (const dictionaryKey of dictionaryKeys) {\n // Update maxDictionaryKeyLength if the new key is longer\n if (dictionaryKey.length > this.maxDictionaryKeyLength) {\n this.maxDictionaryKeyLength = dictionaryKey.length;\n }\n\n let statusObj = this.dictionariesStatuses.find(\n (ds) => ds.dictionaryKey === dictionaryKey\n );\n\n if (!statusObj) {\n // If the dictionaryKey doesn't exist yet, create a new DictionariesStatus\n statusObj = {\n dictionaryKey,\n state: [],\n };\n this.dictionariesStatuses.push(statusObj);\n\n const newState: State = {\n type,\n status: 'pending',\n spinnerFrameIndex: 0,\n };\n statusObj.state.push(newState);\n\n // Output the new status line\n process.stdout.write(this.getStatusLine(statusObj) + '\\n');\n } else {\n const existingState = statusObj.state.find((s) => s.type === type);\n if (!existingState) {\n // Add new state for the type\n const newState: State = {\n type,\n status: 'pending',\n spinnerFrameIndex: 0,\n };\n statusObj.state.push(newState);\n\n // Update the existing line\n const lineIndex = this.dictionariesStatuses.indexOf(statusObj);\n // Move cursor up to the lineIndex from the bottom\n readline.moveCursor(\n process.stdout,\n 0,\n -(this.dictionariesStatuses.length - lineIndex)\n );\n readline.clearLine(process.stdout, 0);\n process.stdout.write(this.getStatusLine(statusObj) + '\\n');\n // Move cursor back to the bottom\n readline.moveCursor(\n process.stdout,\n 0,\n this.dictionariesStatuses.length - lineIndex - 1\n );\n }\n }\n }\n // No need to redraw all status lines\n }\n\n private startSpinner() {\n if (!this.spinnerTimer) {\n this.spinnerTimer = setInterval(() => {\n this.updateAllStatusLines();\n }, 100); // Update every 100ms\n }\n }\n\n private stopSpinner() {\n if (this.spinnerTimer) {\n clearInterval(this.spinnerTimer);\n this.spinnerTimer = null;\n }\n }\n\n public stop() {\n this.stopSpinner();\n // Update statuses one last time\n this.updateAllStatusLines();\n }\n\n public updateStatus(\n dictionaryKey: string,\n type: 'local' | 'distant',\n status: Partial<State>\n ) {\n const statusObj = this.dictionariesStatuses.find(\n (ds) => ds.dictionaryKey === dictionaryKey\n );\n if (statusObj) {\n const state = statusObj.state.find((s) => s.type === type);\n if (state) {\n // Update existing state\n Object.assign(state, status);\n } else {\n // If the state for this type doesn't exist yet, add it\n if (status.status === undefined) {\n status.status = 'pending'; // Provide default status\n }\n const newState: State = {\n type,\n status: status.status,\n icon: status.icon ?? '',\n error: status.error,\n errorMessage: status.errorMessage,\n spinnerFrameIndex: status.spinnerFrameIndex ?? 0,\n };\n statusObj.state.push(newState);\n }\n } else {\n // If the status object doesn't exist, create it\n const newState: State = {\n type,\n status: status.status ?? 'pending',\n icon: status.icon ?? '',\n error: status.error,\n errorMessage: status.errorMessage,\n spinnerFrameIndex: status.spinnerFrameIndex ?? 0,\n };\n this.dictionariesStatuses.push({\n dictionaryKey,\n state: [newState],\n });\n }\n }\n\n // Rest of the Logger class remains the same...\n\n private getStatusIcon(status: string): string {\n const statusIcons: Record<string, string> = {\n pending: '⏲',\n fetching: '', // Spinner handled separately\n built: '✔',\n imported: '✔',\n error: '✖',\n };\n return statusIcons[status] ?? '';\n }\n\n private getStatusLine(statusObj: DictionariesStatus): string {\n const keyPadding =\n this.maxDictionaryKeyLength - statusObj.dictionaryKey.length;\n const paddedKey = statusObj.dictionaryKey + ' '.repeat(keyPadding);\n\n const states = statusObj.state.map((state) => {\n let colorStart = '';\n let colorEnd = '';\n let icon = this.getStatusIcon(state.status);\n if (state.status === 'fetching') {\n // Use spinner frame\n icon =\n this.spinnerFrames[\n state.spinnerFrameIndex! % this.spinnerFrames.length\n ];\n colorStart = this.BLUE;\n colorEnd = this.RESET;\n } else if (state.status === 'error') {\n colorStart = this.RED;\n colorEnd = this.RESET;\n } else if (state.status === 'imported' || state.status === 'built') {\n colorStart = this.GREEN;\n colorEnd = this.RESET;\n } else {\n colorStart = this.GREY;\n colorEnd = this.RESET;\n }\n\n // Format the status block\n const statusBlock = `${this.GREY_DARK}[${state.type}: ${colorStart}${icon} ${state.status}${this.GREY_DARK}]${colorEnd}`;\n\n return `${colorStart}${statusBlock}${colorEnd}`;\n });\n\n return `- ${paddedKey} ${states.join(' ')}`;\n }\n\n private updateAllStatusLines() {\n // Move cursor up to the first status line\n readline.moveCursor(process.stdout, 0, -this.dictionariesStatuses.length);\n\n for (const statusObj of this.dictionariesStatuses) {\n // Clear the line\n readline.clearLine(process.stdout, 0);\n\n if (typeof statusObj?.state === 'undefined') {\n return;\n }\n\n statusObj.state.forEach((state) => {\n if (state.status === 'fetching') {\n // Update spinner frame\n state.spinnerFrameIndex =\n (state.spinnerFrameIndex! + 1) % this.spinnerFrames.length;\n }\n });\n\n // Write the status line\n process.stdout.write(this.getStatusLine(statusObj) + '\\n');\n }\n }\n\n public getStatuses() {\n return this.dictionariesStatuses;\n }\n}\n\nexport const logger = Logger.getInstance();\n"],"mappings":"AAAA,YAAY,cAAc;AAgB1B,MAAM,OAAO;AAAA,EACH,uBAA6C,CAAC;AAAA,EAC9C,gBAAgB,CAAC,UAAK,UAAK,UAAK,UAAK,UAAK,UAAK,UAAK,UAAK,UAAK,QAAG;AAAA,EACjE,eAAsC;AAAA,EACtC,yBAAiC;AAAA;AAAA,EAGjC,QAAQ;AAAA,EACR,QAAQ;AAAA,EACR,MAAM;AAAA,EACN,OAAO;AAAA,EACP,OAAO;AAAA,EACP,YAAY;AAAA;AAAA,EAGpB,OAAe;AAAA,EAEP,cAAc;AAAA,EAAC;AAAA,EAEvB,OAAc,cAAsB;AAClC,QAAI,CAAC,OAAO,UAAU;AACpB,aAAO,WAAW,IAAI,OAAO;AAAA,IAC/B;AACA,WAAO,OAAO;AAAA,EAChB;AAAA,EAEO,KACL,uBACA,yBACA;AACA,UAAM,UAAU,MAAM;AAAA,MACpB,oBAAI,IAAI,CAAC,GAAG,uBAAuB,GAAG,uBAAuB,CAAC;AAAA,IAChE;AAEA,SAAK,yBAAyB,QAAQ;AAAA,MACpC,CAAC,KAAK,QAAS,IAAI,SAAS,MAAM,IAAI,SAAS;AAAA,MAC/C;AAAA,IACF;AAEA,SAAK,uBAAuB,QAAQ,IAAI,CAAC,kBAAkB;AACzD,YAAM,SAAkB,CAAC;AACzB,UAAI,sBAAsB,SAAS,aAAa,GAAG;AACjD,eAAO,KAAK;AAAA,UACV,MAAM;AAAA,UACN,QAAQ;AAAA,UACR,mBAAmB;AAAA,QACrB,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G,CAAC;AAAA,EAC3C;AAAA,EAEQ,uBAAuB;AAE7B,aAAS,WAAW,QAAQ,QAAQ,GAAG,CAAC,KAAK,qBAAqB,MAAM;AAExE,eAAW,aAAa,KAAK,sBAAsB;AAEjD,eAAS,UAAU,QAAQ,QAAQ,CAAC;AAEpC,UAAI,OAAO,WAAW,UAAU,aAAa;AAC3C;AAAA,MACF;AAEA,gBAAU,MAAM,QAAQ,CAAC,UAAU;AACjC,YAAI,MAAM,WAAW,YAAY;AAE/B,gBAAM,qBACH,MAAM,oBAAqB,KAAK,KAAK,cAAc;AAAA,QACxD;AAAA,MACF,CAAC;AAGD,cAAQ,OAAO,MAAM,KAAK,cAAc,SAAS,IAAI,IAAI;AAAA,IAC3D;AAAA,EACF;AAAA,EAEO,cAAc;AACnB,WAAO,KAAK;AAAA,EACd;AACF;AAEO,MAAM,SAAS,OAAO,YAAY;","names":[]}
1
+ {"version":3,"sources":["../../src/log.ts"],"sourcesContent":["import logUpdate from 'log-update';\nimport { sortAlphabetically } from './utils';\n\nexport type State = {\n type: 'local' | 'distant';\n status: 'pending' | 'fetching' | 'fetched' | 'error' | 'imported' | 'built';\n icon?: string;\n error?: Error;\n errorMessage?: string;\n spinnerFrameIndex?: number;\n};\n\nexport type DictionariesStatus = {\n dictionaryKey: string;\n state: State[];\n};\n\nclass Logger {\n private dictionariesStatuses: DictionariesStatus[] = [];\n private spinnerFrames = ['⠋', '⠙', '⠹', '⠸', '⠼', '⠴', '⠦', '⠧', '⠇', '⠏'];\n private spinnerTimer: NodeJS.Timeout | null = null;\n private maxDictionaryKeyLength: number = 0;\n\n // ANSI color codes\n private RESET = '\\x1b[0m';\n private GREEN = '\\x1b[32m';\n private RED = '\\x1b[31m';\n private BLUE = '\\x1b[34m';\n private GREY = '\\x1b[90m';\n private GREY_DARK = '\\x1b[90m';\n\n // Singleton instance\n private static instance: Logger;\n\n private constructor() {}\n\n public static getInstance(): Logger {\n if (!Logger.instance) {\n Logger.instance = new Logger();\n }\n return Logger.instance;\n }\n\n public init(\n localDictionariesKeys: string[],\n distantDictionariesKeys: string[]\n ) {\n const allKeys = Array.from(\n new Set(\n [...localDictionariesKeys, ...distantDictionariesKeys].sort(\n sortAlphabetically\n )\n )\n );\n\n this.maxDictionaryKeyLength = allKeys.reduce(\n (max, key) => (key.length > max ? key.length : max),\n 0\n );\n\n this.dictionariesStatuses = allKeys.map((dictionaryKey) => {\n const states: State[] = [];\n\n if (localDictionariesKeys.includes(dictionaryKey)) {\n states.push({\n type: 'local',\n status: 'pending',\n spinnerFrameIndex: 0,\n });\n }\n if (distantDictionariesKeys.includes(dictionaryKey)) {\n states.push({\n type: 'distant',\n status: 'pending',\n spinnerFrameIndex: 0,\n });\n }\n\n return {\n dictionaryKey,\n state: states,\n };\n });\n\n // Start spinner timer\n this.startSpinner();\n\n // Update all status lines (this will output the initial statuses)\n this.updateAllStatusLines();\n }\n\n // New method to add dictionary keys after initialization\n public addDictionaryKeys(\n type: 'local' | 'distant',\n dictionaryKeys: string[]\n ) {\n for (const dictionaryKey of dictionaryKeys) {\n // Update maxDictionaryKeyLength if the new key is longer\n if (dictionaryKey.length > this.maxDictionaryKeyLength) {\n this.maxDictionaryKeyLength = dictionaryKey.length;\n }\n\n let statusObj = this.dictionariesStatuses.find(\n (ds) => ds.dictionaryKey === dictionaryKey\n );\n\n if (!statusObj) {\n // If the dictionaryKey doesn't exist yet, create a new DictionariesStatus\n\n statusObj = {\n dictionaryKey,\n state: [],\n };\n this.dictionariesStatuses.push(statusObj);\n\n const newState: State = {\n type,\n status: 'pending',\n spinnerFrameIndex: 0,\n };\n statusObj.state.push(newState);\n } else {\n const existingState = statusObj.state.find((s) => s.type === type);\n if (!existingState) {\n // Add new state for the type\n\n const newState: State = {\n type,\n status: 'pending',\n spinnerFrameIndex: 0,\n };\n statusObj.state.push(newState);\n }\n }\n }\n\n // Call updateAllStatusLines() to refresh the output\n this.updateAllStatusLines();\n }\n\n private startSpinner() {\n if (!this.spinnerTimer) {\n this.spinnerTimer = setInterval(() => {\n this.updateAllStatusLines();\n }, 100); // Update every 100ms\n }\n }\n\n private stopSpinner() {\n if (this.spinnerTimer) {\n clearInterval(this.spinnerTimer);\n this.spinnerTimer = null;\n }\n }\n\n public stop() {\n this.stopSpinner();\n logUpdate.clear(); // Clear the logUpdate output\n const lines = this.dictionariesStatuses.map((statusObj) =>\n this.getStatusLine(statusObj)\n );\n console.log(lines.join('\\n')); // Output final statuses\n }\n\n public updateStatus(\n dictionaryKey: string,\n type: 'local' | 'distant',\n status: Partial<State>\n ) {\n const statusObj = this.dictionariesStatuses.find(\n (ds) => ds.dictionaryKey === dictionaryKey\n );\n if (statusObj) {\n const state = statusObj.state.find((s) => s.type === type);\n if (state) {\n // Update existing state\n Object.assign(state, status);\n } else {\n // If the state for this type doesn't exist yet, add it\n if (status.status === undefined) {\n status.status = 'pending'; // Provide default status\n }\n const newState: State = {\n type,\n status: status.status,\n icon: status.icon ?? '',\n error: status.error,\n errorMessage: status.errorMessage,\n spinnerFrameIndex: status.spinnerFrameIndex ?? 0,\n };\n statusObj.state.push(newState);\n }\n } else {\n // If the status object doesn't exist, create it\n const newState: State = {\n type,\n status: status.status ?? 'pending',\n icon: status.icon ?? '',\n error: status.error,\n errorMessage: status.errorMessage,\n spinnerFrameIndex: status.spinnerFrameIndex ?? 0,\n };\n this.dictionariesStatuses.push({\n dictionaryKey,\n state: [newState],\n });\n }\n\n // Update the display after status change\n this.updateAllStatusLines();\n }\n\n private getStatusIcon(status: string): string {\n const statusIcons: Record<string, string> = {\n pending: '⏲',\n fetching: '', // Spinner handled separately\n built: '✔',\n imported: '✔',\n error: '✖',\n };\n return statusIcons[status] ?? '';\n }\n\n private getStatusLine(statusObj: DictionariesStatus): string {\n const keyPadding =\n this.maxDictionaryKeyLength - statusObj.dictionaryKey.length;\n const paddedKey = `${statusObj.dictionaryKey}${' '.repeat(keyPadding)}`;\n\n const states = statusObj.state.map((state) => {\n let colorStart = '';\n let colorEnd = '';\n let icon = this.getStatusIcon(state.status);\n if (state.status === 'fetching') {\n // Use spinner frame\n icon =\n this.spinnerFrames[\n state.spinnerFrameIndex! % this.spinnerFrames.length\n ];\n colorStart = this.BLUE;\n colorEnd = this.RESET;\n } else if (state.status === 'error') {\n colorStart = this.RED;\n colorEnd = this.RESET;\n } else if (state.status === 'imported' || state.status === 'built') {\n colorStart = this.GREEN;\n colorEnd = this.RESET;\n } else {\n colorStart = this.GREY;\n colorEnd = this.RESET;\n }\n\n // Format the status block\n const statusBlock = `${this.GREY_DARK}[${state.type}: ${colorStart}${icon} ${state.status}${this.GREY_DARK}]${colorEnd}`;\n\n return `${colorStart}${statusBlock}${colorEnd}`;\n });\n\n return `- ${paddedKey} ${states.join(' ')}`;\n }\n\n private updateAllStatusLines() {\n const lines = this.dictionariesStatuses.map((statusObj) => {\n statusObj.state.forEach((state) => {\n if (state.status === 'fetching') {\n // Update spinner frame\n state.spinnerFrameIndex =\n (state.spinnerFrameIndex! + 1) % this.spinnerFrames.length;\n }\n });\n return this.getStatusLine(statusObj);\n });\n\n logUpdate(lines.join('\\n'));\n }\n\n public getStatuses() {\n return this.dictionariesStatuses;\n }\n}\n\nexport const logger = Logger.getInstance();\n"],"mappings":"AAAA,OAAO,eAAe;AACtB,SAAS,0BAA0B;AAgBnC,MAAM,OAAO;AAAA,EACH,uBAA6C,CAAC;AAAA,EAC9C,gBAAgB,CAAC,UAAK,UAAK,UAAK,UAAK,UAAK,UAAK,UAAK,UAAK,UAAK,QAAG;AAAA,EACjE,eAAsC;AAAA,EACtC,yBAAiC;AAAA;AAAA,EAGjC,QAAQ;AAAA,EACR,QAAQ;AAAA,EACR,MAAM;AAAA,EACN,OAAO;AAAA,EACP,OAAO;AAAA,EACP,YAAY;AAAA;AAAA,EAGpB,OAAe;AAAA,EAEP,cAAc;AAAA,EAAC;AAAA,EAEvB,OAAc,cAAsB;AAClC,QAAI,CAAC,OAAO,UAAU;AACpB,aAAO,WAAW,IAAI,OAAO;AAAA,IAC/B;AACA,W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G,KAAK,SAAS,IAAI,MAAM,IAAI,KAAK,UAAU,GAAG,IAAI,IAAI,MAAM,MAAM,GAAG,KAAK,SAAS,IAAI,QAAQ;AAEtH,aAAO,GAAG,UAAU,GAAG,WAAW,GAAG,QAAQ;AAAA,IAC/C,CAAC;AAED,WAAO,KAAK,SAAS,IAAI,OAAO,KAAK,GAAG,CAAC;AAAA,EAC3C;AAAA,EAEQ,uBAAuB;AAC7B,UAAM,QAAQ,KAAK,qBAAqB,IAAI,CAAC,cAAc;AACzD,gBAAU,MAAM,QAAQ,CAAC,UAAU;AACjC,YAAI,MAAM,WAAW,YAAY;AAE/B,gBAAM,qBACH,MAAM,oBAAqB,KAAK,KAAK,cAAc;AAAA,QACxD;AAAA,MACF,CAAC;AACD,aAAO,KAAK,cAAc,SAAS;AAAA,IACrC,CAAC;AAED,cAAU,MAAM,KAAK,IAAI,CAAC;AAAA,EAC5B;AAAA,EAEO,cAAc;AACnB,WAAO,KAAK;AAAA,EACd;AACF;AAEO,MAAM,SAAS,OAAO,YAAY;","names":[]}
@@ -1,7 +1,7 @@
1
1
  import { existsSync, mkdirSync, writeFileSync } from "fs";
2
2
  import { basename, extname, relative, resolve } from "path";
3
3
  import { getConfiguration } from "@intlayer/config";
4
- import { sync } from "glob";
4
+ import fg from "fast-glob";
5
5
  import { getFileHash } from '../../utils.mjs';
6
6
  const { content } = getConfiguration();
7
7
  const { dictionariesDir, mainDir } = content;
@@ -40,7 +40,7 @@ const createDictionaryList = () => {
40
40
  if (!existsSync(mainDir)) {
41
41
  mkdirSync(mainDir, { recursive: true });
42
42
  }
43
- const dictionaries = sync(`${dictionariesDir}/**/*.json`);
43
+ const dictionaries = fg.sync(`${dictionariesDir}/**/*.json`);
44
44
  const cjsContent = generateDictionaryListContent(dictionaries, "cjs");
45
45
  writeFileSync(resolve(mainDir, "dictionaries.cjs"), cjsContent);
46
46
  const esmContent = generateDictionaryListContent(dictionaries, "esm");
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/transpiler/dictionary_to_main/createDictionaryList.ts"],"sourcesContent":["import { existsSync, mkdirSync, writeFileSync } from 'fs';\nimport { basename, extname, relative, resolve } from 'path';\nimport { getConfiguration } from '@intlayer/config';\nimport { sync } from 'glob';\nimport { getFileHash } from '../../utils';\n\nconst { content } = getConfiguration();\nconst { dictionariesDir, mainDir } = content;\n\n/**\n * This function generates the content of the dictionary list file\n */\nconst generateDictionaryListContent = (\n dictionaries: string[],\n format: 'cjs' | 'esm' = 'esm'\n): string => {\n let content = '';\n\n const dictionariesRef = dictionaries.map((dictionaryPath) => ({\n relativePath: relative(mainDir, dictionaryPath),\n id: basename(dictionaryPath, extname(dictionaryPath)), // Get the base name as the dictionary id\n hash: `_${getFileHash(dictionaryPath)}`, // Get the hash of the dictionary to avoid conflicts\n }));\n\n // Import all dictionaries\n dictionariesRef.forEach((dictionary) => {\n if (format === 'esm')\n content += `import ${dictionary.hash} from '${dictionary.relativePath}';\\n`;\n if (format === 'cjs')\n content += `const ${dictionary.hash} = require('${dictionary.relativePath}');\\n`;\n });\n\n content += '\\n';\n\n // Format Dictionary Map\n const formattedDictionaryMap: string = dictionariesRef\n .map((dictionary) => `\"${dictionary.id}\": ${dictionary.hash}`)\n .join(',\\n');\n\n if (format === 'esm')\n content += `export default {\\n${formattedDictionaryMap}\\n};\\n`;\n if (format === 'cjs')\n content += `module.exports = {\\n${formattedDictionaryMap}\\n};\\n`;\n\n return content;\n};\n\n/**\n * This function generates a list of dictionaries in the main directory\n */\nexport const createDictionaryList = () => {\n // Create main directory if it doesn't exist\n if (!existsSync(mainDir)) {\n mkdirSync(mainDir, { recursive: true });\n }\n\n const dictionaries: string[] = sync(`${dictionariesDir}/**/*.json`);\n\n // Create the dictionary list file\n const cjsContent = generateDictionaryListContent(dictionaries, 'cjs');\n writeFileSync(resolve(mainDir, 'dictionaries.cjs'), cjsContent);\n\n const esmContent = generateDictionaryListContent(dictionaries, 'esm');\n writeFileSync(resolve(mainDir, 'dictionaries.mjs'), es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G,UAAU;AAE9D,QAAM,aAAa,8BAA8B,cAAc,KAAK;AACpE,gBAAc,QAAQ,SAAS,kBAAkB,GAAG,UAAU;AAChE;","names":["content"]}
1
+ {"version":3,"sources":["../../../../src/transpiler/dictionary_to_main/createDictionaryList.ts"],"sourcesContent":["import { existsSync, mkdirSync, writeFileSync } from 'fs';\nimport { basename, extname, relative, resolve } from 'path';\nimport { getConfiguration } from '@intlayer/config';\nimport fg from 'fast-glob';\nimport { getFileHash } from '../../utils';\n\nconst { content } = getConfiguration();\nconst { dictionariesDir, mainDir } = content;\n\n/**\n * This function generates the content of the dictionary list file\n */\nconst generateDictionaryListContent = (\n dictionaries: string[],\n format: 'cjs' | 'esm' = 'esm'\n): string => {\n let content = '';\n\n const dictionariesRef = dictionaries.map((dictionaryPath) => ({\n relativePath: relative(mainDir, dictionaryPath),\n id: basename(dictionaryPath, extname(dictionaryPath)), // Get the base name as the dictionary id\n hash: `_${getFileHash(dictionaryPath)}`, // Get the hash of the dictionary to avoid conflicts\n }));\n\n // Import all dictionaries\n dictionariesRef.forEach((dictionary) => {\n if (format === 'esm')\n content += `import ${dictionary.hash} from '${dictionary.relativePath}';\\n`;\n if (format === 'cjs')\n content += `const ${dictionary.hash} = require('${dictionary.relativePath}');\\n`;\n });\n\n content += '\\n';\n\n // Format Dictionary Map\n const formattedDictionaryMap: string = dictionariesRef\n .map((dictionary) => `\"${dictionary.id}\": ${dictionary.hash}`)\n .join(',\\n');\n\n if (format === 'esm')\n content += `export default {\\n${formattedDictionaryMap}\\n};\\n`;\n if (format === 'cjs')\n content += `module.exports = {\\n${formattedDictionaryMap}\\n};\\n`;\n\n return content;\n};\n\n/**\n * This function generates a list of dictionaries in the main directory\n */\nexport const createDictionaryList = () => {\n // Create main directory if it doesn't exist\n if (!existsSync(mainDir)) {\n mkdirSync(mainDir, { recursive: true });\n }\n\n const dictionaries: string[] = fg.sync(`${dictionariesDir}/**/*.json`);\n\n // Create the dictionary list file\n const cjsContent = generateDictionaryListContent(dictionaries, 'cjs');\n writeFileSync(resolve(mainDir, 'dictionaries.cjs'), cjsContent);\n\n const esmContent = generateDictionaryListContent(dictionaries, 'esm');\n writeFileSync(resolve(mainDir, 'dictionaries.mjs'), esmContent);\n};\n"],"mappings":"AAAA,SAAS,YAAY,WAAW,qBAAqB;AACrD,SAAS,UAAU,SAAS,UAAU,eAAe;AACrD,SAAS,wBAAwB;AACjC,OAAO,QAAQ;AACf,SAAS,mBAAmB;AAE5B,MAAM,EAAE,QAAQ,IAAI,iBAAiB;AACrC,MAAM,EAAE,iBAAiB,QAAQ,IAAI;AAKrC,MAAM,gCAAgC,CACpC,cACA,SAAwB,UACb;AACX,MAAIA,WAAU;AAEd,QAAM,kBAAkB,aAAa,IAAI,CAAC,oBAAoB;AAAA,IAC5D,cAAc,SAAS,SAAS,cAAc;AAAA,IAC9C,IAAI,SAAS,gBAAgB,QAAQ,cAAc,CAAC;AAAA;AAAA,IACpD,MAAM,IAAI,YAAY,cAAc,CAAC;AAAA;AAAA,EACvC,EAAE;AAGF,kBAAgB,QAAQ,CAAC,eAAe;AACtC,QAAI,WAAW;AACb,MAAAA,YAAW,UAAU,WAAW,IAAI,UAAU,WAAW,YAAY;AAAA;AACvE,QAAI,WAAW;AACb,MAAAA,YAAW,SAAS,WAAW,IAAI,eAAe,WAAW,YAAY;AAAA;AAAA,EAC7E,CAAC;AAED,EAAAA,YAAW;AAGX,QAAM,yBAAiC,gBACpC,IAAI,CAAC,eAAe,IAAI,WAAW,EAAE,MAAM,WAAW,IAAI,EAAE,EAC5D,KAAK,KAAK;AAEb,MAAI,WAAW;AACb,IAAAA,YAAW;AAAA,EAAqB,sBAAsB;AAAA;AAAA;AACxD,MAAI,WAAW;AACb,IAAAA,YAAW;AAAA,EAAuB,sBAAsB;AAAA;AAAA;AAE1D,SAAOA;AACT;AAKO,MAAM,uBAAuB,MAAM;AAExC,MAAI,CAAC,WAAW,OAAO,GAAG;AACxB,cAAU,SAAS,EAAE,WAAW,KAAK,CAAC;AAAA,EACxC;AAEA,QAAM,eAAyB,GAAG,KAAK,GAAG,eAAe,YAAY;AAGrE,QAAM,aAAa,8BAA8B,cAAc,KAAK;AACpE,gBAAc,QAAQ,SAAS,kBAAkB,GAAG,UAAU;AAE9D,QAAM,aAAa,8BAA8B,cAAc,KAAK;AACpE,gBAAc,QAAQ,SAAS,kBAAkB,GAAG,UAAU;AAChE;","names":["content"]}
@@ -1,7 +1,7 @@
1
1
  import { existsSync, mkdirSync, writeFileSync } from "fs";
2
2
  import { basename, join, relative } from "path";
3
3
  import { Locales, getConfiguration } from "@intlayer/config";
4
- import { sync } from "glob";
4
+ import fg from "fast-glob";
5
5
  import { getFileHash, transformToCamelCase } from '../../utils.mjs';
6
6
  const { content, internationalization } = getConfiguration();
7
7
  const { typesDir, moduleAugmentationDir } = content;
@@ -54,7 +54,7 @@ const createModuleAugmentation = () => {
54
54
  if (!existsSync(moduleAugmentationDir)) {
55
55
  mkdirSync(moduleAugmentationDir, { recursive: true });
56
56
  }
57
- const dictionaries = sync(`${typesDir}/**/*.d.ts`);
57
+ const dictionaries = fg.sync(`${typesDir}/**/*.d.ts`);
58
58
  const tsContent = generateTypeIndexContent(dictionaries);
59
59
  writeFileSync(join(moduleAugmentationDir, "intlayer.d.ts"), tsContent);
60
60
  };
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/transpiler/dictionary_to_type/createModuleAugmentation.ts"],"sourcesContent":["import { existsSync, mkdirSync, writeFileSync } from 'fs';\nimport { basename, join, relative } from 'path';\nimport { Locales, getConfiguration } from '@intlayer/config';\nimport { sync } from 'glob';\nimport { getFileHash, transformToCamelCase } from '../../utils';\n\nconst { content, internationalization } = getConfiguration();\nconst { typesDir, moduleAugmentationDir } = content;\nconst { locales, strictMode } = internationalization;\n\nexport const getTypeName = (id: string): string =>\n transformToCamelCase(`${id}Content`);\n\n/**\n * This function generates the content of the module augmentation file\n */\nconst generateTypeIndexContent = (typeFiles: string[]): string => {\n let content = \"/* eslint-disable */\\nimport { Locales } from 'intlayer';\\n\";\n\n const dictionariesRef = typeFiles.map((dictionaryPath) => ({\n relativePath: relative(moduleAugmentationDir, dictionaryPath),\n id: basename(dictionaryPath, '.d.ts'), // Get the base name as the dictionary id\n hash: `_${getFileHash(dictionaryPath)}`, // Get the hash of the dictionary to avoid conflicts\n }));\n\n // Import all dictionaries\n dictionariesRef.forEach((dictionary) => {\n const typeName = getTypeName(dictionary.id);\n content += `import type { ${typeName} as ${dictionary.hash} } from '${dictionary.relativePath}';\\n`;\n });\n\n content += '\\n';\n\n // Format Dictionary Map\n const formattedDictionaryMap: string = dictionariesRef\n .map((dictionary) => ` \"${dictionary.id}\": ${dictionary.hash};`)\n .join('\\n');\n\n const formatLocales = locales\n .map((locale) => {\n for (const key in Locales) {\n if (Locales[key as keyof typeof Locales] === locale) {\n return `Locales.${key}`;\n }\n }\n })\n .join(' | ');\n\n const strictModeRecord =\n strictMode === 'strict'\n ? `interface IConfigLocales<Content> extends Record<ExtractedLocales, Content> {}`\n : strictMode === 'required_only'\n ? `interface IConfigLocales<Content> extends Record<ExtractedLocales, Content>, Partial<Record<ExcludedLocales, Content>> {}`\n : `interface IConfigLocales<Content> extends Partial<Record<Locales, Content>> {}`;\n\n /**\n * Write the module augmentation to extend the intlayer module with the dictionaries types\n * Will suggest the type resulting of the dictionaries\n *\n * declare module 'intlayer' {\n * interface IntlayerDictionaryTypesConnector = {\n * dictionaries: {\n * id: DictionaryType;\n * }\n * }\n *\n * type ConfigLocales = Locales.ENGLISH | Locales.FRENCH | Locales.SPANISH;\n * type ExtractedLocales = Extract<Locales, ConfigLocales>;\n * type ExcludedLocales = Exclude<Locales, ConfigLocales>;\n *\n * interface IConfigLocales<Content> extends Record<ExtractedLocales, Content>, Partial<Record<ExcludedLocales, Content>> {}\n *\n *\n * }\n * See https://www.typescriptlang.org/docs/handbook/declaration-merging.html#module-augmentation\n */\n content += `declare module 'intlayer' {\\n`;\n content += ` interface IntlayerDictionaryTypesConnector {\\n${formattedDictionaryMap}\\n }\\n\\n`;\n content += ` type ConfigLocales = ${formatLocales};\\n`;\n content += ` type ExtractedLocales = Extract<Locales, ConfigLocales>;\\n`;\n content += ` type ExcludedLocales = Exclude<Locales, ConfigLocales>;\\n\\n`;\n content += ` ${strictModeRecord}\\n`;\n content += `}`;\n\n return content;\n};\n\n/**\n * This function generates a index file merging all the types\n */\nexport const createModuleAugmentation = () => {\n // Create main directory if it doesn't exist\n if (!existsSync(moduleAugmentationDir)) {\n mkdirSync(moduleAugmentationDir, { recursive: true });\n }\n\n const dictionaries: string[] = sync(`${typesDir}/**/*.d.ts`);\n // Create the dictionary list file\n\n const tsContent = generateTypeIndexContent(dictionaries);\n writeFileSync(join(moduleAugmentationDir, 'intlayer.d.ts'), tsContent);\n};\n"],"mappings":"AAAA,SAAS,YAAY,WAAW,qBAAqB;AACrD,SAAS,UAAU,MAAM,gBAAgB;AACzC,SAAS,SAAS,wBAAwB;AAC1C,SAAS,YAAY;AACrB,SAAS,aAAa,4BAA4B;AAElD,MAAM,EAAE,SAAS,qBAAqB,IAAI,iBAAiB;AAC3D,MAAM,EAAE,UAAU,sBAAsB,IAAI;AAC5C,MAAM,EAAE,SAAS,WAAW,IAAI;AAEzB,MAAM,cAAc,CAAC,OAC1B,qBAAqB,GAAG,EAAE,SAAS;AAKrC,MAAM,2BAA2B,CAAC,cAAgC;AAChE,MAAIA,WAAU;AAEd,QAAM,kBAAkB,UAAU,IAAI,CAAC,oBAAoB;AAAA,IACzD,cAAc,SAAS,uBAAuB,cAAc;AAAA,IAC5D,IAAI,SAAS,gBAAgB,OAAO;AAAA;AAAA,IACpC,MAAM,IAAI,YAAY,cAAc,CAAC;AAAA;AAAA,EACvC,EAAE;AAGF,kBAAgB,QAAQ,CAAC,eAAe;AACtC,UAAM,WAAW,YAAY,WAAW,EAAE;AAC1C,IAAAA,YAAW,iBAAiB,QAAQ,OAAO,WAAW,IAAI,YAAY,WAAW,YAAY;AAAA;AAAA,EAC/F,CAAC;AAED,EAAAA,YAAW;AAGX,QAAM,yBAAiC,gBACpC,IAAI,CAAC,eAAe,QAAQ,WAAW,EAAE,MAAM,WAAW,IAAI,GAAG,EACjE,KAAK,IAAI;AAEZ,QAAM,gBAAgB,QACnB,IAAI,CAAC,WAAW;AACf,eAAW,OAAO,SAAS;AACzB,UAAI,QAAQ,GAA2B,MAAM,QAAQ;AACnD,eAAO,WAAW,GAAG;AAAA,MACvB;AAAA,IACF;AAAA,EACF,CAAC,EACA,KAAK,KAAK;AAEb,QAAM,mBACJ,eAAe,WACX,mFACA,eAAe,kBACb,8HACA;AAuBR,EAAAA,YAAW;AAAA;AACX,EAAAA,YAAW;AAAA,EAAmD,sBAAsB;AAAA;AAAA;AAAA;AACpF,EAAAA,YAAW,0BAA0B,aAAa;AAAA;AAClD,EAAAA,YAAW;AAAA;AACX,EAAAA,YAAW;AAAA;AAAA;AACX,EAAAA,YAAW,KAAK,gBAAgB;AAAA;AAChC,EAAAA,YAAW;AAEX,SAAOA;AACT;AAKO,MAAM,2BAA2B,MAAM;AAE5C,MAAI,CAAC,WAAW,qBAAqB,GAAG;AACtC,cAAU,uBAAuB,EAAE,WAAW,KAAK,CAAC;AAAA,EACtD;AAEA,QAAM,eAAyB,KAAK,GAAG,QAAQ,YAAY;AAG3D,QAAM,YAAY,yBAAyB,YAAY;AACvD,gBAAc,KAAK,uBAAuB,eAAe,GAAG,SAAS;AACvE;","names":["content"]}
1
+ {"version":3,"sources":["../../../../src/transpiler/dictionary_to_type/createModuleAugmentation.ts"],"sourcesContent":["import { existsSync, mkdirSync, writeFileSync } from 'fs';\nimport { basename, join, relative } from 'path';\nimport { Locales, getConfiguration } from '@intlayer/config';\nimport fg from 'fast-glob';\nimport { getFileHash, transformToCamelCase } from '../../utils';\n\nconst { content, internationalization } = getConfiguration();\nconst { typesDir, moduleAugmentationDir } = content;\nconst { locales, strictMode } = internationalization;\n\nexport const getTypeName = (id: string): string =>\n transformToCamelCase(`${id}Content`);\n\n/**\n * This function generates the content of the module augmentation file\n */\nconst generateTypeIndexContent = (typeFiles: string[]): string => {\n let content = \"/* eslint-disable */\\nimport { Locales } from 'intlayer';\\n\";\n\n const dictionariesRef = typeFiles.map((dictionaryPath) => ({\n relativePath: relative(moduleAugmentationDir, dictionaryPath),\n id: basename(dictionaryPath, '.d.ts'), // Get the base name as the dictionary id\n hash: `_${getFileHash(dictionaryPath)}`, // Get the hash of the dictionary to avoid conflicts\n }));\n\n // Import all dictionaries\n dictionariesRef.forEach((dictionary) => {\n const typeName = getTypeName(dictionary.id);\n content += `import type { ${typeName} as ${dictionary.hash} } from '${dictionary.relativePath}';\\n`;\n });\n\n content += '\\n';\n\n // Format Dictionary Map\n const formattedDictionaryMap: string = dictionariesRef\n .map((dictionary) => ` \"${dictionary.id}\": ${dictionary.hash};`)\n .join('\\n');\n\n const formatLocales = locales\n .map((locale) => {\n for (const key in Locales) {\n if (Locales[key as keyof typeof Locales] === locale) {\n return `Locales.${key}`;\n }\n }\n })\n .join(' | ');\n\n const strictModeRecord =\n strictMode === 'strict'\n ? `interface IConfigLocales<Content> extends Record<ExtractedLocales, Content> {}`\n : strictMode === 'required_only'\n ? `interface IConfigLocales<Content> extends Record<ExtractedLocales, Content>, Partial<Record<ExcludedLocales, Content>> {}`\n : `interface IConfigLocales<Content> extends Partial<Record<Locales, Content>> {}`;\n\n /**\n * Write the module augmentation to extend the intlayer module with the dictionaries types\n * Will suggest the type resulting of the dictionaries\n *\n * declare module 'intlayer' {\n * interface IntlayerDictionaryTypesConnector = {\n * dictionaries: {\n * id: DictionaryType;\n * }\n * }\n *\n * type ConfigLocales = Locales.ENGLISH | Locales.FRENCH | Locales.SPANISH;\n * type ExtractedLocales = Extract<Locales, ConfigLocales>;\n * type ExcludedLocales = Exclude<Locales, ConfigLocales>;\n *\n * interface IConfigLocales<Content> extends Record<ExtractedLocales, Content>, Partial<Record<ExcludedLocales, Content>> {}\n *\n *\n * }\n * See https://www.typescriptlang.org/docs/handbook/declaration-merging.html#module-augmentation\n */\n content += `declare module 'intlayer' {\\n`;\n content += ` interface IntlayerDictionaryTypesConnector {\\n${formattedDictionaryMap}\\n }\\n\\n`;\n content += ` type ConfigLocales = ${formatLocales};\\n`;\n content += ` type ExtractedLocales = Extract<Locales, ConfigLocales>;\\n`;\n content += ` type ExcludedLocales = Exclude<Locales, ConfigLocales>;\\n\\n`;\n content += ` ${strictModeRecord}\\n`;\n content += `}`;\n\n return content;\n};\n\n/**\n * This function generates a index file merging all the types\n */\nexport const createModuleAugmentation = () => {\n // Create main directory if it doesn't exist\n if (!existsSync(moduleAugmentationDir)) {\n mkdirSync(moduleAugmentationDir, { recursive: true });\n }\n\n const dictionaries: string[] = fg.sync(`${typesDir}/**/*.d.ts`);\n // Create the dictionary list file\n\n const tsContent = generateTypeIndexContent(dictionaries);\n writeFileSync(join(moduleAugmentationDir, 'intlayer.d.ts'), tsContent);\n};\n"],"mappings":"AAAA,SAAS,YAAY,WAAW,qBAAqB;AACrD,SAAS,UAAU,MAAM,gBAAgB;AACzC,SAAS,SAAS,wBAAwB;AAC1C,OAAO,QAAQ;AACf,SAAS,aAAa,4BAA4B;AAElD,MAAM,EAAE,SAAS,qBAAqB,IAAI,iBAAiB;AAC3D,MAAM,EAAE,UAAU,sBAAsB,IAAI;AAC5C,MAAM,EAAE,SAAS,WAAW,IAAI;AAEzB,MAAM,cAAc,CAAC,OAC1B,qBAAqB,GAAG,EAAE,SAAS;AAKrC,MAAM,2BAA2B,CAAC,cAAgC;AAChE,MAAIA,WAAU;AAEd,QAAM,kBAAkB,UAAU,IAAI,CAAC,oBAAoB;AAAA,IACzD,cAAc,SAAS,uBAAuB,cAAc;AAAA,IAC5D,IAAI,SAAS,gBAAgB,OAAO;AAAA;AAAA,IACpC,MAAM,IAAI,YAAY,cAAc,CAAC;AAAA;AAAA,EACvC,EAAE;AAGF,kBAAgB,QAAQ,CAAC,eAAe;AACtC,UAAM,WAAW,YAAY,WAAW,EAAE;AAC1C,IAAAA,YAAW,iBAAiB,QAAQ,OAAO,WAAW,IAAI,YAAY,WAAW,YAAY;AAAA;AAAA,EAC/F,CAAC;AAED,EAAAA,YAAW;AAGX,QAAM,yBAAiC,gBACpC,IAAI,CAAC,eAAe,QAAQ,WAAW,EAAE,MAAM,WAAW,IAAI,GAAG,EACjE,KAAK,IAAI;AAEZ,QAAM,gBAAgB,QACnB,IAAI,CAAC,WAAW;AACf,eAAW,OAAO,SAAS;AACzB,UAAI,QAAQ,GAA2B,MAAM,QAAQ;AACnD,eAAO,WAAW,GAAG;AAAA,MACvB;AAAA,IACF;AAAA,EACF,CAAC,EACA,KAAK,KAAK;AAEb,QAAM,mBACJ,eAAe,WACX,mFACA,eAAe,kBACb,8HACA;AAuBR,EAAAA,YAAW;AAAA;AACX,EAAAA,YAAW;AAAA,EAAmD,sBAAsB;AAAA;AAAA;AAAA;AACpF,EAAAA,YAAW,0BAA0B,aAAa;AAAA;AAClD,EAAAA,YAAW;AAAA;AACX,EAAAA,YAAW;AAAA;AAAA;AACX,EAAAA,YAAW,KAAK,gBAAgB;AAAA;AAChC,EAAAA,YAAW;AAEX,SAAOA;AACT;AAKO,MAAM,2BAA2B,MAAM;AAE5C,MAAI,CAAC,WAAW,qBAAqB,GAAG;AACtC,cAAU,uBAAuB,EAAE,WAAW,KAAK,CAAC;AAAA,EACtD;AAEA,QAAM,eAAyB,GAAG,KAAK,GAAG,QAAQ,YAAY;AAG9D,QAAM,YAAY,yBAAyB,YAAY;AACvD,gBAAc,KAAK,uBAAuB,eAAe,GAAG,SAAS;AACvE;","names":["content"]}
@@ -13,8 +13,10 @@ const transformToCamelCase = (string) => {
13
13
  });
14
14
  return camelCasedWords.join("");
15
15
  };
16
+ const sortAlphabetically = (a, b) => a.localeCompare(b);
16
17
  export {
17
18
  getFileHash,
19
+ sortAlphabetically,
18
20
  transformToCamelCase
19
21
  };
20
22
  //# sourceMappingURL=utils.mjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/utils.ts"],"sourcesContent":["import crypto from 'crypto-js';\n\nexport const getFileHash = (filePath: string) => {\n const hash = crypto.SHA3(filePath);\n\n return hash\n .toString(crypto.enc.Base64)\n .replace(/[^A-Z\\d]/gi, '')\n .substring(0, 20);\n};\n\nexport const transformToCamelCase = (string: string): string => {\n // Split the string into words using a regex that finds spaces, hyphens, and underscores\n const words = string.split(/[\\s\\-_]+/);\n\n // Transform each word except the first to have its first letter uppercase\n const camelCasedWords = words.map((word, index) => {\n if (index === 0) {\n return word[0].toUpperCase() + word.slice(1);\n }\n return word.charAt(0).toUpperCase() + word.slice(1);\n });\n\n // Join the words back together\n return camelCasedWords.join('');\n};\n"],"mappings":"AAAA,OAAO,YAAY;AAEZ,MAAM,cAAc,CAAC,aAAqB;AAC/C,QAAM,OAAO,OAAO,KAAK,QAAQ;AAEjC,SAAO,KACJ,SAAS,OAAO,IAAI,MAAM,EAC1B,QAAQ,cAAc,EAAE,EACxB,UAAU,GAAG,EAAE;AACpB;AAEO,MAAM,uBAAuB,CAAC,WAA2B;AAE9D,QAAM,QAAQ,OAAO,MAAM,UAAU;AAGrC,QAAM,kBAAkB,MAAM,IAAI,CAAC,MAAM,UAAU;AACjD,QAAI,UAAU,GAAG;AACf,aAAO,KAAK,CAAC,EAAE,YAAY,IAAI,KAAK,MAAM,CAAC;AAAA,IAC7C;AACA,WAAO,KAAK,OAAO,CAAC,EAAE,YAAY,IAAI,KAAK,MAAM,CAAC;AAAA,EACpD,CAAC;AAGD,SAAO,gBAAgB,KAAK,EAAE;AAChC;","names":[]}
1
+ {"version":3,"sources":["../../src/utils.ts"],"sourcesContent":["import crypto from 'crypto-js';\n\nexport const getFileHash = (filePath: string) => {\n const hash = crypto.SHA3(filePath);\n\n return hash\n .toString(crypto.enc.Base64)\n .replace(/[^A-Z\\d]/gi, '')\n .substring(0, 20);\n};\n\nexport const transformToCamelCase = (string: string): string => {\n // Split the string into words using a regex that finds spaces, hyphens, and underscores\n const words = string.split(/[\\s\\-_]+/);\n\n // Transform each word except the first to have its first letter uppercase\n const camelCasedWords = words.map((word, index) => {\n if (index === 0) {\n return word[0].toUpperCase() + word.slice(1);\n }\n return word.charAt(0).toUpperCase() + word.slice(1);\n });\n\n // Join the words back together\n return camelCasedWords.join('');\n};\n\nexport const sortAlphabetically = (a: string, b: string) => a.localeCompare(b);\n"],"mappings":"AAAA,OAAO,YAAY;AAEZ,MAAM,cAAc,CAAC,aAAqB;AAC/C,QAAM,OAAO,OAAO,KAAK,QAAQ;AAEjC,SAAO,KACJ,SAAS,OAAO,IAAI,MAAM,EAC1B,QAAQ,cAAc,EAAE,EACxB,UAAU,GAAG,EAAE;AACpB;AAEO,MAAM,uBAAuB,CAAC,WAA2B;AAE9D,QAAM,QAAQ,OAAO,MAAM,UAAU;AAGrC,QAAM,kBAAkB,MAAM,IAAI,CAAC,MAAM,UAAU;AACjD,QAAI,UAAU,GAAG;AACf,aAAO,KAAK,CAAC,EAAE,YAAY,IAAI,KAAK,MAAM,CAAC;AAAA,IAC7C;AACA,WAAO,KAAK,OAAO,CAAC,EAAE,YAAY,IAAI,KAAK,MAAM,CAAC;AAAA,EACpD,CAAC;AAGD,SAAO,gBAAgB,KAAK,EAAE;AAChC;AAEO,MAAM,qBAAqB,CAAC,GAAW,MAAc,EAAE,cAAc,CAAC;","names":[]}
@@ -1 +1 @@
1
- {"version":3,"file":"watcher.d.ts","sourceRoot":"","sources":["../../../src/chokidar/watcher.ts"],"names":[],"mappings":"AAEA,2FAA2F;AAC3F,OAAO,EAAE,KAAK,eAAe,EAA0B,MAAM,UAAU,CAAC;AAcxE,eAAO,MAAM,KAAK,aAAc,eAAe,QAiE9C,CAAC"}
1
+ {"version":3,"file":"watcher.d.ts","sourceRoot":"","sources":["../../../src/chokidar/watcher.ts"],"names":[],"mappings":"AAEA,2FAA2F;AAC3F,OAAO,EAAE,KAAK,eAAe,EAA0B,MAAM,UAAU,CAAC;AAexE,eAAO,MAAM,KAAK,aAAc,eAAe,QA2D9C,CAAC"}
@@ -0,0 +1,2 @@
1
+ export declare const cleanOutputDir: () => void;
2
+ //# sourceMappingURL=cleanOutputDir.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cleanOutputDir.d.ts","sourceRoot":"","sources":["../../src/cleanOutputDir.ts"],"names":[],"mappings":"AAGA,eAAO,MAAM,cAAc,YAY1B,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"fetchDistantDictionaryKeys.d.ts","sourceRoot":"","sources":["../../src/fetchDistantDictionaryKeys.ts"],"names":[],"mappings":"AAIA,eAAO,MAAM,0BAA0B,QAAa,OAAO,CAAC,MAAM,EAAE,CA6BnE,CAAC"}
1
+ {"version":3,"file":"fetchDistantDictionaryKeys.d.ts","sourceRoot":"","sources":["../../src/fetchDistantDictionaryKeys.ts"],"names":[],"mappings":"AAIA,eAAO,MAAM,0BAA0B,QAAa,OAAO,CAAC,MAAM,EAAE,CA8BnE,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"loadDictionaries.d.ts","sourceRoot":"","sources":["../../../src/loadDictionaries/loadDictionaries.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAU5C,eAAO,MAAM,gBAAgB,6BACD,MAAM,EAAE,GAAG,MAAM,KAC1C,OAAO,CAAC,UAAU,EAAE,CA8DtB,CAAC"}
1
+ {"version":3,"file":"loadDictionaries.d.ts","sourceRoot":"","sources":["../../../src/loadDictionaries/loadDictionaries.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAW5C,eAAO,MAAM,gBAAgB,6BACD,MAAM,EAAE,GAAG,MAAM,KAC1C,OAAO,CAAC,UAAU,EAAE,CA8DtB,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"log.d.ts","sourceRoot":"","sources":["../../src/log.ts"],"names":[],"mappings":"AAEA,MAAM,MAAM,KAAK,GAAG;IAClB,IAAI,EAAE,OAAO,GAAG,SAAS,CAAC;IAC1B,MAAM,EA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MAAM,EAAE,OAAO,CAAC,KAAK,CAAC;IA6CxB,OAAO,CAAC,aAAa;IAWrB,OAAO,CAAC,aAAa;IAqCrB,OAAO,CAAC,oBAAoB;IAerB,WAAW;CAGnB;AAED,eAAO,MAAM,MAAM,QAAuB,CAAC"}
@@ -1,3 +1,4 @@
1
1
  export declare const getFileHash: (filePath: string) => string;
2
2
  export declare const transformToCamelCase: (string: string) => string;
3
+ export declare const sortAlphabetically: (a: string, b: string) => number;
3
4
  //# sourceMappingURL=utils.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/utils.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,WAAW,aAAc,MAAM,WAO3C,CAAC;AAEF,eAAO,MAAM,oBAAoB,WAAY,MAAM,KAAG,MAcrD,CAAC"}
1
+ {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/utils.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,WAAW,aAAc,MAAM,WAO3C,CAAC;AAEF,eAAO,MAAM,oBAAoB,WAAY,MAAM,KAAG,MAcrD,CAAC;AAEF,eAAO,MAAM,kBAAkB,MAAO,MAAM,KAAK,MAAM,WAAuB,CAAC"}