forked from arei/npmbox
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnpmbox.js
72 lines (58 loc) · 1.63 KB
/
npmbox.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
// npmbox by Glen R. Goodwin (@areinet)
// https://github.com/arei/npmbox.git
// Creates an archive "box" of an npm package and its dependencies.
"use strict";
var box = require("./npmboxxer.js").box;
var utils = require("./utils.js");
var argv = require("optimist")
.boolean(["v","verbose","s","silent"])
.argv;
var args = argv._;
if (args.length<1 || argv.help) {
console.log("npmbox - Create an archive for offline installation of the given package.");
console.log("");
console.log("Usage: ");
console.log("");
console.log(" npmbox --help");
console.log(" npmbox [options] <package> <package>...");
console.log("");
console.log("Options:");
console.log("");
console.log(" -v, -verbose Shows additional output which is normally hidden.");
console.log(" -s, -silent Shows additional output which is normally hidden.");
console.log("");
process.exit(0);
}
var options = {
verbose: argv.v || argv.verbose || false,
silent: argv.s || argv.silent || false,
};
var sources = args;
var errorCount = 0;
var complete = function() {
process.reallyExit(errorCount);
};
var boxDone = function(err) {
if (err) {
var args = utils.flatten(utils.toArray(arguments));
args.forEach(function(arg){
errorCount += 1;
console.error(" ",arg);
});
}
boxNext();
};
var boxNext = function() {
var source = sources.shift();
if (!source) complete();
boxExecute(source);
};
var boxExecute = function(source) {
if (!options.silent) console.log("\nBoxing "+source+"...");
box(source,options,boxDone);
};
sources = sources.filter(function(source){
return !!source;
});
if (sources && sources.length>0) boxNext();
else complete();