-
Notifications
You must be signed in to change notification settings - Fork 0
/
bin.js
executable file
·58 lines (52 loc) · 1.21 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
52
53
54
55
56
57
58
#!/usr/bin/env node
const pkg = require('./package.json');
const clone = require('./lib/clone');
const GitUrl = require('./lib/git-url');
/*
This is the file for the bin command "gnat" that is installed globally.
It has actions including "clone" and later will have "init".
The "clone" action will take a Git URL and a path
clone from git to the path
then open "package.json" in the path
and make modifications.
*/
var args = process.argv.slice(2);
if (args.length === 0) {
plug();
usage();
process.exit(0);
}
else {
var action = args[0];
if (action === 'clone') {
var url = args[1];
var path = args[2];
if (!url || !path) {
console.error('invalid arguments');
usage();
process.exit(1);
}
url = GitUrl.create(url);
console.log('cloning repository:', url);
clone(url, path)
.then(function () {
console.log('');
console.log('successfully cloned into path:', path);
}, function (e) {
console.error('clone action failed:', e.message);
})
;
}
else {
console.error('invalid action');
usage();
process.exit(1);
}
}
function plug() {
console.log('gnat: Version', pkg.version);
}
function usage() {
console.log('Usage:');
console.log('gnat clone git-url target-path');
}