get list of repos from API
Script to clone/fetch all repos in the list
// @ts-check
const { spawnSync } = require("child_process");
const { existsSync, mkdirSync } = require("fs");
const { resolve: resolvePath } = require("path");
const { HOME } = process.env;
const base = resolvePath(HOME, "dev");
const urls = [
// "git@github.com:zaverden/dns-as-code.git",
// "git@github.com:zaverden/dnscontrol.git",
];
for (const url of urls) {
processing(url)
}
function processing(url) {
// git@github.com:zaverden/esbuild-plugin-postcss.git
const [, service, ...path] = url.replace(/\.git$/, "").split(/\@|\:|\//);
// ~/dev/github.com/zaverden/esbuild-plugin-postcss
const repoPath = resolvePath(base, service, ...path);
if (!existsSync(repoPath)) {
mkdirSync(repoPath, { recursive: true });
console.log(`repo folder is created: ${repoPath}`);
spawnSync("git", ["clone", url, repoPath], {
stdio: "inherit",
});
} else {
console.log(`Fetching ${url}`);
spawnSync("git", ["fetch", "--all", "--force", "--prune", "--prune-tags"], {
stdio: "inherit",
cwd: repoPath,
});
}
}