forked from arei/npmbox
-
Notifications
You must be signed in to change notification settings - Fork 0
/
npmbox.js
64 lines (55 loc) · 1.71 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
// npmbox by Glen R. Goodwin (@areinet)
// https://github.com/arei/npmbox.git
// Creates an archive "box" of one or more npm packages and their dependencies.
"use strict";
var boxxer = require("./npmboxxer.js");
var argv = require("optimist")
.string([
"proxy",
"https-proxy"
])
.boolean(["v","verbose","s","silent"])
.options("t", {
alias: "target",
default: null
})
.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 Hide all output.");
console.log(" -t, --target Specify the target .npmbox file to write.");
console.log(" --proxy=<url> npm --proxy switch.");
console.log(" --https-proxy=<url> npm --https-proxy switch.");
console.log("");
process.exit(0);
}
var options = {
verbose: argv.v || argv.verbose || false,
silent: argv.s || argv.silent || false,
target: argv.t || argv.target || null,
proxy: argv.proxy || null,
"https-proxy": argv["https-proxy"] || null
};
var sources = args;
var complete = function(err) {
if (err) console.log("\nERROR: ",err,"\n\nnpmbox halted.");
process.reallyExit(err?1:0);
};
sources = sources.filter(function(source){
return !!source;
});
if (sources && sources.length>0) {
if (!options.silent) console.log("\nBoxing "+sources.join(", ")+"...");
boxxer.box(sources,options,complete);
}
else complete();