Skip to content

Instantly share code, notes, and snippets.

@JCKodel
Created February 16, 2019 17:26
Show Gist options
  • Save JCKodel/6d2eeb0a21119cfba65f20faa0a50bd1 to your computer and use it in GitHub Desktop.
Save JCKodel/6d2eeb0a21119cfba65f20faa0a50bd1 to your computer and use it in GitHub Desktop.
Node git pull
#!/usr/bin/env nodejs
var http = require("http");
function pull(site)
{
return new Promise((resolve) =>
{
const g = require("simple-git")("/data/www/" + site);
g.pull((err, update) =>
{
resolve("<pre>" + (err ? JSON.stringify(err, null, 4) : JSON.stringify(update, null, 4)) + "</pre>");
});
});
}
http.createServer(function(req, res)
{
res.writeHead(200, { "Content-Type": "text/html" });
const sites = ["site1.art.br", "site2.com.br", "site3.ca", "site4.menu"];
const tasks = [];
sites.map((s) =>
{
tasks.push(new Promise((resolve) =>
{
res.write("<h1>Pulling " + s + "</h1>");
pull(s).then((r) =>
{
res.write(r);
res.write("<hr/>");
resolve();
});
}));
});
return Promise.all(tasks).then(() => res.end("<h2>All done!</h2>"));
}).listen(8080, "localhost");
console.log("Server running at http://localhost:8080/");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment