-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathchange-remote-urls.js
More file actions
41 lines (35 loc) · 1.17 KB
/
change-remote-urls.js
File metadata and controls
41 lines (35 loc) · 1.17 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
require("dotenv").config();
const { readdirSync } = require("fs");
const { exec } = require("child_process");
const currentDir = __dirname;
const dir = process.env.DIRECTORY;
const ssh = !!process.env.SSH;
const org = process.env.ORG_NAME;
const getDirectories = (source) =>
readdirSync(source, { withFileTypes: true })
.filter((dirent) => dirent.isDirectory())
.map((dirent) => dirent.name);
const sshTemplate = (full_name) => `git@github.com:${full_name}.git`;
const httpsTemplate = (full_name) => `https://github.com/${full_name}.git`;
Promise.all(
getDirectories(dir).map((name) => {
return new Promise((resolve) => {
const full_name = `${org}/${name}`;
const command = `cd ${dir}/${name} && git remote set-url origin ${
ssh ? sshTemplate(full_name) : httpsTemplate(full_name)
}`;
console.log(`Running \`${command}\``);
exec(command, (error, _, stderr) => {
if (stderr) {
console.log(`${name} failed: ${stderr}`);
}
if (error) {
console.log(`${name} failed: ${error}`);
}
resolve();
});
});
})
).then(() => {
exec(`cd ${currentDir}`, (error, _, stderr) => {});
});