Send logs back
This commit is contained in:
parent
b2d4d811b4
commit
6082683996
32
index.ts
32
index.ts
|
@ -38,9 +38,7 @@ app.post("/", (req, res) => {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
updateWebsite("main");
|
res.send(updateWebsite("main"));
|
||||||
|
|
||||||
res.send("Updated!");
|
|
||||||
});
|
});
|
||||||
|
|
||||||
app.listen(PORT, () => {
|
app.listen(PORT, () => {
|
||||||
|
@ -51,19 +49,39 @@ const USER = process.env.USER!;
|
||||||
const REPO_NAME = "www-new";
|
const REPO_NAME = "www-new";
|
||||||
const URL = `https://git.csclub.uwaterloo.ca/www/${REPO_NAME}.git`;
|
const URL = `https://git.csclub.uwaterloo.ca/www/${REPO_NAME}.git`;
|
||||||
const WWW_DIR = process.env.WWW_DIR ?? "~/www/csc";
|
const WWW_DIR = process.env.WWW_DIR ?? "~/www/csc";
|
||||||
const $ = (cmd: string, cwd?: string) => {
|
const $ = (
|
||||||
console.log(cwd ? `${cwd} >` : ">", cmd);
|
cmd: string,
|
||||||
|
cwd?: string,
|
||||||
|
log: (..._: string[]) => void = console.log,
|
||||||
|
) => {
|
||||||
|
log(cwd ? `${cwd} >` : ">", cmd);
|
||||||
|
|
||||||
const out = execSync(cmd, { cwd, encoding: "utf8" });
|
const out = execSync(cmd, { cwd, encoding: "utf8" });
|
||||||
console.log(out);
|
log(out);
|
||||||
|
|
||||||
return out;
|
return out;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
function createLogger$() {
|
||||||
|
const logs: string[] = [];
|
||||||
|
|
||||||
|
const log = (...args: string[]) => {
|
||||||
|
console.log(...args);
|
||||||
|
logs.push(args.join(" "));
|
||||||
|
};
|
||||||
|
|
||||||
|
return {
|
||||||
|
$: (cmd: string, cwd?: string) => $(cmd, cwd, log),
|
||||||
|
logs,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
// Makes sure that the directory is present
|
// Makes sure that the directory is present
|
||||||
$(`mkdir -p ${WWW_DIR}`);
|
$(`mkdir -p ${WWW_DIR}`);
|
||||||
|
|
||||||
function updateWebsite(branch: string) {
|
function updateWebsite(branch: string) {
|
||||||
|
const { $, logs } = createLogger$();
|
||||||
|
|
||||||
const tmpDir = $("mktemp --directory").trim();
|
const tmpDir = $("mktemp --directory").trim();
|
||||||
|
|
||||||
$(`git clone ${URL}`, tmpDir);
|
$(`git clone ${URL}`, tmpDir);
|
||||||
|
@ -84,4 +102,6 @@ function updateWebsite(branch: string) {
|
||||||
|
|
||||||
$(`rm -rf ${tmpDir}`);
|
$(`rm -rf ${tmpDir}`);
|
||||||
console.log("Done!");
|
console.log("Done!");
|
||||||
|
|
||||||
|
return logs.join("\n");
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue