forked from ryanve/symlinked
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbin.js
51 lines (45 loc) · 1.23 KB
/
bin.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#!/usr/bin/env node
var symlinked = require("./")
var help = false
var dashdash = false
var args = process.argv.slice(2).filter(function(arg) {
if (dashdash)
return !!arg
else if (arg === "--")
dashdash = true
else if (arg.match(/^(-+|\/)(h(elp)?|\?)$/))
help = true
else
return !!arg
})
var argsOk = args.length >= 1 && args.length <= 2 && symlinked.hasOwnProperty(args[0])
if (help || !argsOk) {
// If they didn't ask for help, then this is not a "success"
var log = help ? console.log : console.error
log("Usage: symlinked <command> [<path>]")
log("")
log(" Finds all linked package names of an npm package.")
log("")
if (!help && !argsOk) {
log(" Invalid arguments received.")
log("")
}
log("Commands:")
log("")
log(" names Get linked package names")
log(" paths Get linked package paths")
log(" roots Get linked package roots")
log(" links Get linked package links")
log("")
log("Options:")
log("")
log(" -h, --help Display this usage info")
process.exit(help ? 0 : 1)
} else
go(args[0], args[1] || ".")
function go (command, dir) {
var results = symlinked[command](dir)
for (var i = 0; i < results.length; i++) {
console.log(results[i])
}
}