@isardsat/editorial-server 6.11.0 → 6.12.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/lib/storage.d.ts +1 -1
- package/dist/lib/storage.js +46 -3
- package/dist/routes/data.js +2 -0
- package/package.json +3 -3
package/dist/lib/storage.d.ts
CHANGED
|
@@ -18,7 +18,7 @@ export declare function createStorage(dataDirectory: string): {
|
|
|
18
18
|
production?: boolean;
|
|
19
19
|
}) => Promise<EditorialData>;
|
|
20
20
|
getLocalisationMessages: (langCode: string) => Promise<any>;
|
|
21
|
-
saveLocalisationMessages: (
|
|
21
|
+
saveLocalisationMessages: (newMessages: any) => Promise<boolean>;
|
|
22
22
|
createItem: (item: EditorialDataObjectWithType) => Promise<{
|
|
23
23
|
[x: string]: unknown;
|
|
24
24
|
id: string;
|
package/dist/lib/storage.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { EditorialDataItemSchema, EditorialDataSchema, EditorialSchemaSchema, } from "@isardsat/editorial-common";
|
|
2
|
-
import { readFile } from "fs/promises";
|
|
2
|
+
import { readFile, readdir } from "fs/promises";
|
|
3
3
|
import { join } from "path";
|
|
4
4
|
import { parse } from "yaml";
|
|
5
5
|
import { writeFileSafe } from "./utils/fs.js";
|
|
@@ -8,6 +8,7 @@ export function createStorage(dataDirectory) {
|
|
|
8
8
|
const dataPath = join(dataDirectory, "data.json");
|
|
9
9
|
const dataProdPath = join(dataDirectory, "data.prod.json");
|
|
10
10
|
const dataExtractedPath = join(dataDirectory, "data.messages.json");
|
|
11
|
+
const localesPath = join(dataDirectory, "locales", "messages");
|
|
11
12
|
async function getSchema() {
|
|
12
13
|
const schemaFile = await readFile(schemaPath, "utf-8").then((value) => parse(value));
|
|
13
14
|
const schema = EditorialSchemaSchema.parse(schemaFile);
|
|
@@ -43,8 +44,50 @@ export function createStorage(dataDirectory) {
|
|
|
43
44
|
await writeFileSafe(dataPath, JSON.stringify(EditorialDataSchema.parse(content), null, 2));
|
|
44
45
|
return true;
|
|
45
46
|
}
|
|
46
|
-
async function
|
|
47
|
-
|
|
47
|
+
async function getAllLocalesMessages(dir) {
|
|
48
|
+
const files = await readdir(dir);
|
|
49
|
+
return Promise.all(files.map(async (file) => ({
|
|
50
|
+
file,
|
|
51
|
+
path: join(dir, file),
|
|
52
|
+
messages: JSON.parse(await readFile(join(dir, file), "utf-8")),
|
|
53
|
+
})));
|
|
54
|
+
}
|
|
55
|
+
function pruneMessages(messages, deletedItemKeys) {
|
|
56
|
+
const pruned = { ...messages };
|
|
57
|
+
deletedItemKeys.forEach((key) => {
|
|
58
|
+
if (pruned.hasOwnProperty(key)) {
|
|
59
|
+
delete pruned[key];
|
|
60
|
+
}
|
|
61
|
+
});
|
|
62
|
+
return pruned;
|
|
63
|
+
}
|
|
64
|
+
async function saveLocalisationMessages(newMessages) {
|
|
65
|
+
const productionMessages = await readFile(dataExtractedPath, "utf-8").then((value) => JSON.parse(value));
|
|
66
|
+
await writeFileSafe(dataExtractedPath, JSON.stringify(newMessages, null, 2));
|
|
67
|
+
/**
|
|
68
|
+
* Get deleted items by checking
|
|
69
|
+
* keys that are in productionMessages but not in newMessages
|
|
70
|
+
*/
|
|
71
|
+
const deletedItemKeys = [];
|
|
72
|
+
for (const itemType of Object.keys(productionMessages)) {
|
|
73
|
+
if (!newMessages[itemType]) {
|
|
74
|
+
/**
|
|
75
|
+
* We need to store both the full itemType with hash and the shortItemType without hash
|
|
76
|
+
* The itemType is used for locale files starting with underscore _
|
|
77
|
+
* The shortItemType is used for normal locale files
|
|
78
|
+
*/
|
|
79
|
+
deletedItemKeys.push(itemType);
|
|
80
|
+
const shortItemType = itemType.split(".").slice(0, -1).join(".");
|
|
81
|
+
deletedItemKeys.push(shortItemType);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
if (deletedItemKeys.length === 0)
|
|
85
|
+
return true;
|
|
86
|
+
const locales = await getAllLocalesMessages(localesPath);
|
|
87
|
+
for (const locale of locales) {
|
|
88
|
+
const pruned = pruneMessages(locale.messages, deletedItemKeys);
|
|
89
|
+
await writeFileSafe(locale.path, JSON.stringify(pruned, null, 2));
|
|
90
|
+
}
|
|
48
91
|
return true;
|
|
49
92
|
}
|
|
50
93
|
async function createItem(item) {
|
package/dist/routes/data.js
CHANGED
|
@@ -143,6 +143,8 @@ export function createDataRoutes(config, storage) {
|
|
|
143
143
|
for (const [key, message] of Object.entries(messages)) {
|
|
144
144
|
const [contentKey, typeKey, fieldKey] = key.split(".");
|
|
145
145
|
if (contentKey === itemType) {
|
|
146
|
+
if (!collection[typeKey])
|
|
147
|
+
continue;
|
|
146
148
|
collection[typeKey][fieldKey] = message.defaultMessage;
|
|
147
149
|
}
|
|
148
150
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@isardsat/editorial-server",
|
|
3
|
-
"version": "6.
|
|
3
|
+
"version": "6.12.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -14,8 +14,8 @@
|
|
|
14
14
|
"hono": "^4.9.8",
|
|
15
15
|
"yaml": "^2.8.1",
|
|
16
16
|
"zod": "^4.1.11",
|
|
17
|
-
"@isardsat/editorial-
|
|
18
|
-
"@isardsat/editorial-
|
|
17
|
+
"@isardsat/editorial-admin": "^6.12.0",
|
|
18
|
+
"@isardsat/editorial-common": "^6.12.0"
|
|
19
19
|
},
|
|
20
20
|
"devDependencies": {
|
|
21
21
|
"@tsconfig/node22": "^22.0.0",
|