-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup.js
More file actions
62 lines (56 loc) · 1.74 KB
/
Copy pathsetup.js
File metadata and controls
62 lines (56 loc) · 1.74 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
const fs = require("fs");
const readline = require("readline");
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout
});
const templateRepoName = "badged-alm/template-nodejs-v1-A";
let success = false;
try {
rl.question("Please, insert GitHub repository URL:", githubURL => {
if (!githubURL.includes("github.com/")) {
console.log("Invalid URL.");
rl.close();
} else {
const githubRepo =
githubURL.split("github.com/")[1].split("/")[0] +
"/" +
githubURL.split("github.com/")[1].split("/")[1];
// Package.json
const packageJson = JSON.parse(fs.readFileSync("package.json", "utf8"));
packageJson.name = githubRepo.split("/")[1];
packageJson.repository.url =
"git+https://github.com/" + githubRepo + ".git";
packageJson.bugs.url = "https://github.com/" + githubRepo + "/issues";
packageJson.homepage = "https://github.com/" + githubRepo + "#readme";
// README.md
let readme = fs.readFileSync("README.md", "utf8");
readme = readme.split(templateRepoName).join(githubRepo);
readme = readme
.split(
templateRepoName.split("/")[0] + "_" + templateRepoName.split("/")[1]
)
.join(githubRepo.split("/")[0] + "_" + githubRepo.split("/")[1]);
// Write files and close
fs.writeFileSync(
"package.json",
JSON.stringify(packageJson, null, 2),
"utf8"
);
fs.writeFileSync("README.md", readme, "utf8");
success = true;
rl.close();
}
});
} catch (err) {
console.log(err);
rl.close();
}
rl.on("close", () => {
if (success) {
console.log("Setup success!");
} else {
console.log("Setup failed!");
}
process.exit(0);
});