@intlayer/editor 4.0.4 → 4.0.5

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.
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __copyProps = (to, from, except, desc) => {
7
+ if (from && typeof from === "object" || typeof from === "function") {
8
+ for (let key of __getOwnPropNames(from))
9
+ if (!__hasOwnProp.call(to, key) && key !== except)
10
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
11
+ }
12
+ return to;
13
+ };
14
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
15
+ var dictionaryStatus_exports = {};
16
+ module.exports = __toCommonJS(dictionaryStatus_exports);
17
+ //# sourceMappingURL=dictionaryStatus.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/dictionaryStatus.ts"],"sourcesContent":["export type DictionaryStatus =\n | 'pending'\n | 'fetching'\n | 'up-to-date'\n | 'updated'\n | 'fetched'\n | 'unknown'\n | 'error'\n | 'imported'\n | 'reimported in JSON'\n | 'reimported in new location';\n"],"mappings":";;;;;;;;;;;;;;AAAA;AAAA;","names":[]}
@@ -16,8 +16,10 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
16
16
  var index_exports = {};
17
17
  module.exports = __toCommonJS(index_exports);
18
18
  __reExport(index_exports, require('./dictionaryManipulator/index.cjs'), module.exports);
19
+ __reExport(index_exports, require('./dictionaryStatus.cjs'), module.exports);
19
20
  // Annotate the CommonJS export names for ESM import in node:
20
21
  0 && (module.exports = {
21
- ...require('./dictionaryManipulator/index.cjs')
22
+ ...require('./dictionaryManipulator/index.cjs'),
23
+ ...require('./dictionaryStatus.cjs')
22
24
  });
23
25
  //# sourceMappingURL=index.cjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/index.ts"],"sourcesContent":["export * from './dictionaryManipulator/index';\n"],"mappings":";;;;;;;;;;;;;;;AAAA;AAAA;AAAA,0BAAc,0CAAd;","names":[]}
1
+ {"version":3,"sources":["../../src/index.ts"],"sourcesContent":["export * from './dictionaryManipulator/index';\nexport * from './dictionaryStatus';\n"],"mappings":";;;;;;;;;;;;;;;AAAA;AAAA;AAAA,0BAAc,0CAAd;AACA,0BAAc,+BADd;","names":[]}
@@ -0,0 +1,23 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __copyProps = (to, from, except, desc) => {
7
+ if (from && typeof from === "object" || typeof from === "function") {
8
+ for (let key of __getOwnPropNames(from))
9
+ if (!__hasOwnProp.call(to, key) && key !== except)
10
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
11
+ }
12
+ return to;
13
+ };
14
+ var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
15
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
16
+ var server_exports = {};
17
+ module.exports = __toCommonJS(server_exports);
18
+ __reExport(server_exports, require('./writeContentDeclaration.cjs'), module.exports);
19
+ // Annotate the CommonJS export names for ESM import in node:
20
+ 0 && (module.exports = {
21
+ ...require('./writeContentDeclaration.cjs')
22
+ });
23
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/server/index.ts"],"sourcesContent":["export * from './writeContentDeclaration';\n"],"mappings":";;;;;;;;;;;;;;;AAAA;AAAA;AAAA,2BAAc,sCAAd;","names":[]}
@@ -0,0 +1,118 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+ var writeContentDeclaration_exports = {};
30
+ __export(writeContentDeclaration_exports, {
31
+ writeContentDeclaration: () => writeContentDeclaration
32
+ });
33
+ module.exports = __toCommonJS(writeContentDeclaration_exports);
34
+ var import_fs = require("fs");
35
+ var fsPromises = __toESM(require("fs/promises"));
36
+ var import_path = require("path");
37
+ var import_client = require("@intlayer/config/client");
38
+ var import_dictionaries_entry = __toESM(require("@intlayer/dictionaries-entry"));
39
+ var import_deep_equal = __toESM(require("deep-equal"));
40
+ const DEFAULT_NEW_DICTIONARY_PATH = "intlayer-dictionaries";
41
+ const writeContentDeclaration = async (distantDictionary, config, newDictionariesPath) => {
42
+ const {
43
+ content: { baseDir }
44
+ } = config ?? (0, import_client.getConfiguration)();
45
+ const newDictionaryRelativeLocationPath = newDictionariesPath ?? DEFAULT_NEW_DICTIONARY_PATH;
46
+ const newDictionaryLocationPath = `${baseDir}/${newDictionaryRelativeLocationPath}`;
47
+ const existingDictionary = import_dictionaries_entry.default[distantDictionary.key];
48
+ if (existingDictionary) {
49
+ const { filePath } = existingDictionary;
50
+ if ((0, import_deep_equal.default)(existingDictionary, distantDictionary)) {
51
+ return {
52
+ status: "up-to-date",
53
+ path: filePath
54
+ };
55
+ } else {
56
+ if (filePath) {
57
+ const isDictionaryJSON = filePath.endsWith(".json");
58
+ if (isDictionaryJSON) {
59
+ const contentDeclarationPath = `${baseDir}/${filePath}`;
60
+ await fsPromises.writeFile(
61
+ contentDeclarationPath,
62
+ JSON.stringify(distantDictionary, null, 2)
63
+ );
64
+ return { status: "updated", path: contentDeclarationPath };
65
+ } else {
66
+ const dictionariesDirPath = (0, import_path.dirname)(filePath);
67
+ const dictionariesFileName = (0, import_path.basename)(filePath, (0, import_path.extname)(filePath));
68
+ const newFilePath = `${dictionariesDirPath}/${dictionariesFileName}.json`;
69
+ await writeFileWithDirectories(
70
+ newFilePath,
71
+ JSON.stringify(distantDictionary, null, 2)
72
+ );
73
+ return {
74
+ status: "updated",
75
+ path: newFilePath
76
+ };
77
+ }
78
+ } else {
79
+ const contentDeclarationPath = `${newDictionaryLocationPath}/${distantDictionary.key}.content.json`;
80
+ await writeFileWithDirectories(
81
+ contentDeclarationPath,
82
+ JSON.stringify(distantDictionary, null, 2)
83
+ );
84
+ return {
85
+ status: "reimported in new location",
86
+ path: contentDeclarationPath
87
+ };
88
+ }
89
+ }
90
+ } else {
91
+ const contentDeclarationPath = `${newDictionaryLocationPath}/${distantDictionary.key}.content.json`;
92
+ await writeFileWithDirectories(
93
+ contentDeclarationPath,
94
+ JSON.stringify(distantDictionary, null, 2)
95
+ );
96
+ return {
97
+ status: "imported",
98
+ path: contentDeclarationPath
99
+ };
100
+ }
101
+ };
102
+ const writeFileWithDirectories = async (filePath, data) => {
103
+ try {
104
+ const dir = (0, import_path.dirname)(filePath);
105
+ const directoryExists = (0, import_fs.existsSync)(dir);
106
+ if (!directoryExists) {
107
+ await fsPromises.mkdir(dir, { recursive: true });
108
+ }
109
+ await fsPromises.writeFile(filePath, data);
110
+ } catch (error) {
111
+ throw new Error(`Error writing file to ${filePath}: ${error}`);
112
+ }
113
+ };
114
+ // Annotate the CommonJS export names for ESM import in node:
115
+ 0 && (module.exports = {
116
+ writeContentDeclaration
117
+ });
118
+ //# sourceMappingURL=writeContentDeclaration.cjs.map
@@ -0,0 +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;A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,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,7 +1,7 @@
1
1
  import {
2
2
  NodeType
3
3
  } from "@intlayer/core";
4
- import { isValidElement } from './isValidReactElement.mjs';
4
+ import { isValidElement } from "./isValidReactElement.mjs";
5
5
  const getSectionType = (section) => {
6
6
  if (typeof section === "string") {
7
7
  return NodeType.Text;
@@ -1,6 +1,6 @@
1
- export * from './editDictionaryByKeyPath.mjs';
2
- export * from './getDictionaryValueByKeyPath.mjs';
3
- export * from './getSectionType.mjs';
4
- export * from './removeDictionaryValueByKeyPath.mjs';
5
- export * from './renameDictionaryValueByKeyPath.mjs';
1
+ export * from "./editDictionaryByKeyPath.mjs";
2
+ export * from "./getDictionaryValueByKeyPath.mjs";
3
+ export * from "./getSectionType.mjs";
4
+ export * from "./removeDictionaryValueByKeyPath.mjs";
5
+ export * from "./renameDictionaryValueByKeyPath.mjs";
6
6
  //# sourceMappingURL=index.mjs.map
@@ -0,0 +1 @@
1
+ //# sourceMappingURL=dictionaryStatus.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
@@ -1,2 +1,3 @@
1
- export * from './dictionaryManipulator/index.mjs';
1
+ export * from "./dictionaryManipulator/index.mjs";
2
+ export * from "./dictionaryStatus.mjs";
2
3
  //# sourceMappingURL=index.mjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/index.ts"],"sourcesContent":["export * from './dictionaryManipulator/index';\n"],"mappings":"AAAA,cAAc;","names":[]}
1
+ {"version":3,"sources":["../../src/index.ts"],"sourcesContent":["export * from './dictionaryManipulator/index';\nexport * from './dictionaryStatus';\n"],"mappings":"AAAA,cAAc;AACd,cAAc;","names":[]}
@@ -0,0 +1,2 @@
1
+ export * from "./writeContentDeclaration.mjs";
2
+ //# sourceMappingURL=index.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/server/index.ts"],"sourcesContent":["export * from './writeContentDeclaration';\n"],"mappings":"AAAA,cAAc;","names":[]}
@@ -0,0 +1,84 @@
1
+ import { existsSync } from "fs";
2
+ import * as fsPromises from "fs/promises";
3
+ import { basename, dirname, extname } from "path";
4
+ import { getConfiguration } from "@intlayer/config/client";
5
+ import dictionariesRecord from "@intlayer/dictionaries-entry";
6
+ import deepEqual from "deep-equal";
7
+ const DEFAULT_NEW_DICTIONARY_PATH = "intlayer-dictionaries";
8
+ const writeContentDeclaration = async (distantDictionary, config, newDictionariesPath) => {
9
+ const {
10
+ content: { baseDir }
11
+ } = config ?? getConfiguration();
12
+ const newDictionaryRelativeLocationPath = newDictionariesPath ?? DEFAULT_NEW_DICTIONARY_PATH;
13
+ const newDictionaryLocationPath = `${baseDir}/${newDictionaryRelativeLocationPath}`;
14
+ const existingDictionary = dictionariesRecord[distantDictionary.key];
15
+ if (existingDictionary) {
16
+ const { filePath } = existingDictionary;
17
+ if (deepEqual(existingDictionary, distantDictionary)) {
18
+ return {
19
+ status: "up-to-date",
20
+ path: filePath
21
+ };
22
+ } else {
23
+ if (filePath) {
24
+ const isDictionaryJSON = filePath.endsWith(".json");
25
+ if (isDictionaryJSON) {
26
+ const contentDeclarationPath = `${baseDir}/${filePath}`;
27
+ await fsPromises.writeFile(
28
+ contentDeclarationPath,
29
+ JSON.stringify(distantDictionary, null, 2)
30
+ );
31
+ return { status: "updated", path: contentDeclarationPath };
32
+ } else {
33
+ const dictionariesDirPath = dirname(filePath);
34
+ const dictionariesFileName = basename(filePath, extname(filePath));
35
+ const newFilePath = `${dictionariesDirPath}/${dictionariesFileName}.json`;
36
+ await writeFileWithDirectories(
37
+ newFilePath,
38
+ JSON.stringify(distantDictionary, null, 2)
39
+ );
40
+ return {
41
+ status: "updated",
42
+ path: newFilePath
43
+ };
44
+ }
45
+ } else {
46
+ const contentDeclarationPath = `${newDictionaryLocationPath}/${distantDictionary.key}.content.json`;
47
+ await writeFileWithDirectories(
48
+ contentDeclarationPath,
49
+ JSON.stringify(distantDictionary, null, 2)
50
+ );
51
+ return {
52
+ status: "reimported in new location",
53
+ path: contentDeclarationPath
54
+ };
55
+ }
56
+ }
57
+ } else {
58
+ const contentDeclarationPath = `${newDictionaryLocationPath}/${distantDictionary.key}.content.json`;
59
+ await writeFileWithDirectories(
60
+ contentDeclarationPath,
61
+ JSON.stringify(distantDictionary, null, 2)
62
+ );
63
+ return {
64
+ status: "imported",
65
+ path: contentDeclarationPath
66
+ };
67
+ }
68
+ };
69
+ const writeFileWithDirectories = async (filePath, data) => {
70
+ try {
71
+ const dir = dirname(filePath);
72
+ const directoryExists = existsSync(dir);
73
+ if (!directoryExists) {
74
+ await fsPromises.mkdir(dir, { recursive: true });
75
+ }
76
+ await fsPromises.writeFile(filePath, data);
77
+ } catch (error) {
78
+ throw new Error(`Error writing file to ${filePath}: ${error}`);
79
+ }
80
+ };
81
+ export {
82
+ writeContentDeclaration
83
+ };
84
+ //# sourceMappingURL=writeContentDeclaration.mjs.map
@@ -0,0 +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,YAAY,gBAAgB;AAC5B,SAAS,UAAU,SAAS,eAAe;AAC3C,SAAS,wBAAwC;AAEjD,OAAO,wBAAwB;AAC/B,OAAO,eAAe;AAGtB,MAAM,8BAA8B;AAE7B,MAAM,0BAA0B,OACrC,mBACA,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,kBAAkB,GAAG;AAEnE,MAAI,oBAAoB;AACtB,UAAM,EAAE,SAAS,IAAI;AAGrB,QAAI,UAAU,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,Y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AO;AACd,UAAM,IAAI,MAAM,yBAAyB,QAAQ,KAAK,KAAK,EAAE;AAAA,EAC/D;AACF;","names":[]}
@@ -0,0 +1,2 @@
1
+ export type DictionaryStatus = 'pending' | 'fetching' | 'up-to-date' | 'updated' | 'fetched' | 'unknown' | 'error' | 'imported' | 'reimported in JSON' | 'reimported in new location';
2
+ //# sourceMappingURL=dictionaryStatus.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"dictionaryStatus.d.ts","sourceRoot":"","sources":["../../src/dictionaryStatus.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,gBAAgB,GACxB,SAAS,GACT,UAAU,GACV,YAAY,GACZ,SAAS,GACT,SAAS,GACT,SAAS,GACT,OAAO,GACP,UAAU,GACV,oBAAoB,GACpB,4BAA4B,CAAC"}
@@ -1,2 +1,3 @@
1
1
  export * from './dictionaryManipulator/index';
2
+ export * from './dictionaryStatus';
2
3
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,+BAA+B,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,+BAA+B,CAAC;AAC9C,cAAc,oBAAoB,CAAC"}
@@ -0,0 +1,2 @@
1
+ export * from './writeContentDeclaration';
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/server/index.ts"],"names":[],"mappings":"AAAA,cAAc,2BAA2B,CAAC"}
@@ -0,0 +1,8 @@
1
+ import { IntlayerConfig } from '@intlayer/config/client';
2
+ import { Dictionary } from '@intlayer/core';
3
+ import { DictionaryStatus } from '../dictionaryStatus';
4
+ export declare const writeContentDeclaration: (distantDictionary: Dictionary, config?: IntlayerConfig, newDictionariesPath?: string) => Promise<{
5
+ status: DictionaryStatus;
6
+ path: string;
7
+ }>;
8
+ //# sourceMappingURL=writeContentDeclaration.d.ts.map
@@ -0,0 +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"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@intlayer/editor",
3
- "version": "4.0.4",
3
+ "version": "4.0.5",
4
4
  "private": false,
5
5
  "description": "Provides the utilities to interface the application with the Intlayer editor and manipulate dictionaries",
6
6
  "keywords": [
@@ -34,6 +34,11 @@
34
34
  "require": "./dist/cjs/index.cjs",
35
35
  "import": "./dist/esm/index.mjs"
36
36
  },
37
+ "./server": {
38
+ "types": "./dist/types/server/index.d.ts",
39
+ "require": "./dist/cjs/server/index.cjs",
40
+ "import": "./dist/esm/server/index.mjs"
41
+ },
37
42
  "./package.json": "./package.json"
38
43
  },
39
44
  "main": "dist/cjs/index.cjs",
@@ -51,9 +56,13 @@
51
56
  "./package.json"
52
57
  ],
53
58
  "dependencies": {
54
- "@intlayer/core": "4.0.4"
59
+ "deep-equal": "^2.2.3",
60
+ "@intlayer/config": "4.0.5",
61
+ "@intlayer/dictionaries-entry": "4.0.5",
62
+ "@intlayer/core": "4.0.5"
55
63
  },
56
64
  "devDependencies": {
65
+ "@types/deep-equal": "^1.0.4",
57
66
  "@types/node": "^22.10.6",
58
67
  "@typescript-eslint/parser": "^8.20.0",
59
68
  "concurrently": "^9.1.2",
@@ -63,13 +72,15 @@
63
72
  "tsc-alias": "^1.8.10",
64
73
  "tsup": "^8.3.5",
65
74
  "typescript": "^5.7.3",
66
- "@utils/ts-config": "1.0.4",
67
75
  "@utils/eslint-config": "1.0.4",
76
+ "@utils/tsup-config": "1.0.4",
68
77
  "@utils/ts-config-types": "1.0.4",
69
- "@utils/tsup-config": "1.0.4"
78
+ "@utils/ts-config": "1.0.4"
70
79
  },
71
80
  "peerDependencies": {
72
- "@intlayer/core": "4.0.4"
81
+ "@intlayer/config": "4.0.5",
82
+ "@intlayer/core": "4.0.5",
83
+ "@intlayer/dictionaries-entry": "4.0.5"
73
84
  },
74
85
  "engines": {
75
86
  "node": ">=14.18"