diff --git a/lib/client/bundler/index.js b/lib/client/bundler/index.js index a8c790d7..c6462910 100644 --- a/lib/client/bundler/index.js +++ b/lib/client/bundler/index.js @@ -518,6 +518,21 @@ module.exports = function(ss,options) { } }, + //TODO task for generating the on-demand stuff to target assets dir + + updateCachedOndemandAssets: function UpdateCachedOndemandAssets() { + + var files = glob.sync('**/*.js', {cwd: path.join(ss.root,options.dirs.code)}); //TODO need root *.js as well + files.forEach(function(rel) { + ss.http.cached.route('assets/ondemand/'+ (rel.replace('\\','/')), null, path.join(ss.root, options.dirs.code, rel) ); + },this); + + files = glob.sync('**/*.js', {cwd: path.join(ss.root,options.dirs.workers)}); //TODO need root *.js as well + files.forEach(function(rel) { + ss.http.cached.route('assets/workers/'+ (rel.replace('\\','/')), null, path.join(ss.root, options.dirs.workers, rel) ); + },this); + }, + /** * Make a list of asset entries for JS/CSS bundle. * diff --git a/lib/client/bundler/proto.js b/lib/client/bundler/proto.js index d56895c8..904ee594 100644 --- a/lib/client/bundler/proto.js +++ b/lib/client/bundler/proto.js @@ -3,7 +3,6 @@ var fs = require('fs'), path = require('path'), - glob = require('glob'), shortid = require('shortid'), system = require('../system'), view = require('../view'); @@ -111,7 +110,6 @@ module.exports = function(ss, bundlers, bundlerById, options) { ss.bundler.loadFile(entry,options,formatter,cb, errCb); //TODO call loadFile 'html' }, - updateCachedOndemandAssets: UpdateCachedOndemandAssets, updateCachedDevAssets: UpdateCachedDevAssets, clientFilePath: function(rel) { @@ -365,34 +363,6 @@ module.exports = function(ss, bundlers, bundlerById, options) { return ss.bundler.wrapModule(modPath, code); } - //TODO task for generating the on-demand stuff to target assets dir - - function UpdateCachedOndemandAssets() { - - var files = glob.sync('**/*.js', {cwd: path.join(ss.root,options.dirs.code)}); //TODO need root *.js as well - files.forEach(function(rel) { - ss.http.cached.route('assets/'+this.client.name+'/code/'+ (rel.replace('\\','/')), null, path.join(ss.root, options.dirs.code, rel) ); - },this); - - files = glob.sync('**/*.js', {cwd: path.join(ss.root,options.dirs.workers)}); //TODO need root *.js as well - files.forEach(function(rel) { - ss.http.cached.route('assets/'+this.client.name+'/workers/'+ (rel.replace('\\','/')), null, path.join(ss.root, options.dirs.workers, rel) ); - },this); - - /*TODO render with bundler - var entry = ss.bundler.entryFor('worker',options.dirs.workers.substring(1),path), - opts = { - //TODO packAssets vs packedAssets - compress: options.packAssets - }; - - ss.bundler.loadFile(entry, opts, null, cb, function(err) { - ss.log.clientIssue({name:'unknown','id':'unknown'},options,err,entry); - cb('console.log("error","'+ err.userInfoText +'")'); - }); - */ - } - function UpdateCachedDevAssets() { var url = 'assets/'+this.client.name+'/'+this.client.id+'.html'; view(ss, this.client, options, function(content) { diff --git a/lib/client/system/modules/socketstream.js b/lib/client/system/modules/socketstream.js index 52440da7..bc63c1af 100644 --- a/lib/client/system/modules/socketstream.js +++ b/lib/client/system/modules/socketstream.js @@ -2,20 +2,17 @@ // SocketStream Browser Client // --------------------------- // The code in this file is always sent to the browser, regardless which websocket transport is used -var EventEmitter2, async, message, server, transport; - -EventEmitter2 = require('eventemitter2').EventEmitter2; +var message, server, transport = null, + EventEmitter2 = require('eventemitter2').EventEmitter2; // Setup message emitters -server = exports.server = new EventEmitter2; +server = exports.server = new EventEmitter2(); -message = exports.message = new EventEmitter2; +message = exports.message = new EventEmitter2(); // Provide a place to store templates exports.tmpl = {}; -transport = null; - exports.assignTransport = function (config) { transport = require('socketstream-transport')(server, message, config); transport.send = transport.connect(); @@ -43,7 +40,7 @@ exports.send = function(responderId) { */ -async = { +var async = { loaded: {}, loading: new EventEmitter2 }; @@ -94,7 +91,7 @@ exports.load = { // Send request to server return $.ajax({ - url: '/_serve/code?' + nameOrDir, + url: '/assets/ondemand/' + nameOrDir, type: 'GET', cache: false, dataType: 'script', @@ -106,7 +103,7 @@ exports.load = { // Load Web Workers from /client/workers worker: function(name) { - return new Worker('/_serve/worker?' + name); + return new Worker('/assets/workers/' + name); } }; diff --git a/lib/tasks/defaults.js b/lib/tasks/defaults.js index 004ddb41..a781de8a 100644 --- a/lib/tasks/defaults.js +++ b/lib/tasks/defaults.js @@ -51,9 +51,7 @@ module.exports = function(ss, router, options, orchestrator) { // task: ondemand // Listen out for requests to async load new assets ss.defaultTask('serve', ['load-api'], function serveOndemand(done) { - ss.bundler.forEach(function(bundler) { - bundler.updateCachedOndemandAssets(); - }); + ss.bundler.updateCachedOndemandAssets(); // Send server instance to any registered modules (e.g. console) ss.events.emit('server:start', ss.server);