-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconvert_logs_to_piml.js
More file actions
38 lines (35 loc) · 1.07 KB
/
convert_logs_to_piml.js
File metadata and controls
38 lines (35 loc) · 1.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
const fs = require('fs');
const path = require('path');
const piml = require('piml');
const publicLogsDir = path.join(__dirname, '../public/logs');
const categories = [
'Book',
'Movie',
'Video',
'Game',
'Article',
'Music',
'Series',
'Food',
'Websites',
'Tools',
];
categories.forEach(category => {
const lowerCat = category.toLowerCase();
const jsonPath = path.join(publicLogsDir, lowerCat, `${lowerCat}.json`);
const pimlPath = path.join(publicLogsDir, lowerCat, `${lowerCat}.piml`);
if (fs.existsSync(jsonPath)) {
try {
const jsonData = JSON.parse(fs.readFileSync(jsonPath, 'utf8'));
// Wrap in an object to match the structure expected by piml parser (if needed) or just consistent with stories
const pimlData = { logs: jsonData };
const pimlString = piml.stringify(pimlData);
fs.writeFileSync(pimlPath, pimlString);
console.log(`Converted ${jsonPath} to ${pimlPath}`);
} catch (err) {
console.error(`Error converting ${jsonPath}:`, err);
}
} else {
console.warn(`File not found: ${jsonPath}`);
}
});