Skip to content

Instantly share code, notes, and snippets.

@pvencill
Created June 16, 2014 13:27
Show Gist options
  • Save pvencill/6ce03cd7ae02eef37d9c to your computer and use it in GitHub Desktop.
Save pvencill/6ce03cd7ae02eef37d9c to your computer and use it in GitHub Desktop.
Full example of an app using a custom REPL
'use strict';
var repl = require('repl'),
_ = require('lodash'),
inflection = require('inflection'),
history = require('repl.history'),
requireDirectory = require('require-directory'),
pkg = require('../package.json');
var app = require('../');
function modelCheck(path){
if(/plugins/.test(path) || /schemas/.test(path) || /enumerations/.test(path))
return false;
return true;
}
var models = requireDirectory(module, './app/models', modelCheck);
// brute force. :P
delete models.plugins;
delete models.schemas;
delete models.enumerations;
models = _.transform(models, function(res, val, key){ res[inflection.camelize(key)] = val; });
var r = repl.start({
prompt: pkg.name + ' >',
input : process.stdin,
output: process.stdout
});
history(r, process.env.HOME+'/.node_history');
r.context.app = app;
//for now
r.context.models = models;
r.on('exit', process.exit);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment