-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
41 lines (36 loc) · 879 Bytes
/
index.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
#! /usr/bin/env node
const { spawn } = require("child_process");
const ora = require("ora");
const spinner = ora();
const name = process.argv[2];
if (!name || name.indexOf("/") === -1) {
console.log('error')
return console.log(`
Invalid format.
Usage: gcopy username/repo
`);
}
const repo = `https://github.com/${name}.git`;
spinner.start()
runCommand("git", ["clone", repo])
.then(() => {
console.log(repo)
})
.then(() => {
spinner.succeed('done')
spinner.stop();
});
function runCommand(command, args, options = undefined) {
const spawned = spawn(command, args, options);
return new Promise(resolve => {
spawned.stdout.on("data", data => {
console.log(data.toString());
});
spawned.stderr.on("data", data => {
console.error(data.toString());
});
spawned.on("close", () => {
resolve();
});
});
}