-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
executable file
·127 lines (84 loc) · 2.59 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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
#!/usr/bin/env node
const chalk = require('chalk');
const clear = require('clear');
const figlet = require('figlet');
const meanGenerator = require('./lib/utils/generator/meangenerator');
const mernGenerator = require('./lib/utils/generator/merngenerator');
const files = require('./lib/githubmanager/files');
const github = require('./lib/githubmanager/github');
const repo = require('./lib/githubmanager/repo');
const inquirer = require('./lib/utils/inquirer');
const gitinquirer = require('./lib/githubmanager/inquirer');
var stackName;
console.log(
chalk.yellow(
figlet.textSync('Ginit', { horizontalLayout: 'full' })
)
);
const getGithubToken = async () => {
if (files.directoryExists('.git')) {
console.log(chalk.red('Already a Git repository!'));
process.exit();
}
// Fetch token from config store
let token = github.getStoredGithubToken();
if(token) {
return token;
}
// No token found, use credentials to access GitHub account
token = await github.getPersonalAccesToken();
return token;
};
const run = async () => {
try {
// Retrieve & Set Authentication Token
const token = await getGithubToken();
github.githubAuth(token);
// Create remote repository
const url = await repo.createRemoteRepo();
// console.log(url);
// Create .gitignore file
await repo.createGitignore();
// Set up local repository and push to remote
await repo.setupRepo(url);
console.log(chalk.green('All done!'));
} catch(err) {
if (err) {
switch (err.status) {
case 401:
console.log(chalk.red('Couldn\'t log you in. Please provide correct credentials/token.'));
break;
case 422:
console.log(chalk.red('There is already a remote repository or token with the same name'));
break;
default:
console.log(chalk.red(err));
}
}
}
};
const getFlags = async()=>{
var args = process.argv.splice(2);
stackName= args[0];
if(stackName == "--mean"){
await meanGenerator.run();
console.log(chalk.green("Your project is generated : "));
var res = await gitinquirer.askIfWantToPushToGithub();
if(res.permission){
run();
}
}
else if(stackName == "--mern"){
await mernGenerator.run();
console.log(chalk.green("Your project is generated : "));
var res = await gitinquirer.askIfWantToPushToGithub();
if(res.permission){
run();
}
}
else{
console.error("Currently we support generation of mean stack apps only ;");
console.log("generate --mean");
}
}
getFlags();