-
Notifications
You must be signed in to change notification settings - Fork 2
/
generateThemesMD.js
56 lines (44 loc) · 1.89 KB
/
generateThemesMD.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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
const fs = require("fs");
const path = require("path");
const themesDirectory = path.join(__dirname, "themes");
const outputFile = path.join(__dirname, "themes.md");
// Markdown header with instructions for contributing
const mdHeader = `# Themes Gallery
This document showcases the available themes for the application. Each theme has an image preview and the corresponding code snippet for download.
## Contributing a New Theme
To contribute a new theme, follow these steps:
1. Fork the repository.
2. Add your theme JSON and image preview to the \`themes\` directory.
3. Generate the image preview for your theme with \`npm run generate:img\` script.
4. Run the \`npm run generate:md\` script to update the themes gallery.
## Available Themes
`;
// Start with the header
let mdContent = mdHeader;
// Read the themes directory
fs.readdir(themesDirectory, (err, files) => {
if (err) {
console.error("Could not list the directory.", err);
return;
}
const themes = files.filter(file => path.extname(file) === ".json");
themes.forEach(themeFile => {
const filePath = path.join(themesDirectory, themeFile);
const theme = JSON.parse(fs.readFileSync(filePath, "utf8"));
const themeName = theme.name;
const imageFileName = themeName + ".svg";
const imageFilePath = path.relative(__dirname, path.join(themesDirectory, imageFileName));
const jsonFileUrl = path.relative(__dirname, path.join(themesDirectory, themeFile));
// Append theme information to markdown content
mdContent += `### ${theme.displayName}\n`;
mdContent += `![${themeName}](${imageFilePath})\n\n`;
mdContent += `JSON File: [${themeName}.json](${jsonFileUrl})\n\n`;
mdContent += "Download Code: \n";
mdContent += "```txt\n";
mdContent += `${themeName}\n`;
mdContent += "```\n\n";
});
// Write to the output file
fs.writeFileSync(outputFile, mdContent);
console.log(`Markdown file ${outputFile} has been generated.`);
});