forked from codeforpdx/PASS
-
Notifications
You must be signed in to change notification settings - Fork 0
/
clearDocs.js
28 lines (23 loc) · 963 Bytes
/
clearDocs.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
/* Simple script that removes all documents
* within the docs folder except for all .md files */
const fs = require('fs');
const path = require('path');
// Defining path for both /docs and /temp
const docsDir = path.join(__dirname, 'docs');
const tempDir = path.join(__dirname, 'temp');
// Creates a temp directory if it doesn't exist
if (!fs.existsSync(tempDir)) {
fs.mkdirSync(tempDir);
}
/* Returns an array of strings which are the names
* of all .md files within the docs directory */
const allMds = fs.readdirSync(docsDir).filter((file) => path.extname(file) === '.md');
// Copies all mdFiles over to the temp directory
allMds.forEach((mdFile) => {
fs.copyFileSync(`${docsDir}/${mdFile}`, `${tempDir}/${mdFile}`);
});
/* Removes the docs directory and then renames
* the temp directory as the docs directory,
* now containing only the original .md files */
fs.rmSync(docsDir, { recursive: true, force: true });
fs.renameSync(tempDir, docsDir);