-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
executable file
·93 lines (81 loc) · 2.07 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
83
84
85
86
87
88
89
90
91
92
93
#!/usr/bin/env node
const chalk = require('chalk');
const clear = require('clear');
const figlet = require('figlet');
const files = require('./lib/files');
const repo = require('./lib/repo');
const github = require('./lib/github');
clear();
console.log(
chalk.yellow(figlet.textSync('ginit', { horizontalLayout: 'full' }))
);
if (files.directoryExists('.git')) {
console.log(chalk.red('Aleady a git repository!'));
process.exit();
}
const getGithubToken = async () => {
let token = github.getStoredGithubToken();
if (token) {
return token;
}
await github.setGithubCredentials();
const accessToken = await github.hasAccessToken();
if (accessToken) {
console.log(chalk.yellow('An existing access token has been found!'));
token = await github.regenerateNewToken(accessToken.id);
return token;
}
token = await github.registerNewToken();
return token;
};
const run = async () => {
try {
const token = await getGithubToken();
github.githubAuth(token);
const url = await repo.createRemoteRepo();
await repo.createGitignore();
const done = await repo.setupRepo(url);
if (done) {
console.log(chalk.green('All done!'));
}
} catch (err) {
if (err) {
switch (err.code) {
case 401:
console.log(
chalk.red(
"couldn't log you in. Please provide correct credentials/ token. "
)
);
break;
case 422:
console.log(
chalk.red(
'There already exists as remote repository with the same name'
)
);
break;
default:
console.log(err);
}
}
}
};
run();
// // const run = async () => {
// // const credentials = await inquirer.askGithubCredentials();
// // console.log(credentials);
// // };
// //
// // run();
//
// const run = async () => {
// let token = await github.getStoredGithubToken();
// if (!token) {
// await github.setGithubCredentials();
// token = await github.registerNewToken();
// }
// console.log(token);
// };
//
// run();