-
Notifications
You must be signed in to change notification settings - Fork 0
/
js.js
38 lines (29 loc) · 897 Bytes
/
js.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
const { Command, flags } = require("@oclif/command");
const glob = require("globby");
const Terser = require("terser");
const getFile = require("../../lib/utils/getFile");
const saveFile = require("../../lib/utils/saveFile");
const minify = (filePath) => {
const fileContent = getFile(filePath);
const processed = Terser.minify(fileContent);
return {
filePath,
fileContent: processed.code,
};
};
class JSCommand extends Command {
async run() {
const { flags } = this.parse(JSCommand);
const files = await glob([`**/*.js`, `!**/*.min.js`]);
if (files.length === 0) {
return console.log("No JS to minify.");
}
files.map(minify);
console.log(`Minified ${files.length} JS files.`);
}
}
JSCommand.description = `Minify JS code
Makes your JS files smaller and production ready
Ignores files that end with .min.js
`;
module.exports = JSCommand;