-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
97 additions
and
37 deletions.
There are no files selected for viewing
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,49 +1,74 @@ | ||
/*globals require exports process*/ | ||
|
||
var jsp = require("uglify-js").parser; | ||
var pro = require("uglify-js").uglify; | ||
var fs = require("fs"); | ||
var util = require("util"); | ||
var Buffer = require('buffer').Buffer; | ||
|
||
var concatenateClientFiles = function (distDir) { | ||
var buffers = [], uber, fd, stats, i, size = 0, file, files = ["msg.js", "client/acequiaClient.js"]; | ||
var fullCode = ""; | ||
var minifiedCode = ""; | ||
|
||
/** | ||
* Reads the client-side files and concatenate them into a single file | ||
* @returns {String} the concatenated file | ||
*/ | ||
var concatenateClientFiles = function () { | ||
var buffer, code = "", fd, stats, i, size = 0, file, files = ["msg.js", "client/acequiaClient.js"]; | ||
|
||
for (i in files) { | ||
file = process.cwd() + "/lib/" + files[i]; | ||
stats = fs.statSync(file); | ||
buffers.push(new Buffer(stats.size)); | ||
buffer = new Buffer(stats.size); | ||
|
||
fd = fs.openSync(file, "r"); | ||
size += fs.readSync(fd, buffers[i], 0, stats.size, null); | ||
size += fs.readSync(fd, buffer, 0, stats.size, null); | ||
fs.close(fd); | ||
|
||
code += buffer.toString("utf8"); | ||
} | ||
|
||
uber = ""; | ||
for (i in buffers) { | ||
uber += buffers[i].toString("utf8"); | ||
} | ||
return code; | ||
}; | ||
|
||
/** | ||
* Write the code generated in concatenateClientFiles to two files: | ||
* one as is, the other minified. | ||
* @param {String} code The code to write out. | ||
* @param {String} distDir The directories where the files should be written. | ||
*/ | ||
var writeClientFiles = function (code, distDir) { | ||
var fd, ast; | ||
|
||
// Write the non-minified version | ||
fd = fs.openSync(distDir + "acequia.js", "w"); | ||
fs.writeSync(fd, uber, 0); | ||
fs.writeSync(fd, code, 0); | ||
fs.close(fd); | ||
|
||
return uber; | ||
}; | ||
|
||
var minifyClientFiles = function (code, distDir) { | ||
var ast = jsp.parse(code); | ||
// Minify the code | ||
ast = jsp.parse(code); | ||
ast = pro.ast_mangle(ast); | ||
ast = pro.ast_squeeze(ast); | ||
var final_code = pro.gen_code(ast); | ||
minifiedCode = pro.gen_code(ast); | ||
|
||
// Write the minified version | ||
fd = fs.openSync(distDir + "acequia.min.js", "w"); | ||
fs.writeSync(fd, final_code, 0); | ||
fs.writeSync(fd, minifiedCode, 0); | ||
fs.close(fd); | ||
}; | ||
|
||
/** | ||
* Generates the client code for the server to serve up. | ||
*/ | ||
exports.generateClientCode = function () { | ||
var distDir = process.cwd() + "/lib/dist/"; | ||
var distDir; | ||
|
||
distDir = process.cwd() + "/lib/dist/"; | ||
fs.mkdir(distDir, 0777); | ||
|
||
var code = concatenateClientFiles(distDir); | ||
minifyClientFiles(code, distDir); | ||
}; | ||
fullCode = concatenateClientFiles(); | ||
writeClientFiles(fullCode, distDir); | ||
}; | ||
|
||
exports.code = fullCode; | ||
exports.minifiedCode = minifiedCode; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,10 @@ | ||
{ "description":"Message router for node.js supporting multiple protocols" | ||
, "directories":{"doc":"./doc","lib":"./lib/ws"} | ||
, "engines":{"node":">=0.2.0-0"} | ||
, "name" : "Acequia" | ||
, "repository":{"type":"git","url":"http://github.com/miksago/node-websocket-server.git"} | ||
, "scripts": { "start": "node ./acequia.js" } | ||
, "version" : "0.5.0" | ||
{ | ||
"name" : "Acequia" | ||
,"description":"Message router for node.js supporting multiple protocols" | ||
, "main": "index" | ||
, "directories": {"lib": "./lib"} | ||
, "engines":{"node":">=0.6.0-0"} | ||
, "repository":{"type":"git","url":"https://prgsmall@github.com/prgsmall/acequia.git"} | ||
, "scripts": { "start": "node ." } | ||
, "version" : "0.1.0" | ||
} |