-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathcreateConfig.js
More file actions
120 lines (113 loc) · 3.32 KB
/
Copy pathcreateConfig.js
File metadata and controls
120 lines (113 loc) · 3.32 KB
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
var inquirer = require("inquirer");
var path = require("path");
var fs = require("fs");
var os = require("os");
var colors = require("colors/safe");
//const { Console } = require("console");
//var homedir = (process.platform === 'win32') ? process.env.HOMEPATH : process.env.HOME;
var homedir = os.homedir();
async function createConfig() {
if (!fs.existsSync(homedir)) {
console.log(colors.red("No home path found, cannot save config!"));
process.exit(1);
}
var dir = path.join(homedir, ".cagr");
var conffile = path.join(dir, "config.json");
// if (fs.existsSync(dir)) {
// fs.rmdirSync(dir, { recursive: true });
// console.log(dir + " removed to start over");
// }
if (!fs.existsSync(dir)) {
fs.mkdirSync(dir);
}
if (fs.existsSync(conffile)) {
console.log(
colors.yellow("Note: Using exisiting config file at: " + conffile)
);
console.log(
colors.yellow(
"Note: Use cagr or clone-all-github-repos to clone all your repos into the current folder"
)
);
} else {
if (process.env.NODE_ENV != "testing") {
console.log(
colors.yellow(
"Please input your GitHub Username and a token to access public/private repository information (to be created on GitHub Settings > Personal access tokens)"
)
);
var questions = [
{
type: "input",
name: "User",
message: "GitHub username",
},
{
type: "input",
name: "token",
message: "GitHub token",
},
];
//noinspection JSUnresolvedFunction
await inquirer
.prompt(questions)
.then(function (answers) {
answers.gitaccess = "https";
try {
fs.writeFileSync(
conffile,
JSON.stringify(answers, null, " "),
);
} catch (err){
if (err) {
console.log(colors.red("Cannot save config!"));
console.log(err);
process.exit(1);
}
console.log(
colors.yellow("Note: Created config file at: " + conffile)
);
console.log(
colors.yellow(
"Note: Use cagr or clone-all-github-repos to clone all your repos into the current folder"
)
);
}
})
.catch((error) => {
console.log(error);
if (error.isTtyError) {
// Prompt couldn't be rendered in the current environment
} else {
// Something else went wrong
}
});
} else {
await fs.writeFile(
conffile,
await JSON.stringify(
{ gitaccess: "https", token: "abc", User: "def" },
null,
" "
),
function (err) {
if (err) {
console.log(colors.red("Cannot save config!"));
console.log(err);
process.exit(1);
}
console.log(
colors.yellow("Note: Created config file at: " + conffile)
);
console.log(
colors.yellow(
"Note: Use cagr or clone-all-github-repos to clone all y our repos into the current folder"
)
);
}
);
}
}
}
exports.createConfig = createConfig;
module.exports = exports;