@intlayer/editor 5.1.8 → 5.2.1
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/server/writeContentDeclaration.cjs +4 -5
- package/dist/cjs/server/writeContentDeclaration.cjs.map +1 -1
- package/dist/esm/server/writeContentDeclaration.mjs +4 -5
- package/dist/esm/server/writeContentDeclaration.mjs.map +1 -1
- package/dist/types/server/writeContentDeclaration.d.ts +1 -1
- package/dist/types/server/writeContentDeclaration.d.ts.map +1 -1
- package/package.json +8 -8
|
@@ -34,14 +34,13 @@ module.exports = __toCommonJS(writeContentDeclaration_exports);
|
|
|
34
34
|
var import_fs = require("fs");
|
|
35
35
|
var fsPromises = __toESM(require("fs/promises"));
|
|
36
36
|
var import_path = require("path");
|
|
37
|
-
var
|
|
37
|
+
var import_built = __toESM(require("@intlayer/config/built"));
|
|
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 (dictionary, config, newDictionariesPath) => {
|
|
42
|
-
const {
|
|
43
|
-
|
|
44
|
-
} = config ?? (0, import_client.getConfiguration)();
|
|
41
|
+
const writeContentDeclaration = async (dictionary, config = import_built.default, newDictionariesPath) => {
|
|
42
|
+
const { content } = config;
|
|
43
|
+
const { baseDir } = content;
|
|
45
44
|
const newDictionaryRelativeLocationPath = newDictionariesPath ?? DEFAULT_NEW_DICTIONARY_PATH;
|
|
46
45
|
const newDictionaryLocationPath = `${baseDir}/${newDictionaryRelativeLocationPath}`;
|
|
47
46
|
const existingDictionary = import_dictionaries_entry.default[dictionary.key];
|
|
@@ -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 {
|
|
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;AAAA;AAAA;AAAA;AAAA;AAAA,gBAA2B;AAC3B,iBAA4B;AAC5B,kBAA2C;AAE3C,mBAA0B;AAE1B,gCAA+B;AAC/B,wBAAsB;AAGtB,MAAM,8BAA8B;AAE7B,MAAM,0BAA0B,OACrC,YACA,SAAyB,aAAAA,SACzB,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,0BAAAC,QAAmB,WAAW,GAAG;AAE5D,MAAI,oBAAoB;AACtB,UAAM,EAAE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F;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,14 +1,13 @@
|
|
|
1
1
|
import { existsSync } from "fs";
|
|
2
2
|
import * as fsPromises from "fs/promises";
|
|
3
3
|
import { basename, dirname, extname } from "path";
|
|
4
|
-
import
|
|
4
|
+
import configuration from "@intlayer/config/built";
|
|
5
5
|
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 (dictionary, config, newDictionariesPath) => {
|
|
9
|
-
const {
|
|
10
|
-
|
|
11
|
-
} = config ?? getConfiguration();
|
|
8
|
+
const writeContentDeclaration = async (dictionary, config = configuration, newDictionariesPath) => {
|
|
9
|
+
const { content } = config;
|
|
10
|
+
const { baseDir } = content;
|
|
12
11
|
const newDictionaryRelativeLocationPath = newDictionariesPath ?? DEFAULT_NEW_DICTIONARY_PATH;
|
|
13
12
|
const newDictionaryLocationPath = `${baseDir}/${newDictionaryRelativeLocationPath}`;
|
|
14
13
|
const existingDictionary = dictionariesRecord[dictionary.key];
|
|
@@ -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 {
|
|
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,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AG5B,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,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type { IntlayerConfig } from '@intlayer/config/client';
|
|
2
2
|
import type { Dictionary } from '@intlayer/core';
|
|
3
3
|
import type { DictionaryStatus } from '../dictionaryStatus';
|
|
4
4
|
export declare const writeContentDeclaration: (dictionary: Dictionary, config?: IntlayerConfig, newDictionariesPath?: string) => Promise<{
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"writeContentDeclaration.d.ts","sourceRoot":"","sources":["../../../src/server/writeContentDeclaration.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,
|
|
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"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@intlayer/editor",
|
|
3
|
-
"version": "5.1
|
|
3
|
+
"version": "5.2.1",
|
|
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": "5.1
|
|
61
|
-
"@intlayer/core": "5.1
|
|
62
|
-
"@intlayer/dictionaries-entry": "5.1
|
|
60
|
+
"@intlayer/config": "5.2.1",
|
|
61
|
+
"@intlayer/core": "5.2.1",
|
|
62
|
+
"@intlayer/dictionaries-entry": "5.2.1"
|
|
63
63
|
},
|
|
64
64
|
"devDependencies": {
|
|
65
65
|
"@types/deep-equal": "^1.0.4",
|
|
@@ -72,15 +72,15 @@
|
|
|
72
72
|
"tsc-alias": "^1.8.10",
|
|
73
73
|
"tsup": "^8.3.5",
|
|
74
74
|
"typescript": "^5.7.3",
|
|
75
|
-
"@utils/tsup-config": "1.0.4",
|
|
76
75
|
"@utils/eslint-config": "1.0.4",
|
|
77
76
|
"@utils/ts-config-types": "1.0.4",
|
|
77
|
+
"@utils/tsup-config": "1.0.4",
|
|
78
78
|
"@utils/ts-config": "1.0.4"
|
|
79
79
|
},
|
|
80
80
|
"peerDependencies": {
|
|
81
|
-
"@intlayer/
|
|
82
|
-
"@intlayer/dictionaries-entry": "5.1
|
|
83
|
-
"@intlayer/
|
|
81
|
+
"@intlayer/core": "5.2.1",
|
|
82
|
+
"@intlayer/dictionaries-entry": "5.2.1",
|
|
83
|
+
"@intlayer/config": "5.2.1"
|
|
84
84
|
},
|
|
85
85
|
"engines": {
|
|
86
86
|
"node": ">=14.18"
|