-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
77 lines (66 loc) · 2.52 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
const musette = require('commander');
const chalk = require('chalk');
const figlet = require('figlet');
const clear = require('clear');
const files = require('./lib/files');
const github = require('./lib/github_credentials');
const inquirer = require('./lib/inquirer');
const repo = require('./lib/create_a_repo');
musette
.command('init')
.description('Draw app banner')
.action(() =>{
clear();
console.log(chalk.magenta(figlet.textSync('musette', {horizontalLayout:'full'})));
});
musette
.command('octocheck')
.description('authenticate user GitHub credentials')
.action(async () => {
let token = github.getStoredGitHubToken();
if(!token){
await github.setGitHubCredentials();
token = await github.registerNewToken();
}
console.log(token);
});
musette.command('create_repo')
.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 nam.'));
default:
console.log(error);
break;
}
}
}
});
musette.parse(process.argv);
if(!musette.args.length){
musette.help();
}