-
Notifications
You must be signed in to change notification settings - Fork 40
/
generate-markdown.js
39 lines (30 loc) · 1.19 KB
/
generate-markdown.js
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
39
import fs from 'fs';
import path from 'path';
import { jsonToTaskString, parseTaskToJSON } from './parser.js';
const tasksJsonDir = './tasks-json';
const tasksMdDir = './tasks';
// Ensure the output directory exists
if (!fs.existsSync(tasksMdDir)) {
fs.mkdirSync(tasksMdDir);
}
const jsonFiles = fs.readdirSync(tasksJsonDir);
jsonFiles.forEach(file => {
if (path.extname(file) === '.json') {
const jsonPath = path.join(tasksJsonDir, file);
const mdPath = path.join(tasksMdDir, file.replace('.json', '.md'));
// Read and parse the JSON file
const jsonContent = fs.readFileSync(jsonPath, 'utf8');
const taskObject = JSON.parse(jsonContent);
if (taskObject.examples.length === 0) {
console.log(`Skipping ${file} because it has no examples`);
console.log('Something has gone wrong with the parsing')
return;
}
// Convert the JSON object to a markdown string
const taskString = jsonToTaskString(taskObject);
// Write the markdown string to a file
fs.writeFileSync(mdPath, taskString);
console.log(`Converted ${file} to markdown`);
}
});
console.log('Conversion complete!');