Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 20 additions & 16 deletions lib/consign.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ var fs = require('fs')
, util = require('util')
, path = require('path')
, pack = require(path.join(__dirname, '..', 'package'))
;
;

/**
* Consign constructor.
Expand Down Expand Up @@ -61,7 +61,7 @@ function Consign(options) {
* @param push
*/

Consign.prototype._setLocations = function(parent, entity, push) {
Consign.prototype._setLocations = function (parent, entity, push) {
if (!entity) {
this._log(['! Entity name not provided or doesn\'t exist', location], 'error');
return this;
Expand Down Expand Up @@ -101,7 +101,7 @@ Consign.prototype._setLocations = function(parent, entity, push) {

var regex = new RegExp(this._options.extensions.join('$|'), 'gi')
, extension = path.extname(location)
;
;

if (!regex.test(extension)) {
this._log(['!', this._['Ignoring extension'], ':', extension]);
Expand All @@ -126,7 +126,7 @@ Consign.prototype._setLocations = function(parent, entity, push) {
* @returns
*/

Consign.prototype._getRelativeTo = function(location) {
Consign.prototype._getRelativeTo = function (location) {
return '.' + location.split(this._options.cwd).pop();
};

Expand All @@ -138,7 +138,7 @@ Consign.prototype._getRelativeTo = function(location) {
* @returns
*/

Consign.prototype._createNamespace = function(parent, parts, mod) {
Consign.prototype._createNamespace = function (parent, parts, mod) {
var part = parts.shift();

if (!parent[part]) {
Expand All @@ -159,7 +159,7 @@ Consign.prototype._createNamespace = function(parent, parts, mod) {
* @returns
*/

Consign.prototype._getKeyName = function(name) {
Consign.prototype._getKeyName = function (name) {
return path.basename(name, path.extname(name));
};

Expand All @@ -171,7 +171,7 @@ Consign.prototype._getKeyName = function(name) {
* @returns
*/

Consign.prototype._log = function(message, type) {
Consign.prototype._log = function (message, type) {
if (this._options.verbose) {
this._options.logger[type || this._options.loggingType](message.join(' '));
}
Expand All @@ -186,7 +186,7 @@ Consign.prototype._log = function(message, type) {
* @returns
*/

Consign.prototype.include = function(entity) {
Consign.prototype.include = function (entity) {
this._lastOperation = 'include';
return this._setLocations(this._options.cwd, entity, true);
};
Expand All @@ -198,7 +198,7 @@ Consign.prototype.include = function(entity) {
* @returns
*/

Consign.prototype.exclude = function(entity) {
Consign.prototype.exclude = function (entity) {
this._lastOperation = 'exclude';
return this._setLocations(this._options.cwd, entity, false);
};
Expand All @@ -210,7 +210,7 @@ Consign.prototype.exclude = function(entity) {
* @returns
*/

Consign.prototype.then = function(entity) {
Consign.prototype.then = function (entity) {
this[this._lastOperation].call(this, entity);
return this;
};
Expand All @@ -222,19 +222,19 @@ Consign.prototype.then = function(entity) {
* @returns
*/

Consign.prototype.into = function(object) {
Consign.prototype.into = function (object) {
for (var f in this._files) {
delete require.cache[this._files[f]];

var script = this._files[f]
, parts = this._getRelativeTo(script).split(path.sep).slice(1)
, args = []
;
;

try {
var mod = require(script);
} catch(err) {
throw('Failed to require: ' + script + ', because: ' + err.message);
} catch (err) {
throw ('Failed to require: ' + script + ', because: ' + err.message);
}

// Handle ES6 default exports (ie. named export called default)
Expand All @@ -247,7 +247,11 @@ Consign.prototype.into = function(object) {
}

if ('function' === typeof mod) {
mod = mod.apply(mod, args);
try {
mod = mod.apply(mod, args);
} catch (e) {
mod = new mod(args);
}
}

var ns = this._createNamespace(object, parts, mod);
Expand All @@ -264,6 +268,6 @@ Consign.prototype.into = function(object) {
* @returns
*/

module.exports = function(options) {
module.exports = function (options) {
return new Consign(options);
};