Skip to content
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
9 changes: 3 additions & 6 deletions bin/hapi
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,14 @@
var Fs = require('fs');
var Optimist = require('optimist');
var Hapi = require('../');
var Alce = require('alce');


// Declare internals

var internals = {};


internals.argv = Optimist.usage('Usage: $0 -c manifest.json [-p node_modules_path] [--filter.criterion=value]')
internals.argv = Optimist.usage('Usage: $0 -c manifest.json [-p node_modules_path]')
.demand(['c'])
.argv;

Expand All @@ -24,7 +23,7 @@ internals.getManifest = function () {
var manifestPath = internals.argv.c[0] !== '/' ? process.cwd() + '/' + internals.argv.c : internals.argv.c;

try {
manifest = Alce.parse(Fs.readFileSync(manifestPath));
manifest = JSON.parse(Fs.readFileSync(manifestPath));
}
catch (err) {
console.log('Failed loading configuration file: ' + internals.argv.c + ' (' + err.message + ')');
Expand All @@ -37,9 +36,7 @@ internals.getManifest = function () {

internals.loadPacks = function (manifest, callback) {

var options = {
criteria: internals.argv.filter
};
var options = {};

if (!internals.argv.p) {
return callback(null, options);
Expand Down
10 changes: 10 additions & 0 deletions docs/Reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@
- [`Hapi.types`](#hapitypes)
- [`Hapi.state`](#hapistate)
- [`prepareValue(name, value, options, callback)`](#preparevaluename-value-options-callback)
- ['Hapi CLI'](#hapi-cli)

## `Hapi.Server`

Expand Down Expand Up @@ -3504,3 +3505,12 @@ var handler = function (request, reply) {
};
```

## `Hapi CLI`
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should add a reference here to confidence so that people can look it up if they want to manage config files for multiple env.


The **hapi** command line interface allows a pack of servers to be composed and started from a configuration file only from the command line.
When installing **hapi** with global flag the **hapi** binary script will be installed in the path. The following arguments are available to the
**hapi** CLI:

- '-c' - the path to configuration json file (required)
- '-p' - the path to the node_modules folder to load plugins from (optional)

6 changes: 0 additions & 6 deletions lib/composer.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// Load modules

var Async = require('async');
var Confidence = require('confidence');
var Pack = require('./pack');
var Utils = require('./utils');

Expand Down Expand Up @@ -54,16 +53,11 @@ internals.Composer.prototype.compose = function (callback) {

var self = this;

var callbackTick = Utils.nextTick(callback);

// Create packs

var sets = [];
this._manifest.forEach(function (set) {

var store = new Confidence.Store(set);
set = store.get('/', self._settings.criteria);

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

Expand Down
4 changes: 1 addition & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,13 @@
"shot": "1.x.x",
"cryptiles": "1.x.x",
"iron": "1.x.x",
"confidence": "0.8.x",
"async": "0.2.x",
"multiparty": "3.0.x",
"mime": "1.2.x",
"lru-cache": "2.3.x",
"optimist": "0.6.x",
"negotiator": "0.2.x",
"semver": "2.0.x",
"alce": "1.0.x"
"semver": "2.0.x"
},
"devDependencies": {
"lab": "1.x.x",
Expand Down
69 changes: 0 additions & 69 deletions test/integration/hapi.js
Original file line number Diff line number Diff line change
Expand Up @@ -212,73 +212,4 @@ describe('Hapi command line', function () {
done();
});
});

it('composes pack with criteria', function (done) {

var manifest = {
$filter: 'env',
testing: {
pack: {
cache: {
engine: 'memory'
},
app: {
my: 'special-value'
}
},
servers: [
{
port: 0,
options: {
labels: ['api', 'nasty', 'test']
}
},
{
host: 'localhost',
port: 0,
options: {
labels: ['api', 'nice']
}
}
],
plugins: {
'--loaded': {}
},
permissions: {
ext: true
}
}
};

var configPath = Path.join(__dirname, 'manifest5.json');
var hapiPath = Path.join(__dirname, '..', '..', 'bin', 'hapi');
var modulePath = Path.join(__dirname, 'pack');

if (!Fs.existsSync(configPath)) {
Fs.writeFileSync(configPath, JSON.stringify(manifest));
}

var hapi = ChildProcess.spawn('node', [hapiPath, '-c', configPath, '-p', modulePath, '--filter.env=testing']);
var clean = function () {

hapi.kill();

if (Fs.existsSync(configPath)) {
Fs.unlinkSync(configPath);
}
};

hapi.stdout.on('data', function (data) {

clean();
expect(data.toString()).to.equal('loaded\n');
done();
});

hapi.stderr.on('data', function (data) {

clean();
expect(data.toString()).to.not.exist;
});
});
});