Skip to content

Commit

Permalink
workers/ondemand in assets
Browse files Browse the repository at this point in the history
  • Loading branch information
thepian committed Oct 25, 2015
1 parent 29cee59 commit 78d42cf
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 43 deletions.
15 changes: 15 additions & 0 deletions lib/client/bundler/index.js
Expand Up @@ -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.
*
Expand Down
30 changes: 0 additions & 30 deletions lib/client/bundler/proto.js
Expand Up @@ -3,7 +3,6 @@

var fs = require('fs'),
path = require('path'),
glob = require('glob'),
shortid = require('shortid'),
system = require('../system'),
view = require('../view');
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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) {
Expand Down
17 changes: 7 additions & 10 deletions lib/client/system/modules/socketstream.js
Expand Up @@ -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();
Expand Down Expand Up @@ -43,7 +40,7 @@ exports.send = function(responderId) {
*/


async = {
var async = {
loaded: {},
loading: new EventEmitter2
};
Expand Down Expand Up @@ -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',
Expand All @@ -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);
}
};

Expand Down
4 changes: 1 addition & 3 deletions lib/tasks/defaults.js
Expand Up @@ -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);
Expand Down

0 comments on commit 78d42cf

Please sign in to comment.