Skip to content
Browse files

MODIFIED - build process is now an explicit call, not done implicitly…

… in production
  • Loading branch information...
1 parent 20c67aa commit ba1c51b1e28580d4e837cd59bee098ec45055ff1 @astalwick astalwick committed May 15, 2015
Showing with 147 additions and 172 deletions.
  1. +134 −171 lib/client/client.js
  2. +1 −0 lib/index.js
  3. +11 −0 lib/loader.js
  4. +1 −1 package.json
View
305 lib/client/client.js
@@ -589,178 +589,18 @@ exports.setup = function setup_client() {
callback.apply(this, arguments)
}
- if (process.env['NODE_ENV'] === 'production') {
-
- async.waterfall(
- [ function (callback) {
- fs.readFile(app_package_json_path, 'utf8', function (err, packageJSON) {
-
- if (err && err.code === 'ENOENT')
- callback(null, true);
- else if (err)
- callback(err);
-
- else {
- packageInfo = JSON.parse(packageJSON);
-
- fs.readFile(client_build_json_path, 'utf8', function (err, buildJSON) {
- var buildInfo;
-
- if (err && err.code === 'ENOENT')
- callback(null, true);
- else if (err)
- callback(err);
-
- else {
- buildInfo = JSON.parse(buildJSON);
-
- if (buildInfo.version === packageInfo.version)
- callback(null, false);
- else
- callback(null, true);
- }
- })
- }
- })
- }
-
- , function (_buildClient, callback) {
- buildClient = _buildClient;
-
- if (buildClient) {
- console.log('--- Building optimized client bundle. This may take several minutes.');
-
- rimraf(client_build_dir_path, function (err) {
- if (err && err.code === 'ENOENT')
- callback(null);
- else
- callback(err);
- });
- }
-
- else
- callback(null);
- }
-
- , function (callback) {
-
- if (buildClient)
- async.forEachSeries(
- [ client_build_dir_path
- , client_build_js_dir_path
- , client_build_css_dir_path
- ]
-
- , function (dirPath, callback) {
- fs.mkdir(dirPath, callback);
- }
-
- , callback
- );
-
- else
- callback(null);
- }
-
- , function (callback) {
- async.parallel(
- [ function (callback) {
- async.waterfall(
- [ function (callback) {
- if (buildClient)
- watchAndOptimize(js_dir_path, { path : client_build_js_dir_path }, optimize_js_tmpdir, callback);
-
- else
- callback(null);
- }
-
- , function (callback) {
- if (packageInfo)
- fs.writeFile(client_build_json_path, JSON.stringify(packageInfo), 'utf8', function (err) {
- callback(err);
- });
- else
- callback(null);
- }
-
- , function (callback) {
- if (buildClient)
- wrench.copyDirRecursive(
- path.join(__dirname, 'rocket-js')
- , path.join(client_build_js_dir_path, 'rocket')
- , callback);
-
- else
- callback(null);
- }
-
- , function(callback) {
-
- //sets up a static middleware to serve the webapp optimized tmp js folder
- //as `/js`
- app.use('/js', express.static(client_build_js_dir_path));
-
- if (buildClient) {
- console.log('\t--- JS build done.');
- }
-
- callback(null);
- }
-
- , async.apply(watchAndBuildClientFilesInventory, routes_dadt, js_dir_path)
-
- ]
- , callback
- );
- }
-
- , function (callback) {
- async.waterfall(
-
- [ function (callback) {
- if (buildClient)
- watchAndOptimize(css_dir_path, { path : client_build_css_dir_path }, optimize_css_tmpdir, callback);
-
- else
- callback(null);
- }
-
- , function(callback) {
-
- if (buildClient) {
- console.log('\t--- CSS build done.');
- }
-
- //sets up a static middleware to serve the webapp optimized tmp css folder
- //as `/css`
- app.use('/css', express.static(client_build_css_dir_path));
-
- callback(null);
- }
-
- ]
- , callback
- );
- }
-
- , async.apply(watchAndExportConfig, require_js_config_path)
- ]
- , function (err) {
- if (buildClient) {
- if (err)
- console.log('xxx ERROR Building client:', err);
- else
- console.log('--- Client Bundle Successfully Built');
- }
+ if(process.env['NODE_ENV'] === 'production') {
+ //sets up a static middleware to serve the webapp `client/js` folder
+ //as `/js`
+ app.use('/js', express.static(client_build_js_dir_path));
+ app.use('/css', express.static(client_build_css_dir_path));
- callback(err);
- }
- );
- }
- ]
- , doneCallback);
-
- } else {
+ async.parallel([
+ async.apply(watchAndExportConfig, require_js_config_path)
+ , async.apply(watchAndBuildClientFilesInventory, routes_dadt, js_dir_path)
+ ], doneCallback);
+ }
+ else {
/***
* sets up a static middleware to serve the rocket `rocket-js` folder
@@ -785,3 +625,126 @@ exports.setup = function setup_client() {
}
}
+
+
+exports.build = function() {
+
+ var args = Array.prototype.slice.call(arguments)
+ , routes_dadt = args.shift()
+ , client = args.shift()
+ , doneCallback = args.pop()
+
+ , js_dir_path = path.join(client.path, CLIENT_JS_DIR_NAME)
+ , css_dir_path = path.join(client.path, CLIENT_CSS_DIR_NAME)
+ , require_js_config_path = path.join(js_dir_path, REQUIRE_JS_CONFIG_FILE_NAME)
+
+ , optimize_js_tmpdir = tmpdir.mkuniqueSync()
+ , optimize_css_tmpdir = tmpdir.mkuniqueSync()
+
+ , app_dir_path = path.join(client.path, '..')
+ , app_package_json_path = path.join(app_dir_path, 'package.json')
+
+ , client_build_dir_path = path.join(app_dir_path, CLIENT_BUILD_DIR_NAME)
+
+ , client_build_json_path = path.join(client_build_dir_path, CLIENT_BUILD_JSON_FILE_NAME)
+ , client_build_js_dir_path = path.join(client_build_dir_path, CLIENT_JS_DIR_NAME)
+ , client_build_css_dir_path = path.join(client_build_dir_path, CLIENT_CSS_DIR_NAME)
+
+ , packageInfo
+ ;
+
+ async.waterfall(
+ [ function (callback) {
+ fs.readFile(app_package_json_path, 'utf8', function (err, packageJSON) {
+
+ if (err)
+ return callback(err);
+
+ packageInfo = JSON.parse(packageJSON);
+ callback();
+ })
+ }
+
+ , function (callback) {
+
+ console.log('--- Building optimized client bundle. This may take several minutes.');
+
+ rimraf(client_build_dir_path, function (err) {
+ if (err && err.code === 'ENOENT')
+ callback(null);
+ else
+ callback(err);
+ });
+ }
+
+ , function (callback) {
+ async.forEachSeries(
+ [ client_build_dir_path
+ , client_build_js_dir_path
+ , client_build_css_dir_path
+ ]
+
+ , function (dirPath, callback) {
+ fs.mkdir(dirPath, callback);
+ }
+
+ , callback
+ );
+ }
+
+ , function (callback) {
+ async.parallel(
+ [ function (callback) {
+ async.waterfall(
+ [ function (callback) {
+ watchAndOptimize(js_dir_path, { path : client_build_js_dir_path }, optimize_js_tmpdir, callback);
+ }
+
+ , function (callback) {
+ fs.writeFile(client_build_json_path, JSON.stringify(packageInfo), 'utf8', function (err) {
+ callback(err);
+ });
+ }
+
+ , function (callback) {
+ wrench.copyDirRecursive(
+ path.join(__dirname, 'rocket-js')
+ , path.join(client_build_js_dir_path, 'rocket')
+ , callback);
+ }
+
+ , function(callback) {
+ console.log(' --- JS build done.');
+
+ callback(null);
+ }
+
+ , async.apply(watchAndBuildClientFilesInventory, routes_dadt, js_dir_path)
+
+ ]
+ , callback
+ );
+ }
+
+ , function (callback) {
+ watchAndOptimize(css_dir_path, { path : client_build_css_dir_path }, optimize_css_tmpdir, function() {
+ console.log(' --- CSS build done.');
+ callback(null);
+ });
+ }
+
+ , async.apply(watchAndExportConfig, require_js_config_path)
+ ]
+ , function (err) {
+ if (err)
+ console.log('xxx ERROR Building client:', err);
+ else
+ console.log('--- Client Bundle Successfully Built');
+
+ callback(err);
+ }
+ );
+ }
+ ]
+ , doneCallback);
+}
View
1 lib/index.js
@@ -13,6 +13,7 @@ module.exports = oo.extend({
version : pkg_json_info.version
, util : require('./util')
, createServer : require('./loader').createServer
+ , build : require('./loader').build
, i18n : require('./locale').i18n
, _ : require('./locale')._
}, express);
View
11 lib/loader.js
@@ -85,3 +85,14 @@ exports.createServer = function createServer_rocket() {
);
}
+
+exports.build = function build_rocket() {
+
+ var args = Array.prototype.slice.call(arguments)
+ , app_dir = args.shift()
+ , callback = args.pop()
+ , routes = dadt.createNode()
+ ;
+
+ asyncFs.mapDir(app_dir, [CLIENT_DIR_NAME , async.apply(client.build, routes)], callback);
+}
View
2 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.6.5"
+, "version": "0.7.0"
, "homepage": "http://wavo.me"
, "repository":
{ "type" : "git"

0 comments on commit ba1c51b

Please sign in to comment.
Something went wrong with that request. Please try again.