Permalink
Browse files

use get deps to read the dir, or stdin

  • Loading branch information...
1 parent 5cf606a commit 13f68edbb7a65141eb1d23ca3fc0587df14fdfe5 @dominictarr committed Nov 28, 2013
Showing with 27 additions and 14 deletions.
  1. +27 −14 index.js
View
@@ -10,19 +10,32 @@ module.exports = function (db, config) {
if(!module.parent) {
var resolvePackage = createResolvePackage(null, {})
var resolve = createResolve(resolvePackage)
- var opts = {}
- var args = process.argv.slice(2).filter(function (e) {
- if(/(^-v|^--version)/.test(e)) {
- console.log(require('./package').version)
- process.exit(0)
- }
- if(/^--online/.test(e)) return !(opts.online = true)
- if(/^--greedy/.test(e)) return !(opts.greedy = true)
- return true
- })
+ var getDeps = require('get-deps')
+ var config = require('npmd-config')
+ var args = config._
+ if(config.version) {
+ console.log(require('./package').version)
+ process.exit()
+ }
- resolve(args, opts, function (err, tree) {
- if(err) throw err
- console.log(JSON.stringify(tree, null, 2))
- })
+ var data = ''
+ if(!process.stdin.isTTY)
+ process.stdin
+ .on('data', function (d) { data += d })
+ .on('end', function () {
+ args = getDeps.mergeDeps(JSON.stringify(data), {dev: true})
+ next()
+ })
+ else
+ next()
+
+ function next () {
+ if(!args.length)
+ args = getDeps(process.cwd(), {dev: true})
+ resolve(args, config, function (err, tree) {
+ if(err) throw err
+ console.log(JSON.stringify(tree, null, 2))
+ })
+
+ }
}

0 comments on commit 13f68ed

Please sign in to comment.