-
-
Save liverbool/6256341 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var fs = require("fs"); | |
var dir = __dirname+"/functions"; | |
/** | |
* Build packages by you want. | |
* Added by ツ Liverbool | |
* | |
* List of packages | |
* @see https://github.com/kvz/phpjs/tree/master/functions | |
* | |
* @origin-branch https://gist.github.com/bmatusiak/5578424 | |
*/ | |
var uses = {'_phpjs_shared': 1 // required | |
,'array': 1 | |
,'ctype': 1 | |
,'info': 1 | |
,'json': 1 | |
,'math': 1 | |
,'pcre': 1 | |
,'strings': 1 | |
,'url': 1 | |
,'var': 1 | |
,'xml': 0 | |
}; | |
// also minify | |
var minify = true; | |
var mainDirs = []; | |
var mainFiles = []; | |
var files = fs.readdirSync(dir); | |
for(var i in files){ | |
var fileStats = fs.statSync(dir+"/"+files[i]); | |
if(fileStats.isDirectory()){ | |
if(uses[files[i]] !== 1) continue; | |
mainDirs.push(dir+"/"+files[i]); | |
console.log(dir+"/"+files[i]); | |
} | |
} | |
for(var j in mainDirs){ | |
var files2 = fs.readdirSync(mainDirs[j]); | |
for(var k in files2){ | |
var currentFile = mainDirs[j]+"/"+files2[k]; | |
var fileStats2 = fs.statSync(currentFile); | |
if(fileStats2.isFile()){ | |
mainFiles.push({ | |
id:files2[k].replace(".js","") , | |
file: mainDirs[j]+"/"+files2[k] | |
}); | |
} | |
} | |
} | |
var compiledFileS = "var PHPJS = {\n"; | |
var compiledFileE = "}"; | |
for(var l in mainFiles){ | |
compiledFileS += '"'+mainFiles[l].id+'" : ' + fs.readFileSync(mainFiles[l].file); | |
if(mainFiles.length-1 != l) | |
compiledFileS += ","; | |
} | |
compiledFileS += compiledFileE; | |
fs.writeFileSync(__dirname+"/out.js", compiledFileS ); | |
function doCompress(){ | |
//npm install node-minify | |
var compressor = require('node-minify'); | |
// Using UglifyJS for JS | |
new compressor.minify({ | |
type: 'uglifyjs', | |
fileIn: __dirname+"/out.js", | |
fileOut: __dirname+"/out-min.js", | |
callback: function(err){ | |
console.log(err); | |
} | |
}); | |
} | |
if(minify) doCompress(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment