-
Notifications
You must be signed in to change notification settings - Fork 0
/
build-min.js
58 lines (52 loc) · 2.26 KB
/
build-min.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
51
52
53
54
55
56
57
58
var enums = require('./core/enum.js'); //Contants used across he app
/*
* Important configuation variables - minFolder, build
*/
var minFolder = 'minified'; //Target folder here your output file will be written
var build = enums.MIN_BUILD.BUILD; //Change this to 'enums.MIN_BUILD.DEBUG' to debug the Output file generated
var uglify = require("uglify-js"),
scha = require("./core/scha.js"),
fs = require('fs'),
fsWrite = function(dest, data, encoding){
return new Promise(function(resolve, reject){
fs.writeFile(dest, data, encoding || "utf8", function(err){
if(err) {reject(err, dest)} else {resolve(dest)}
});
});
};
try {
fs.mkdirSync(minFolder);
} catch(e) {
if ( e.code != 'EEXIST' ) throw e;
}
//Protection.js
fsWrite("./"+minFolder+"/protection.min.js", (function(){
// Simple closure function , since i didnt want to referece code variable
var code = uglify.minify("./core/protection.js").code;
return code.substring(0, code.length - 1); /*this is to remove the trailing semicolon generated by uglify*/
})())
.then(function(file){
console.log("File processed:".green+file);
})
.catch(function(err, dest){
console.log("Unable to write file:".red + dest +"\nException:"+err);
});
//Unpacker.v2.js - New Browsers
// fsWrite("./minified/unpacker.v2.min.js", jsfuck.encode((uglify.minify("./core/unpacker.v2.js")).code))
var code = build === enums.MIN_BUILD.DEBUG ? '(function(n, i, r, u, s) {' + fs.readFileSync('./core/unpacker.v2.1.js') + '\n})' : scha((uglify.minify("./core/unpacker.v2.1.js")).code)
fsWrite("./"+minFolder+"/unpacker.v2.min.js",code)
.then(function(file){
console.log("File processed:".green+file);
})
.catch(function(err, dest){
console.log("Unable to write file:".red + dest +"\nException:"+err);
});
//Unpacker.js - Old browser ie 9
//fsWrite("./minified/unpacker.min.js", jsfuck.encode((uglify.minify("./core/unpacker.js")).code))
fsWrite("./"+minFolder+"/unpacker.min.js", scha((uglify.minify("./core/unpacker.js")).code))
.then(function(file){
console.log("File processed:".green + file);
})
.catch(function(err, dest){
console.log("Unable to write file:".red + dest +"\nException:"+err);
});