forked from chatscope/chat-ui-kit-react
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathterser.js
32 lines (26 loc) · 807 Bytes
/
terser.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
// Warning this script is not used for now
const Terser = require("terser");
const fs = require("fs");
const path = require("path");
function getAllFiles(dirPath, arrayOfFiles) {
let files = fs.readdirSync(dirPath);
arrayOfFiles = arrayOfFiles || [];
files.forEach(function (file) {
if (fs.statSync(dirPath + "/" + file).isDirectory()) {
arrayOfFiles = getAllFiles(dirPath + "/" + file, arrayOfFiles);
} else {
arrayOfFiles.push(path.join(dirPath, "/", file));
}
});
return arrayOfFiles.filter((path) => path.match(/\.js$/));
}
function minifyFiles(filePaths) {
filePaths.forEach((filePath) => {
fs.writeFileSync(
filePath,
Terser.minify(fs.readFileSync(filePath, "utf8")).code
);
});
}
const files = getAllFiles("./es/");
minifyFiles(files);