-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
49 lines (40 loc) · 1.15 KB
/
index.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
/*
* Shimly
* https://github.com/nicbell/shimly
*/
var uglify = require('uglify-js'),
fs = require('fs'),
path = require('path');
module.exports = {
list: function () {
var folder = path.normalize(__dirname + '/shims/'),
fileNames = fs.readdirSync(folder);
return fileNames.map(function (fileName) {
return fileName.replace('.js', '');
});
},
shim: function (shim, minify, destination) {
var banner = '/*! \nIncluded shims: ' + shim + '\n*/\n\n',
files = [],
uglified;
//Convert files into paths.
for (var i = 0; i < shim.length; i++) {
files[i] = path.normalize(__dirname + '/shims/' + shim[i] + '.js');
}
if (minify) {
uglified = uglify.minify(files, { output: null, preserveComments: false, compress: {} });
} else {
uglified = uglify.minify(files, { output: { comments: true, beautify: true }, compress: null });
}
//If destination is specified write to file.
if (destination) {
var dest = path.resolve(destination),
destDir = path.dirname(dest);
if (!fs.existsSync(destDir)) {
fs.mkdirSync(destDir);
}
fs.writeFileSync(dest, banner + uglified.code);
}
return banner + uglified.code;
}
};