Files
socket.io/bin/build
2011-06-07 20:14:09 -03:00

60 lines
1.7 KiB
JavaScript
Executable File

#!/usr/bin/env node
/**
* Socket.IO client
*
* @author Guillermo Rauch <guillermo@learnboost.com>
* @license The MIT license.
* @copyright Copyright (c) 2010 LearnBoost <dev@learnboost.com>
*/
/*
* This file will help you take all the Socket.IO client files and build socket.io.js.
* You can later use Google Closure Compiler on it.
*/
var fs = require('fs'),
io = require('../lib/io'),
jsp = require('../lib/vendor/uglifyjs/lib/parse-js'),
pro = require("../lib/vendor/uglifyjs/lib/process"),
ast,
files = [
'io.js',
'util.js',
'events.js',
'json.js',
'parser.js',
'transport.js',
'transports/xhr.js',
'transports/xhr-polling.js',
'transports/jsonp-polling.js',
'transports/websocket.js',
'transports/htmlfile.js',
'namespace.js',
'socket.js'
],
content = "/** Socket.IO "+ io.version +" - Built with build.js */\n",
license = "/* Socket.IO.min "+ io.version +" @author Guillermo Rauch <guillermo@learnboost.com>, @license The MIT license., @copyright Copyright (c) 2010 LearnBoost <dev@learnboost.com> */\n";
console.log('Reading files…');
files.forEach(function(file){
var path = __dirname + '/../lib/' + file;
console.log(' + ' + path);
content += fs.readFileSync(path) + "\n";
});
console.log('Generating…');
fs.write(fs.openSync(__dirname + '/../dist/socket.io.js', 'w'), content, 0, 'utf8');
console.log(' + ' + __dirname + '/../dist/socket.io.js');
console.log('Uglyfying…');
ast = jsp.parse(content);
ast = pro.ast_mangle(ast); // get a new AST with mangled names
ast = pro.ast_squeeze(ast);
fs.write(fs.openSync(__dirname + '/../dist/socket.io.min.js', 'w'), license + pro.gen_code(ast), 0, 'utf8');
console.log(' + ' + __dirname + '/../dist/socket.io.min.js');
console.log('All done!');