Skip to content

Commit

Permalink
refactor(tools): migrate link update script to TS
Browse files Browse the repository at this point in the history
  • Loading branch information
postspectacular committed Oct 4, 2021
1 parent 8a3f1ff commit faefb2b
Showing 1 changed file with 11 additions and 11 deletions.
22 changes: 11 additions & 11 deletions scripts/update-thing-links → tools/src/update-thing-links.ts
100755 → 100644
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
#!/usr/bin/env node
const fs = require("fs");
const getIn = require("@thi.ng/paths").getIn;
const execSync = require("child_process").execSync;
import { getIn } from "@thi.ng/paths";
import { execSync } from "child_process";
import { readdirSync, statSync, unlinkSync, writeFileSync } from "fs";
import { readJSON } from "./io";

const baseDir = "./packages/";
const tmpFile = `./temp-${Date.now()}`;

for (let f of fs.readdirSync(baseDir)) {
for (let f of readdirSync(baseDir)) {
f = baseDir + f;
if (f.indexOf(".DS_Store") >= 0 || !fs.statSync(f).isDirectory) continue;
if (f.indexOf(".DS_Store") >= 0 || !statSync(f).isDirectory) continue;
try {
const pkg = JSON.parse(fs.readFileSync(f + "/package.json"));
const pkg = readJSON(f + "/package.json");
const id = pkg.name.split("/")[1];
if (getIn(pkg, ["thi.ng", "shortlink"]) === false) {
console.log(`\tskipping: ${id}`);
Expand All @@ -19,13 +19,13 @@ for (let f of fs.readdirSync(baseDir)) {
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);
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"`
`aws s3 cp ${tmpFile} s3://thi.ng/${id} --profile thing-umbrella --acl public-read --content-type "text/html" --cache-control "no-cache"`
);
} catch (e) {
console.warn(`error: ${e.message}`);
console.warn(`error: ${(<Error>e).message}`);
}
}

fs.unlinkSync(tmpFile);
unlinkSync(tmpFile);

0 comments on commit faefb2b

Please sign in to comment.