Permalink
Browse files

add build for client/now.js

  • Loading branch information...
1 parent 501e393 commit 176050bfbc5c4375cae31506acc7a7771d5359e8 Peter Qian committed with ericz Dec 28, 2011
Showing with 73 additions and 7 deletions.
  1. +3 −0 Makefile
  2. +44 −0 bin/build_now.js
  3. +2 −0 lib/dist/now.js
  4. +24 −7 lib/fileServer.js
View
@@ -0,0 +1,3 @@
+build:
+ @node ./bin/build_now.js;
+
View
@@ -0,0 +1,44 @@
+/*
+ * Module dependencies.
+ */
+var fs = require('fs')
+ , package = JSON.parse(fs.readFileSync(__dirname + '/../package.json'))
+ , jsp = require("uglify-js").parser
+ , pro = require("uglify-js").uglify;
+
+
+
+var template = '/*! now.%ext% build:' + package.version + ', %type%. Copyright(c) 2011 Flotype <team@flotype.com> MIT Licensed */\n'
+ , development = template.replace('%type%', 'development').replace('%ext%', 'js')
+ , production = template.replace('%type%', 'production').replace('%ext%', 'min.js');
+
+
+
+ //array base containing all the files to be read.
+ base = ['now.js'];
+ var files = [];
+ base.forEach(function (file) {
+ files.push(__dirname + '/../lib/client/' + file);
+ });
+
+ var results = {};
+ files.forEach(function (file) {
+ fs.readFile(file, function (err, content) {
+
+ if (err) throw err;
+ var code = content.toString();
+ var ast = jsp.parse(code);
+ ast = pro.ast_squeeze(ast, {make_seqs: false, dead_code: false});
+ var code = production + pro.gen_code(ast, {ascii_only: true});
+
+ code += ';';
+ fs.write(
+ fs.openSync(__dirname + '/../lib/dist/now.js', 'w')
+ , code
+ , 0
+ , 'utf8'
+ );
+
+ });
+ });
+
View

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.
View
@@ -1,6 +1,7 @@
var fs = require('fs');
var nowUtil = require('./nowUtil').nowUtil;
-
+//redirect the client/now.js to ../dist/now.min.js
+var clientNow = '/dist/now.js';
var fileCache = {};
var nowFileCache = {};
@@ -30,7 +31,16 @@ handleResponse = function (request, response) {
// Detect if request involves the now.js file
if (request.url.split('?')[0] === '/nowjs/now.js') {
- serveFile(__dirname + '/client/now.js', request, response, options);
+ try {
+ console.log("serveFile: the directory is " + clientNow);
+ serveFile(__dirname + clientNow, request, response, options);
+ }
+ catch(err)
+ {
+ console.log("/client/now.js not found, while serving file");
+ return;
+ };
+
} else {
// Make sure default listeners are still handled
for (i in defaultListeners) {
@@ -99,15 +109,22 @@ serveFile = function (filename, request, response, options) {
// Takes host and port and call callback with now.js as parameter
generateClientLibs = function (hostServer, hostPort, callback) {
- fs.readFile(__dirname + '/client/now.js', function (err, data) {
- var nowText = data.toString();
- var initString = options.scope + '.now = nowInitialize("' +
+ try {
+ console.log("readFile: the directory is " + clientNow);
+ fs.readFile(__dirname + clientNow, function (err, data) {
+ var nowText = data.toString();
+ var initString = options.scope + '.now = nowInitialize("' +
(options.protocol !== undefined ? options.protocol + ':' : '') +
'//' + hostServer + ':' + hostPort + '", ' + options.client + ');\n';
- nowText += initString;
+ nowText += initString;
- callback(nowText);
+ callback(nowText);
});
+ } catch(err){
+ console.log("/client/now.js not found while reading file");
+ return;
+
+ };
};
exports.generateClientLibs = generateClientLibs;

0 comments on commit 176050b

Please sign in to comment.