@contentstorage/core 0.3.12 → 0.3.13

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.
@@ -4,7 +4,7 @@ import { DotNotationPaths } from '../types.js';
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(languageCode: string): Promise<void>;
7
+ export declare function setContentLanguage(contentDir: string, languageCode: string): 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.
@@ -1,45 +1,25 @@
1
1
  import fs from 'fs/promises';
2
2
  import path from 'path';
3
- import { loadConfig } from './configLoader.js';
4
3
  let activeContent = null;
5
4
  let activeLanguage = null;
6
- let loadedAppConfig = null; // Cache for the loaded config
7
- /**
8
- * Ensures the application configuration (especially contentDir) is loaded.
9
- * Calls your library's loadConfig function.
10
- */
11
- async function ensureConfigInitialized() {
12
- if (loadedAppConfig) {
13
- return loadedAppConfig;
14
- }
15
- try {
16
- const config = await loadConfig(); // This is your library's function
17
- if (!config || !config.contentDir) {
18
- throw new Error('contentDir not found in the loaded configuration (contentstorage.config.js).');
19
- }
20
- loadedAppConfig = config; // Ensure it matches the expected structure
21
- console.log(`[LocalizationLibrary] Configuration loaded. Content directory set to: ${loadedAppConfig.contentDir}`);
22
- return loadedAppConfig;
23
- }
24
- catch (error) {
25
- console.error('[Contentstorage] Failed to initialize configuration:', error);
26
- throw new Error(`[Contentstorage] Critical error: Could not load or validate app configuration. ${error.message}`);
27
- }
28
- }
29
5
  /**
30
6
  * Loads and sets the content for a specific language.
31
7
  * It will internally ensure the application configuration (for contentDir) is loaded.
32
8
  * @param languageCode The language code (e.g., 'EN', 'FR') for the JSON file to load.
33
9
  */
34
- export async function setContentLanguage(languageCode) {
10
+ export async function setContentLanguage(contentDir, languageCode) {
11
+ if (!contentDir ||
12
+ typeof contentDir !== 'string' ||
13
+ contentDir.trim() === '') {
14
+ throw new Error('[Contentstorage] Invalid contentUrl provided to setContentLanguage.');
15
+ }
35
16
  if (!languageCode ||
36
17
  typeof languageCode !== 'string' ||
37
18
  languageCode.trim() === '') {
38
19
  throw new Error('[Contentstorage] Invalid language code provided to setContentLanguage.');
39
20
  }
40
- const config = await ensureConfigInitialized(); // Gets contentDir from loaded config
41
21
  const targetFilename = `${languageCode}.json`;
42
- const jsonFilePath = path.join(config.contentDir, targetFilename);
22
+ const jsonFilePath = path.join(contentDir, targetFilename);
43
23
  console.log(`[Contentstorage] Attempting to load content for language '${languageCode}' from ${jsonFilePath}...`);
44
24
  try {
45
25
  const jsonContentString = await fs.readFile(jsonFilePath, 'utf-8');
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.12",
5
+ "version": "0.3.13",
6
6
  "type": "module",
7
7
  "description": "Fetch content from contentstorage and generate TypeScript types",
8
8
  "module": "dist/index.js",