-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
82 lines (70 loc) · 1.74 KB
/
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
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
73
74
75
76
77
78
79
80
81
82
const guito = require('commander');
const chalk = require('chalk');
const clear = require('clear');
const figlet = require('figlet');
const github = require('./lib/github_credentials');
const repo = require('./lib/create_a_repo');
guito
.command('init')
.description('Draw app banner')
.action(() => {
clear();
console.log(
chalk.magenta(
figlet.textSync('guito', { horizontalLayout: 'full' })
)
);
});
guito
.command('connect')
.description('Check user GitHub credentials')
.action(async () => {
let token = github.getStoredGitHubToken();
if (!token) {
await github.setGitHubCredentials();
token = await github.registerNewToken();
}
console.log(token);
});
guito
.command('create')
.description('Create a new repository on GitHub')
.action(async() => {
const getGitHubToken = async () => {
let token = github.getStoredGitHubToken();
if (token) {
return token;
}
await github.setGitHubCredentials();
token = await github.registerNewToken();
return token;
}
try {
const token = await getGitHubToken();
github.gitHubAuth(token);
const url = await repo.createRemoteRepository();
await repo.createGitIgnore();
const complete = await repo.setupRepository(url);
if (complete) {
console.log(chalk.green('All done!'));
}
} catch (error) {
if (error) {
switch (error.status) {
case 401:
console.log(chalk.red('Couldn\'t log you in. Please provide correct credentials or token.'));
break;
case 422:
console.log(chalk.red('There already exists a remote repository with the same name.'));
break;
default:
console.log(error);
break;
}
}
}
});
guito.parse(process.argv);
if (!guito.args.length) {
guito.help();
}