@intlayer/editor 4.1.1 → 4.1.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -38,16 +38,16 @@ var import_client = require("@intlayer/config/client");
38
38
  var import_dictionaries_entry = __toESM(require("@intlayer/dictionaries-entry"));
39
39
  var import_deep_equal = __toESM(require("deep-equal"));
40
40
  const DEFAULT_NEW_DICTIONARY_PATH = "intlayer-dictionaries";
41
- const writeContentDeclaration = async (distantDictionary, config, newDictionariesPath) => {
41
+ const writeContentDeclaration = async (dictionary, config, newDictionariesPath) => {
42
42
  const {
43
43
  content: { baseDir }
44
44
  } = config ?? (0, import_client.getConfiguration)();
45
45
  const newDictionaryRelativeLocationPath = newDictionariesPath ?? DEFAULT_NEW_DICTIONARY_PATH;
46
46
  const newDictionaryLocationPath = `${baseDir}/${newDictionaryRelativeLocationPath}`;
47
- const existingDictionary = import_dictionaries_entry.default[distantDictionary.key];
47
+ const existingDictionary = import_dictionaries_entry.default[dictionary.key];
48
48
  if (existingDictionary) {
49
- const { filePath } = existingDictionary;
50
- if ((0, import_deep_equal.default)(existingDictionary, distantDictionary)) {
49
+ const { filePath, ...dictionaryWithoutPath } = dictionary;
50
+ if ((0, import_deep_equal.default)(existingDictionary, dictionary)) {
51
51
  return {
52
52
  status: "up-to-date",
53
53
  path: filePath
@@ -59,7 +59,7 @@ const writeContentDeclaration = async (distantDictionary, config, newDictionarie
59
59
  const contentDeclarationPath = `${baseDir}/${filePath}`;
60
60
  await fsPromises.writeFile(
61
61
  contentDeclarationPath,
62
- JSON.stringify(distantDictionary, null, 2)
62
+ JSON.stringify(dictionaryWithoutPath, null, 2)
63
63
  );
64
64
  return { status: "updated", path: contentDeclarationPath };
65
65
  } else {
@@ -68,7 +68,7 @@ const writeContentDeclaration = async (distantDictionary, config, newDictionarie
68
68
  const newFilePath = `${dictionariesDirPath}/${dictionariesFileName}.json`;
69
69
  await writeFileWithDirectories(
70
70
  newFilePath,
71
- JSON.stringify(distantDictionary, null, 2)
71
+ JSON.stringify(dictionaryWithoutPath, null, 2)
72
72
  );
73
73
  return {
74
74
  status: "updated",
@@ -76,10 +76,10 @@ const writeContentDeclaration = async (distantDictionary, config, newDictionarie
76
76
  };
77
77
  }
78
78
  } else {
79
- const contentDeclarationPath = `${newDictionaryLocationPath}/${distantDictionary.key}.content.json`;
79
+ const contentDeclarationPath = `${newDictionaryLocationPath}/${dictionary.key}.content.json`;
80
80
  await writeFileWithDirectories(
81
81
  contentDeclarationPath,
82
- JSON.stringify(distantDictionary, null, 2)
82
+ JSON.stringify(dictionaryWithoutPath, null, 2)
83
83
  );
84
84
  return {
85
85
  status: "reimported in new location",
@@ -88,10 +88,10 @@ const writeContentDeclaration = async (distantDictionary, config, newDictionarie
88
88
  }
89
89
  }
90
90
  } else {
91
- const contentDeclarationPath = `${newDictionaryLocationPath}/${distantDictionary.key}.content.json`;
91
+ const contentDeclarationPath = `${newDictionaryLocationPath}/${dictionary.key}.content.json`;
92
92
  await writeFileWithDirectories(
93
93
  contentDeclarationPath,
94
- JSON.stringify(distantDictionary, null, 2)
94
+ JSON.stringify(dictionary, null, 2)
95
95
  );
96
96
  return {
97
97
  status: "imported",
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/server/writeContentDeclaration.ts"],"sourcesContent":["import { existsSync } from 'fs';\nimport * as fsPromises from 'fs/promises';\nimport { basename, dirname, extname } from 'path';\nimport { getConfiguration, IntlayerConfig } from '@intlayer/config/client';\nimport { Dictionary } from '@intlayer/core';\nimport dictionariesRecord from '@intlayer/dictionaries-entry';\nimport deepEqual from 'deep-equal';\nimport { DictionaryStatus } from '../dictionaryStatus';\n\nconst DEFAULT_NEW_DICTIONARY_PATH = 'intlayer-dictionaries';\n\nexport const writeContentDeclaration = async (\n distantDictionary: Dictionary,\n config?: IntlayerConfig,\n newDictionariesPath?: string\n): Promise<{ status: DictionaryStatus; path: string }> => {\n const {\n content: { baseDir },\n } = config ?? getConfiguration();\n\n const newDictionaryRelativeLocationPath =\n newDictionariesPath ?? DEFAULT_NEW_DICTIONARY_PATH;\n const newDictionaryLocationPath = `${baseDir}/${newDictionaryRelativeLocationPath}`;\n\n const existingDictionary = dictionariesRecord[distantDictionary.key];\n\n if (existingDictionary) {\n const { filePath } = existingDictionary;\n\n // Compare existing dictionary with distant dictionary\n if (deepEqual(existingDictionary, distantDictionary)) {\n // Up to date, nothing to do\n return {\n status: 'up-to-date',\n path: filePath!,\n };\n } else {\n if (filePath) {\n const isDictionaryJSON = filePath.endsWith('.json');\n\n if (isDictionaryJSON) {\n const contentDeclarationPath = `${baseDir}/${filePath}`;\n // Write the dictionary to the same location of the existing dictionary file\n await fsPromises.writeFile(\n contentDeclarationPath,\n JSON.stringify(distantDictionary, null, 2)\n );\n return { status: 'updated', path: contentDeclarationPath };\n } else {\n // Write the dictionary to the intlayer-dictionaries directory\n const dictionariesDirPath = dirname(filePath);\n const dictionariesFileName = basename(filePath, extname(filePath));\n\n const newFilePath = `${dictionariesDirPath}/${dictionariesFileName}.json`;\n\n await writeFileWithDirectories(\n newFilePath,\n JSON.stringify(distantDictionary, null, 2)\n );\n\n return {\n status: 'updated',\n path: newFilePath,\n };\n }\n } else {\n // Write the dictionary to the intlayer-dictionaries directory\n const contentDeclarationPath = `${newDictionaryLocationPath}/${distantDictionary.key}.content.json`;\n await writeFileWithDirectories(\n contentDeclarationPath,\n JSON.stringify(distantDictionary, null, 2)\n );\n return {\n status: 'reimported in new location',\n path: contentDeclarationPath,\n };\n }\n }\n } else {\n // No existing dictionary, write to new location\n const contentDeclarationPath = `${newDictionaryLocationPath}/${distantDictionary.key}.content.json`;\n\n await writeFileWithDirectories(\n contentDeclarationPath,\n JSON.stringify(distantDictionary, null, 2)\n );\n\n return {\n status: 'imported',\n path: contentDeclarationPath,\n };\n }\n};\n\nconst writeFileWithDirectories = async (\n filePath: string,\n data: string | Buffer\n): Promise<void> => {\n try {\n // Extract the directory from the file path\n const dir = dirname(filePath);\n\n // Check if the directory exists\n const directoryExists = existsSync(dir);\n\n if (!directoryExists) {\n // Create the directory recursively\n await fsPromises.mkdir(dir, { recursive: true });\n }\n\n // Write the file\n await fsPromises.writeFile(filePath, data);\n } catch (error) {\n throw new Error(`Error writing file to ${filePath}: ${error}`);\n }\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,gBAA2B;AAC3B,iBAA4B;AAC5B,kBAA2C;AAC3C,oBAAiD;AAEjD,gCAA+B;AAC/B,wBAAsB;AAGtB,MAAM,8BAA8B;AAE7B,MAAM,0BAA0B,OACrC,mBACA,QACA,wBACwD;AACxD,QAAM;AAAA,IACJ,SAAS,EAAE,QAAQ;AAAA,EACrB,IAAI,cAAU,gCAAiB;AAE/B,QAAM,oCACJ,uBAAuB;AACzB,QAAM,4BAA4B,GAAG,OAAO,IAAI,iCAAiC;AAEjF,QAAM,qBAAqB,0BAAAA,QAAmB,kBAAkB,GAAG;AAEnE,MAAI,oBAAoB;AACtB,UAAM,EAAE,SAAS,IAAI;AAGrB,YAAI,kBAAAC,SAAU,oBAAoB,iBAAiB,GAAG;AAEpD,aAAO;AAAA,QACL,QAAQ;AAAA,QACR,MAAM;AAAA,MACR;AAAA,IACF,OAAO;AACL,UAAI,UAAU;AACZ,cAAM,mBAAmB,SAAS,SAAS,OAAO;AAElD,YAAI,kBAAkB;AACpB,gBAAM,yBAAyB,GAAG,OAAO,IAAI,QAAQ;AAErD,gBAAM,WAAW;AAAA,YACf;AAAA,YACA,KAAK,UAAU,mBAAmB,MAAM,CAAC;AAAA,UAC3C;AACA,iBAAO,EAAE,QAAQ,WAAW,MAAM,uBAAuB;AAAA,QAC3D,OAAO;AAEL,gBAAM,0BAAsB,qBAAQ,QAAQ;AAC5C,gBAAM,2BAAuB,sBAAS,cAAU,qBAAQ,QAAQ,CAAC;AAEjE,gBAAM,cAAc,GAAG,mBAAmB,IAAI,oBAAoB;AAElE,gBAAM;AAAA,YACJ;AAAA,YACA,KAAK,UAAU,mBAAmB,MAAM,CAAC;AAAA,UAC3C;AAEA,iBAAO;AAAA,YACL,QAAQ;AAAA,YACR,MAAM;AAAA,UACR;AAAA,QACF;AAAA,MACF,OAAO;AAEL,cAAM,yBAAyB,GAAG,yBAAyB,IAAI,kBAAkB,GAAG;AACpF,cAAM;AAAA,UACJ;AAAA,UACA,KAAK,UAAU,mBAAmB,MAAM,CAAC;AAAA,QAC3C;AACA,eAAO;AAAA,UACL,QAAQ;AAAA,UACR,MAAM;AAAA,QACR;AAAA,MACF;AAAA,IACF;AAAA,EACF,OAAO;AAEL,UAAM,yBAAyB,GAAG,yBAAyB,IAAI,kBAAkB,GAAG;AAEpF,UAAM;AAAA,MACJ;AAAA,MACA,KAAK,UAAU,mBAAmB,MAAM,CAAC;AAAA,IAC3C;AAEA,WAAO;AAAA,MACL,QAAQ;AAAA,MACR,MAAM;AAAA,IACR;AAAA,EACF;AACF;AAEA,MAAM,2BAA2B,OAC/B,UACA,SACkB;AAClB,MAAI;AAEF,UAAM,UAAM,qBAAQ,QAAQ;AAG5B,UAAM,sBAAkB,sBAAW,GAAG;AAEtC,QAAI,CAAC,iBAAiB;AAEpB,YAAM,WAAW,MAAM,KAAK,EAAE,WAAW,KAAK,CAAC;AAAA,IACjD;AAGA,UAAM,WAAW,UAAU,UAAU,IAAI;AAAA,EAC3C,SAAS,OAAO;AACd,UAAM,IAAI,MAAM,yBAAyB,QAAQ,KAAK,KAAK,EAAE;AAAA,EAC/D;AACF;","names":["dictionariesRecord","deepEqual"]}
1
+ {"version":3,"sources":["../../../src/server/writeContentDeclaration.ts"],"sourcesContent":["import { existsSync } from 'fs';\nimport * as fsPromises from 'fs/promises';\nimport { basename, dirname, extname } from 'path';\nimport { getConfiguration, IntlayerConfig } from '@intlayer/config/client';\nimport { Dictionary } from '@intlayer/core';\nimport dictionariesRecord from '@intlayer/dictionaries-entry';\nimport deepEqual from 'deep-equal';\nimport { DictionaryStatus } from '../dictionaryStatus';\n\nconst DEFAULT_NEW_DICTIONARY_PATH = 'intlayer-dictionaries';\n\nexport const writeContentDeclaration = async (\n dictionary: Dictionary,\n config?: IntlayerConfig,\n newDictionariesPath?: string\n): Promise<{ status: DictionaryStatus; path: string }> => {\n const {\n content: { baseDir },\n } = config ?? getConfiguration();\n\n const newDictionaryRelativeLocationPath =\n newDictionariesPath ?? DEFAULT_NEW_DICTIONARY_PATH;\n const newDictionaryLocationPath = `${baseDir}/${newDictionaryRelativeLocationPath}`;\n\n const existingDictionary = dictionariesRecord[dictionary.key];\n\n if (existingDictionary) {\n const { filePath, ...dictionaryWithoutPath } = dictionary;\n\n // Compare existing dictionary with distant dictionary\n if (deepEqual(existingDictionary, dictionary)) {\n // Up to date, nothing to do\n return {\n status: 'up-to-date',\n path: filePath!,\n };\n } else {\n if (filePath) {\n const isDictionaryJSON = filePath.endsWith('.json');\n\n if (isDictionaryJSON) {\n const contentDeclarationPath = `${baseDir}/${filePath}`;\n // Write the dictionary to the same location of the existing dictionary file\n await fsPromises.writeFile(\n contentDeclarationPath,\n JSON.stringify(dictionaryWithoutPath, null, 2)\n );\n return { status: 'updated', path: contentDeclarationPath };\n } else {\n // Write the dictionary to the intlayer-dictionaries directory\n const dictionariesDirPath = dirname(filePath);\n const dictionariesFileName = basename(filePath, extname(filePath));\n\n const newFilePath = `${dictionariesDirPath}/${dictionariesFileName}.json`;\n\n await writeFileWithDirectories(\n newFilePath,\n JSON.stringify(dictionaryWithoutPath, null, 2)\n );\n\n return {\n status: 'updated',\n path: newFilePath,\n };\n }\n } else {\n // Write the dictionary to the intlayer-dictionaries directory\n const contentDeclarationPath = `${newDictionaryLocationPath}/${dictionary.key}.content.json`;\n await writeFileWithDirectories(\n contentDeclarationPath,\n JSON.stringify(dictionaryWithoutPath, null, 2)\n );\n return {\n status: 'reimported in new location',\n path: contentDeclarationPath,\n };\n }\n }\n } else {\n // No existing dictionary, write to new location\n const contentDeclarationPath = `${newDictionaryLocationPath}/${dictionary.key}.content.json`;\n\n await writeFileWithDirectories(\n contentDeclarationPath,\n JSON.stringify(dictionary, null, 2)\n );\n\n return {\n status: 'imported',\n path: contentDeclarationPath,\n };\n }\n};\n\nconst writeFileWithDirectories = async (\n filePath: string,\n data: string | Buffer\n): Promise<void> => {\n try {\n // Extract the directory from the file path\n const dir = dirname(filePath);\n\n // Check if the directory exists\n const directoryExists = existsSync(dir);\n\n if (!directoryExists) {\n // Create the directory recursively\n await fsPromises.mkdir(dir, { recursive: true });\n }\n\n // Write the file\n await fsPromises.writeFile(filePath, data);\n } catch (error) {\n throw new Error(`Error writing file to ${filePath}: ${error}`);\n }\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,gBAA2B;AAC3B,iBAA4B;AAC5B,kBAA2C;AAC3C,oBAAiD;AAEjD,gCAA+B;AAC/B,wBAAsB;AAGtB,MAAM,8BAA8B;AAE7B,MAAM,0BAA0B,OACrC,YACA,QACA,wBACwD;AACxD,QAAM;AAAA,IACJ,SAAS,EAAE,QAAQ;AAAA,EACrB,IAAI,cAAU,gCAAiB;AAE/B,QAAM,oCACJ,uBAAuB;AACzB,QAAM,4BAA4B,GAAG,OAAO,IAAI,iCAAiC;AAEjF,QAAM,qBAAqB,0BAAAA,QAAmB,WAAW,GAAG;AAE5D,MAAI,oBAAoB;AACtB,UAAM,EAAE,UAAU,GAAG,sBAAsB,IAAI;AAG/C,YAAI,kBAAAC,SAAU,oBAAoB,UAAU,GAAG;AAE7C,aAAO;AAAA,QACL,QAAQ;AAAA,QACR,MAAM;AAAA,MACR;AAAA,IACF,OAAO;AACL,UAAI,UAAU;AACZ,cAAM,mBAAmB,SAAS,SAAS,OAAO;AAElD,YAAI,kBAAkB;AACpB,gBAAM,yBAAyB,GAAG,OAAO,IAAI,QAAQ;AAErD,gBAAM,WAAW;AAAA,YACf;AAAA,YACA,KAAK,UAAU,uBAAuB,MAAM,CAAC;AAAA,UAC/C;AACA,i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
  import dictionariesRecord from "@intlayer/dictionaries-entry";
6
6
  import deepEqual from "deep-equal";
7
7
  const DEFAULT_NEW_DICTIONARY_PATH = "intlayer-dictionaries";
8
- const writeContentDeclaration = async (distantDictionary, config, newDictionariesPath) => {
8
+ const writeContentDeclaration = async (dictionary, config, newDictionariesPath) => {
9
9
  const {
10
10
  content: { baseDir }
11
11
  } = config ?? getConfiguration();
12
12
  const newDictionaryRelativeLocationPath = newDictionariesPath ?? DEFAULT_NEW_DICTIONARY_PATH;
13
13
  const newDictionaryLocationPath = `${baseDir}/${newDictionaryRelativeLocationPath}`;
14
- const existingDictionary = dictionariesRecord[distantDictionary.key];
14
+ const existingDictionary = dictionariesRecord[dictionary.key];
15
15
  if (existingDictionary) {
16
- const { filePath } = existingDictionary;
17
- if (deepEqual(existingDictionary, distantDictionary)) {
16
+ const { filePath, ...dictionaryWithoutPath } = dictionary;
17
+ if (deepEqual(existingDictionary, dictionary)) {
18
18
  return {
19
19
  status: "up-to-date",
20
20
  path: filePath
@@ -26,7 +26,7 @@ const writeContentDeclaration = async (distantDictionary, config, newDictionarie
26
26
  const contentDeclarationPath = `${baseDir}/${filePath}`;
27
27
  await fsPromises.writeFile(
28
28
  contentDeclarationPath,
29
- JSON.stringify(distantDictionary, null, 2)
29
+ JSON.stringify(dictionaryWithoutPath, null, 2)
30
30
  );
31
31
  return { status: "updated", path: contentDeclarationPath };
32
32
  } else {
@@ -35,7 +35,7 @@ const writeContentDeclaration = async (distantDictionary, config, newDictionarie
35
35
  const newFilePath = `${dictionariesDirPath}/${dictionariesFileName}.json`;
36
36
  await writeFileWithDirectories(
37
37
  newFilePath,
38
- JSON.stringify(distantDictionary, null, 2)
38
+ JSON.stringify(dictionaryWithoutPath, null, 2)
39
39
  );
40
40
  return {
41
41
  status: "updated",
@@ -43,10 +43,10 @@ const writeContentDeclaration = async (distantDictionary, config, newDictionarie
43
43
  };
44
44
  }
45
45
  } else {
46
- const contentDeclarationPath = `${newDictionaryLocationPath}/${distantDictionary.key}.content.json`;
46
+ const contentDeclarationPath = `${newDictionaryLocationPath}/${dictionary.key}.content.json`;
47
47
  await writeFileWithDirectories(
48
48
  contentDeclarationPath,
49
- JSON.stringify(distantDictionary, null, 2)
49
+ JSON.stringify(dictionaryWithoutPath, null, 2)
50
50
  );
51
51
  return {
52
52
  status: "reimported in new location",
@@ -55,10 +55,10 @@ const writeContentDeclaration = async (distantDictionary, config, newDictionarie
55
55
  }
56
56
  }
57
57
  } else {
58
- const contentDeclarationPath = `${newDictionaryLocationPath}/${distantDictionary.key}.content.json`;
58
+ const contentDeclarationPath = `${newDictionaryLocationPath}/${dictionary.key}.content.json`;
59
59
  await writeFileWithDirectories(
60
60
  contentDeclarationPath,
61
- JSON.stringify(distantDictionary, null, 2)
61
+ JSON.stringify(dictionary, null, 2)
62
62
  );
63
63
  return {
64
64
  status: "imported",
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/server/writeContentDeclaration.ts"],"sourcesContent":["import { existsSync } from 'fs';\nimport * as fsPromises from 'fs/promises';\nimport { basename, dirname, extname } from 'path';\nimport { getConfiguration, IntlayerConfig } from '@intlayer/config/client';\nimport { Dictionary } from '@intlayer/core';\nimport dictionariesRecord from '@intlayer/dictionaries-entry';\nimport deepEqual from 'deep-equal';\nimport { DictionaryStatus } from '../dictionaryStatus';\n\nconst DEFAULT_NEW_DICTIONARY_PATH = 'intlayer-dictionaries';\n\nexport const writeContentDeclaration = async (\n distantDictionary: Dictionary,\n config?: IntlayerConfig,\n newDictionariesPath?: string\n): Promise<{ status: DictionaryStatus; path: string }> => {\n const {\n content: { baseDir },\n } = config ?? getConfiguration();\n\n const newDictionaryRelativeLocationPath =\n newDictionariesPath ?? DEFAULT_NEW_DICTIONARY_PATH;\n const newDictionaryLocationPath = `${baseDir}/${newDictionaryRelativeLocationPath}`;\n\n const existingDictionary = dictionariesRecord[distantDictionary.key];\n\n if (existingDictionary) {\n const { filePath } = existingDictionary;\n\n // Compare existing dictionary with distant dictionary\n if (deepEqual(existingDictionary, distantDictionary)) {\n // Up to date, nothing to do\n return {\n status: 'up-to-date',\n path: filePath!,\n };\n } else {\n if (filePath) {\n const isDictionaryJSON = filePath.endsWith('.json');\n\n if (isDictionaryJSON) {\n const contentDeclarationPath = `${baseDir}/${filePath}`;\n // Write the dictionary to the same location of the existing dictionary file\n await fsPromises.writeFile(\n contentDeclarationPath,\n JSON.stringify(distantDictionary, null, 2)\n );\n return { status: 'updated', path: contentDeclarationPath };\n } else {\n // Write the dictionary to the intlayer-dictionaries directory\n const dictionariesDirPath = dirname(filePath);\n const dictionariesFileName = basename(filePath, extname(filePath));\n\n const newFilePath = `${dictionariesDirPath}/${dictionariesFileName}.json`;\n\n await writeFileWithDirectories(\n newFilePath,\n JSON.stringify(distantDictionary, null, 2)\n );\n\n return {\n status: 'updated',\n path: newFilePath,\n };\n }\n } else {\n // Write the dictionary to the intlayer-dictionaries directory\n const contentDeclarationPath = `${newDictionaryLocationPath}/${distantDictionary.key}.content.json`;\n await writeFileWithDirectories(\n contentDeclarationPath,\n JSON.stringify(distantDictionary, null, 2)\n );\n return {\n status: 'reimported in new location',\n path: contentDeclarationPath,\n };\n }\n }\n } else {\n // No existing dictionary, write to new location\n const contentDeclarationPath = `${newDictionaryLocationPath}/${distantDictionary.key}.content.json`;\n\n await writeFileWithDirectories(\n contentDeclarationPath,\n JSON.stringify(distantDictionary, null, 2)\n );\n\n return {\n status: 'imported',\n path: contentDeclarationPath,\n };\n }\n};\n\nconst writeFileWithDirectories = async (\n filePath: string,\n data: string | Buffer\n): Promise<void> => {\n try {\n // Extract the directory from the file path\n const dir = dirname(filePath);\n\n // Check if the directory exists\n const directoryExists = existsSync(dir);\n\n if (!directoryExists) {\n // Create the directory recursively\n await fsPromises.mkdir(dir, { recursive: true });\n }\n\n // Write the file\n await fsPromises.writeFile(filePath, data);\n } catch (error) {\n throw new Error(`Error writing file to ${filePath}: ${error}`);\n }\n};\n"],"mappings":"AAAA,SAAS,kBAAkB;AAC3B,Y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B,MAAM,CAAC;AAAA,QAC3C;AACA,eAAO;AAAA,UACL,QAAQ;AAAA,UACR,MAAM;AAAA,QACR;AAAA,MACF;AAAA,IACF;AAAA,EACF,OAAO;AAEL,UAAM,yBAAyB,GAAG,yBAAyB,IAAI,kBAAkB,GAAG;AAEpF,UAAM;AAAA,MACJ;AAAA,MACA,KAAK,UAAU,mBAAmB,MAAM,CAAC;AAAA,IAC3C;AAEA,WAAO;AAAA,MACL,QAAQ;AAAA,MACR,MAAM;AAAA,IACR;AAAA,EACF;AACF;AAEA,MAAM,2BAA2B,OAC/B,UACA,SACkB;AAClB,MAAI;AAEF,UAAM,MAAM,QAAQ,QAAQ;AAG5B,UAAM,kBAAkB,WAAW,GAAG;AAEtC,QAAI,CAAC,iBAAiB;AAEpB,YAAM,WAAW,MAAM,KAAK,EAAE,WAAW,KAAK,CAAC;AAAA,IACjD;AAGA,UAAM,WAAW,UAAU,UAAU,IAAI;AAAA,EAC3C,SAAS,OAAO;AACd,UAAM,IAAI,MAAM,yBAAyB,QAAQ,KAAK,KAAK,EAAE;AAAA,EAC/D;AACF;","names":[]}
1
+ {"version":3,"sources":["../../../src/server/writeContentDeclaration.ts"],"sourcesContent":["import { existsSync } from 'fs';\nimport * as fsPromises from 'fs/promises';\nimport { basename, dirname, extname } from 'path';\nimport { getConfiguration, IntlayerConfig } from '@intlayer/config/client';\nimport { Dictionary } from '@intlayer/core';\nimport dictionariesRecord from '@intlayer/dictionaries-entry';\nimport deepEqual from 'deep-equal';\nimport { DictionaryStatus } from '../dictionaryStatus';\n\nconst DEFAULT_NEW_DICTIONARY_PATH = 'intlayer-dictionaries';\n\nexport const writeContentDeclaration = async (\n dictionary: Dictionary,\n config?: IntlayerConfig,\n newDictionariesPath?: string\n): Promise<{ status: DictionaryStatus; path: string }> => {\n const {\n content: { baseDir },\n } = config ?? getConfiguration();\n\n const newDictionaryRelativeLocationPath =\n newDictionariesPath ?? DEFAULT_NEW_DICTIONARY_PATH;\n const newDictionaryLocationPath = `${baseDir}/${newDictionaryRelativeLocationPath}`;\n\n const existingDictionary = dictionariesRecord[dictionary.key];\n\n if (existingDictionary) {\n const { filePath, ...dictionaryWithoutPath } = dictionary;\n\n // Compare existing dictionary with distant dictionary\n if (deepEqual(existingDictionary, dictionary)) {\n // Up to date, nothing to do\n return {\n status: 'up-to-date',\n path: filePath!,\n };\n } else {\n if (filePath) {\n const isDictionaryJSON = filePath.endsWith('.json');\n\n if (isDictionaryJSON) {\n const contentDeclarationPath = `${baseDir}/${filePath}`;\n // Write the dictionary to the same location of the existing dictionary file\n await fsPromises.writeFile(\n contentDeclarationPath,\n JSON.stringify(dictionaryWithoutPath, null, 2)\n );\n return { status: 'updated', path: contentDeclarationPath };\n } else {\n // Write the dictionary to the intlayer-dictionaries directory\n const dictionariesDirPath = dirname(filePath);\n const dictionariesFileName = basename(filePath, extname(filePath));\n\n const newFilePath = `${dictionariesDirPath}/${dictionariesFileName}.json`;\n\n await writeFileWithDirectories(\n newFilePath,\n JSON.stringify(dictionaryWithoutPath, null, 2)\n );\n\n return {\n status: 'updated',\n path: newFilePath,\n };\n }\n } else {\n // Write the dictionary to the intlayer-dictionaries directory\n const contentDeclarationPath = `${newDictionaryLocationPath}/${dictionary.key}.content.json`;\n await writeFileWithDirectories(\n contentDeclarationPath,\n JSON.stringify(dictionaryWithoutPath, null, 2)\n );\n return {\n status: 'reimported in new location',\n path: contentDeclarationPath,\n };\n }\n }\n } else {\n // No existing dictionary, write to new location\n const contentDeclarationPath = `${newDictionaryLocationPath}/${dictionary.key}.content.json`;\n\n await writeFileWithDirectories(\n contentDeclarationPath,\n JSON.stringify(dictionary, null, 2)\n );\n\n return {\n status: 'imported',\n path: contentDeclarationPath,\n };\n }\n};\n\nconst writeFileWithDirectories = async (\n filePath: string,\n data: string | Buffer\n): Promise<void> => {\n try {\n // Extract the directory from the file path\n const dir = dirname(filePath);\n\n // Check if the directory exists\n const directoryExists = existsSync(dir);\n\n if (!directoryExists) {\n // Create the directory recursively\n await fsPromises.mkdir(dir, { recursive: true });\n }\n\n // Write the file\n await fsPromises.writeFile(filePath, data);\n } catch (error) {\n throw new Error(`Error writing file to ${filePath}: ${error}`);\n }\n};\n"],"mappings":"AAAA,SAAS,kBAAkB;AAC3B,YAAY,gBAAgB;AAC5B,SAAS,UAAU,SAAS,eAAe;AAC3C,SAAS,wBAAwC;AAEjD,OAAO,wBAAwB;AAC/B,OAAO,eAAe;AAGtB,MAAM,8BAA8B;AAE7B,MAAM,0BAA0B,OACrC,YACA,QACA,wBACwD;AACxD,QAAM;AAAA,IACJ,SAAS,EAAE,QAAQ;AAAA,EACrB,IAAI,UAAU,iBAAiB;AAE/B,QAAM,oCACJ,uBAAuB;AACzB,QAAM,4BAA4B,GAAG,OAAO,IAAI,iCAAiC;AAEjF,QAAM,qBAAqB,mBAAmB,WAAW,GAAG;AAE5D,MAAI,oBAAoB;AACtB,UAAM,EAAE,UAAU,GAAG,sBAAsB,IAAI;AAG/C,QAAI,UAAU,oBAAoB,UAAU,GAAG;AAE7C,aAAO;AAAA,QACL,QAAQ;AAAA,QACR,MAAM;AAAA,MACR;AAAA,IACF,OAAO;AACL,UAAI,UAAU;AACZ,cAAM,mBAAmB,SAAS,SAAS,OAAO;AAElD,YAAI,kBAAkB;AACpB,gBAAM,yBAAyB,GAAG,OAAO,IAAI,QAAQ;AAErD,gBAAM,WAAW;AAAA,YACf;AAAA,YACA,KAAK,UAAU,uBAAuB,MAAM,CAAC;AAAA,UAC/C;AACA,iBAAO,EAAE,QAAQ,WAAW,MAAM,uBAAuB;AAAA,QAC3D,OAAO;AAEL,gBAAM,sBAAsB,QAAQ,QAAQ;AAC5C,gBAAM,uBAAuB,SAAS,UAAU,QAAQ,QAAQ,CAAC;AAEjE,gBAAM,cAAc,GAAG,mBAAmB,IAAI,oBAAoB;AAElE,gBAAM;AAAA,YACJ;AAAA,YACA,KAAK,UAAU,uBAAuB,MAAM,CAAC;AAAA,UAC/C;AAEA,iBAAO;AAAA,YACL,QAAQ;AAAA,YACR,MAAM;AAAA,UACR;AAAA,QACF;AAAA,MACF,OAAO;AAEL,cAAM,yBAAyB,GAAG,yBAAyB,IAAI,WAAW,GAAG;AAC7E,cAAM;AAAA,UACJ;AAAA,UACA,KAAK,UAAU,uBAAuB,MAAM,CAAC;AAAA,QAC/C;AACA,eAAO;AAAA,UACL,QAAQ;AAAA,UACR,MAAM;AAAA,QACR;AAAA,MACF;AAAA,IACF;AAAA,EACF,OAAO;AAEL,UAAM,yBAAyB,GAAG,yBAAyB,IAAI,WAAW,GAAG;AAE7E,UAAM;AAAA,MACJ;AAAA,MACA,KAAK,UAAU,YAAY,MAAM,CAAC;AAAA,IACpC;AAEA,WAAO;AAAA,MACL,QAAQ;AAAA,MACR,MAAM;AAAA,IACR;AAAA,EACF;AACF;AAEA,MAAM,2BAA2B,OAC/B,UACA,SACkB;AAClB,MAAI;AAEF,UAAM,MAAM,QAAQ,QAAQ;AAG5B,UAAM,kBAAkB,WAAW,GAAG;AAEtC,QAAI,CAAC,iBAAiB;AAEpB,YAAM,WAAW,MAAM,KAAK,EAAE,WAAW,KAAK,CAAC;AAAA,IACjD;AAGA,UAAM,WAAW,UAAU,UAAU,IAAI;AAAA,EAC3C,SAAS,OAAO;AACd,UAAM,IAAI,MAAM,yBAAyB,QAAQ,KAAK,KAAK,EAAE;AAAA,EAC/D;AACF;","names":[]}
@@ -1,7 +1,7 @@
1
1
  import { IntlayerConfig } from '@intlayer/config/client';
2
2
  import { Dictionary } from '@intlayer/core';
3
3
  import { DictionaryStatus } from '../dictionaryStatus';
4
- export declare const writeContentDeclaration: (distantDictionary: Dictionary, config?: IntlayerConfig, newDictionariesPath?: string) => Promise<{
4
+ export declare const writeContentDeclaration: (dictionary: Dictionary, config?: IntlayerConfig, newDictionariesPath?: string) => Promise<{
5
5
  status: DictionaryStatus;
6
6
  path: string;
7
7
  }>;
@@ -1 +1 @@
1
- {"version":3,"file":"writeContentDeclaration.d.ts","sourceRoot":"","sources":["../../../src/server/writeContentDeclaration.ts"],"names":[],"mappings":"AAGA,OAAO,EAAoB,cAAc,EAAE,MAAM,yBAAyB,CAAC;AAC3E,OAAO,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAG5C,OAAO,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AAIvD,eAAO,MAAM,uBAAuB,sBACf,UAAU,WACpB,cAAc,wBACD,MAAM,KAC3B,OAAO,CAAC;IAAE,MAAM,EAAE,gBAAgB,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,CA6EpD,CAAC"}
1
+ {"version":3,"file":"writeContentDeclaration.d.ts","sourceRoot":"","sources":["../../../src/server/writeContentDeclaration.ts"],"names":[],"mappings":"AAGA,OAAO,EAAoB,cAAc,EAAE,MAAM,yBAAyB,CAAC;AAC3E,OAAO,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAG5C,OAAO,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AAIvD,eAAO,MAAM,uBAAuB,eACtB,UAAU,WACb,cAAc,wBACD,MAAM,KAC3B,OAAO,CAAC;IAAE,MAAM,EAAE,gBAAgB,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,CA6EpD,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@intlayer/editor",
3
- "version": "4.1.1",
3
+ "version": "4.1.3",
4
4
  "private": false,
5
5
  "description": "Provides the utilities to interface the application with the Intlayer editor and manipulate dictionaries",
6
6
  "keywords": [
@@ -57,9 +57,9 @@
57
57
  ],
58
58
  "dependencies": {
59
59
  "deep-equal": "^2.2.3",
60
- "@intlayer/config": "4.1.1",
61
- "@intlayer/core": "4.1.1",
62
- "@intlayer/dictionaries-entry": "4.1.1"
60
+ "@intlayer/dictionaries-entry": "4.1.3",
61
+ "@intlayer/core": "4.1.3",
62
+ "@intlayer/config": "4.1.3"
63
63
  },
64
64
  "devDependencies": {
65
65
  "@types/deep-equal": "^1.0.4",
@@ -78,9 +78,9 @@
78
78
  "@utils/tsup-config": "1.0.4"
79
79
  },
80
80
  "peerDependencies": {
81
- "@intlayer/config": "4.1.1",
82
- "@intlayer/core": "4.1.1",
83
- "@intlayer/dictionaries-entry": "4.1.1"
81
+ "@intlayer/config": "4.1.3",
82
+ "@intlayer/dictionaries-entry": "4.1.3",
83
+ "@intlayer/core": "4.1.3"
84
84
  },
85
85
  "engines": {
86
86
  "node": ">=14.18"