-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcloneMD.cjs
100 lines (89 loc) · 2.85 KB
/
cloneMD.cjs
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
const fs = require("fs-extra");
const path = require("path");
const gitClone = require("git-clone/promise");
const showdown = require("showdown");
const ffmpeg = require('fluent-ffmpeg');
function convertMarkdownToHTML(markdown) {
const converter = new showdown.Converter();
return converter.makeHtml(markdown);
}
function traverseDirectory(directory) {
const files = fs.readdirSync(directory);
const filePaths = [];
for (const file of files) {
const filePath = path.join(directory, file);
const fileStat = fs.statSync(filePath);
if (fileStat.isDirectory()) {
traverseDirectory(filePath);
} else if (file.endsWith(".md")) {
const markdown = fs.readFileSync(filePath, "utf-8");
const html = convertMarkdownToHTML(markdown);
const htmlFileName = file.replace(".md", ".html");
const destinationPath = path.join(filePath, "..", htmlFileName);
fs.writeFileSync(destinationPath, html);
filePaths.push(htmlFileName)
fs.unlinkSync(filePath);
console.log(`Converted ${filePath} to ${htmlFileName}`);
} else if (file.endsWith(".mp4")) {
console.log(filePath)
ffmpeg(filePath)
.screenshots({
timestamps: ['00:00:05'],
filename: file.replace(".mp4", ".jpg"),
folder: path.join(filePath, ".."),
size: '640x360'
})
.on('end', () => {
console.log(`${file} thumbnail image generated successfully!`);
})
.on('error', (err) => {
console.error('Error occurred while generating thumbnail:', err);
});
}
}
//create JSON with all file names
const filePathsJSON = path.join(directory, "fileNames.json")
fs.writeFileSync(filePathsJSON, JSON.stringify(filePaths))
}
const repositories = [
{
name: "documentation",
repositoryURL: "https://github.com/PankratzLab/Genvisis-Docs",
destinationDirectory: path.join(__dirname, "dist/docs"),
},
];
const localDirectories = [
{
name: "Downloads",
directory: path.join(__dirname, "Downloads")
},
{
name: "Features",
directory: path.join(__dirname, "Features")
},
{
name: "Tutorials",
directory: path.join(__dirname, "Tutorials")
}
]
async function cloneRepositories() {
for (r of repositories) {
if (fs.existsSync(r.destinationDirectory)) {
fs.emptyDirSync(r.destinationDirectory);
}
try {
await gitClone(r.repositoryURL, r.destinationDirectory, null);
traverseDirectory(r.destinationDirectory);
console.log(`${r.name} conversion completed!`);
} catch (error) {
console.error(error);
}
}
for (l of localDirectories) {
const destinationDirectory = path.join(__dirname, `dist/${l.name}`)
fs.copySync(l.directory, destinationDirectory)
traverseDirectory(destinationDirectory)
console.log(`${l.name} conversion completed!`)
}
}
cloneRepositories();