Skip to content

Commit

Permalink
added code to write the client files to the lib/dist folder
Browse files Browse the repository at this point in the history
  • Loading branch information
prgsmall committed Nov 12, 2011
1 parent ba93878 commit 08f9e26
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 0 deletions.
File renamed without changes.
File renamed without changes.
49 changes: 49 additions & 0 deletions lib/genclient.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
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"];

for (i in files) {
file = process.cwd() + "/lib/" + files[i];
stats = fs.statSync(file);
buffers.push(new Buffer(stats.size));

fd = fs.openSync(file, "r");
size += fs.readSync(fd, buffers[i], 0, stats.size, null);
fs.close(fd);
}

uber = "";
for (i in buffers) {
uber += buffers[i].toString("utf8");
}

fd = fs.openSync(distDir + "acequia.js", "w");
fs.writeSync(fd, uber, 0);
fs.close(fd);

return uber;
};

var minifyClientFiles = function (code, distDir) {
var ast = jsp.parse(code);
ast = pro.ast_mangle(ast);
ast = pro.ast_squeeze(ast);
var final_code = pro.gen_code(ast);

fd = fs.openSync(distDir + "acequia.min.js", "w");
fs.writeSync(fd, final_code, 0);
fs.close(fd);
};

exports.generateClientCode = function () {
var distDir = process.cwd() + "/lib/dist/";
fs.mkdir(distDir, 0777);

var code = concatenateClientFiles(distDir);
minifyClientFiles(code, distDir);
};

0 comments on commit 08f9e26

Please sign in to comment.