@intlayer/editor 5.3.3 → 5.3.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/index.cjs +0 -21
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/esm/index.mjs +0 -1
- package/dist/esm/index.mjs.map +1 -1
- package/dist/types/index.d.ts +0 -1
- package/dist/types/index.d.ts.map +1 -1
- package/package.json +1 -13
- package/dist/cjs/dictionaryStatus.cjs +0 -17
- package/dist/cjs/dictionaryStatus.cjs.map +0 -1
- package/dist/cjs/server/index.cjs +0 -23
- package/dist/cjs/server/index.cjs.map +0 -1
- package/dist/cjs/server/writeContentDeclaration.cjs +0 -124
- package/dist/cjs/server/writeContentDeclaration.cjs.map +0 -1
- package/dist/esm/dictionaryStatus.mjs +0 -1
- package/dist/esm/dictionaryStatus.mjs.map +0 -1
- package/dist/esm/server/index.mjs +0 -2
- package/dist/esm/server/index.mjs.map +0 -1
- package/dist/esm/server/writeContentDeclaration.mjs +0 -90
- package/dist/esm/server/writeContentDeclaration.mjs.map +0 -1
- package/dist/types/dictionaryStatus.d.ts +0 -2
- package/dist/types/dictionaryStatus.d.ts.map +0 -1
- package/dist/types/server/index.d.ts +0 -2
- package/dist/types/server/index.d.ts.map +0 -1
- package/dist/types/server/writeContentDeclaration.d.ts +0 -8
- package/dist/types/server/writeContentDeclaration.d.ts.map +0 -1
package/dist/cjs/index.cjs
CHANGED
|
@@ -1,23 +1,2 @@
|
|
|
1
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 index_exports = {};
|
|
17
|
-
module.exports = __toCommonJS(index_exports);
|
|
18
|
-
__reExport(index_exports, require('./dictionaryStatus.cjs'), module.exports);
|
|
19
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
20
|
-
0 && (module.exports = {
|
|
21
|
-
...require('./dictionaryStatus.cjs')
|
|
22
|
-
});
|
|
23
2
|
//# sourceMappingURL=index.cjs.map
|
package/dist/cjs/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":[
|
|
1
|
+
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
package/dist/esm/index.mjs
CHANGED
package/dist/esm/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":[
|
|
1
|
+
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
package/dist/types/index.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":""}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@intlayer/editor",
|
|
3
|
-
"version": "5.3.
|
|
3
|
+
"version": "5.3.4",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "Provides the utilities to interface the application with the Intlayer editor and manipulate dictionaries",
|
|
6
6
|
"keywords": [
|
|
@@ -56,14 +56,7 @@
|
|
|
56
56
|
"./dist",
|
|
57
57
|
"./package.json"
|
|
58
58
|
],
|
|
59
|
-
"dependencies": {
|
|
60
|
-
"deep-equal": "^2.2.3",
|
|
61
|
-
"@intlayer/config": "5.3.3",
|
|
62
|
-
"@intlayer/core": "5.3.3",
|
|
63
|
-
"@intlayer/dictionaries-entry": "5.3.3"
|
|
64
|
-
},
|
|
65
59
|
"devDependencies": {
|
|
66
|
-
"@types/deep-equal": "^1.0.4",
|
|
67
60
|
"@types/node": "^22.10.6",
|
|
68
61
|
"@typescript-eslint/parser": "^8.24.0",
|
|
69
62
|
"concurrently": "^9.1.2",
|
|
@@ -78,11 +71,6 @@
|
|
|
78
71
|
"@utils/ts-config-types": "1.0.4",
|
|
79
72
|
"@utils/tsup-config": "1.0.4"
|
|
80
73
|
},
|
|
81
|
-
"peerDependencies": {
|
|
82
|
-
"@intlayer/config": "5.3.3",
|
|
83
|
-
"@intlayer/core": "5.3.3",
|
|
84
|
-
"@intlayer/dictionaries-entry": "5.3.3"
|
|
85
|
-
},
|
|
86
74
|
"engines": {
|
|
87
75
|
"node": ">=14.18"
|
|
88
76
|
},
|
|
@@ -1,17 +0,0 @@
|
|
|
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
|
|
@@ -1 +0,0 @@
|
|
|
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":[]}
|
|
@@ -1,23 +0,0 @@
|
|
|
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
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/server/index.ts"],"sourcesContent":["export * from './writeContentDeclaration';\n"],"mappings":";;;;;;;;;;;;;;;AAAA;AAAA;AAAA,2BAAc,sCAAd;","names":[]}
|
|
@@ -1,124 +0,0 @@
|
|
|
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_built = __toESM(require("@intlayer/config/built"));
|
|
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 (dictionary, config = import_built.default, newDictionariesPath) => {
|
|
42
|
-
const { content } = config;
|
|
43
|
-
const { baseDir } = content;
|
|
44
|
-
const newDictionaryRelativeLocationPath = newDictionariesPath ?? DEFAULT_NEW_DICTIONARY_PATH;
|
|
45
|
-
const newDictionaryLocationPath = `${baseDir}/${newDictionaryRelativeLocationPath}`;
|
|
46
|
-
const existingDictionary = import_dictionaries_entry.default[dictionary.key];
|
|
47
|
-
if (existingDictionary) {
|
|
48
|
-
const { filePath, ...dictionaryWithoutPath } = dictionary;
|
|
49
|
-
if ((0, import_deep_equal.default)(existingDictionary, dictionary)) {
|
|
50
|
-
return {
|
|
51
|
-
status: "up-to-date",
|
|
52
|
-
path: filePath
|
|
53
|
-
};
|
|
54
|
-
} else {
|
|
55
|
-
if (filePath) {
|
|
56
|
-
const isDictionaryJSON = filePath.endsWith(".json");
|
|
57
|
-
if (isDictionaryJSON) {
|
|
58
|
-
const contentDeclarationPath = `${baseDir}/${filePath}`;
|
|
59
|
-
await fsPromises.writeFile(
|
|
60
|
-
contentDeclarationPath,
|
|
61
|
-
JSON.stringify(
|
|
62
|
-
{
|
|
63
|
-
$schema: "https://intlayer.org/schema.json",
|
|
64
|
-
...dictionaryWithoutPath
|
|
65
|
-
},
|
|
66
|
-
null,
|
|
67
|
-
2
|
|
68
|
-
)
|
|
69
|
-
);
|
|
70
|
-
return { status: "updated", path: contentDeclarationPath };
|
|
71
|
-
} else {
|
|
72
|
-
const dictionariesDirPath = (0, import_path.dirname)(filePath);
|
|
73
|
-
const dictionariesFileName = (0, import_path.basename)(filePath, (0, import_path.extname)(filePath));
|
|
74
|
-
const newFilePath = `${dictionariesDirPath}/${dictionariesFileName}.json`;
|
|
75
|
-
await writeFileWithDirectories(
|
|
76
|
-
newFilePath,
|
|
77
|
-
JSON.stringify(dictionaryWithoutPath, null, 2)
|
|
78
|
-
);
|
|
79
|
-
return {
|
|
80
|
-
status: "updated",
|
|
81
|
-
path: newFilePath
|
|
82
|
-
};
|
|
83
|
-
}
|
|
84
|
-
} else {
|
|
85
|
-
const contentDeclarationPath = `${newDictionaryLocationPath}/${dictionary.key}.content.json`;
|
|
86
|
-
await writeFileWithDirectories(
|
|
87
|
-
contentDeclarationPath,
|
|
88
|
-
JSON.stringify(dictionaryWithoutPath, null, 2)
|
|
89
|
-
);
|
|
90
|
-
return {
|
|
91
|
-
status: "reimported in new location",
|
|
92
|
-
path: contentDeclarationPath
|
|
93
|
-
};
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
} else {
|
|
97
|
-
const contentDeclarationPath = `${newDictionaryLocationPath}/${dictionary.key}.content.json`;
|
|
98
|
-
await writeFileWithDirectories(
|
|
99
|
-
contentDeclarationPath,
|
|
100
|
-
JSON.stringify(dictionary, null, 2)
|
|
101
|
-
);
|
|
102
|
-
return {
|
|
103
|
-
status: "imported",
|
|
104
|
-
path: contentDeclarationPath
|
|
105
|
-
};
|
|
106
|
-
}
|
|
107
|
-
};
|
|
108
|
-
const writeFileWithDirectories = async (filePath, data) => {
|
|
109
|
-
try {
|
|
110
|
-
const dir = (0, import_path.dirname)(filePath);
|
|
111
|
-
const directoryExists = (0, import_fs.existsSync)(dir);
|
|
112
|
-
if (!directoryExists) {
|
|
113
|
-
await fsPromises.mkdir(dir, { recursive: true });
|
|
114
|
-
}
|
|
115
|
-
await fsPromises.writeFile(filePath, data);
|
|
116
|
-
} catch (error) {
|
|
117
|
-
throw new Error(`Error writing file to ${filePath}: ${error}`);
|
|
118
|
-
}
|
|
119
|
-
};
|
|
120
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
121
|
-
0 && (module.exports = {
|
|
122
|
-
writeContentDeclaration
|
|
123
|
-
});
|
|
124
|
-
//# sourceMappingURL=writeContentDeclaration.cjs.map
|
|
@@ -1 +0,0 @@
|
|
|
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 type { IntlayerConfig } from '@intlayer/config/client';\nimport configuration from '@intlayer/config/built';\nimport type { Dictionary } from '@intlayer/core';\nimport dictionariesRecord from '@intlayer/dictionaries-entry';\nimport deepEqual from 'deep-equal';\nimport type { DictionaryStatus } from '../dictionaryStatus';\n\nconst DEFAULT_NEW_DICTIONARY_PATH = 'intlayer-dictionaries';\n\nexport const writeContentDeclaration = async (\n dictionary: Dictionary,\n config: IntlayerConfig = configuration,\n newDictionariesPath?: string\n): Promise<{ status: DictionaryStatus; path: string }> => {\n const { content } = config;\n const { baseDir } = content;\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(\n {\n $schema: 'https://intlayer.org/schema.json',\n ...dictionaryWithoutPath,\n },\n null,\n 2\n )\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":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAA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,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,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":["configuration","dictionariesRecord","deepEqual"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
//# sourceMappingURL=dictionaryStatus.mjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/server/index.ts"],"sourcesContent":["export * from './writeContentDeclaration';\n"],"mappings":"AAAA,cAAc;","names":[]}
|
|
@@ -1,90 +0,0 @@
|
|
|
1
|
-
import { existsSync } from "fs";
|
|
2
|
-
import * as fsPromises from "fs/promises";
|
|
3
|
-
import { basename, dirname, extname } from "path";
|
|
4
|
-
import configuration from "@intlayer/config/built";
|
|
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 (dictionary, config = configuration, newDictionariesPath) => {
|
|
9
|
-
const { content } = config;
|
|
10
|
-
const { baseDir } = content;
|
|
11
|
-
const newDictionaryRelativeLocationPath = newDictionariesPath ?? DEFAULT_NEW_DICTIONARY_PATH;
|
|
12
|
-
const newDictionaryLocationPath = `${baseDir}/${newDictionaryRelativeLocationPath}`;
|
|
13
|
-
const existingDictionary = dictionariesRecord[dictionary.key];
|
|
14
|
-
if (existingDictionary) {
|
|
15
|
-
const { filePath, ...dictionaryWithoutPath } = dictionary;
|
|
16
|
-
if (deepEqual(existingDictionary, dictionary)) {
|
|
17
|
-
return {
|
|
18
|
-
status: "up-to-date",
|
|
19
|
-
path: filePath
|
|
20
|
-
};
|
|
21
|
-
} else {
|
|
22
|
-
if (filePath) {
|
|
23
|
-
const isDictionaryJSON = filePath.endsWith(".json");
|
|
24
|
-
if (isDictionaryJSON) {
|
|
25
|
-
const contentDeclarationPath = `${baseDir}/${filePath}`;
|
|
26
|
-
await fsPromises.writeFile(
|
|
27
|
-
contentDeclarationPath,
|
|
28
|
-
JSON.stringify(
|
|
29
|
-
{
|
|
30
|
-
$schema: "https://intlayer.org/schema.json",
|
|
31
|
-
...dictionaryWithoutPath
|
|
32
|
-
},
|
|
33
|
-
null,
|
|
34
|
-
2
|
|
35
|
-
)
|
|
36
|
-
);
|
|
37
|
-
return { status: "updated", path: contentDeclarationPath };
|
|
38
|
-
} else {
|
|
39
|
-
const dictionariesDirPath = dirname(filePath);
|
|
40
|
-
const dictionariesFileName = basename(filePath, extname(filePath));
|
|
41
|
-
const newFilePath = `${dictionariesDirPath}/${dictionariesFileName}.json`;
|
|
42
|
-
await writeFileWithDirectories(
|
|
43
|
-
newFilePath,
|
|
44
|
-
JSON.stringify(dictionaryWithoutPath, null, 2)
|
|
45
|
-
);
|
|
46
|
-
return {
|
|
47
|
-
status: "updated",
|
|
48
|
-
path: newFilePath
|
|
49
|
-
};
|
|
50
|
-
}
|
|
51
|
-
} else {
|
|
52
|
-
const contentDeclarationPath = `${newDictionaryLocationPath}/${dictionary.key}.content.json`;
|
|
53
|
-
await writeFileWithDirectories(
|
|
54
|
-
contentDeclarationPath,
|
|
55
|
-
JSON.stringify(dictionaryWithoutPath, null, 2)
|
|
56
|
-
);
|
|
57
|
-
return {
|
|
58
|
-
status: "reimported in new location",
|
|
59
|
-
path: contentDeclarationPath
|
|
60
|
-
};
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
} else {
|
|
64
|
-
const contentDeclarationPath = `${newDictionaryLocationPath}/${dictionary.key}.content.json`;
|
|
65
|
-
await writeFileWithDirectories(
|
|
66
|
-
contentDeclarationPath,
|
|
67
|
-
JSON.stringify(dictionary, null, 2)
|
|
68
|
-
);
|
|
69
|
-
return {
|
|
70
|
-
status: "imported",
|
|
71
|
-
path: contentDeclarationPath
|
|
72
|
-
};
|
|
73
|
-
}
|
|
74
|
-
};
|
|
75
|
-
const writeFileWithDirectories = async (filePath, data) => {
|
|
76
|
-
try {
|
|
77
|
-
const dir = dirname(filePath);
|
|
78
|
-
const directoryExists = existsSync(dir);
|
|
79
|
-
if (!directoryExists) {
|
|
80
|
-
await fsPromises.mkdir(dir, { recursive: true });
|
|
81
|
-
}
|
|
82
|
-
await fsPromises.writeFile(filePath, data);
|
|
83
|
-
} catch (error) {
|
|
84
|
-
throw new Error(`Error writing file to ${filePath}: ${error}`);
|
|
85
|
-
}
|
|
86
|
-
};
|
|
87
|
-
export {
|
|
88
|
-
writeContentDeclaration
|
|
89
|
-
};
|
|
90
|
-
//# sourceMappingURL=writeContentDeclaration.mjs.map
|
|
@@ -1 +0,0 @@
|
|
|
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 type { IntlayerConfig } from '@intlayer/config/client';\nimport configuration from '@intlayer/config/built';\nimport type { Dictionary } from '@intlayer/core';\nimport dictionariesRecord from '@intlayer/dictionaries-entry';\nimport deepEqual from 'deep-equal';\nimport type { DictionaryStatus } from '../dictionaryStatus';\n\nconst DEFAULT_NEW_DICTIONARY_PATH = 'intlayer-dictionaries';\n\nexport const writeContentDeclaration = async (\n dictionary: Dictionary,\n config: IntlayerConfig = configuration,\n newDictionariesPath?: string\n): Promise<{ status: DictionaryStatus; path: string }> => {\n const { content } = config;\n const { baseDir } = content;\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(\n {\n $schema: 'https://intlayer.org/schema.json',\n ...dictionaryWithoutPath,\n },\n null,\n 2\n )\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;AAE3C,OAAO,mBAAmB;AAE1B,OAAO,wBAAwB;AAC/B,OAAO,eAAe;AAGtB,MAAM,8BAA8B;AAE7B,MAAM,0BAA0B,OACrC,YACA,SAAyB,eACzB,wBACwD;AACxD,QAAM,EAAE,QAAQ,IAAI;AACpB,QAAM,EAAE,QAAQ,IAAI;AAEpB,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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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 +0,0 @@
|
|
|
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 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/server/index.ts"],"names":[],"mappings":"AAAA,cAAc,2BAA2B,CAAC"}
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import type { IntlayerConfig } from '@intlayer/config/client';
|
|
2
|
-
import type { Dictionary } from '@intlayer/core';
|
|
3
|
-
import type { DictionaryStatus } from '../dictionaryStatus';
|
|
4
|
-
export declare const writeContentDeclaration: (dictionary: Dictionary, config?: IntlayerConfig, newDictionariesPath?: string) => Promise<{
|
|
5
|
-
status: DictionaryStatus;
|
|
6
|
-
path: string;
|
|
7
|
-
}>;
|
|
8
|
-
//# sourceMappingURL=writeContentDeclaration.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"writeContentDeclaration.d.ts","sourceRoot":"","sources":["../../../src/server/writeContentDeclaration.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,yBAAyB,CAAC;AAE9D,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAGjD,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AAI5D,eAAO,MAAM,uBAAuB,GAClC,YAAY,UAAU,EACtB,SAAQ,cAA8B,EACtC,sBAAsB,MAAM,KAC3B,OAAO,CAAC;IAAE,MAAM,EAAE,gBAAgB,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,CAmFpD,CAAC"}
|