Permalink
Browse files

MODIFIED - Now uses requirejs npm package to optimize

  • Loading branch information...
1 parent 1e4ea68 commit 36f121c5278606b77e2987ed4b00f1c2200deb80 @glesperance committed Apr 25, 2012
Showing with 14 additions and 8,382 deletions.
  1. +12 −106 lib/client/client.js
  2. +0 −8,275 lib/vendors/r.js
  3. +2 −1 package.json
View
118 lib/client/client.js
@@ -11,6 +11,7 @@ var async = require('async')
, EventEmitter = events.EventEmitter
, gzip = require('gzippo')
+ , requirejs = require('requirejs')
;
var asyncFs = require('../util/async_fs')
@@ -255,27 +256,17 @@ function watchAndExportConfig(config_file_path, callback) {
function optimizeDir(dir_path, dst_tmpdir, options_tmpdir, callback) {
var options_filename = Date.now() + '.js'
-
- , blank_filename = Date.now() + '-blank.js'
-
- , jade_runtime_filename = Date.now() + '-jade-runtime.js'
, require_config_path = path.join(dir_path, REQUIRE_JS_CONFIG_FILE_NAME)
, options_file_path = path.join(options_tmpdir.path, options_filename)
-
- , blank_file_path = path.join(options_tmpdir.path, blank_filename)
- , blank_file_path_no_ext = path.join(options_tmpdir.path, blank_filename.slice(0, blank_filename.length - 3))
-
- , tmp_jade_runtime_path = path.join(options_tmpdir.path, jade_runtime_filename)
- , tmp_jade_runtime_path_no_ext = path.join(options_tmpdir.path, jade_runtime_filename.slice(0, jade_runtime_filename.length - 3))
, options = {
appDir : dir_path
, baseUrl : './'
, dir : dst_tmpdir.path
, modules : []
- //, optimize: 'none'
+ , optimize: 'uglify'
}
, external_modules = []
@@ -319,7 +310,7 @@ function optimizeDir(dir_path, dst_tmpdir, options_tmpdir, callback) {
if (src.substr(0,4) === 'http') {
external_modules.push(name);
- config.paths[name] = blank_file_path_no_ext;
+ config.paths[name] = 'empty:';
}
@@ -329,14 +320,14 @@ function optimizeDir(dir_path, dst_tmpdir, options_tmpdir, callback) {
}
- options.optimize = config.optimize;
+ config.optimize && (options.optimize = config.optimize);
options.paths = options.paths || {};
- options.paths['jade-runtime'] = tmp_jade_runtime_path_no_ext
+ options.paths['jade-runtime'] = 'empty:';
external_modules.push('now');
- options.paths['now'] = blank_file_path_no_ext
+ options.paths['now'] = 'empty:';
callback(null);
@@ -395,11 +386,10 @@ function optimizeDir(dir_path, dst_tmpdir, options_tmpdir, callback) {
if (filename.substr(-suffix.length) === suffix) {
- module_name = filename.substr(0, filename.length - 3)
+ module_name = filename.substr(0, filename.length - 3);
options.modules.push(
- {
- name: module_name
+ { name : module_name
, exclude : external_modules
}
);
@@ -416,97 +406,13 @@ function optimizeDir(dir_path, dst_tmpdir, options_tmpdir, callback) {
)
}
-
- , function(callback) {
-
- dst_tmpdir.clear(callback);
-
- }
-
- , function(callback) {
-
- var data = JSON.stringify(options)
- ;
-
- fs.writeFile(
-
- options_file_path
-
- , data
-
- , 'utf8'
-
- , callback
-
- );
-
- }
-
- , async.apply(fs.writeFile, blank_file_path, '', 'utf8')
-
- , function(callback) {
-
- if (views) {
-
- fs.symlink(path.join(__dirname, 'rocket-js', 'vendors', JADE_RUNTIME_FILE_NAME), tmp_jade_runtime_path, callback);
-
- } else {
-
+
+ , function (callback) {
+ requirejs.optimize(options, function (buildResponse) {
callback(null);
-
- }
-
+ })
}
- , function(callback) {
-
- var rjs_path = path.join(__dirname, '../vendors/r.js')
- , child = child_process.spawn(
- 'node'
- , [rjs_path, '-o', options_file_path]
- )
- , done
- ;
-
- child.stdout.on('data', function(data) {
- process.stdout.write(".");
-
- //TODO: Replace/remove this hack when node properly supports child processes / VMs inside a cluster worker.
- if (data + '' === 'DONE\n') {
- done = true;
- child.kill();
- callback(null);
- }
- });
-
- child.stderr.on('data', function(data) {
- console.log('xxx r.js : ' + data);
- });
-
- child.on('exit', function(code) {
-
- var error
- ;
-
- if (!done) {
-
- if (code !== 0) {
-
- error = 'xxx r.js : process exited with code [' + code + ']';
-
- console.log(error);
-
- callback(error)
-
- }
-
- callback(null);
- }
-
- });
-
- }
-
, function(callback) {
options_tmpdir.clear(callback);
View
8,275 lib/vendors/r.js
0 additions, 8,275 deletions not shown because the diff is too large. Please use a local Git client to view these changes.
View
3 package.json
@@ -2,7 +2,7 @@
"name": "rocket"
, "description": "The rapid development framework for node.js"
, "keywords": ["mvc", "model view controller", "comet","rapid development", "Rocket", "framework"]
-, "version": "0.3.1"
+, "version": "0.3.2"
, "homepage": "http://wavo.me"
, "repository":
{ "type" : "git"
@@ -29,6 +29,7 @@
, "now" : "0.8.x"
, "colors" : "0.6.x"
, "gzippo" : "0.1.x"
+ , "requirejs" : "1.0.x"
}
, "devDependencies": {
}

0 comments on commit 36f121c

Please sign in to comment.