@intlayer/chokidar 7.5.1 → 7.5.2-canary.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (86) hide show
  1. package/dist/cjs/buildIntlayerDictionary/buildIntlayerDictionary.cjs +1 -1
  2. package/dist/cjs/buildIntlayerDictionary/writeDynamicDictionary.cjs +1 -1
  3. package/dist/cjs/buildIntlayerDictionary/writeFetchDictionary.cjs +1 -1
  4. package/dist/cjs/buildIntlayerDictionary/writeMergedDictionary.cjs +1 -1
  5. package/dist/cjs/buildIntlayerDictionary/writeRemoteDictionary.cjs +2 -2
  6. package/dist/cjs/buildIntlayerDictionary/writeUnmergedDictionary.cjs +2 -2
  7. package/dist/cjs/cleanRemovedContentDeclaration.cjs +67 -0
  8. package/dist/cjs/cleanRemovedContentDeclaration.cjs.map +1 -0
  9. package/dist/cjs/createDictionaryEntryPoint/createDictionaryEntryPoint.cjs +1 -1
  10. package/dist/cjs/createDictionaryEntryPoint/generateDictionaryListContent.cjs +1 -1
  11. package/dist/cjs/createType/createModuleAugmentation.cjs +1 -1
  12. package/dist/cjs/createType/createType.cjs +1 -1
  13. package/dist/cjs/fetchDistantDictionaries.cjs +1 -1
  14. package/dist/cjs/handleAdditionalContentDeclarationFile.cjs +2 -2
  15. package/dist/cjs/handleContentDeclarationFileChange.cjs +8 -3
  16. package/dist/cjs/handleContentDeclarationFileChange.cjs.map +1 -1
  17. package/dist/cjs/handleUnlinkedContentDeclarationFile.cjs +8 -3
  18. package/dist/cjs/handleUnlinkedContentDeclarationFile.cjs.map +1 -1
  19. package/dist/cjs/index.cjs +5 -5
  20. package/dist/cjs/listGitFiles.cjs +1 -1
  21. package/dist/cjs/loadDictionaries/getIntlayerBundle.cjs +1 -1
  22. package/dist/cjs/loadDictionaries/loadContentDeclaration.cjs +1 -1
  23. package/dist/cjs/loadDictionaries/loadRemoteDictionaries.cjs +1 -1
  24. package/dist/cjs/prepareIntlayer.cjs +2 -2
  25. package/dist/cjs/transformFiles/transformFiles.cjs +1 -1
  26. package/dist/cjs/utils/formatter.cjs +1 -1
  27. package/dist/cjs/watcher.cjs +12 -3
  28. package/dist/cjs/watcher.cjs.map +1 -1
  29. package/dist/cjs/writeContentDeclaration/processContentDeclarationContent.cjs +1 -1
  30. package/dist/cjs/writeContentDeclaration/writeContentDeclaration.cjs +1 -1
  31. package/dist/cjs/writeContentDeclaration/writeContentDeclaration.cjs.map +1 -1
  32. package/dist/cjs/writeContentDeclaration/writeJSFile.cjs +7 -2
  33. package/dist/cjs/writeContentDeclaration/writeJSFile.cjs.map +1 -1
  34. package/dist/esm/buildIntlayerDictionary/buildIntlayerDictionary.mjs +1 -1
  35. package/dist/esm/buildIntlayerDictionary/writeDynamicDictionary.mjs +1 -1
  36. package/dist/esm/buildIntlayerDictionary/writeFetchDictionary.mjs +1 -1
  37. package/dist/esm/buildIntlayerDictionary/writeMergedDictionary.mjs +1 -1
  38. package/dist/esm/buildIntlayerDictionary/writeRemoteDictionary.mjs +2 -2
  39. package/dist/esm/buildIntlayerDictionary/writeUnmergedDictionary.mjs +2 -2
  40. package/dist/esm/cleanRemovedContentDeclaration.mjs +66 -0
  41. package/dist/esm/cleanRemovedContentDeclaration.mjs.map +1 -0
  42. package/dist/esm/createDictionaryEntryPoint/createDictionaryEntryPoint.mjs +1 -1
  43. package/dist/esm/createDictionaryEntryPoint/generateDictionaryListContent.mjs +1 -1
  44. package/dist/esm/createType/createModuleAugmentation.mjs +1 -1
  45. package/dist/esm/createType/createType.mjs +1 -1
  46. package/dist/esm/fetchDistantDictionaries.mjs +1 -1
  47. package/dist/esm/handleAdditionalContentDeclarationFile.mjs +2 -2
  48. package/dist/esm/handleContentDeclarationFileChange.mjs +8 -3
  49. package/dist/esm/handleContentDeclarationFileChange.mjs.map +1 -1
  50. package/dist/esm/handleUnlinkedContentDeclarationFile.mjs +8 -3
  51. package/dist/esm/handleUnlinkedContentDeclarationFile.mjs.map +1 -1
  52. package/dist/esm/index.mjs +5 -5
  53. package/dist/esm/listGitFiles.mjs +1 -1
  54. package/dist/esm/loadDictionaries/getIntlayerBundle.mjs +1 -1
  55. package/dist/esm/loadDictionaries/loadContentDeclaration.mjs +1 -1
  56. package/dist/esm/loadDictionaries/loadRemoteDictionaries.mjs +1 -1
  57. package/dist/esm/prepareIntlayer.mjs +2 -2
  58. package/dist/esm/transformFiles/transformFiles.mjs +1 -1
  59. package/dist/esm/utils/formatter.mjs +1 -1
  60. package/dist/esm/watcher.mjs +12 -3
  61. package/dist/esm/watcher.mjs.map +1 -1
  62. package/dist/esm/writeContentDeclaration/processContentDeclarationContent.mjs +1 -1
  63. package/dist/esm/writeContentDeclaration/writeContentDeclaration.mjs +1 -1
  64. package/dist/esm/writeContentDeclaration/writeContentDeclaration.mjs.map +1 -1
  65. package/dist/esm/writeContentDeclaration/writeJSFile.mjs +7 -2
  66. package/dist/esm/writeContentDeclaration/writeJSFile.mjs.map +1 -1
  67. package/dist/types/buildIntlayerDictionary/buildIntlayerDictionary.d.ts +2 -2
  68. package/dist/types/buildIntlayerDictionary/buildIntlayerDictionary.d.ts.map +1 -1
  69. package/dist/types/buildIntlayerDictionary/writeDynamicDictionary.d.ts +3 -3
  70. package/dist/types/buildIntlayerDictionary/writeDynamicDictionary.d.ts.map +1 -1
  71. package/dist/types/buildIntlayerDictionary/writeFetchDictionary.d.ts +3 -3
  72. package/dist/types/buildIntlayerDictionary/writeMergedDictionary.d.ts +2 -2
  73. package/dist/types/buildIntlayerDictionary/writeRemoteDictionary.d.ts +2 -2
  74. package/dist/types/buildIntlayerDictionary/writeRemoteDictionary.d.ts.map +1 -1
  75. package/dist/types/cleanRemovedContentDeclaration.d.ts +7 -0
  76. package/dist/types/cleanRemovedContentDeclaration.d.ts.map +1 -0
  77. package/dist/types/createDictionaryEntryPoint/createDictionaryEntryPoint.d.ts +2 -2
  78. package/dist/types/createDictionaryEntryPoint/generateDictionaryListContent.d.ts +2 -2
  79. package/dist/types/formatDictionary.d.ts +15 -15
  80. package/dist/types/handleContentDeclarationFileChange.d.ts.map +1 -1
  81. package/dist/types/handleUnlinkedContentDeclarationFile.d.ts.map +1 -1
  82. package/dist/types/loadDictionaries/loadRemoteDictionaries.d.ts +2 -2
  83. package/dist/types/loadDictionaries/loadRemoteDictionaries.d.ts.map +1 -1
  84. package/dist/types/utils/getFormatFromExtension.d.ts.map +1 -1
  85. package/dist/types/watcher.d.ts.map +1 -1
  86. package/package.json +10 -10
@@ -1 +1 @@
1
- {"version":3,"file":"writeJSFile.cjs","names":["getFormatFromExtension","getContentDeclarationFileTemplate","transformJSFile","detectFormatCommand"],"sources":["../../../src/writeContentDeclaration/writeJSFile.ts"],"sourcesContent":["import { execSync } from 'node:child_process';\nimport { existsSync } from 'node:fs';\nimport { readFile, writeFile } from 'node:fs/promises';\nimport { extname } from 'node:path';\nimport { getAppLogger, logger } from '@intlayer/config';\nimport type { Dictionary, IntlayerConfig } from '@intlayer/types';\nimport { getContentDeclarationFileTemplate } from '../getContentDeclarationFileTemplate/getContentDeclarationFileTemplate';\nimport {\n type Extension,\n getFormatFromExtension,\n} from '../utils/getFormatFromExtension';\nimport { detectFormatCommand } from './detectFormatCommand';\nimport { transformJSFile } from './transformJSFile';\n\n/**\n * Updates a JavaScript/TypeScript file based on the provided JSON instructions.\n * It targets a specific dictionary object within the file (identified by its 'key' property)\n * and updates its 'content' entries. Currently, it focuses on modifying arguments\n * of 't' (translation) function calls.\n */\nexport const writeJSFile = async (\n filePath: string,\n dictionary: Dictionary,\n configuration: IntlayerConfig\n): Promise<void> => {\n const mergedDictionary = {\n ...configuration.dictionary,\n ...dictionary,\n };\n\n const appLogger = getAppLogger(configuration);\n\n // Check if the file exist\n if (!existsSync(filePath)) {\n const fileExtension = extname(filePath) as Extension;\n\n const format = getFormatFromExtension(fileExtension);\n\n appLogger('File does not exist, creating it', {\n isVerbose: true,\n });\n const template = await getContentDeclarationFileTemplate(\n mergedDictionary.key,\n format,\n // Filter out undefined values\n Object.fromEntries(\n Object.entries({\n id: mergedDictionary.id,\n locale: mergedDictionary.locale,\n filled: mergedDictionary.filled,\n fill: mergedDictionary.fill,\n description: mergedDictionary.description,\n title: mergedDictionary.title,\n tags: mergedDictionary.tags,\n version: mergedDictionary.version,\n priority: mergedDictionary.priority,\n live: mergedDictionary.live,\n }).filter(([, value]) => value !== undefined)\n )\n );\n\n await writeFile(filePath, template, 'utf-8');\n }\n\n const fileContent = await readFile(filePath, 'utf-8');\n\n const finalCode = await transformJSFile(fileContent, dictionary);\n\n // Write the modified code back to the file\n try {\n await writeFile(filePath, finalCode, 'utf-8');\n logger(`Successfully updated ${filePath}`, {\n level: 'info',\n isVerbose: true,\n });\n } catch (error) {\n const err = error as Error;\n logger(`Failed to write updated file: ${filePath}`, {\n level: 'error',\n });\n throw new Error(`Failed to write updated file ${filePath}: ${err.message}`);\n }\n\n const formatCommand = detectFormatCommand(configuration);\n\n if (formatCommand) {\n try {\n execSync(formatCommand.replace('{{file}}', filePath), {\n stdio: 'inherit',\n cwd: configuration.content.baseDir,\n });\n } catch (error) {\n console.error(error);\n }\n }\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;AAoBA,MAAa,cAAc,OACzB,UACA,YACA,kBACkB;CAClB,MAAM,mBAAmB;EACvB,GAAG,cAAc;EACjB,GAAG;EACJ;CAED,MAAM,+CAAyB,cAAc;AAG7C,KAAI,yBAAY,SAAS,EAAE;EAGzB,MAAM,SAASA,mFAFe,SAAS,CAEa;AAEpD,YAAU,oCAAoC,EAC5C,WAAW,MACZ,CAAC;AAqBF,wCAAgB,UApBC,MAAMC,8GACrB,iBAAiB,KACjB,QAEA,OAAO,YACL,OAAO,QAAQ;GACb,IAAI,iBAAiB;GACrB,QAAQ,iBAAiB;GACzB,QAAQ,iBAAiB;GACzB,MAAM,iBAAiB;GACvB,aAAa,iBAAiB;GAC9B,OAAO,iBAAiB;GACxB,MAAM,iBAAiB;GACvB,SAAS,iBAAiB;GAC1B,UAAU,iBAAiB;GAC3B,MAAM,iBAAiB;GACxB,CAAC,CAAC,QAAQ,GAAG,WAAW,UAAU,OAAU,CAC9C,CACF,EAEmC,QAAQ;;CAK9C,MAAM,YAAY,MAAMC,gEAFJ,qCAAe,UAAU,QAAQ,EAEA,WAAW;AAGhE,KAAI;AACF,wCAAgB,UAAU,WAAW,QAAQ;AAC7C,+BAAO,wBAAwB,YAAY;GACzC,OAAO;GACP,WAAW;GACZ,CAAC;UACK,OAAO;EACd,MAAM,MAAM;AACZ,+BAAO,iCAAiC,YAAY,EAClD,OAAO,SACR,CAAC;AACF,QAAM,IAAI,MAAM,gCAAgC,SAAS,IAAI,IAAI,UAAU;;CAG7E,MAAM,gBAAgBC,wEAAoB,cAAc;AAExD,KAAI,cACF,KAAI;AACF,mCAAS,cAAc,QAAQ,YAAY,SAAS,EAAE;GACpD,OAAO;GACP,KAAK,cAAc,QAAQ;GAC5B,CAAC;UACK,OAAO;AACd,UAAQ,MAAM,MAAM"}
1
+ {"version":3,"file":"writeJSFile.cjs","names":["getFormatFromExtension","getContentDeclarationFileTemplate","transformJSFile","detectFormatCommand"],"sources":["../../../src/writeContentDeclaration/writeJSFile.ts"],"sourcesContent":["import { execSync } from 'node:child_process';\nimport { existsSync } from 'node:fs';\nimport { readFile, writeFile } from 'node:fs/promises';\nimport { extname } from 'node:path';\nimport { getAppLogger, logger } from '@intlayer/config';\nimport type { Dictionary, IntlayerConfig } from '@intlayer/types';\nimport { getContentDeclarationFileTemplate } from '../getContentDeclarationFileTemplate/getContentDeclarationFileTemplate';\nimport {\n type Extension,\n getFormatFromExtension,\n} from '../utils/getFormatFromExtension';\nimport { detectFormatCommand } from './detectFormatCommand';\nimport { transformJSFile } from './transformJSFile';\n\n/**\n * Updates a JavaScript/TypeScript file based on the provided JSON instructions.\n * It targets a specific dictionary object within the file (identified by its 'key' property)\n * and updates its 'content' entries. Currently, it focuses on modifying arguments\n * of 't' (translation) function calls.\n */\nexport const writeJSFile = async (\n filePath: string,\n dictionary: Dictionary,\n configuration: IntlayerConfig\n): Promise<void> => {\n const mergedDictionary = {\n ...configuration.dictionary,\n ...dictionary,\n };\n\n const appLogger = getAppLogger(configuration);\n\n // Check if the file exist\n if (!existsSync(filePath)) {\n const fileExtension = extname(filePath) as Extension;\n\n const format = getFormatFromExtension(fileExtension);\n\n appLogger('File does not exist, creating it', {\n isVerbose: true,\n });\n const template = await getContentDeclarationFileTemplate(\n mergedDictionary.key,\n format,\n // Filter out undefined values\n Object.fromEntries(\n Object.entries({\n id: mergedDictionary.id,\n locale: mergedDictionary.locale,\n filled: mergedDictionary.filled,\n fill: mergedDictionary.fill,\n description: mergedDictionary.description,\n title: mergedDictionary.title,\n tags: mergedDictionary.tags,\n version: mergedDictionary.version,\n priority: mergedDictionary.priority,\n live: mergedDictionary.live,\n }).filter(([, value]) => value !== undefined)\n )\n );\n\n await writeFile(filePath, template, 'utf-8');\n }\n\n let fileContent = await readFile(filePath, 'utf-8');\n\n if (fileContent === '') {\n const format = getFormatFromExtension(extname(filePath) as Extension);\n\n fileContent = await getContentDeclarationFileTemplate(\n mergedDictionary.key,\n format\n );\n }\n\n const finalCode = await transformJSFile(fileContent, dictionary);\n\n // Write the modified code back to the file\n try {\n await writeFile(filePath, finalCode, 'utf-8');\n logger(`Successfully updated ${filePath}`, {\n level: 'info',\n isVerbose: true,\n });\n } catch (error) {\n const err = error as Error;\n logger(`Failed to write updated file: ${filePath}`, {\n level: 'error',\n });\n throw new Error(`Failed to write updated file ${filePath}: ${err.message}`);\n }\n\n const formatCommand = detectFormatCommand(configuration);\n\n if (formatCommand) {\n try {\n execSync(formatCommand.replace('{{file}}', filePath), {\n stdio: 'inherit',\n cwd: configuration.content.baseDir,\n });\n } catch (error) {\n console.error(error);\n }\n }\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;AAoBA,MAAa,cAAc,OACzB,UACA,YACA,kBACkB;CAClB,MAAM,mBAAmB;EACvB,GAAG,cAAc;EACjB,GAAG;EACJ;CAED,MAAM,+CAAyB,cAAc;AAG7C,KAAI,yBAAY,SAAS,EAAE;EAGzB,MAAM,SAASA,mFAFe,SAAS,CAEa;AAEpD,YAAU,oCAAoC,EAC5C,WAAW,MACZ,CAAC;AAqBF,wCAAgB,UApBC,MAAMC,8GACrB,iBAAiB,KACjB,QAEA,OAAO,YACL,OAAO,QAAQ;GACb,IAAI,iBAAiB;GACrB,QAAQ,iBAAiB;GACzB,QAAQ,iBAAiB;GACzB,MAAM,iBAAiB;GACvB,aAAa,iBAAiB;GAC9B,OAAO,iBAAiB;GACxB,MAAM,iBAAiB;GACvB,SAAS,iBAAiB;GAC1B,UAAU,iBAAiB;GAC3B,MAAM,iBAAiB;GACxB,CAAC,CAAC,QAAQ,GAAG,WAAW,UAAU,OAAU,CAC9C,CACF,EAEmC,QAAQ;;CAG9C,IAAI,cAAc,qCAAe,UAAU,QAAQ;AAEnD,KAAI,gBAAgB,IAAI;EACtB,MAAM,SAASD,mFAA+B,SAAS,CAAc;AAErE,gBAAc,MAAMC,8GAClB,iBAAiB,KACjB,OACD;;CAGH,MAAM,YAAY,MAAMC,gEAAgB,aAAa,WAAW;AAGhE,KAAI;AACF,wCAAgB,UAAU,WAAW,QAAQ;AAC7C,+BAAO,wBAAwB,YAAY;GACzC,OAAO;GACP,WAAW;GACZ,CAAC;UACK,OAAO;EACd,MAAM,MAAM;AACZ,+BAAO,iCAAiC,YAAY,EAClD,OAAO,SACR,CAAC;AACF,QAAM,IAAI,MAAM,gCAAgC,SAAS,IAAI,IAAI,UAAU;;CAG7E,MAAM,gBAAgBC,wEAAoB,cAAc;AAExD,KAAI,cACF,KAAI;AACF,mCAAS,cAAc,QAAQ,YAAY,SAAS,EAAE;GACpD,OAAO;GACP,KAAK,cAAc,QAAQ;GAC5B,CAAC;UACK,OAAO;AACd,UAAQ,MAAM,MAAM"}
@@ -2,8 +2,8 @@ import { writeDynamicDictionary } from "./writeDynamicDictionary.mjs";
2
2
  import { writeFetchDictionary } from "./writeFetchDictionary.mjs";
3
3
  import { writeMergedDictionaries } from "./writeMergedDictionary.mjs";
4
4
  import { writeUnmergedDictionaries } from "./writeUnmergedDictionary.mjs";
5
- import { getConfiguration } from "@intlayer/config";
6
5
  import { getUnmergedDictionaries } from "@intlayer/unmerged-dictionaries-entry";
6
+ import { getConfiguration } from "@intlayer/config";
7
7
 
8
8
  //#region src/buildIntlayerDictionary/buildIntlayerDictionary.ts
9
9
  /**
@@ -2,8 +2,8 @@ import { parallelize } from "../utils/parallelize.mjs";
2
2
  import { writeFileIfChanged } from "../writeFileIfChanged.mjs";
3
3
  import { writeJsonIfChanged } from "../writeJsonIfChanged.mjs";
4
4
  import { mkdir } from "node:fs/promises";
5
- import { colorizePath, getConfiguration, normalizePath } from "@intlayer/config";
6
5
  import { relative, resolve } from "node:path";
6
+ import { colorizePath, getConfiguration, normalizePath } from "@intlayer/config";
7
7
  import { getPerLocaleDictionary } from "@intlayer/core";
8
8
 
9
9
  //#region src/buildIntlayerDictionary/writeDynamicDictionary.ts
@@ -1,8 +1,8 @@
1
1
  import { parallelize } from "../utils/parallelize.mjs";
2
2
  import { writeFileIfChanged } from "../writeFileIfChanged.mjs";
3
3
  import { mkdir } from "node:fs/promises";
4
- import { colorizePath, getConfiguration, normalizePath } from "@intlayer/config";
5
4
  import { relative, resolve } from "node:path";
5
+ import { colorizePath, getConfiguration, normalizePath } from "@intlayer/config";
6
6
 
7
7
  //#region src/buildIntlayerDictionary/writeFetchDictionary.ts
8
8
  /**
@@ -1,8 +1,8 @@
1
1
  import { parallelize } from "../utils/parallelize.mjs";
2
2
  import { writeJsonIfChanged } from "../writeJsonIfChanged.mjs";
3
3
  import { mkdir } from "node:fs/promises";
4
- import { colorizePath, getConfiguration } from "@intlayer/config";
5
4
  import { resolve } from "node:path";
5
+ import { colorizePath, getConfiguration } from "@intlayer/config";
6
6
  import { mergeDictionaries, normalizeDictionaries } from "@intlayer/core";
7
7
 
8
8
  //#region src/buildIntlayerDictionary/writeMergedDictionary.ts
@@ -1,11 +1,11 @@
1
1
  import { parallelize } from "../utils/parallelize.mjs";
2
- import { filterInvalidDictionaries } from "../filterInvalidDictionaries.mjs";
3
2
  import { writeJsonIfChanged } from "../writeJsonIfChanged.mjs";
3
+ import { filterInvalidDictionaries } from "../filterInvalidDictionaries.mjs";
4
4
  import { groupDictionariesByKey } from "./writeUnmergedDictionary.mjs";
5
5
  import { formatDistantDictionaries } from "../loadDictionaries/loadRemoteDictionaries.mjs";
6
6
  import { mkdir } from "node:fs/promises";
7
- import { colorizePath, getConfiguration, x } from "@intlayer/config";
8
7
  import { resolve } from "node:path";
8
+ import { colorizePath, getConfiguration, x } from "@intlayer/config";
9
9
  import { orderDictionaries } from "@intlayer/core";
10
10
 
11
11
  //#region src/buildIntlayerDictionary/writeRemoteDictionary.ts
@@ -1,9 +1,9 @@
1
1
  import { parallelize } from "../utils/parallelize.mjs";
2
- import { filterInvalidDictionaries } from "../filterInvalidDictionaries.mjs";
3
2
  import { writeJsonIfChanged } from "../writeJsonIfChanged.mjs";
3
+ import { filterInvalidDictionaries } from "../filterInvalidDictionaries.mjs";
4
4
  import { mkdir } from "node:fs/promises";
5
- import { colorizePath, x } from "@intlayer/config";
6
5
  import { resolve } from "node:path";
6
+ import { colorizePath, x } from "@intlayer/config";
7
7
  import { orderDictionaries } from "@intlayer/core";
8
8
 
9
9
  //#region src/buildIntlayerDictionary/writeUnmergedDictionary.ts
@@ -0,0 +1,66 @@
1
+ import { createDictionaryEntryPoint } from "./createDictionaryEntryPoint/createDictionaryEntryPoint.mjs";
2
+ import { createTypes } from "./createType/createType.mjs";
3
+ import { writeJsonIfChanged } from "./writeJsonIfChanged.mjs";
4
+ import { readFile, rm } from "node:fs/promises";
5
+ import { colorizeKey, getAppLogger } from "@intlayer/config/client";
6
+ import { join, normalize, relative } from "node:path";
7
+ import { getDictionaries } from "@intlayer/dictionaries-entry";
8
+ import { getUnmergedDictionaries } from "@intlayer/unmerged-dictionaries-entry";
9
+
10
+ //#region src/cleanRemovedContentDeclaration.ts
11
+ const cleanRemovedContentDeclaration = async (filePath, key, configuration) => {
12
+ const appLogger = getAppLogger(configuration);
13
+ const unmergedDictionaries = getUnmergedDictionaries(configuration);
14
+ const relativeFilePath = relative(configuration.content.baseDir, filePath);
15
+ const filteredUnmergedDictionaries = Object.values(unmergedDictionaries).flat().filter((dictionary) => dictionary.filePath === relativeFilePath && dictionary.key !== key);
16
+ const changedDictionariesLocalIds = [];
17
+ const removedDictionariesLocalIds = [];
18
+ const removedDictionariesKeys = [];
19
+ filteredUnmergedDictionaries.forEach(async (dictionary) => {
20
+ const unmergedFilePath = normalize(join(configuration.content.unmergedDictionariesDir, `${dictionary.key}.json`));
21
+ try {
22
+ const jsonContent = await readFile(unmergedFilePath, "utf8");
23
+ const parsedContent = JSON.parse(jsonContent);
24
+ if (parsedContent.length === 1) {
25
+ appLogger(`Removing outdated dictionary ${colorizeKey(dictionary.key)}`, { isVerbose: true });
26
+ await rm(unmergedFilePath);
27
+ removedDictionariesLocalIds.push(dictionary.localId);
28
+ } else {
29
+ await writeJsonIfChanged(unmergedFilePath, parsedContent.filter((content) => content.filePath !== relativeFilePath));
30
+ changedDictionariesLocalIds.push(dictionary.localId);
31
+ }
32
+ } catch {
33
+ appLogger(`Error while processing unmerged dictionary file ${colorizeKey(dictionary.key)}`, { isVerbose: true });
34
+ }
35
+ });
36
+ const dictionaries = getDictionaries(configuration);
37
+ const flatDictionaries = Object.values(dictionaries);
38
+ (flatDictionaries?.filter((dictionary) => dictionary.key !== key && dictionary.localIds?.length === 1 && dictionary.localIds[0].endsWith(`::local::${relativeFilePath}`))).forEach(async (dictionary) => {
39
+ const mergedFilePath = normalize(join(configuration.content.dictionariesDir, `${dictionary.key}.json`));
40
+ try {
41
+ const fileContent = await readFile(mergedFilePath, "utf8");
42
+ const parsedContent = JSON.parse(fileContent);
43
+ if (parsedContent.localIds?.length === 1) {
44
+ appLogger(`Removing outdated dictionary ${colorizeKey(dictionary.key)}`, { isVerbose: true });
45
+ rm(mergedFilePath);
46
+ rm(normalize(join(configuration.content.typesDir, `${dictionary.key}.ts`)));
47
+ removedDictionariesKeys.push(dictionary.key);
48
+ } else {
49
+ const localIds = parsedContent.localIds?.filter((localeId) => localeId !== relativeFilePath);
50
+ await writeJsonIfChanged(mergedFilePath, {
51
+ ...parsedContent,
52
+ localIds
53
+ });
54
+ }
55
+ } catch (error) {
56
+ appLogger([`Error while processing merged dictionary file ${colorizeKey(dictionary.key)}`, error], { isVerbose: true });
57
+ }
58
+ });
59
+ await createTypes(flatDictionaries.filter((dictionary) => !removedDictionariesKeys.includes(dictionary.key)).map((dictionary) => join(configuration.content.dictionariesDir, `${dictionary.key}.json`)), configuration);
60
+ await createDictionaryEntryPoint(configuration);
61
+ return changedDictionariesLocalIds;
62
+ };
63
+
64
+ //#endregion
65
+ export { cleanRemovedContentDeclaration };
66
+ //# sourceMappingURL=cleanRemovedContentDeclaration.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cleanRemovedContentDeclaration.mjs","names":["changedDictionariesLocalIds: string[]","removedDictionariesLocalIds: string[]","removedDictionariesKeys: string[]"],"sources":["../../src/cleanRemovedContentDeclaration.ts"],"sourcesContent":["import { readFile, rm } from 'node:fs/promises';\nimport { join, normalize, relative } from 'node:path';\nimport { colorizeKey, getAppLogger } from '@intlayer/config/client';\nimport { getDictionaries } from '@intlayer/dictionaries-entry';\nimport type { Dictionary, IntlayerConfig } from '@intlayer/types';\nimport { getUnmergedDictionaries } from '@intlayer/unmerged-dictionaries-entry';\nimport { createDictionaryEntryPoint } from './createDictionaryEntryPoint';\nimport { createTypes } from './createType';\nimport { writeJsonIfChanged } from './writeJsonIfChanged';\n\nexport const cleanRemovedContentDeclaration = async (\n filePath: string,\n key: string,\n configuration: IntlayerConfig\n): Promise<string[]> => {\n const appLogger = getAppLogger(configuration);\n\n const unmergedDictionaries = getUnmergedDictionaries(configuration);\n\n const relativeFilePath = relative(configuration.content.baseDir, filePath);\n const flatUnmergedDictionaries = Object.values(unmergedDictionaries).flat();\n\n const filteredUnmergedDictionaries = flatUnmergedDictionaries.filter(\n (dictionary) =>\n dictionary.filePath === relativeFilePath && dictionary.key !== key\n );\n\n const changedDictionariesLocalIds: string[] = [];\n const removedDictionariesLocalIds: string[] = [];\n const removedDictionariesKeys: string[] = [];\n\n filteredUnmergedDictionaries.forEach(async (dictionary) => {\n const unmergedFilePath = normalize(\n join(\n configuration.content.unmergedDictionariesDir,\n `${dictionary.key}.json`\n )\n );\n\n try {\n const jsonContent = await readFile(unmergedFilePath, 'utf8');\n const parsedContent = JSON.parse(jsonContent);\n\n if (parsedContent.length === 1) {\n appLogger(\n `Removing outdated dictionary ${colorizeKey(dictionary.key)}`,\n {\n isVerbose: true,\n }\n );\n\n await rm(unmergedFilePath);\n\n removedDictionariesLocalIds.push(dictionary.localId!);\n } else {\n const filteredContent = parsedContent.filter(\n (content: any) => content.filePath !== relativeFilePath\n );\n\n await writeJsonIfChanged(unmergedFilePath, filteredContent);\n\n changedDictionariesLocalIds.push(dictionary.localId!);\n }\n } catch {\n appLogger(\n `Error while processing unmerged dictionary file ${colorizeKey(dictionary.key)}`,\n {\n isVerbose: true,\n }\n );\n }\n });\n\n const dictionaries = getDictionaries(configuration);\n const flatDictionaries = Object.values(dictionaries);\n\n const filteredMergedDictionaries = flatDictionaries?.filter(\n (dictionary) =>\n dictionary.key !== key &&\n dictionary.localIds?.length === 1 &&\n (dictionary.localIds[0] as string).endsWith(\n `::local::${relativeFilePath}`\n )\n );\n\n filteredMergedDictionaries.forEach(async (dictionary) => {\n const mergedFilePath = normalize(\n join(configuration.content.dictionariesDir, `${dictionary.key}.json`)\n );\n\n try {\n const fileContent = await readFile(mergedFilePath, 'utf8');\n const parsedContent = JSON.parse(fileContent) as Dictionary;\n\n if (parsedContent.localIds?.length === 1) {\n appLogger(\n `Removing outdated dictionary ${colorizeKey(dictionary.key)}`,\n {\n isVerbose: true,\n }\n );\n\n rm(mergedFilePath);\n\n const typesFilePath = normalize(\n join(configuration.content.typesDir, `${dictionary.key}.ts`)\n );\n\n rm(typesFilePath);\n\n removedDictionariesKeys.push(dictionary.key);\n } else {\n const localIds = parsedContent.localIds?.filter(\n (localeId) => localeId !== relativeFilePath\n );\n\n const newContent = { ...parsedContent, localIds };\n\n await writeJsonIfChanged(mergedFilePath, newContent);\n }\n } catch (error) {\n appLogger(\n [\n `Error while processing merged dictionary file ${colorizeKey(dictionary.key)}`,\n error,\n ],\n {\n isVerbose: true,\n }\n );\n }\n });\n\n const dictionariesPaths = flatDictionaries\n .filter((dictionary) => !removedDictionariesKeys.includes(dictionary.key))\n .map((dictionary) =>\n join(configuration.content.dictionariesDir, `${dictionary.key}.json`)\n );\n\n await createTypes(dictionariesPaths, configuration);\n\n await createDictionaryEntryPoint(configuration);\n\n return changedDictionariesLocalIds;\n};\n"],"mappings":";;;;;;;;;;AAUA,MAAa,iCAAiC,OAC5C,UACA,KACA,kBACsB;CACtB,MAAM,YAAY,aAAa,cAAc;CAE7C,MAAM,uBAAuB,wBAAwB,cAAc;CAEnE,MAAM,mBAAmB,SAAS,cAAc,QAAQ,SAAS,SAAS;CAG1E,MAAM,+BAF2B,OAAO,OAAO,qBAAqB,CAAC,MAAM,CAEb,QAC3D,eACC,WAAW,aAAa,oBAAoB,WAAW,QAAQ,IAClE;CAED,MAAMA,8BAAwC,EAAE;CAChD,MAAMC,8BAAwC,EAAE;CAChD,MAAMC,0BAAoC,EAAE;AAE5C,8BAA6B,QAAQ,OAAO,eAAe;EACzD,MAAM,mBAAmB,UACvB,KACE,cAAc,QAAQ,yBACtB,GAAG,WAAW,IAAI,OACnB,CACF;AAED,MAAI;GACF,MAAM,cAAc,MAAM,SAAS,kBAAkB,OAAO;GAC5D,MAAM,gBAAgB,KAAK,MAAM,YAAY;AAE7C,OAAI,cAAc,WAAW,GAAG;AAC9B,cACE,gCAAgC,YAAY,WAAW,IAAI,IAC3D,EACE,WAAW,MACZ,CACF;AAED,UAAM,GAAG,iBAAiB;AAE1B,gCAA4B,KAAK,WAAW,QAAS;UAChD;AAKL,UAAM,mBAAmB,kBAJD,cAAc,QACnC,YAAiB,QAAQ,aAAa,iBACxC,CAE0D;AAE3D,gCAA4B,KAAK,WAAW,QAAS;;UAEjD;AACN,aACE,mDAAmD,YAAY,WAAW,IAAI,IAC9E,EACE,WAAW,MACZ,CACF;;GAEH;CAEF,MAAM,eAAe,gBAAgB,cAAc;CACnD,MAAM,mBAAmB,OAAO,OAAO,aAAa;AAWpD,EATmC,kBAAkB,QAClD,eACC,WAAW,QAAQ,OACnB,WAAW,UAAU,WAAW,KAC/B,WAAW,SAAS,GAAc,SACjC,YAAY,mBACb,CACJ,EAE0B,QAAQ,OAAO,eAAe;EACvD,MAAM,iBAAiB,UACrB,KAAK,cAAc,QAAQ,iBAAiB,GAAG,WAAW,IAAI,OAAO,CACtE;AAED,MAAI;GACF,MAAM,cAAc,MAAM,SAAS,gBAAgB,OAAO;GAC1D,MAAM,gBAAgB,KAAK,MAAM,YAAY;AAE7C,OAAI,cAAc,UAAU,WAAW,GAAG;AACxC,cACE,gCAAgC,YAAY,WAAW,IAAI,IAC3D,EACE,WAAW,MACZ,CACF;AAED,OAAG,eAAe;AAMlB,OAJsB,UACpB,KAAK,cAAc,QAAQ,UAAU,GAAG,WAAW,IAAI,KAAK,CAC7D,CAEgB;AAEjB,4BAAwB,KAAK,WAAW,IAAI;UACvC;IACL,MAAM,WAAW,cAAc,UAAU,QACtC,aAAa,aAAa,iBAC5B;AAID,UAAM,mBAAmB,gBAFN;KAAE,GAAG;KAAe;KAAU,CAEG;;WAE/C,OAAO;AACd,aACE,CACE,iDAAiD,YAAY,WAAW,IAAI,IAC5E,MACD,EACD,EACE,WAAW,MACZ,CACF;;GAEH;AAQF,OAAM,YANoB,iBACvB,QAAQ,eAAe,CAAC,wBAAwB,SAAS,WAAW,IAAI,CAAC,CACzE,KAAK,eACJ,KAAK,cAAc,QAAQ,iBAAiB,GAAG,WAAW,IAAI,OAAO,CACtE,EAEkC,cAAc;AAEnD,OAAM,2BAA2B,cAAc;AAE/C,QAAO"}
@@ -7,8 +7,8 @@ import { getBuiltFetchDictionariesPath } from "./getBuiltFetchDictionariesPath.m
7
7
  import { getBuiltRemoteDictionariesPath } from "./getBuiltRemoteDictionariesPath.mjs";
8
8
  import { getBuiltUnmergedDictionariesPath } from "./getBuiltUnmergedDictionariesPath.mjs";
9
9
  import { mkdir } from "node:fs/promises";
10
- import { getConfiguration } from "@intlayer/config";
11
10
  import { resolve } from "node:path";
11
+ import { getConfiguration } from "@intlayer/config";
12
12
 
13
13
  //#region src/createDictionaryEntryPoint/createDictionaryEntryPoint.ts
14
14
  const writeDictionaryFiles = async (paths, fileName, importType, functionName, format, configuration = getConfiguration()) => {
@@ -1,6 +1,6 @@
1
1
  import { getFileHash } from "../utils/getFileHash.mjs";
2
- import { getConfiguration, normalizePath } from "@intlayer/config";
3
2
  import { basename, extname, relative } from "node:path";
3
+ import { getConfiguration, normalizePath } from "@intlayer/config";
4
4
 
5
5
  //#region src/createDictionaryEntryPoint/generateDictionaryListContent.ts
6
6
  /**
@@ -1,8 +1,8 @@
1
1
  import { writeFileIfChanged } from "../writeFileIfChanged.mjs";
2
2
  import { getFileHash } from "../utils/getFileHash.mjs";
3
3
  import { mkdir } from "node:fs/promises";
4
- import { kebabCaseToCamelCase, normalizePath } from "@intlayer/config";
5
4
  import { basename, extname, join, relative } from "node:path";
5
+ import { kebabCaseToCamelCase, normalizePath } from "@intlayer/config";
6
6
  import fg from "fast-glob";
7
7
 
8
8
  //#region src/createType/createModuleAugmentation.ts
@@ -1,7 +1,7 @@
1
1
  import { parallelize } from "../utils/parallelize.mjs";
2
2
  import { mkdir, writeFile } from "node:fs/promises";
3
- import { clearModuleCache, getProjectRequire } from "@intlayer/config";
4
3
  import { resolve } from "node:path";
4
+ import { clearModuleCache, getProjectRequire } from "@intlayer/config";
5
5
 
6
6
  //#region src/createType/createType.ts
7
7
  const generateTypeScriptType = (dictionary) => {
@@ -1,6 +1,6 @@
1
1
  import { parallelize } from "./utils/parallelize.mjs";
2
- import { getIntlayerAPIProxy } from "@intlayer/api";
3
2
  import { getAppLogger, getConfiguration, x } from "@intlayer/config";
3
+ import { getIntlayerAPIProxy } from "@intlayer/api";
4
4
 
5
5
  //#region src/fetchDistantDictionaries.ts
6
6
  /**
@@ -1,8 +1,8 @@
1
- import { formatPath } from "./utils/formatter.mjs";
2
- import { buildDictionary } from "./buildIntlayerDictionary/buildIntlayerDictionary.mjs";
3
1
  import { createDictionaryEntryPoint } from "./createDictionaryEntryPoint/createDictionaryEntryPoint.mjs";
4
2
  import { createModuleAugmentation } from "./createType/createModuleAugmentation.mjs";
5
3
  import { createTypes } from "./createType/createType.mjs";
4
+ import { formatPath } from "./utils/formatter.mjs";
5
+ import { buildDictionary } from "./buildIntlayerDictionary/buildIntlayerDictionary.mjs";
6
6
  import { loadLocalDictionaries } from "./loadDictionaries/loadLocalDictionaries.mjs";
7
7
  import { getAppLogger } from "@intlayer/config";
8
8
 
@@ -1,9 +1,10 @@
1
- import { formatPath } from "./utils/formatter.mjs";
2
- import { buildDictionary } from "./buildIntlayerDictionary/buildIntlayerDictionary.mjs";
3
1
  import { getBuiltDictionariesPath } from "./createDictionaryEntryPoint/getBuiltDictionariesPath.mjs";
4
2
  import { createDictionaryEntryPoint } from "./createDictionaryEntryPoint/createDictionaryEntryPoint.mjs";
5
3
  import { createModuleAugmentation } from "./createType/createModuleAugmentation.mjs";
6
4
  import { createTypes } from "./createType/createType.mjs";
5
+ import { cleanRemovedContentDeclaration } from "./cleanRemovedContentDeclaration.mjs";
6
+ import { formatPath } from "./utils/formatter.mjs";
7
+ import { buildDictionary } from "./buildIntlayerDictionary/buildIntlayerDictionary.mjs";
7
8
  import { loadLocalDictionaries } from "./loadDictionaries/loadLocalDictionaries.mjs";
8
9
  import { getAppLogger } from "@intlayer/config";
9
10
 
@@ -11,7 +12,11 @@ import { getAppLogger } from "@intlayer/config";
11
12
  const handleContentDeclarationFileChange = async (filePath, config) => {
12
13
  const appLogger = getAppLogger(config);
13
14
  appLogger(`Change detected: ${formatPath(filePath)}`, { isVerbose: true });
14
- const dictionariesOutput = await buildDictionary(await loadLocalDictionaries(filePath, config), config);
15
+ const localeDictionaries = await loadLocalDictionaries(filePath, config);
16
+ localeDictionaries.forEach(async (dictionary) => {
17
+ await cleanRemovedContentDeclaration(filePath, dictionary.key, config);
18
+ });
19
+ const dictionariesOutput = await buildDictionary(localeDictionaries, config);
15
20
  const updatedDictionariesPaths = Object.values(dictionariesOutput?.mergedDictionaries ?? {}).map((dictionary) => dictionary.dictionaryPath);
16
21
  const allDictionariesPaths = await getBuiltDictionariesPath(config);
17
22
  createTypes(updatedDictionariesPaths, config);
@@ -1 +1 @@
1
- {"version":3,"file":"handleContentDeclarationFileChange.mjs","names":["allDictionariesPaths: string[]"],"sources":["../../src/handleContentDeclarationFileChange.ts"],"sourcesContent":["import { getAppLogger } from '@intlayer/config';\nimport type { IntlayerConfig } from '@intlayer/types';\nimport { buildDictionary } from './buildIntlayerDictionary/buildIntlayerDictionary';\nimport { createDictionaryEntryPoint } from './createDictionaryEntryPoint/createDictionaryEntryPoint';\nimport { getBuiltDictionariesPath } from './createDictionaryEntryPoint/getBuiltDictionariesPath';\nimport { createTypes } from './createType';\nimport { createModuleAugmentation } from './createType/createModuleAugmentation';\nimport { loadLocalDictionaries } from './loadDictionaries/loadLocalDictionaries';\nimport { formatPath } from './utils/formatter';\n\nexport const handleContentDeclarationFileChange = async (\n filePath: string,\n config: IntlayerConfig\n) => {\n const appLogger = getAppLogger(config);\n\n // Process the file with the functionToRun\n appLogger(`Change detected: ${formatPath(filePath)}`, {\n isVerbose: true,\n });\n\n const localeDictionaries = await loadLocalDictionaries(filePath, config);\n\n const dictionariesOutput = await buildDictionary(localeDictionaries, config);\n const updatedDictionariesPaths = Object.values(\n dictionariesOutput?.mergedDictionaries ?? {}\n ).map((dictionary) => dictionary.dictionaryPath);\n\n const allDictionariesPaths: string[] = await getBuiltDictionariesPath(config);\n\n createTypes(updatedDictionariesPaths, config);\n appLogger('TypeScript types built', {\n isVerbose: true,\n });\n\n if (\n updatedDictionariesPaths.some(\n (updatedDictionaryPath) =>\n !allDictionariesPaths.includes(updatedDictionaryPath)\n )\n ) {\n await createDictionaryEntryPoint(config);\n\n appLogger('Dictionary list built', {\n isVerbose: true,\n });\n }\n\n createModuleAugmentation(config);\n\n appLogger('Module augmentation built', {\n isVerbose: true,\n });\n\n // Plugin transformation\n // Allow plugins to post-process the final build output (e.g., write back ICU JSON)\n for await (const plugin of config.plugins ?? []) {\n const { unmergedDictionaries, mergedDictionaries } = dictionariesOutput;\n\n await plugin.afterBuild?.({\n dictionaries: {\n unmergedDictionaries,\n mergedDictionaries,\n },\n configuration: config,\n });\n }\n};\n"],"mappings":";;;;;;;;;;AAUA,MAAa,qCAAqC,OAChD,UACA,WACG;CACH,MAAM,YAAY,aAAa,OAAO;AAGtC,WAAU,oBAAoB,WAAW,SAAS,IAAI,EACpD,WAAW,MACZ,CAAC;CAIF,MAAM,qBAAqB,MAAM,gBAFN,MAAM,sBAAsB,UAAU,OAAO,EAEH,OAAO;CAC5E,MAAM,2BAA2B,OAAO,OACtC,oBAAoB,sBAAsB,EAAE,CAC7C,CAAC,KAAK,eAAe,WAAW,eAAe;CAEhD,MAAMA,uBAAiC,MAAM,yBAAyB,OAAO;AAE7E,aAAY,0BAA0B,OAAO;AAC7C,WAAU,0BAA0B,EAClC,WAAW,MACZ,CAAC;AAEF,KACE,yBAAyB,MACtB,0BACC,CAAC,qBAAqB,SAAS,sBAAsB,CACxD,EACD;AACA,QAAM,2BAA2B,OAAO;AAExC,YAAU,yBAAyB,EACjC,WAAW,MACZ,CAAC;;AAGJ,0BAAyB,OAAO;AAEhC,WAAU,6BAA6B,EACrC,WAAW,MACZ,CAAC;AAIF,YAAW,MAAM,UAAU,OAAO,WAAW,EAAE,EAAE;EAC/C,MAAM,EAAE,sBAAsB,uBAAuB;AAErD,QAAM,OAAO,aAAa;GACxB,cAAc;IACZ;IACA;IACD;GACD,eAAe;GAChB,CAAC"}
1
+ {"version":3,"file":"handleContentDeclarationFileChange.mjs","names":["allDictionariesPaths: string[]"],"sources":["../../src/handleContentDeclarationFileChange.ts"],"sourcesContent":["import { getAppLogger } from '@intlayer/config';\nimport type { IntlayerConfig } from '@intlayer/types';\nimport { buildDictionary } from './buildIntlayerDictionary/buildIntlayerDictionary';\nimport { cleanRemovedContentDeclaration } from './cleanRemovedContentDeclaration';\nimport { createDictionaryEntryPoint } from './createDictionaryEntryPoint/createDictionaryEntryPoint';\nimport { getBuiltDictionariesPath } from './createDictionaryEntryPoint/getBuiltDictionariesPath';\nimport { createTypes } from './createType';\nimport { createModuleAugmentation } from './createType/createModuleAugmentation';\nimport { loadLocalDictionaries } from './loadDictionaries/loadLocalDictionaries';\nimport { formatPath } from './utils/formatter';\n\nexport const handleContentDeclarationFileChange = async (\n filePath: string,\n config: IntlayerConfig\n) => {\n const appLogger = getAppLogger(config);\n\n // Process the file with the functionToRun\n appLogger(`Change detected: ${formatPath(filePath)}`, {\n isVerbose: true,\n });\n\n const localeDictionaries = await loadLocalDictionaries(filePath, config);\n\n localeDictionaries.forEach(async (dictionary) => {\n await cleanRemovedContentDeclaration(filePath, dictionary.key, config);\n });\n\n const dictionariesOutput = await buildDictionary(localeDictionaries, config);\n const updatedDictionariesPaths = Object.values(\n dictionariesOutput?.mergedDictionaries ?? {}\n ).map((dictionary) => dictionary.dictionaryPath);\n\n const allDictionariesPaths: string[] = await getBuiltDictionariesPath(config);\n\n createTypes(updatedDictionariesPaths, config);\n appLogger('TypeScript types built', {\n isVerbose: true,\n });\n\n if (\n updatedDictionariesPaths.some(\n (updatedDictionaryPath) =>\n !allDictionariesPaths.includes(updatedDictionaryPath)\n )\n ) {\n await createDictionaryEntryPoint(config);\n\n appLogger('Dictionary list built', {\n isVerbose: true,\n });\n }\n\n createModuleAugmentation(config);\n\n appLogger('Module augmentation built', {\n isVerbose: true,\n });\n\n // Plugin transformation\n // Allow plugins to post-process the final build output (e.g., write back ICU JSON)\n for await (const plugin of config.plugins ?? []) {\n const { unmergedDictionaries, mergedDictionaries } = dictionariesOutput;\n\n await plugin.afterBuild?.({\n dictionaries: {\n unmergedDictionaries,\n mergedDictionaries,\n },\n configuration: config,\n });\n }\n};\n"],"mappings":";;;;;;;;;;;AAWA,MAAa,qCAAqC,OAChD,UACA,WACG;CACH,MAAM,YAAY,aAAa,OAAO;AAGtC,WAAU,oBAAoB,WAAW,SAAS,IAAI,EACpD,WAAW,MACZ,CAAC;CAEF,MAAM,qBAAqB,MAAM,sBAAsB,UAAU,OAAO;AAExE,oBAAmB,QAAQ,OAAO,eAAe;AAC/C,QAAM,+BAA+B,UAAU,WAAW,KAAK,OAAO;GACtE;CAEF,MAAM,qBAAqB,MAAM,gBAAgB,oBAAoB,OAAO;CAC5E,MAAM,2BAA2B,OAAO,OACtC,oBAAoB,sBAAsB,EAAE,CAC7C,CAAC,KAAK,eAAe,WAAW,eAAe;CAEhD,MAAMA,uBAAiC,MAAM,yBAAyB,OAAO;AAE7E,aAAY,0BAA0B,OAAO;AAC7C,WAAU,0BAA0B,EAClC,WAAW,MACZ,CAAC;AAEF,KACE,yBAAyB,MACtB,0BACC,CAAC,qBAAqB,SAAS,sBAAsB,CACxD,EACD;AACA,QAAM,2BAA2B,OAAO;AAExC,YAAU,yBAAyB,EACjC,WAAW,MACZ,CAAC;;AAGJ,0BAAyB,OAAO;AAEhC,WAAU,6BAA6B,EACrC,WAAW,MACZ,CAAC;AAIF,YAAW,MAAM,UAAU,OAAO,WAAW,EAAE,EAAE;EAC/C,MAAM,EAAE,sBAAsB,uBAAuB;AAErD,QAAM,OAAO,aAAa;GACxB,cAAc;IACZ;IACA;IACD;GACD,eAAe;GAChB,CAAC"}
@@ -1,8 +1,9 @@
1
- import { formatPath } from "./utils/formatter.mjs";
2
- import { buildDictionary } from "./buildIntlayerDictionary/buildIntlayerDictionary.mjs";
3
1
  import { createDictionaryEntryPoint } from "./createDictionaryEntryPoint/createDictionaryEntryPoint.mjs";
4
2
  import { createModuleAugmentation } from "./createType/createModuleAugmentation.mjs";
5
3
  import { createTypes } from "./createType/createType.mjs";
4
+ import { cleanRemovedContentDeclaration } from "./cleanRemovedContentDeclaration.mjs";
5
+ import { formatPath } from "./utils/formatter.mjs";
6
+ import { buildDictionary } from "./buildIntlayerDictionary/buildIntlayerDictionary.mjs";
6
7
  import { loadLocalDictionaries } from "./loadDictionaries/loadLocalDictionaries.mjs";
7
8
  import { listDictionaries } from "./listDictionariesPath.mjs";
8
9
  import { getAppLogger } from "@intlayer/config";
@@ -11,7 +12,11 @@ import { getAppLogger } from "@intlayer/config";
11
12
  const handleUnlinkedContentDeclarationFile = async (filePath, config) => {
12
13
  const appLogger = getAppLogger(config);
13
14
  appLogger(`Unlinked detected: ${formatPath(filePath)}`, { isVerbose: true });
14
- const dictionariesOutput = await buildDictionary(await loadLocalDictionaries(await listDictionaries(config), config), config);
15
+ const localeDictionaries = await loadLocalDictionaries(await listDictionaries(config), config);
16
+ localeDictionaries.forEach(async (dictionary) => {
17
+ await cleanRemovedContentDeclaration(filePath, dictionary.key, config);
18
+ });
19
+ const dictionariesOutput = await buildDictionary(localeDictionaries, config);
15
20
  await createTypes(Object.values(dictionariesOutput?.mergedDictionaries ?? {}).map((dictionary) => dictionary.dictionaryPath), config);
16
21
  await createDictionaryEntryPoint();
17
22
  appLogger("Dictionaries rebuilt", { isVerbose: true });
@@ -1 +1 @@
1
- {"version":3,"file":"handleUnlinkedContentDeclarationFile.mjs","names":[],"sources":["../../src/handleUnlinkedContentDeclarationFile.ts"],"sourcesContent":["import { getAppLogger } from '@intlayer/config';\nimport type { IntlayerConfig } from '@intlayer/types';\nimport { buildDictionary } from './buildIntlayerDictionary/buildIntlayerDictionary';\nimport { createDictionaryEntryPoint } from './createDictionaryEntryPoint/createDictionaryEntryPoint';\nimport { createTypes } from './createType';\nimport { createModuleAugmentation } from './createType/createModuleAugmentation';\nimport { listDictionaries } from './listDictionariesPath';\nimport { loadLocalDictionaries } from './loadDictionaries/loadLocalDictionaries';\nimport { formatPath } from './utils/formatter';\n\nexport const handleUnlinkedContentDeclarationFile = async (\n filePath: string,\n config: IntlayerConfig\n) => {\n const appLogger = getAppLogger(config);\n\n // Process the file with the functionToRun\n appLogger(`Unlinked detected: ${formatPath(filePath)}`, {\n isVerbose: true,\n });\n\n const files: string[] = await listDictionaries(config);\n\n const localeDictionaries = await loadLocalDictionaries(files, config);\n\n const dictionariesOutput = await buildDictionary(localeDictionaries, config);\n\n const dictionariesPaths = Object.values(\n dictionariesOutput?.mergedDictionaries ?? {}\n ).map((dictionary) => dictionary.dictionaryPath);\n\n await createTypes(dictionariesPaths, config);\n\n await createDictionaryEntryPoint();\n\n appLogger('Dictionaries rebuilt', {\n isVerbose: true,\n });\n\n await createModuleAugmentation(config);\n\n appLogger('Module augmentation built', {\n isVerbose: true,\n });\n\n // Plugin transformation\n // Allow plugins to post-process the final build output (e.g., write back ICU JSON)\n for await (const plugin of config.plugins ?? []) {\n const { unmergedDictionaries, mergedDictionaries } = dictionariesOutput;\n\n await plugin.afterBuild?.({\n dictionaries: {\n unmergedDictionaries,\n mergedDictionaries,\n },\n configuration: config,\n });\n }\n};\n"],"mappings":";;;;;;;;;;AAUA,MAAa,uCAAuC,OAClD,UACA,WACG;CACH,MAAM,YAAY,aAAa,OAAO;AAGtC,WAAU,sBAAsB,WAAW,SAAS,IAAI,EACtD,WAAW,MACZ,CAAC;CAMF,MAAM,qBAAqB,MAAM,gBAFN,MAAM,sBAFT,MAAM,iBAAiB,OAAO,EAEQ,OAAO,EAEA,OAAO;AAM5E,OAAM,YAJoB,OAAO,OAC/B,oBAAoB,sBAAsB,EAAE,CAC7C,CAAC,KAAK,eAAe,WAAW,eAAe,EAEX,OAAO;AAE5C,OAAM,4BAA4B;AAElC,WAAU,wBAAwB,EAChC,WAAW,MACZ,CAAC;AAEF,OAAM,yBAAyB,OAAO;AAEtC,WAAU,6BAA6B,EACrC,WAAW,MACZ,CAAC;AAIF,YAAW,MAAM,UAAU,OAAO,WAAW,EAAE,EAAE;EAC/C,MAAM,EAAE,sBAAsB,uBAAuB;AAErD,QAAM,OAAO,aAAa;GACxB,cAAc;IACZ;IACA;IACD;GACD,eAAe;GAChB,CAAC"}
1
+ {"version":3,"file":"handleUnlinkedContentDeclarationFile.mjs","names":[],"sources":["../../src/handleUnlinkedContentDeclarationFile.ts"],"sourcesContent":["import { getAppLogger } from '@intlayer/config';\nimport type { IntlayerConfig } from '@intlayer/types';\nimport { buildDictionary } from './buildIntlayerDictionary/buildIntlayerDictionary';\nimport { cleanRemovedContentDeclaration } from './cleanRemovedContentDeclaration';\nimport { createDictionaryEntryPoint } from './createDictionaryEntryPoint/createDictionaryEntryPoint';\nimport { createTypes } from './createType';\nimport { createModuleAugmentation } from './createType/createModuleAugmentation';\nimport { listDictionaries } from './listDictionariesPath';\nimport { loadLocalDictionaries } from './loadDictionaries/loadLocalDictionaries';\nimport { formatPath } from './utils/formatter';\n\nexport const handleUnlinkedContentDeclarationFile = async (\n filePath: string,\n config: IntlayerConfig\n) => {\n const appLogger = getAppLogger(config);\n\n // Process the file with the functionToRun\n appLogger(`Unlinked detected: ${formatPath(filePath)}`, {\n isVerbose: true,\n });\n\n const files: string[] = await listDictionaries(config);\n\n const localeDictionaries = await loadLocalDictionaries(files, config);\n\n localeDictionaries.forEach(async (dictionary) => {\n await cleanRemovedContentDeclaration(filePath, dictionary.key, config);\n });\n\n const dictionariesOutput = await buildDictionary(localeDictionaries, config);\n\n const dictionariesPaths = Object.values(\n dictionariesOutput?.mergedDictionaries ?? {}\n ).map((dictionary) => dictionary.dictionaryPath);\n\n await createTypes(dictionariesPaths, config);\n\n await createDictionaryEntryPoint();\n\n appLogger('Dictionaries rebuilt', {\n isVerbose: true,\n });\n\n await createModuleAugmentation(config);\n\n appLogger('Module augmentation built', {\n isVerbose: true,\n });\n\n // Plugin transformation\n // Allow plugins to post-process the final build output (e.g., write back ICU JSON)\n for await (const plugin of config.plugins ?? []) {\n const { unmergedDictionaries, mergedDictionaries } = dictionariesOutput;\n\n await plugin.afterBuild?.({\n dictionaries: {\n unmergedDictionaries,\n mergedDictionaries,\n },\n configuration: config,\n });\n }\n};\n"],"mappings":";;;;;;;;;;;AAWA,MAAa,uCAAuC,OAClD,UACA,WACG;CACH,MAAM,YAAY,aAAa,OAAO;AAGtC,WAAU,sBAAsB,WAAW,SAAS,IAAI,EACtD,WAAW,MACZ,CAAC;CAIF,MAAM,qBAAqB,MAAM,sBAFT,MAAM,iBAAiB,OAAO,EAEQ,OAAO;AAErE,oBAAmB,QAAQ,OAAO,eAAe;AAC/C,QAAM,+BAA+B,UAAU,WAAW,KAAK,OAAO;GACtE;CAEF,MAAM,qBAAqB,MAAM,gBAAgB,oBAAoB,OAAO;AAM5E,OAAM,YAJoB,OAAO,OAC/B,oBAAoB,sBAAsB,EAAE,CAC7C,CAAC,KAAK,eAAe,WAAW,eAAe,EAEX,OAAO;AAE5C,OAAM,4BAA4B;AAElC,WAAU,wBAAwB,EAChC,WAAW,MACZ,CAAC;AAEF,OAAM,yBAAyB,OAAO;AAEtC,WAAU,6BAA6B,EACrC,WAAW,MACZ,CAAC;AAIF,YAAW,MAAM,UAAU,OAAO,WAAW,EAAE,EAAE;EAC/C,MAAM,EAAE,sBAAsB,uBAAuB;AAErD,QAAM,OAAO,aAAa;GACxB,cAAc;IACZ;IACA;IACD;GACD,eAAe;GAChB,CAAC"}
@@ -1,11 +1,6 @@
1
1
  import { cleanOutputDir } from "./cleanOutputDir.mjs";
2
2
  import { pLimit } from "./utils/pLimit.mjs";
3
3
  import { parallelize } from "./utils/parallelize.mjs";
4
- import { fetchDistantDictionaries } from "./fetchDistantDictionaries.mjs";
5
- import { formatLocale, formatPath } from "./utils/formatter.mjs";
6
- import { isInvalidDictionary } from "./filterInvalidDictionaries.mjs";
7
- import { formatDictionaries, formatDictionariesOutput, formatDictionary, formatDictionaryOutput } from "./formatDictionary.mjs";
8
- import { buildDictionary } from "./buildIntlayerDictionary/buildIntlayerDictionary.mjs";
9
4
  import { getFileHash } from "./utils/getFileHash.mjs";
10
5
  import { generateDictionaryListContent } from "./createDictionaryEntryPoint/generateDictionaryListContent.mjs";
11
6
  import { getBuiltDictionariesPath } from "./createDictionaryEntryPoint/getBuiltDictionariesPath.mjs";
@@ -16,6 +11,11 @@ import { getBuiltUnmergedDictionariesPath } from "./createDictionaryEntryPoint/g
16
11
  import { createDictionaryEntryPoint } from "./createDictionaryEntryPoint/createDictionaryEntryPoint.mjs";
17
12
  import { createModuleAugmentation } from "./createType/createModuleAugmentation.mjs";
18
13
  import { createTypes } from "./createType/createType.mjs";
14
+ import { fetchDistantDictionaries } from "./fetchDistantDictionaries.mjs";
15
+ import { formatLocale, formatPath } from "./utils/formatter.mjs";
16
+ import { isInvalidDictionary } from "./filterInvalidDictionaries.mjs";
17
+ import { formatDictionaries, formatDictionariesOutput, formatDictionary, formatDictionaryOutput } from "./formatDictionary.mjs";
18
+ import { buildDictionary } from "./buildIntlayerDictionary/buildIntlayerDictionary.mjs";
19
19
  import { resolveObjectPromises } from "./utils/resolveObjectPromises.mjs";
20
20
  import { loadContentDeclarations } from "./loadDictionaries/loadContentDeclaration.mjs";
21
21
  import { loadLocalDictionaries } from "./loadDictionaries/loadLocalDictionaries.mjs";
@@ -1,6 +1,6 @@
1
1
  import { readFileSync } from "node:fs";
2
- import { getAppLogger } from "@intlayer/config";
3
2
  import { join } from "node:path";
3
+ import { getAppLogger } from "@intlayer/config";
4
4
  import configuration from "@intlayer/config/built";
5
5
  import simpleGit from "simple-git";
6
6
 
@@ -1,7 +1,7 @@
1
1
  import { __require } from "../_virtual/rolldown_runtime.mjs";
2
2
  import { readFile } from "node:fs/promises";
3
- import { bundleFile, configESMxCJSRequire, getProjectRequire, isESModule } from "@intlayer/config";
4
3
  import { join } from "node:path";
4
+ import { bundleFile, configESMxCJSRequire, getProjectRequire, isESModule } from "@intlayer/config";
5
5
  import { builtinModules, createRequire } from "node:module";
6
6
 
7
7
  //#region src/loadDictionaries/getIntlayerBundle.ts
@@ -3,8 +3,8 @@ import { filterInvalidDictionaries, isInvalidDictionary } from "../filterInvalid
3
3
  import { processContentDeclaration } from "../buildIntlayerDictionary/processContentDeclaration.mjs";
4
4
  import { getIntlayerBundle } from "./getIntlayerBundle.mjs";
5
5
  import { writeFile } from "node:fs/promises";
6
- import { cacheDisk, getProjectRequire, loadExternalFile } from "@intlayer/config";
7
6
  import { join, relative } from "node:path";
7
+ import { cacheDisk, getProjectRequire, loadExternalFile } from "@intlayer/config";
8
8
 
9
9
  //#region src/loadDictionaries/loadContentDeclaration.ts
10
10
  const formatLocalDictionaries = (dictionariesRecord, configuration) => Object.entries(dictionariesRecord).filter(([_relativePath, dict]) => isInvalidDictionary(dict, configuration)).map(([relativePath, dict]) => ({
@@ -1,7 +1,7 @@
1
1
  import { fetchDistantDictionaries } from "../fetchDistantDictionaries.mjs";
2
2
  import { sortAlphabetically } from "../utils/sortAlphabetically.mjs";
3
- import { getIntlayerAPIProxy } from "@intlayer/api";
4
3
  import { getConfiguration } from "@intlayer/config";
4
+ import { getIntlayerAPIProxy } from "@intlayer/api";
5
5
  import { getRemoteDictionaries } from "@intlayer/remote-dictionaries-entry";
6
6
 
7
7
  //#region src/loadDictionaries/loadRemoteDictionaries.ts
@@ -1,16 +1,16 @@
1
1
  import { cleanOutputDir } from "./cleanOutputDir.mjs";
2
- import { buildDictionary } from "./buildIntlayerDictionary/buildIntlayerDictionary.mjs";
3
2
  import { createDictionaryEntryPoint } from "./createDictionaryEntryPoint/createDictionaryEntryPoint.mjs";
4
3
  import { createModuleAugmentation } from "./createType/createModuleAugmentation.mjs";
5
4
  import { createTypes } from "./createType/createType.mjs";
5
+ import { buildDictionary } from "./buildIntlayerDictionary/buildIntlayerDictionary.mjs";
6
6
  import { listDictionariesWithStats } from "./listDictionariesPath.mjs";
7
7
  import { loadDictionaries } from "./loadDictionaries/loadDictionaries.mjs";
8
8
  import { writeRemoteDictionary } from "./buildIntlayerDictionary/writeRemoteDictionary.mjs";
9
9
  import { runOnce } from "./utils/runOnce.mjs";
10
10
  import { isCachedConfigurationUpToDate, writeConfiguration } from "./writeConfiguration/index.mjs";
11
11
  import { stat } from "node:fs/promises";
12
- import { ANSIColors, cacheDisk, colorize, getAppLogger } from "@intlayer/config";
13
12
  import { join } from "node:path";
13
+ import { ANSIColors, cacheDisk, colorize, getAppLogger } from "@intlayer/config";
14
14
  import packageJson from "@intlayer/config/package.json" with { type: "json" };
15
15
 
16
16
  //#region src/prepareIntlayer.ts
@@ -2,8 +2,8 @@ import { extractDictionaryKey } from "./extractDictionaryKey.mjs";
2
2
  import { detectFormatCommand } from "../writeContentDeclaration/detectFormatCommand.mjs";
3
3
  import { writeContentDeclaration } from "../writeContentDeclaration/writeContentDeclaration.mjs";
4
4
  import fs from "node:fs/promises";
5
- import { ANSIColors, camelCaseToKebabCase, colorizePath, getAppLogger, getConfiguration } from "@intlayer/config";
6
5
  import { basename, dirname, extname, join, relative, resolve } from "node:path";
6
+ import { ANSIColors, camelCaseToKebabCase, colorizePath, getAppLogger, getConfiguration } from "@intlayer/config";
7
7
  import { execSync } from "node:child_process";
8
8
  import { Node, Project, SyntaxKind } from "ts-morph";
9
9
 
@@ -1,5 +1,5 @@
1
- import { ANSIColors, colorize, colorizePath } from "@intlayer/config";
2
1
  import { relative } from "node:path";
2
+ import { ANSIColors, colorize, colorizePath } from "@intlayer/config";
3
3
  import configuration from "@intlayer/config/built";
4
4
  import { getLocaleName } from "@intlayer/core";
5
5
  import { Locales } from "@intlayer/types";
@@ -2,8 +2,10 @@ import { handleAdditionalContentDeclarationFile } from "./handleAdditionalConten
2
2
  import { handleContentDeclarationFileChange } from "./handleContentDeclarationFileChange.mjs";
3
3
  import { handleUnlinkedContentDeclarationFile } from "./handleUnlinkedContentDeclarationFile.mjs";
4
4
  import { prepareIntlayer } from "./prepareIntlayer.mjs";
5
- import { getAppLogger, getConfiguration } from "@intlayer/config";
5
+ import { writeContentDeclaration } from "./writeContentDeclaration/writeContentDeclaration.mjs";
6
+ import { readFile } from "node:fs/promises";
6
7
  import { basename } from "node:path";
8
+ import { getAppLogger, getConfiguration } from "@intlayer/config";
7
9
  import { watch as watch$1 } from "chokidar";
8
10
 
9
11
  //#region src/watcher.ts
@@ -12,8 +14,7 @@ const recentlyAddedFiles = /* @__PURE__ */ new Set();
12
14
  const watch = (options) => {
13
15
  const configuration = options?.configuration ?? getConfiguration(options?.configOptions);
14
16
  const appLogger = getAppLogger(configuration);
15
- const { watch: isWatchMode, watchedFilesPatternWithPath } = configuration.content;
16
- /** @ts-ignore remove error Expected 0-1 arguments, but got 2. */
17
+ const { watch: isWatchMode, watchedFilesPatternWithPath, fileExtensions } = configuration.content;
17
18
  return watch$1(watchedFilesPatternWithPath, {
18
19
  persistent: isWatchMode,
19
20
  ignoreInitial: true,
@@ -31,6 +32,14 @@ const watch = (options) => {
31
32
  }).on("add", async (filePath) => {
32
33
  const fileName = basename(filePath);
33
34
  recentlyAddedFiles.add(fileName);
35
+ if (await readFile(filePath, "utf-8") === "") {
36
+ const extensionPattern = fileExtensions.map((ext) => ext.replace(/\./g, "\\.")).join("|");
37
+ await writeContentDeclaration({
38
+ key: fileName.replace(/* @__PURE__ */ new RegExp(`(${extensionPattern})$`), ""),
39
+ content: {},
40
+ filePath
41
+ }, configuration);
42
+ }
34
43
  await handleAdditionalContentDeclarationFile(filePath, configuration);
35
44
  setTimeout(() => recentlyAddedFiles.delete(fileName), 1e3);
36
45
  }).on("change", async (filePath) => await handleContentDeclarationFileChange(filePath, configuration)).on("unlink", async (filePath) => {
@@ -1 +1 @@
1
- {"version":3,"file":"watcher.mjs","names":["chokidarWatch"],"sources":["../../src/watcher.ts"],"sourcesContent":["import { basename } from 'node:path';\nimport {\n type GetConfigurationOptions,\n getAppLogger,\n getConfiguration,\n} from '@intlayer/config';\nimport type { IntlayerConfig } from '@intlayer/types';\n/** @ts-ignore remove error Module '\"chokidar\"' has no exported member 'ChokidarOptions'. */\nimport { type ChokidarOptions, watch as chokidarWatch } from 'chokidar';\nimport { handleAdditionalContentDeclarationFile } from './handleAdditionalContentDeclarationFile';\nimport { handleContentDeclarationFileChange } from './handleContentDeclarationFileChange';\nimport { handleUnlinkedContentDeclarationFile } from './handleUnlinkedContentDeclarationFile';\nimport { prepareIntlayer } from './prepareIntlayer';\n\nconst recentlyAddedFiles = new Set<string>();\n\ntype WatchOptions = ChokidarOptions & {\n configuration?: IntlayerConfig;\n configOptions?: GetConfigurationOptions;\n skipPrepare?: boolean;\n};\n\n// Initialize chokidar watcher (non-persistent)\nexport const watch = (options?: WatchOptions) => {\n const configuration =\n options?.configuration ?? getConfiguration(options?.configOptions);\n const appLogger = getAppLogger(configuration);\n\n const { watch: isWatchMode, watchedFilesPatternWithPath } =\n configuration.content;\n\n /** @ts-ignore remove error Expected 0-1 arguments, but got 2. */\n return chokidarWatch(watchedFilesPatternWithPath, {\n persistent: isWatchMode, // Make the watcher persistent\n ignoreInitial: true, // Process existing files\n awaitWriteFinish: {\n stabilityThreshold: 1000,\n pollInterval: 100,\n },\n ignored: [\n '**/node_modules/**',\n '**/dist/**',\n '**/build/**',\n '**/.intlayer/**',\n ],\n ...options,\n })\n .on('add', async (filePath) => {\n const fileName = basename(filePath);\n recentlyAddedFiles.add(fileName);\n\n await handleAdditionalContentDeclarationFile(filePath, configuration);\n\n setTimeout(() => recentlyAddedFiles.delete(fileName), 1000); // Allow time for unlink to trigger if it's a move\n })\n .on(\n 'change',\n async (filePath) =>\n await handleContentDeclarationFileChange(filePath, configuration)\n )\n .on('unlink', async (filePath) => {\n setTimeout(async () => {\n const fileName = basename(filePath);\n\n if (recentlyAddedFiles.has(fileName)) {\n // The file was moved, so ignore unlink\n return;\n }\n\n await handleUnlinkedContentDeclarationFile(filePath, configuration);\n }, 300); // Allow time for unlink to trigger if it's a move\n })\n .on('error', async (error) => {\n appLogger(`Watcher error: ${error}`, {\n level: 'error',\n });\n\n appLogger('Restarting watcher');\n\n await prepareIntlayer(configuration);\n });\n};\n\nexport const buildAndWatchIntlayer = async (options?: WatchOptions) => {\n const { skipPrepare, ...rest } = options ?? {};\n const configuration =\n options?.configuration ?? getConfiguration(options?.configOptions);\n\n if (!options?.skipPrepare) {\n await prepareIntlayer(configuration, { forceRun: true });\n }\n\n if (configuration.content.watch || options?.persistent) {\n const appLogger = getAppLogger(configuration);\n\n appLogger('Watching Intlayer content declarations');\n // Start watching (assuming watch is also async)\n watch({ ...rest, configuration });\n }\n};\n"],"mappings":";;;;;;;;;;AAcA,MAAM,qCAAqB,IAAI,KAAa;AAS5C,MAAa,SAAS,YAA2B;CAC/C,MAAM,gBACJ,SAAS,iBAAiB,iBAAiB,SAAS,cAAc;CACpE,MAAM,YAAY,aAAa,cAAc;CAE7C,MAAM,EAAE,OAAO,aAAa,gCAC1B,cAAc;;AAGhB,QAAOA,QAAc,6BAA6B;EAChD,YAAY;EACZ,eAAe;EACf,kBAAkB;GAChB,oBAAoB;GACpB,cAAc;GACf;EACD,SAAS;GACP;GACA;GACA;GACA;GACD;EACD,GAAG;EACJ,CAAC,CACC,GAAG,OAAO,OAAO,aAAa;EAC7B,MAAM,WAAW,SAAS,SAAS;AACnC,qBAAmB,IAAI,SAAS;AAEhC,QAAM,uCAAuC,UAAU,cAAc;AAErE,mBAAiB,mBAAmB,OAAO,SAAS,EAAE,IAAK;GAC3D,CACD,GACC,UACA,OAAO,aACL,MAAM,mCAAmC,UAAU,cAAc,CACpE,CACA,GAAG,UAAU,OAAO,aAAa;AAChC,aAAW,YAAY;GACrB,MAAM,WAAW,SAAS,SAAS;AAEnC,OAAI,mBAAmB,IAAI,SAAS,CAElC;AAGF,SAAM,qCAAqC,UAAU,cAAc;KAClE,IAAI;GACP,CACD,GAAG,SAAS,OAAO,UAAU;AAC5B,YAAU,kBAAkB,SAAS,EACnC,OAAO,SACR,CAAC;AAEF,YAAU,qBAAqB;AAE/B,QAAM,gBAAgB,cAAc;GACpC;;AAGN,MAAa,wBAAwB,OAAO,YAA2B;CACrE,MAAM,EAAE,aAAa,GAAG,SAAS,WAAW,EAAE;CAC9C,MAAM,gBACJ,SAAS,iBAAiB,iBAAiB,SAAS,cAAc;AAEpE,KAAI,CAAC,SAAS,YACZ,OAAM,gBAAgB,eAAe,EAAE,UAAU,MAAM,CAAC;AAG1D,KAAI,cAAc,QAAQ,SAAS,SAAS,YAAY;AAGtD,EAFkB,aAAa,cAAc,CAEnC,yCAAyC;AAEnD,QAAM;GAAE,GAAG;GAAM;GAAe,CAAC"}
1
+ {"version":3,"file":"watcher.mjs","names":["chokidarWatch"],"sources":["../../src/watcher.ts"],"sourcesContent":["import { readFile } from 'node:fs/promises';\nimport { basename } from 'node:path';\nimport {\n type GetConfigurationOptions,\n getAppLogger,\n getConfiguration,\n} from '@intlayer/config';\nimport type { IntlayerConfig } from '@intlayer/types';\n/** @ts-ignore remove error Module '\"chokidar\"' has no exported member 'ChokidarOptions'. */\nimport { type ChokidarOptions, watch as chokidarWatch } from 'chokidar';\nimport { handleAdditionalContentDeclarationFile } from './handleAdditionalContentDeclarationFile';\nimport { handleContentDeclarationFileChange } from './handleContentDeclarationFileChange';\nimport { handleUnlinkedContentDeclarationFile } from './handleUnlinkedContentDeclarationFile';\nimport { prepareIntlayer } from './prepareIntlayer';\nimport { writeContentDeclaration } from './writeContentDeclaration';\n\nconst recentlyAddedFiles = new Set<string>();\n\ntype WatchOptions = ChokidarOptions & {\n configuration?: IntlayerConfig;\n configOptions?: GetConfigurationOptions;\n skipPrepare?: boolean;\n};\n\n// Initialize chokidar watcher (non-persistent)\nexport const watch = (options?: WatchOptions) => {\n const configuration =\n options?.configuration ?? getConfiguration(options?.configOptions);\n const appLogger = getAppLogger(configuration);\n\n const {\n watch: isWatchMode,\n watchedFilesPatternWithPath,\n fileExtensions,\n } = configuration.content;\n\n return chokidarWatch(watchedFilesPatternWithPath, {\n persistent: isWatchMode, // Make the watcher persistent\n ignoreInitial: true, // Process existing files\n awaitWriteFinish: {\n stabilityThreshold: 1000,\n pollInterval: 100,\n },\n ignored: [\n '**/node_modules/**',\n '**/dist/**',\n '**/build/**',\n '**/.intlayer/**',\n ],\n ...options,\n })\n .on('add', async (filePath) => {\n const fileName = basename(filePath);\n recentlyAddedFiles.add(fileName);\n\n const fileContent = await readFile(filePath, 'utf-8');\n\n const isEmpty = fileContent === '';\n\n // Fill template content declaration file if it is empty\n if (isEmpty) {\n // Extract name from filename by removing any configured extension\n // e.g., \"example.content.ts\" -> \"example\" or \"example.i18n.json\" -> \"example\"\n const extensionPattern = fileExtensions\n .map((ext) => ext.replace(/\\./g, '\\\\.'))\n .join('|');\n const name = fileName.replace(new RegExp(`(${extensionPattern})$`), '');\n\n await writeContentDeclaration(\n {\n key: name,\n content: {},\n filePath,\n },\n configuration\n );\n }\n\n await handleAdditionalContentDeclarationFile(filePath, configuration);\n\n setTimeout(() => recentlyAddedFiles.delete(fileName), 1000); // Allow time for unlink to trigger if it's a move\n })\n .on(\n 'change',\n async (filePath) =>\n await handleContentDeclarationFileChange(filePath, configuration)\n )\n .on('unlink', async (filePath) => {\n setTimeout(async () => {\n const fileName = basename(filePath);\n\n if (recentlyAddedFiles.has(fileName)) {\n // The file was moved, so ignore unlink\n return;\n }\n\n await handleUnlinkedContentDeclarationFile(filePath, configuration);\n }, 300); // Allow time for unlink to trigger if it's a move\n })\n .on('error', async (error) => {\n appLogger(`Watcher error: ${error}`, {\n level: 'error',\n });\n\n appLogger('Restarting watcher');\n\n await prepareIntlayer(configuration);\n });\n};\n\nexport const buildAndWatchIntlayer = async (options?: WatchOptions) => {\n const { skipPrepare, ...rest } = options ?? {};\n const configuration =\n options?.configuration ?? getConfiguration(options?.configOptions);\n\n if (!options?.skipPrepare) {\n await prepareIntlayer(configuration, { forceRun: true });\n }\n\n if (configuration.content.watch || options?.persistent) {\n const appLogger = getAppLogger(configuration);\n\n appLogger('Watching Intlayer content declarations');\n // Start watching (assuming watch is also async)\n watch({ ...rest, configuration });\n }\n};\n"],"mappings":";;;;;;;;;;;;AAgBA,MAAM,qCAAqB,IAAI,KAAa;AAS5C,MAAa,SAAS,YAA2B;CAC/C,MAAM,gBACJ,SAAS,iBAAiB,iBAAiB,SAAS,cAAc;CACpE,MAAM,YAAY,aAAa,cAAc;CAE7C,MAAM,EACJ,OAAO,aACP,6BACA,mBACE,cAAc;AAElB,QAAOA,QAAc,6BAA6B;EAChD,YAAY;EACZ,eAAe;EACf,kBAAkB;GAChB,oBAAoB;GACpB,cAAc;GACf;EACD,SAAS;GACP;GACA;GACA;GACA;GACD;EACD,GAAG;EACJ,CAAC,CACC,GAAG,OAAO,OAAO,aAAa;EAC7B,MAAM,WAAW,SAAS,SAAS;AACnC,qBAAmB,IAAI,SAAS;AAOhC,MALoB,MAAM,SAAS,UAAU,QAAQ,KAErB,IAGnB;GAGX,MAAM,mBAAmB,eACtB,KAAK,QAAQ,IAAI,QAAQ,OAAO,MAAM,CAAC,CACvC,KAAK,IAAI;AAGZ,SAAM,wBACJ;IACE,KAJS,SAAS,wBAAQ,IAAI,OAAO,IAAI,iBAAiB,IAAI,EAAE,GAAG;IAKnE,SAAS,EAAE;IACX;IACD,EACD,cACD;;AAGH,QAAM,uCAAuC,UAAU,cAAc;AAErE,mBAAiB,mBAAmB,OAAO,SAAS,EAAE,IAAK;GAC3D,CACD,GACC,UACA,OAAO,aACL,MAAM,mCAAmC,UAAU,cAAc,CACpE,CACA,GAAG,UAAU,OAAO,aAAa;AAChC,aAAW,YAAY;GACrB,MAAM,WAAW,SAAS,SAAS;AAEnC,OAAI,mBAAmB,IAAI,SAAS,CAElC;AAGF,SAAM,qCAAqC,UAAU,cAAc;KAClE,IAAI;GACP,CACD,GAAG,SAAS,OAAO,UAAU;AAC5B,YAAU,kBAAkB,SAAS,EACnC,OAAO,SACR,CAAC;AAEF,YAAU,qBAAqB;AAE/B,QAAM,gBAAgB,cAAc;GACpC;;AAGN,MAAa,wBAAwB,OAAO,YAA2B;CACrE,MAAM,EAAE,aAAa,GAAG,SAAS,WAAW,EAAE;CAC9C,MAAM,gBACJ,SAAS,iBAAiB,iBAAiB,SAAS,cAAc;AAEpE,KAAI,CAAC,SAAS,YACZ,OAAM,gBAAgB,eAAe,EAAE,UAAU,MAAM,CAAC;AAG1D,KAAI,cAAc,QAAQ,SAAS,SAAS,YAAY;AAGtD,EAFkB,aAAa,cAAc,CAEnC,yCAAyC;AAEnD,QAAM;GAAE,GAAG;GAAM;GAAe,CAAC"}
@@ -1,6 +1,6 @@
1
1
  import { existsSync, mkdirSync, writeFileSync } from "node:fs";
2
- import { colorizePath, x } from "@intlayer/config";
3
2
  import { dirname, join } from "node:path";
3
+ import { colorizePath, x } from "@intlayer/config";
4
4
  import { deepTransformNode } from "@intlayer/core";
5
5
  import { NodeType } from "@intlayer/types";
6
6
 
@@ -3,8 +3,8 @@ import { processContentDeclarationContent } from "./processContentDeclarationCon
3
3
  import { writeJSFile } from "./writeJSFile.mjs";
4
4
  import { mkdir, rm, writeFile } from "node:fs/promises";
5
5
  import { dirname, extname, join, resolve } from "node:path";
6
- import { getFilteredLocalesDictionary, getPerLocaleDictionary } from "@intlayer/core";
7
6
  import { getUnmergedDictionaries } from "@intlayer/unmerged-dictionaries-entry";
7
+ import { getFilteredLocalesDictionary, getPerLocaleDictionary } from "@intlayer/core";
8
8
  import { isDeepStrictEqual } from "node:util";
9
9
 
10
10
  //#region src/writeContentDeclaration/writeContentDeclaration.ts
@@ -1 +1 @@
1
- {"version":3,"file":"writeContentDeclaration.mjs","names":["pluginFormatResult: any","result: Dictionary","extension"],"sources":["../../../src/writeContentDeclaration/writeContentDeclaration.ts"],"sourcesContent":["import { mkdir, rm, writeFile } from 'node:fs/promises';\nimport { dirname, extname, join, resolve } from 'node:path';\nimport { isDeepStrictEqual } from 'node:util';\nimport {\n getFilteredLocalesDictionary,\n getPerLocaleDictionary,\n} from '@intlayer/core';\nimport type {\n Dictionary,\n IntlayerConfig,\n Locale,\n LocalesValues,\n} from '@intlayer/types';\nimport { getUnmergedDictionaries } from '@intlayer/unmerged-dictionaries-entry';\nimport {\n type Extension,\n getFormatFromExtension,\n} from '../utils/getFormatFromExtension';\nimport type { DictionaryStatus } from './dictionaryStatus';\nimport { processContentDeclarationContent } from './processContentDeclarationContent';\nimport { writeJSFile } from './writeJSFile';\n\nconst formatContentDeclaration = async (\n dictionary: Dictionary,\n configuration: IntlayerConfig,\n localeList?: LocalesValues[]\n) => {\n /**\n * Clean Markdown, Insertion, File, etc. node metadata\n */\n const processedDictionary =\n await processContentDeclarationContent(dictionary);\n\n let content = processedDictionary.content;\n\n /**\n * Filter locales content\n */\n\n if (dictionary.locale) {\n content = getPerLocaleDictionary(\n processedDictionary,\n dictionary.locale\n ).content;\n } else if (localeList) {\n content = getFilteredLocalesDictionary(\n processedDictionary,\n localeList\n ).content;\n }\n\n let pluginFormatResult: any = {\n ...dictionary,\n content,\n } satisfies Dictionary;\n\n /**\n * Format the dictionary with the plugins\n */\n\n for await (const plugin of configuration.plugins ?? []) {\n if (plugin.formatOutput) {\n const formattedResult = await plugin.formatOutput?.({\n dictionary: pluginFormatResult,\n configuration,\n });\n\n if (formattedResult) {\n pluginFormatResult = formattedResult;\n }\n }\n }\n\n const isDictionaryFormat =\n pluginFormatResult.content && pluginFormatResult.key;\n\n if (!isDictionaryFormat) return pluginFormatResult;\n\n let result: Dictionary = {\n key: dictionary.key,\n id: dictionary.id,\n title: dictionary.title,\n description: dictionary.description,\n tags: dictionary.tags,\n locale: dictionary.locale,\n fill: dictionary.fill,\n filled: dictionary.filled,\n priority: dictionary.priority,\n live: dictionary.live,\n version: dictionary.version,\n content,\n };\n\n /**\n * Add $schema to JSON dictionaries\n */\n const extension = (\n dictionary.filePath ? extname(dictionary.filePath) : '.json'\n ) as Extension;\n const format = getFormatFromExtension(extension);\n\n if (\n format === 'json' &&\n pluginFormatResult.content &&\n pluginFormatResult.key\n ) {\n result = {\n $schema: 'https://intlayer.org/schema.json',\n ...result,\n };\n }\n\n return result;\n};\n\ntype WriteContentDeclarationOptions = {\n newDictionariesPath?: string;\n localeList?: LocalesValues[];\n fallbackLocale?: Locale;\n};\n\nconst defaultOptions = {\n newDictionariesPath: 'intlayer-dictionaries',\n} satisfies WriteContentDeclarationOptions;\n\nexport const writeContentDeclaration = async (\n dictionary: Dictionary,\n configuration: IntlayerConfig,\n options?: WriteContentDeclarationOptions\n): Promise<{ status: DictionaryStatus; path: string }> => {\n const { content } = configuration;\n const { baseDir } = content;\n const { newDictionariesPath, localeList } = {\n ...defaultOptions,\n ...options,\n };\n\n const newDictionaryLocationPath = join(baseDir, newDictionariesPath);\n\n const unmergedDictionariesRecord = getUnmergedDictionaries(configuration);\n const unmergedDictionaries = unmergedDictionariesRecord[\n dictionary.key\n ] as Dictionary[];\n\n const existingDictionary = unmergedDictionaries?.find(\n (el) => el.localId === dictionary.localId\n );\n\n const formattedContentDeclaration = await formatContentDeclaration(\n dictionary,\n configuration,\n localeList\n );\n\n if (existingDictionary?.filePath) {\n // Compare existing dictionary content with new dictionary content\n const isSameContent = isDeepStrictEqual(existingDictionary, dictionary);\n\n const filePath = resolve(\n configuration.content.baseDir,\n existingDictionary.filePath\n );\n\n // Up to date, nothing to do\n if (isSameContent) {\n return {\n status: 'up-to-date',\n path: filePath,\n };\n }\n\n await writeFileWithDirectories(\n filePath,\n formattedContentDeclaration,\n configuration\n );\n\n return { status: 'updated', path: filePath };\n }\n\n if (dictionary.filePath) {\n const filePath = resolve(\n configuration.content.baseDir,\n dictionary.filePath\n );\n await writeFileWithDirectories(\n filePath,\n formattedContentDeclaration,\n configuration\n );\n\n return { status: 'created', path: filePath };\n }\n\n // No existing dictionary, write to new location\n const contentDeclarationPath = join(\n newDictionaryLocationPath,\n `${dictionary.key}.content.json`\n );\n\n await writeFileWithDirectories(\n contentDeclarationPath,\n formattedContentDeclaration,\n configuration\n );\n\n return {\n status: 'imported',\n path: contentDeclarationPath,\n };\n};\n\nconst writeFileWithDirectories = async (\n absoluteFilePath: string,\n dictionary: Dictionary,\n configuration: IntlayerConfig\n): Promise<void> => {\n // Extract the directory from the file path\n const dir = dirname(absoluteFilePath);\n\n // Create the directory recursively\n await mkdir(dir, { recursive: true });\n\n const extension = extname(absoluteFilePath);\n const acceptedExtensions = configuration.content.fileExtensions.map(\n (extension) => extname(extension)\n );\n\n if (!acceptedExtensions.includes(extension)) {\n throw new Error(\n `Invalid file extension: ${extension}, file: ${absoluteFilePath}`\n );\n }\n\n if (extension === '.json') {\n const jsonDictionary = JSON.stringify(dictionary, null, 2);\n\n // Write the file\n await writeFile(absoluteFilePath, `${jsonDictionary}\\n`); // Add a new line at the end of the file to avoid formatting issues with VSCode\n\n return;\n }\n\n await writeJSFile(absoluteFilePath, dictionary, configuration);\n\n // remove the cache as content has changed\n // Will force a new preparation of the intlayer on next build\n try {\n const sentinelPath = join(\n configuration.content.cacheDir,\n 'intlayer-prepared.lock'\n );\n await rm(sentinelPath, { recursive: true });\n } catch {}\n};\n"],"mappings":";;;;;;;;;;AAsBA,MAAM,2BAA2B,OAC/B,YACA,eACA,eACG;;;;CAIH,MAAM,sBACJ,MAAM,iCAAiC,WAAW;CAEpD,IAAI,UAAU,oBAAoB;;;;AAMlC,KAAI,WAAW,OACb,WAAU,uBACR,qBACA,WAAW,OACZ,CAAC;UACO,WACT,WAAU,6BACR,qBACA,WACD,CAAC;CAGJ,IAAIA,qBAA0B;EAC5B,GAAG;EACH;EACD;;;;AAMD,YAAW,MAAM,UAAU,cAAc,WAAW,EAAE,CACpD,KAAI,OAAO,cAAc;EACvB,MAAM,kBAAkB,MAAM,OAAO,eAAe;GAClD,YAAY;GACZ;GACD,CAAC;AAEF,MAAI,gBACF,sBAAqB;;AAQ3B,KAAI,EAFF,mBAAmB,WAAW,mBAAmB,KAE1B,QAAO;CAEhC,IAAIC,SAAqB;EACvB,KAAK,WAAW;EAChB,IAAI,WAAW;EACf,OAAO,WAAW;EAClB,aAAa,WAAW;EACxB,MAAM,WAAW;EACjB,QAAQ,WAAW;EACnB,MAAM,WAAW;EACjB,QAAQ,WAAW;EACnB,UAAU,WAAW;EACrB,MAAM,WAAW;EACjB,SAAS,WAAW;EACpB;EACD;AAUD,KAFe,uBAFb,WAAW,WAAW,QAAQ,WAAW,SAAS,GAAG,QAEP,KAGnC,UACX,mBAAmB,WACnB,mBAAmB,IAEnB,UAAS;EACP,SAAS;EACT,GAAG;EACJ;AAGH,QAAO;;AAST,MAAM,iBAAiB,EACrB,qBAAqB,yBACtB;AAED,MAAa,0BAA0B,OACrC,YACA,eACA,YACwD;CACxD,MAAM,EAAE,YAAY;CACpB,MAAM,EAAE,YAAY;CACpB,MAAM,EAAE,qBAAqB,eAAe;EAC1C,GAAG;EACH,GAAG;EACJ;CAED,MAAM,4BAA4B,KAAK,SAAS,oBAAoB;CAOpE,MAAM,qBAL6B,wBAAwB,cAAc,CAEvE,WAAW,MAGoC,MAC9C,OAAO,GAAG,YAAY,WAAW,QACnC;CAED,MAAM,8BAA8B,MAAM,yBACxC,YACA,eACA,WACD;AAED,KAAI,oBAAoB,UAAU;EAEhC,MAAM,gBAAgB,kBAAkB,oBAAoB,WAAW;EAEvE,MAAM,WAAW,QACf,cAAc,QAAQ,SACtB,mBAAmB,SACpB;AAGD,MAAI,cACF,QAAO;GACL,QAAQ;GACR,MAAM;GACP;AAGH,QAAM,yBACJ,UACA,6BACA,cACD;AAED,SAAO;GAAE,QAAQ;GAAW,MAAM;GAAU;;AAG9C,KAAI,WAAW,UAAU;EACvB,MAAM,WAAW,QACf,cAAc,QAAQ,SACtB,WAAW,SACZ;AACD,QAAM,yBACJ,UACA,6BACA,cACD;AAED,SAAO;GAAE,QAAQ;GAAW,MAAM;GAAU;;CAI9C,MAAM,yBAAyB,KAC7B,2BACA,GAAG,WAAW,IAAI,eACnB;AAED,OAAM,yBACJ,wBACA,6BACA,cACD;AAED,QAAO;EACL,QAAQ;EACR,MAAM;EACP;;AAGH,MAAM,2BAA2B,OAC/B,kBACA,YACA,kBACkB;AAKlB,OAAM,MAHM,QAAQ,iBAAiB,EAGpB,EAAE,WAAW,MAAM,CAAC;CAErC,MAAM,YAAY,QAAQ,iBAAiB;AAK3C,KAAI,CAJuB,cAAc,QAAQ,eAAe,KAC7D,gBAAc,QAAQC,YAAU,CAClC,CAEuB,SAAS,UAAU,CACzC,OAAM,IAAI,MACR,2BAA2B,UAAU,UAAU,mBAChD;AAGH,KAAI,cAAc,SAAS;AAIzB,QAAM,UAAU,kBAAkB,GAHX,KAAK,UAAU,YAAY,MAAM,EAAE,CAGN,IAAI;AAExD;;AAGF,OAAM,YAAY,kBAAkB,YAAY,cAAc;AAI9D,KAAI;AAKF,QAAM,GAJe,KACnB,cAAc,QAAQ,UACtB,yBACD,EACsB,EAAE,WAAW,MAAM,CAAC;SACrC"}
1
+ {"version":3,"file":"writeContentDeclaration.mjs","names":["pluginFormatResult: any","result: Dictionary","extension"],"sources":["../../../src/writeContentDeclaration/writeContentDeclaration.ts"],"sourcesContent":["import { mkdir, rm, writeFile } from 'node:fs/promises';\nimport { dirname, extname, join, resolve } from 'node:path';\nimport { isDeepStrictEqual } from 'node:util';\nimport {\n getFilteredLocalesDictionary,\n getPerLocaleDictionary,\n} from '@intlayer/core';\nimport type {\n Dictionary,\n IntlayerConfig,\n Locale,\n LocalesValues,\n} from '@intlayer/types';\nimport { getUnmergedDictionaries } from '@intlayer/unmerged-dictionaries-entry';\nimport {\n type Extension,\n getFormatFromExtension,\n} from '../utils/getFormatFromExtension';\nimport type { DictionaryStatus } from './dictionaryStatus';\nimport { processContentDeclarationContent } from './processContentDeclarationContent';\nimport { writeJSFile } from './writeJSFile';\n\nconst formatContentDeclaration = async (\n dictionary: Dictionary,\n configuration: IntlayerConfig,\n localeList?: LocalesValues[]\n) => {\n /**\n * Clean Markdown, Insertion, File, etc. node metadata\n */\n const processedDictionary =\n await processContentDeclarationContent(dictionary);\n\n let content = processedDictionary.content;\n\n /**\n * Filter locales content\n */\n\n if (dictionary.locale) {\n content = getPerLocaleDictionary(\n processedDictionary,\n dictionary.locale\n ).content;\n } else if (localeList) {\n content = getFilteredLocalesDictionary(\n processedDictionary,\n localeList\n ).content;\n }\n\n let pluginFormatResult: any = {\n ...dictionary,\n content,\n } satisfies Dictionary;\n\n /**\n * Format the dictionary with the plugins\n */\n\n for await (const plugin of configuration.plugins ?? []) {\n if (plugin.formatOutput) {\n const formattedResult = await plugin.formatOutput?.({\n dictionary: pluginFormatResult,\n configuration,\n });\n\n if (formattedResult) {\n pluginFormatResult = formattedResult;\n }\n }\n }\n\n const isDictionaryFormat =\n pluginFormatResult.content && pluginFormatResult.key;\n\n if (!isDictionaryFormat) return pluginFormatResult;\n\n let result: Dictionary = {\n key: dictionary.key,\n id: dictionary.id,\n title: dictionary.title,\n description: dictionary.description,\n tags: dictionary.tags,\n locale: dictionary.locale,\n fill: dictionary.fill,\n filled: dictionary.filled,\n priority: dictionary.priority,\n live: dictionary.live,\n version: dictionary.version,\n content,\n };\n\n /**\n * Add $schema to JSON dictionaries\n */\n const extension = (\n dictionary.filePath ? extname(dictionary.filePath) : '.json'\n ) as Extension;\n const format = getFormatFromExtension(extension);\n\n if (\n format === 'json' &&\n pluginFormatResult.content &&\n pluginFormatResult.key\n ) {\n result = {\n $schema: 'https://intlayer.org/schema.json',\n ...result,\n };\n }\n\n return result;\n};\n\ntype WriteContentDeclarationOptions = {\n newDictionariesPath?: string;\n localeList?: LocalesValues[];\n fallbackLocale?: Locale;\n};\n\nconst defaultOptions = {\n newDictionariesPath: 'intlayer-dictionaries',\n} satisfies WriteContentDeclarationOptions;\n\nexport const writeContentDeclaration = async (\n dictionary: Dictionary,\n configuration: IntlayerConfig,\n options?: WriteContentDeclarationOptions\n): Promise<{ status: DictionaryStatus; path: string }> => {\n const { content } = configuration;\n const { baseDir } = content;\n const { newDictionariesPath, localeList } = {\n ...defaultOptions,\n ...options,\n };\n\n const newDictionaryLocationPath = join(baseDir, newDictionariesPath);\n\n const unmergedDictionariesRecord = getUnmergedDictionaries(configuration);\n const unmergedDictionaries = unmergedDictionariesRecord[\n dictionary.key\n ] as Dictionary[];\n\n const existingDictionary = unmergedDictionaries?.find(\n (el) => el.localId === dictionary.localId\n );\n\n const formattedContentDeclaration = await formatContentDeclaration(\n dictionary,\n configuration,\n localeList\n );\n\n if (existingDictionary?.filePath) {\n // Compare existing dictionary content with new dictionary content\n const isSameContent = isDeepStrictEqual(existingDictionary, dictionary);\n\n const filePath = resolve(\n configuration.content.baseDir,\n existingDictionary.filePath\n );\n\n // Up to date, nothing to do\n if (isSameContent) {\n return {\n status: 'up-to-date',\n path: filePath,\n };\n }\n\n await writeFileWithDirectories(\n filePath,\n formattedContentDeclaration,\n configuration\n );\n\n return { status: 'updated', path: filePath };\n }\n\n if (dictionary.filePath) {\n const filePath = resolve(\n configuration.content.baseDir,\n dictionary.filePath\n );\n\n await writeFileWithDirectories(\n filePath,\n formattedContentDeclaration,\n configuration\n );\n\n return { status: 'created', path: filePath };\n }\n\n // No existing dictionary, write to new location\n const contentDeclarationPath = join(\n newDictionaryLocationPath,\n `${dictionary.key}.content.json`\n );\n\n await writeFileWithDirectories(\n contentDeclarationPath,\n formattedContentDeclaration,\n configuration\n );\n\n return {\n status: 'imported',\n path: contentDeclarationPath,\n };\n};\n\nconst writeFileWithDirectories = async (\n absoluteFilePath: string,\n dictionary: Dictionary,\n configuration: IntlayerConfig\n): Promise<void> => {\n // Extract the directory from the file path\n const dir = dirname(absoluteFilePath);\n\n // Create the directory recursively\n await mkdir(dir, { recursive: true });\n\n const extension = extname(absoluteFilePath);\n const acceptedExtensions = configuration.content.fileExtensions.map(\n (extension) => extname(extension)\n );\n\n if (!acceptedExtensions.includes(extension)) {\n throw new Error(\n `Invalid file extension: ${extension}, file: ${absoluteFilePath}`\n );\n }\n\n if (extension === '.json') {\n const jsonDictionary = JSON.stringify(dictionary, null, 2);\n\n // Write the file\n await writeFile(absoluteFilePath, `${jsonDictionary}\\n`); // Add a new line at the end of the file to avoid formatting issues with VSCode\n\n return;\n }\n\n await writeJSFile(absoluteFilePath, dictionary, configuration);\n\n // remove the cache as content has changed\n // Will force a new preparation of the intlayer on next build\n try {\n const sentinelPath = join(\n configuration.content.cacheDir,\n 'intlayer-prepared.lock'\n );\n await rm(sentinelPath, { recursive: true });\n } catch {}\n};\n"],"mappings":"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"}
@@ -4,8 +4,8 @@ import { getFormatFromExtension } from "../utils/getFormatFromExtension.mjs";
4
4
  import { detectFormatCommand } from "./detectFormatCommand.mjs";
5
5
  import { existsSync } from "node:fs";
6
6
  import { readFile, writeFile } from "node:fs/promises";
7
- import { getAppLogger, logger } from "@intlayer/config";
8
7
  import { extname } from "node:path";
8
+ import { getAppLogger, logger } from "@intlayer/config";
9
9
  import { execSync } from "node:child_process";
10
10
 
11
11
  //#region src/writeContentDeclaration/writeJSFile.ts
@@ -37,7 +37,12 @@ const writeJSFile = async (filePath, dictionary, configuration) => {
37
37
  live: mergedDictionary.live
38
38
  }).filter(([, value]) => value !== void 0))), "utf-8");
39
39
  }
40
- const finalCode = await transformJSFile(await readFile(filePath, "utf-8"), dictionary);
40
+ let fileContent = await readFile(filePath, "utf-8");
41
+ if (fileContent === "") {
42
+ const format = getFormatFromExtension(extname(filePath));
43
+ fileContent = await getContentDeclarationFileTemplate(mergedDictionary.key, format);
44
+ }
45
+ const finalCode = await transformJSFile(fileContent, dictionary);
41
46
  try {
42
47
  await writeFile(filePath, finalCode, "utf-8");
43
48
  logger(`Successfully updated ${filePath}`, {