@contentstorage/core 0.3.29 → 0.3.30
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/configLoader.js
CHANGED
|
@@ -33,10 +33,9 @@ export async function loadConfig() {
|
|
|
33
33
|
};
|
|
34
34
|
// Validate required fields
|
|
35
35
|
if (!mergedConfig.contentKey) {
|
|
36
|
-
console.error('Error: Configuration is missing the required "
|
|
37
|
-
process.exit(1);
|
|
36
|
+
console.error('Error: Configuration is missing the required "contentKey" property.');
|
|
37
|
+
process.exit(1);
|
|
38
38
|
}
|
|
39
|
-
// Resolve paths relative to the user's project root (process.cwd())
|
|
40
39
|
const finalConfig = {
|
|
41
40
|
languageCodes: mergedConfig.languageCodes || [],
|
|
42
41
|
contentKey: mergedConfig.contentKey,
|
|
@@ -6,7 +6,7 @@ let activeContent = null;
|
|
|
6
6
|
*/
|
|
7
7
|
export function setContentLanguage(contentJson) {
|
|
8
8
|
if (!contentJson || typeof contentJson !== 'object') {
|
|
9
|
-
throw new Error('[Contentstorage] Invalid
|
|
9
|
+
throw new Error('[Contentstorage] Invalid contentKey might be provided which caused setContentLanguage to fail.');
|
|
10
10
|
}
|
|
11
11
|
try {
|
|
12
12
|
activeContent = contentJson; // Relies on augmentation
|
|
@@ -21,7 +21,7 @@ export async function generateTypes() {
|
|
|
21
21
|
console.error(chalk.red.bold("Configuration error: 'languageCodes' must be a non-empty array."));
|
|
22
22
|
process.exit(1);
|
|
23
23
|
}
|
|
24
|
-
console.log(chalk.
|
|
24
|
+
console.log(chalk.blue(`TypeScript types will be saved to: ${config.typesOutputFile}`));
|
|
25
25
|
let jsonObject; // To hold the JSON data from either local or remote source
|
|
26
26
|
let dataSourceDescription = ''; // For clearer logging
|
|
27
27
|
const firstLanguageCode = config.languageCodes[0];
|
|
@@ -31,7 +31,7 @@ export async function generateTypes() {
|
|
|
31
31
|
try {
|
|
32
32
|
await fs.stat(config.contentDir); // Check if directory exists
|
|
33
33
|
attemptLocalLoad = true;
|
|
34
|
-
console.log(chalk.
|
|
34
|
+
console.log(chalk.blue(`Local content directory found: ${config.contentDir}`));
|
|
35
35
|
}
|
|
36
36
|
catch (statError) {
|
|
37
37
|
if (statError.code === 'ENOENT') {
|
|
@@ -52,12 +52,12 @@ export async function generateTypes() {
|
|
|
52
52
|
const targetFilename = `${firstLanguageCode}.json`;
|
|
53
53
|
const jsonFilePath = path.join(config.contentDir, targetFilename);
|
|
54
54
|
dataSourceDescription = `local file (${jsonFilePath})`;
|
|
55
|
-
console.log(chalk.
|
|
55
|
+
console.log(chalk.blue(`Attempting to read JSON from: ${jsonFilePath}`));
|
|
56
56
|
try {
|
|
57
57
|
const jsonContentString = await fs.readFile(jsonFilePath, 'utf-8');
|
|
58
|
-
console.log(chalk.
|
|
58
|
+
console.log(chalk.blue('Parsing JSON'));
|
|
59
59
|
const parsendJsonObject = JSON.parse(jsonContentString);
|
|
60
|
-
console.log(chalk.
|
|
60
|
+
console.log(chalk.blue('Flattening JSON for type generation'));
|
|
61
61
|
jsonObject = flattenJson(parsendJsonObject);
|
|
62
62
|
console.log(chalk.green(`Successfully read and parsed JSON from ${jsonFilePath}.`));
|
|
63
63
|
}
|
|
@@ -76,11 +76,11 @@ export async function generateTypes() {
|
|
|
76
76
|
}
|
|
77
77
|
const fileUrl = `${CONTENTSTORAGE_CONFIG.BASE_URL}/${config.contentKey}/content/${firstLanguageCode}.json`; // Adjust URL construction if necessary
|
|
78
78
|
dataSourceDescription = `remote URL (${fileUrl})`;
|
|
79
|
-
console.log(chalk.
|
|
79
|
+
console.log(chalk.blue(`Attempting to fetch JSON from: ${fileUrl}`));
|
|
80
80
|
try {
|
|
81
81
|
const response = await axios.get(fileUrl, { responseType: 'json' });
|
|
82
82
|
const jsonResponse = response.data;
|
|
83
|
-
console.log(chalk.
|
|
83
|
+
console.log(chalk.blue('Flattening JSON for type generation'));
|
|
84
84
|
jsonObject = flattenJson(jsonResponse);
|
|
85
85
|
if (typeof jsonObject !== 'object' || jsonObject === null) {
|
|
86
86
|
throw new Error(`Workspaceed data from ${fileUrl} is not a valid JSON object. Received type: ${typeof jsonObject}`);
|
|
@@ -105,7 +105,7 @@ export async function generateTypes() {
|
|
|
105
105
|
}
|
|
106
106
|
// Generate TypeScript interfaces using json-to-ts
|
|
107
107
|
const rootTypeName = 'ContentRoot'; // As per your previous update
|
|
108
|
-
console.log(chalk.
|
|
108
|
+
console.log(chalk.blue(`Generating TypeScript types with root name '${rootTypeName}'...`));
|
|
109
109
|
const typeDeclarations = jsonToTS.default(jsonObject, {
|
|
110
110
|
rootName: rootTypeName,
|
|
111
111
|
});
|
|
@@ -9,8 +9,8 @@ export async function pullContent() {
|
|
|
9
9
|
console.log(chalk.blue('Starting content pull...'));
|
|
10
10
|
// Load configuration (assuming this function is defined elsewhere and works)
|
|
11
11
|
const config = await loadConfig();
|
|
12
|
-
console.log(chalk.
|
|
13
|
-
console.log(chalk.
|
|
12
|
+
console.log(chalk.blue(`Content key: ${config.contentKey}`));
|
|
13
|
+
console.log(chalk.blue(`Saving content to: ${config.contentDir}`));
|
|
14
14
|
try {
|
|
15
15
|
// Validate languageCodes array
|
|
16
16
|
if (!Array.isArray(config.languageCodes)) {
|
|
@@ -29,7 +29,7 @@ export async function pullContent() {
|
|
|
29
29
|
const filename = `${languageCode}.json`;
|
|
30
30
|
const outputPath = path.join(config.contentDir, filename);
|
|
31
31
|
console.log(chalk.blue(`\nProcessing language: ${languageCode}`));
|
|
32
|
-
console.log(chalk.
|
|
32
|
+
console.log(chalk.blue(`Using following contentKey to fetch json: ${config.contentKey}`));
|
|
33
33
|
try {
|
|
34
34
|
// Fetch data for the current language
|
|
35
35
|
const response = await axios.get(fileUrl);
|
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.30",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"description": "Fetch content from contentstorage and generate TypeScript types",
|
|
8
8
|
"module": "dist/index.js",
|