-
Notifications
You must be signed in to change notification settings - Fork 0
/
clutter.js
50 lines (35 loc) · 1.33 KB
/
clutter.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
import fs, { mkdir } from "fs";
import path from "path";
const directory = "./";
const Clutter = ( ...values ) => {
const restrictedFile = [...values]
fs.readdir(directory, (err, files) => {
files.forEach((file) => {
// For getting the absolute path of the files
const filePath = fs.lstatSync(path.resolve(directory, file));
// Check for only file excluding directories
if (filePath.isFile()){
const fileName = file.split(".")
const extension = fileName[fileName.length - 1]
// if (!(extension == "json") && !(file == "clutter.js") && !(file == "README.md")) {
if (!["json"].includes(extension) && !["clutter.js", "README.md"].includes(file) && !restrictedFile.includes(file)) {
// Creating directories for each file excluding json files and js file
mkdir(extension, () => null)
// Moving files to the corresponding directories
setTimeout(() => {
fs.copyFile(file, `${extension}/${file}`, (err)=> {
if (err) {
console.log(err)
}
})
}, 0);
// Removing files
setTimeout(() => {
fs.unlinkSync(file)
}, 100);
}
}
})
});
}
export { Clutter }