Created
October 23, 2012 16:57
-
-
Save bryanforbes/3940067 to your computer and use it in GitHub Desktop.
bdLoad Dojo node command line
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env node | |
var repl = require('repl'), | |
vm = require('vm'), | |
useGlobal = true; | |
function evalWithHistory(code, context, file, callback){ | |
// TOOD: write history saving routines | |
var err, result; | |
try{ | |
if(useGlobal){ | |
result = vm.runInThisContext(code, file); | |
}else{ | |
result = vm.runInContext(code, context, file); | |
} | |
}catch(e){ | |
err = e; | |
} | |
callback(err, result); | |
} | |
var req = require('../bdLoad/lib/bdload-so'); | |
req.signal = function(type, args){ | |
if(args[0] instanceof Error){ | |
console.log('ERROR ' + type + ': ' + args[0]); | |
} | |
}; | |
req.set( | |
// baseUrl | |
'../', | |
// paths | |
null, | |
// packages | |
[ | |
{ name: 'dojo', location: 'dojo2' } | |
] | |
); | |
var r = repl.start({ | |
prompt: '> ', | |
input: process.stdin, | |
output: process.stdout, | |
useGlobal: useGlobal, | |
eval: evalWithHistory | |
}); | |
r.context.require = function(module){ | |
var mod; | |
req([module], function(m){ | |
mod = m; | |
}); | |
return mod; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment