Skip to content

Commit

Permalink
Merge f83c6df into 899d9a9
Browse files Browse the repository at this point in the history
  • Loading branch information
thepian committed Sep 27, 2015
2 parents 899d9a9 + f83c6df commit 6cbc023
Show file tree
Hide file tree
Showing 25 changed files with 252 additions and 219 deletions.
13 changes: 7 additions & 6 deletions lib/client/bundler/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,17 +116,17 @@ module.exports = function(ss,options) {
define: function defineBundler(client,args) {

var name = args[0],
pathsOrFunc = args[1],
pathsOrPlugin = args[1],
bundler;

if (typeof pathsOrFunc === "function") {
bundler = bundlers[name] = pathsOrFunc(ss,client,options);
if (typeof pathsOrPlugin === "string") {
bundler = bundlers[name] = ss.require(options.servePacked?'production':args[1],'client/bundler','default')(ss,client,options);
bundler.client = client;
bundler.define(args[2], args[3], args[4], args[5]);
} else {
bundler = bundlers[name] = require('./default')(ss,client,options);
bundler = bundlers[name] = require('./default')(ss,client,options); //TODO production bundler switch
bundler.client = client;
bundler.define(args[1]);
bundler.define(args[1],args[2]);
}
bundler.useLatestsPackedId();
},
Expand Down Expand Up @@ -166,7 +166,8 @@ module.exports = function(ss,options) {

for(var i = 0,rel; (rel = client.paths.code[i]); ++i) {
var p = path.join(ss.root, rel);
if (fs.statSync(p).isDirectory()) {
//TODO if not exists error handling
if (fs.existsSync(p) && fs.statSync(p).isDirectory()) {

var files = fs.readdirSync(p);
var entry = files.filter(onlyModuleEntry);
Expand Down
68 changes: 68 additions & 0 deletions lib/client/bundler/production.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
'use strict'

//TODO just load from assets folder

module.exports = function(ss,client,options){

var bundler = ss.bundler.create({
define: define,
asset: asset
});
return bundler;


function define(paths) {

if (typeof paths.view !== 'string') {
throw new Error('You may only define one HTML view per single-page client. Please pass a filename as a string, not an Array');
}
if (paths.view.lastIndexOf('.') <= 0) {
throw new Error('The \'' + paths.view + '\' view must have a valid HTML extension (such as .html or .jade)');
}

// Define new client object
client.paths = ss.bundler.sourcePaths(paths);
client.constants = paths.constants || paths.consts;
client.locals = paths.locals;
client.entryInitPath = ss.bundler.findEntryPoint(client);
}

//TODO callback(err,output) for pack to flag error
function asset(entry, opts, cb) {
ss.bundler.loadFile(entry, opts, null,
function(output) {
switch(entry.bundle) {
case 'html':
return cb(ss.bundler.injectTailIfNeeded(output,opts));
case 'css':
return cb( client.includes.css? output:'');
case 'worker':
//TODO
if (opts.compress && entry.file.indexOf('.min') === -1) {
output = ss.bundler.minifyJSFile(output, entry.file);
}
break;

default:
//TODO with options compress saved to avoid double compression
output = bundler.wrapCode(output, entry, opts);
if (opts.compress && entry.file.indexOf('.min') === -1) {
output = ss.bundler.minifyJSFile(output, entry.file);
}
return cb(output);
}
},
function(err) {
ss.log.clientIssue(client,options,err,entry);
switch(entry.ext) {
case 'html':
return cb('Couldn\'t format ' + entry.file + err.userInfoHTML);
case 'css':
return cb('/* couldn\'t format ' + entry.file + err.userInfoText+' */');
default:
return cb('// couldn\'t format ' + entry.file + err.userInfoText);
}
});
}
};

163 changes: 0 additions & 163 deletions lib/client/bundler/webpack.js

This file was deleted.

18 changes: 18 additions & 0 deletions lib/client/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -167,13 +167,22 @@ module.exports = function(ss) {
return _results;
},

servePacked: function(opts) {
if (opts && typeof opts !== 'object') {
throw new Error('Options passed to ss.client.servePacked() must be an object');
}
options.servePacked = opts || true;
options.liveReload = false;
},

// Tell the asset manager to pack and minimise all assets
packAssets: function(opts) {
if (opts && typeof opts !== 'object') {
throw new Error('Options passed to ss.client.packAssets() must be an object');
}
options.packedAssets = opts || true;
options.servePacked = opts || true;
options.liveReload = false;

// As it's safe to assume we're running in production mode at this point, if your app is not catching uncaught
// errors with its own custom error handling code, step in and prevent any exceptions from taking the server down
Expand Down Expand Up @@ -223,6 +232,15 @@ module.exports = function(ss) {
return client;
},

/**
* Standard plugins or ones loaded by require. These plugins do not need to be loaded
* in production.
* - bundler
* - formatter
* - template engine
*/
plugins: {},

/**
* @ngdoc service
* @name client.task
Expand Down
2 changes: 1 addition & 1 deletion lib/publish/transport.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ module.exports = function() {
if (!transport) {
this.use('internal');
}
return transport(config);
return transport(config); //TODO should this be (ss,config) ?
}
};
};
19 changes: 5 additions & 14 deletions lib/socketstream.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,6 @@
// ----------------
'use strict';

// console.log('CHECK');
// console.log(process.env);
// console.log('/CHECK');

require('colors');

var EventEmitter2 = require('eventemitter2').EventEmitter2;
Expand Down Expand Up @@ -98,6 +94,11 @@ var api = exports.api = {
}
};

/**
* Internal API for loading bundler plugins.
*/
api.require = require('./utils/require')(api);

/**
* @ngdoc service
* @name events
Expand All @@ -122,16 +123,6 @@ var client = exports.client = require('./client/index')(api).init();
// Tasks for Orchestrator
var tasks = exports.tasks = require('./tasks')(api, http.router, client.options);

/**
* @ngdoc service
* @name ss.orchestrator
* @description
* Internal Orchestrator for starting the server or building resources.
*
* Note: currently experimental
*/
api.orchestrator = tasks.orchestrator;

// This is an experimental API, expect changes
exports.task = api.task = tasks.add;
api.defaultTask = tasks.defaultTask;
Expand Down
2 changes: 1 addition & 1 deletion lib/tasks/defaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ module.exports = function(ss, router, options, orchestrator) {
defaultDeps.push('load-socketstream');
if (options.packedAssets) {
defaultDeps.push(options.packedAssets.all? 'pack-all':'pack-if-needed');
} else {
} else if (!options.servePacked) {
defaultDeps.push('live-assets');
}
if (options.liveReload) {
Expand Down
5 changes: 5 additions & 0 deletions lib/tasks/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,14 @@ module.exports = function(ss, router, options) {
}
},

use: function(gulp) {
orchestrator = gulp;
return this;
},

start: function(tasks, done) {
orchestrator.start(tasks, doneIfAllDone);
return this;

function doneIfAllDone(err) {
if (err) {
Expand Down

0 comments on commit 6cbc023

Please sign in to comment.