forked from thi-ng/umbrella
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathupdate-thing-links
executable file
·31 lines (28 loc) · 1.17 KB
/
update-thing-links
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
#!/usr/bin/env node
const fs = require("fs");
const getIn = require("@thi.ng/paths").getIn;
const execSync = require("child_process").execSync;
const baseDir = "./packages/";
const tmpFile = `./temp-${Date.now()}`;
for (let f of fs.readdirSync(baseDir)) {
f = baseDir + f;
if (f.indexOf(".DS_Store") >= 0 || !fs.statSync(f).isDirectory) continue;
try {
const pkg = JSON.parse(fs.readFileSync(f + "/package.json"));
const id = pkg.name.split("/")[1];
if (getIn(pkg, ["thi.ng", "shortlink"]) === false) {
console.log(`\tskipping: ${id}`);
continue;
}
const branch = getIn(pkg, ["thi.ng", "branch"]) || "develop";
const html = `<html><head><meta http-equiv="refresh" content="0; url=https://github.com/thi-ng/umbrella/tree/${branch}/packages/${id}"/></head></html>`;
console.log(`${id} -> ${branch}`);
fs.writeFileSync(tmpFile, html);
execSync(
`aws s3 cp ${tmpFile} s3://thi.ng/${id} --profile toxi-s3 --acl public-read --content-type "text/html" --cache-control "no-cache"`
);
} catch (e) {
console.warn(`error: ${e.message}`);
}
}
fs.unlinkSync(tmpFile);