-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
/
minify-vendor.es6.js
47 lines (43 loc) · 1.35 KB
/
minify-vendor.es6.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
const Fs = require('fs');
const Path = require('path');
const RootPath = require('../utils/rootpath.es6.js')._();
const UglifyJS = require('uglify-es');
const WalkSync = require('../utils/walk-sync.es6.js');
/**
* Method that will minify a set of vendor javascript files
*/
module.exports.compile = () => {
Promise.resolve()
.then(() => {
const folders = [
Path.join(RootPath, 'media/vendor/codemirror'),
Path.join(RootPath, 'media/vendor/punycode/js'),
Path.join(RootPath, 'media/vendor/webcomponentsjs'),
];
// Loop to get some text for the packgage.json
folders.forEach((folder) => {
const files = WalkSync.run(folder, []);
if (files.length) {
files.forEach(
(file) => {
if (file.match(/\.js/) && !file.match(/LICENSE\.md/)) {
console.log(`Processing ES5 file: ${file}`);
// Write the file
Fs.writeFileSync(
file.replace('.js', '.min.js'),
UglifyJS.minify(Fs.readFileSync(file, 'utf8')).code,
{ encoding: 'utf8' },
);
}
},
);
}
});
})
// Handle errors
.catch((error) => {
// eslint-disable-next-line no-console
console.error(`${error}`);
process.exit(1);
});
};