Comparing version 0.1.0 to 0.2.0
62
cli.js
@@ -6,21 +6,63 @@ #!/usr/bin/env node | ||
var helpVersion = require('help-version')(usage()), | ||
minimist = require('minimist'), | ||
textTable = require('text-table'), | ||
pairs = require('object-pairs'), | ||
chalk = require('chalk'), | ||
tableHeader = require('table-header'), | ||
stringLength = require('string-length'); | ||
var Repl = require('repl'); | ||
var usage = function (code) { | ||
console.log('Usage: repl-here'); | ||
process.exit(code || 0); | ||
function usage() { | ||
return 'Usage: repl-here [-v | --verbose]'; | ||
} | ||
var opts = minimist(process.argv.slice(2), { | ||
boolean: 'verbose', | ||
alias: { v: 'verbose' }, | ||
unknown: function () { | ||
helpVersion.help(1); | ||
} | ||
}); | ||
var printNameTable = function (names) { | ||
var table = pairs(names); | ||
table.forEach(function (row) { | ||
if (!row[1]) { | ||
row[1] = chalk.red('(failed to load)'); | ||
} | ||
}); | ||
tableHeader.add(table, ['MODULE', 'VARIABLE'], { stringLength: stringLength }); | ||
table.push(table[1]); | ||
console.log('\r' + textTable(table)); | ||
}; | ||
var main = function () { | ||
(function main() { | ||
var repl = Repl.start('> '); | ||
var names = {}; | ||
replHere(repl, process.cwd()) | ||
.on('load', function (module, name) { | ||
names[module] = name; | ||
}) | ||
.on('fail', function (err, module) { | ||
console.error('\rModule failed to load: ' + module); | ||
if (opts.verbose) { | ||
names[module] = false; | ||
} | ||
else { | ||
console.error('\rModule failed to load: ' + module); | ||
} | ||
}) | ||
.on('end', repl.displayPrompt.bind(repl)); | ||
}; | ||
(process.argv.slice(2) == '--help') ? usage() : main(); | ||
.on('end', function () { | ||
if (opts.verbose) { | ||
printNameTable(names); | ||
} | ||
repl.displayPrompt(); | ||
}); | ||
}()); |
@@ -26,3 +26,5 @@ 'use strict'; | ||
try { | ||
repl.context[camelCase(module)] = require(resolveFrom(dir, module)); | ||
var name = camelCase(module); | ||
repl.context[name] = require(resolveFrom(dir, module)); | ||
ee.emit('load', module, name); | ||
} | ||
@@ -29,0 +31,0 @@ catch (e) { |
{ | ||
"name": "repl-here", | ||
"version": "0.1.0", | ||
"version": "0.2.0", | ||
"description": "Start the REPL and load the entire ./node_modules/ into it", | ||
@@ -36,3 +36,10 @@ "author": "Eugene Sharygin <eush77@gmail.com>", | ||
"camel-case": "^1.1.1", | ||
"chalk": "^1.0.0", | ||
"help-version": "^0.2.0", | ||
"minimist": "^1.1.1", | ||
"object-pairs": "^0.1.0", | ||
"resolve-from": "^1.0.0", | ||
"string-length": "^1.0.0", | ||
"table-header": "^0.2.0", | ||
"text-table": "^0.2.0", | ||
"validate-npm-package-name": "^2.2.0" | ||
@@ -39,0 +46,0 @@ }, |
@@ -15,5 +15,7 @@ [![npm](https://nodei.co/npm/repl-here.png)](https://nodei.co/npm/repl-here/) | ||
``` | ||
Usage: repl-here | ||
Usage: repl-here [-v | --verbose] | ||
``` | ||
`--verbose` flag prints a table describing how a particular module is named inside the REPL. Module names are effectively camel-cased versions of module names. | ||
## API | ||
@@ -27,2 +29,10 @@ | ||
### Event: `load` | ||
``` | ||
ee.on('fail', function(module, name)) | ||
``` | ||
Emitted if `module` is loaded as `name`. | ||
### Event: `fail` | ||
@@ -34,3 +44,3 @@ | ||
Emitted whenever module fails to load. | ||
Emitted whenever `module` fails to load. | ||
@@ -53,9 +63,8 @@ ### Event: `end` | ||
## Why not X? | ||
## Related | ||
- [repl-it](http://npm.im/repl-it): works in the context of a project, hence walks up the directory tree, parses `package.json` for dependencies and devDependencies, has options like loading main project files, etc. | ||
- [repl-it](http://npm.im/repl-it) works in the context of a project. It walks up the directory tree, parses `package.json` for dependencies and devDependencies, has options like loading main project files, etc. | ||
- [scratchy](http://npm.im/scratchy): does not work quite as advertised because it also walks up the directory tree and so you can't `npm install foo` and load it into the repl immediately afterwards (which is kind of a problem this module is trying to solve). | ||
- [scratchy](http://npm.im/scratchy) is sort of a hybrid of `repl-it` and `repl-here`: it walks up the directory tree as `repl-it` does but requires everything inside `node_modules` just like `repl-here`. This means you can't simply `npm install foo` and load it into the repl immediately afterwards (which is the problem this module is trying to solve). | ||
## Install | ||
@@ -62,0 +71,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
6407
90
75
10
+ Addedchalk@^1.0.0
+ Addedhelp-version@^0.2.0
+ Addedminimist@^1.1.1
+ Addedobject-pairs@^0.1.0
+ Addedstring-length@^1.0.0
+ Addedtable-header@^0.2.0
+ Addedtext-table@^0.2.0
+ Addedansi-regex@2.1.1(transitive)
+ Addedansi-styles@2.2.1(transitive)
+ Addedcallsites@1.0.1(transitive)
+ Addedchalk@1.1.3(transitive)
+ Addedescape-string-regexp@1.0.5(transitive)
+ Addedfind-root@0.1.2(transitive)
+ Addedhas-ansi@2.0.0(transitive)
+ Addedhelp-version@0.2.0(transitive)
+ Addedminimist@1.2.8(transitive)
+ Addedobject-pairs@0.1.0(transitive)
+ Addedrepeat-string@1.6.1(transitive)
+ Addedstring-length@1.0.1(transitive)
+ Addedstrip-ansi@3.0.1(transitive)
+ Addedsupports-color@2.0.0(transitive)
+ Addedtable-header@0.2.2(transitive)
+ Addedtext-table@0.2.0(transitive)