Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Composer config options #587

Merged
merged 2 commits into from
Feb 26, 2013
Merged
Show file tree
Hide file tree
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
12 changes: 8 additions & 4 deletions bin/hapi
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,24 @@
var Optimist = require('optimist');
var Hapi = require('../');

var argv = Optimist.usage('Usage: $0 -c config.json')
var argv = Optimist.usage('Usage: $0 -c config.json [-p node_modules_path]')
.demand(['c'])
.argv;

var options = null;
var config = null;
try {
options = require(process.cwd() + '/' + argv.c);
config = require(argv.c[0] !== '/' ? process.cwd() + '/' + argv.c : argv.c);
}
catch (err) {
console.log('Failed loading configuration file: ' + argv.c + ' (' + err.message + ')');
process.exit(1);
}

var composer = new Hapi.Composer(options);
var packOptions = {
requirePath: argv.p || null
};

var composer = new Hapi.Composer(config, packOptions);
composer.compose(function (err) {

Hapi.utils.assert(!err, 'Failed loading plugins: ' + (err && err.message));
Expand Down
10 changes: 6 additions & 4 deletions lib/composer.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ var Utils = require('./utils');
var internals = {};

/*
var options = [{
var config = [{
servers: {
ren: {
port: 8001,
Expand Down Expand Up @@ -43,15 +43,17 @@ var options = [{
}];
*/

exports = module.exports = internals.Composer = function (options) {
exports = module.exports = internals.Composer = function (config, packOptions) {

this.settings = Utils.clone(options);
this.settings = Utils.clone(config);
if (this.settings instanceof Array === false) {
this.settings = [this.settings];
}

this.packs = [];

this.packOptions = Utils.clone(packOptions);

return this;
};

Expand All @@ -67,7 +69,7 @@ internals.Composer.prototype.compose = function (callback) {

Utils.assert(set.servers && Object.keys(set.servers).length, 'Pack missing servers definition');

var pack = new Pack();
var pack = new Pack(self.packOptions);
Object.keys(set.servers).forEach(function (serverName) {

// Load servers
Expand Down
12 changes: 10 additions & 2 deletions lib/pack.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,21 @@ internals.defaultPermissions = {
};


exports = module.exports = internals.Pack = function () {
exports = module.exports = internals.Pack = function (options) {

options = options || {};

Utils.assert(!options || !options.requirePath || options.requirePath[0] === '/', 'Pack option \'requirePath\' must be an absolute path');

this.servers = []; // List of all pack server members
this.labels = {}; // Server [names] organized by labels
this.names = {}; // Servers indexed by name
this.events = new Events.EventEmitter(); // Consolidated subscription to all servers' events

this.settings = {
requirePath: options.requirePath || process.cwd() + '/node_modules'
};

return this;
};

Expand Down Expand Up @@ -332,7 +340,7 @@ internals.Pack.prototype._require = function (name, permissions, options, callba
itemName = callerPath + '/' + itemName;
}
else if (itemName[0] !== '/') {
itemName = process.cwd() + '/node_modules/' + itemName;
itemName = self.settings.requirePath + '/' + itemName;
}

var plugin = null;
Expand Down