-
Notifications
You must be signed in to change notification settings - Fork 0
/
copyFile.js
50 lines (44 loc) · 971 Bytes
/
copyFile.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
const fs = require("fs");
const filesTopCopy = [
{
src: "../CONTRIBUTORS.md",
dest: "../docs/contributors.md",
hideHeader: true,
},
{
src: "../CONTRIBUTING.md",
dest: "../docs/contributing.md",
hideHeader: true,
},
];
const generatingPageOptions = `---
hide_title: true
---
`;
function writeNewFile(src, dest) {
const fileContent = fs.readFileSync(src).toString();
const data = new Uint8Array(Buffer.from(generatingPageOptions + fileContent));
fs.writeFile(dest, data, (err) => {
if (err) {
console.log("Error Found:", err);
} else {
console.log("Files added");
}
});
}
function copyFile(src, dest) {
fs.copyFile(src, dest, (err) => {
if (err) {
console.log("Error Found:", err);
} else {
console.log("Files copied");
}
});
}
filesTopCopy.forEach(({ src, dest, hideHeader }) => {
if (hideHeader) {
writeNewFile(src, dest);
} else {
copyFile(src, dest);
}
});