Skip to content

Commit

Permalink
Some refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
Mario Behrendt committed Dec 13, 2012
1 parent 1994101 commit efe0c31
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 17 deletions.
2 changes: 2 additions & 0 deletions Chukfile
@@ -1,3 +1,5 @@
// vim:set ft=javascript:

module.exports = function(scope) { module.exports = function(scope) {
scope.cb = require('./lib/cb')(scope); scope.cb = require('./lib/cb')(scope);
}; };
1 change: 0 additions & 1 deletion bin/chuk
@@ -1,5 +1,4 @@
#!/usr/bin/env node #!/usr/bin/env node


var env = process.argv[2] || 'default'; var env = process.argv[2] || 'default';

require('../lib/index.js')(env); require('../lib/index.js')(env);
2 changes: 2 additions & 0 deletions example/Chukfile
@@ -1,3 +1,5 @@
// vim:set ft=javascript:

module.exports = { module.exports = {
'foo': function(scope) { 'foo': function(scope) {
scope.foo = 1; scope.foo = 1;
Expand Down
17 changes: 8 additions & 9 deletions lib/index.js
@@ -1,27 +1,26 @@
var repl = require('repl'); var repl = require('repl')

, cwd = process.cwd();
var cwd = process.cwd();


function isFunction(thing) { function isFunction(thing) {
return 'function' === typeof thing; return 'function' === typeof thing;
} }


function createRepl() { function createRepl() {
return repl.start({ return repl.start({
prompt: "chuk > ", prompt: 'chuk > ',
input: process.stdin, input: process.stdin,
output: process.stdout output: process.stdout
}).on('exit', function() { }).on('exit', function() {
console.log('Exit'); console.log('Exit');
}); });
} }


function getInitFromConfig(env, config) { function getInitFromConfig(env, config) {
if (isFunction(config[env])) { if (isFunction(config[env])) {
// config is an object with property [env] which is a function // config is an object with property [env] which is a function
return config[env]; return config[env];
} else if (isFunction(config['default']) && !env) { } else if (isFunction(config['default']) && !env) {
// config is an object with property 'default' which is a function // config is an object with property 'default' which is a function
return config['default']; return config['default'];
} else if (isFunction(config)) { } else if (isFunction(config)) {
// config is a function itself // config is a function itself
Expand All @@ -33,7 +32,7 @@ function chuk(env, config) {
var chukRepl = createRepl(); var chukRepl = createRepl();
var config = config || require(cwd + '/Chukfile'); var config = config || require(cwd + '/Chukfile');
var init = getInitFromConfig(env, config); var init = getInitFromConfig(env, config);
init(chukRepl.context.global); init(chukRepl.context);
return chukRepl; return chukRepl;
}; };


Expand Down
11 changes: 4 additions & 7 deletions package.json
Expand Up @@ -7,19 +7,16 @@
"test": "make test" "test": "make test"
}, },
"repository": "git://github.com/stephanhoyer/chuk.git", "repository": "git://github.com/stephanhoyer/chuk.git",
"author": [ "author": "Stephan Hoyer <ste.hoyer@gmail.com>",
"Mario Behrendt <info@mario-behrendt.de>", "contributors": ["Mario Behrendt <info@mario-behrendt.de>"],
"Stephan Hoyer <ste.hoyer@gmail.com>"
],
"license": "MIT", "license": "MIT",
"dependencies": { "dependencies": { },
},
"bin": { "bin": {
"chuk": "./bin/chuk" "chuk": "./bin/chuk"
}, },
"devDependencies": { "devDependencies": {
"mocha": "1.7.3", "mocha": "1.7.3",
"gently": "*", "gently": "0.9.2",
"should": "1.2.1" "should": "1.2.1"
} }
} }

0 comments on commit efe0c31

Please sign in to comment.