@contentstorage/core 0.3.13 → 0.3.14
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/index.d.ts +2 -2
- package/dist/index.js +2 -2
- package/dist/lib/contentManagement.d.ts +2 -7
- package/dist/lib/contentManagement.js +6 -29
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import { AppConfig, LanguageCode } from './types.js';
|
|
2
|
-
import { setContentLanguage,
|
|
2
|
+
import { setContentLanguage, getText } from './lib/contentManagement.js';
|
|
3
3
|
export { AppConfig, LanguageCode };
|
|
4
|
-
export { setContentLanguage, getText
|
|
4
|
+
export { setContentLanguage, getText };
|
package/dist/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { setContentLanguage,
|
|
2
|
-
export { setContentLanguage, getText
|
|
1
|
+
import { setContentLanguage, getText } from './lib/contentManagement.js';
|
|
2
|
+
export { setContentLanguage, getText };
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { DotNotationPaths } from '../types.js';
|
|
1
|
+
import { ContentStructure, DotNotationPaths } from '../types.js';
|
|
2
2
|
/**
|
|
3
3
|
* Loads and sets the content for a specific language.
|
|
4
4
|
* It will internally ensure the application configuration (for contentDir) is loaded.
|
|
5
5
|
* @param languageCode The language code (e.g., 'EN', 'FR') for the JSON file to load.
|
|
6
6
|
*/
|
|
7
|
-
export declare function setContentLanguage(
|
|
7
|
+
export declare function setContentLanguage(contentJson: ContentStructure | null): Promise<void>;
|
|
8
8
|
/**
|
|
9
9
|
* Retrieves the text string from the loaded JSON content for the given path.
|
|
10
10
|
* Autocompletion for pathString is enabled via module augmentation of CustomContentStructure.
|
|
@@ -16,8 +16,3 @@ export declare function setContentLanguage(contentDir: string, languageCode: str
|
|
|
16
16
|
* @returns The text string from the JSON, or the fallbackValue, or undefined.
|
|
17
17
|
*/
|
|
18
18
|
export declare function getText(pathString: DotNotationPaths, fallbackValue?: string): string | undefined;
|
|
19
|
-
/**
|
|
20
|
-
* Gets the currently active language code.
|
|
21
|
-
* @returns The active language code or null if no language is set.
|
|
22
|
-
*/
|
|
23
|
-
export declare function getCurrentLanguage(): string | null;
|
|
@@ -1,36 +1,20 @@
|
|
|
1
|
-
import fs from 'fs/promises';
|
|
2
|
-
import path from 'path';
|
|
3
1
|
let activeContent = null;
|
|
4
|
-
let activeLanguage = null;
|
|
5
2
|
/**
|
|
6
3
|
* Loads and sets the content for a specific language.
|
|
7
4
|
* It will internally ensure the application configuration (for contentDir) is loaded.
|
|
8
5
|
* @param languageCode The language code (e.g., 'EN', 'FR') for the JSON file to load.
|
|
9
6
|
*/
|
|
10
|
-
export async function setContentLanguage(
|
|
11
|
-
if (!
|
|
12
|
-
typeof contentDir !== 'string' ||
|
|
13
|
-
contentDir.trim() === '') {
|
|
7
|
+
export async function setContentLanguage(contentJson) {
|
|
8
|
+
if (!contentJson || typeof contentJson !== 'object') {
|
|
14
9
|
throw new Error('[Contentstorage] Invalid contentUrl provided to setContentLanguage.');
|
|
15
10
|
}
|
|
16
|
-
if (!languageCode ||
|
|
17
|
-
typeof languageCode !== 'string' ||
|
|
18
|
-
languageCode.trim() === '') {
|
|
19
|
-
throw new Error('[Contentstorage] Invalid language code provided to setContentLanguage.');
|
|
20
|
-
}
|
|
21
|
-
const targetFilename = `${languageCode}.json`;
|
|
22
|
-
const jsonFilePath = path.join(contentDir, targetFilename);
|
|
23
|
-
console.log(`[Contentstorage] Attempting to load content for language '${languageCode}' from ${jsonFilePath}...`);
|
|
24
11
|
try {
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
activeLanguage = languageCode;
|
|
28
|
-
console.log(`[Contentstorage] Content for language '${languageCode}' loaded successfully.`);
|
|
12
|
+
activeContent = contentJson; // Relies on augmentation
|
|
13
|
+
console.log(`[Contentstorage] Content loaded.`);
|
|
29
14
|
}
|
|
30
15
|
catch (error) {
|
|
31
16
|
activeContent = null; // Reset on failure
|
|
32
|
-
console.error(`[Contentstorage] Failed to load content
|
|
33
|
-
throw new Error(`[Contentstorage] Could not load content for language: ${languageCode}. Ensure file exists at '${jsonFilePath}' and is valid JSON.`);
|
|
17
|
+
console.error(`[Contentstorage] Failed to load content. Error: ${error.message}`);
|
|
34
18
|
}
|
|
35
19
|
}
|
|
36
20
|
/**
|
|
@@ -58,7 +42,7 @@ pathString, fallbackValue) {
|
|
|
58
42
|
current = current[key];
|
|
59
43
|
}
|
|
60
44
|
else {
|
|
61
|
-
const msg = `[Contentstorage] getText: Path "${String(pathString)}" not found in loaded content
|
|
45
|
+
const msg = `[Contentstorage] getText: Path "${String(pathString)}" not found in loaded content.`;
|
|
62
46
|
console.warn(msg);
|
|
63
47
|
return fallbackValue;
|
|
64
48
|
}
|
|
@@ -72,10 +56,3 @@ pathString, fallbackValue) {
|
|
|
72
56
|
return fallbackValue;
|
|
73
57
|
}
|
|
74
58
|
}
|
|
75
|
-
/**
|
|
76
|
-
* Gets the currently active language code.
|
|
77
|
-
* @returns The active language code or null if no language is set.
|
|
78
|
-
*/
|
|
79
|
-
export function getCurrentLanguage() {
|
|
80
|
-
return activeLanguage;
|
|
81
|
-
}
|
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "@contentstorage/core",
|
|
3
3
|
"author": "Kaido Hussar <kaidohus@gmail.com>",
|
|
4
4
|
"homepage": "https://contentstorage.app",
|
|
5
|
-
"version": "0.3.
|
|
5
|
+
"version": "0.3.14",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"description": "Fetch content from contentstorage and generate TypeScript types",
|
|
8
8
|
"module": "dist/index.js",
|