-
-
Notifications
You must be signed in to change notification settings - Fork 151
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
build: update/rewrite deploy scripts
- Loading branch information
1 parent
2a1031d
commit e56cae6
Showing
5 changed files
with
115 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
#!/usr/bin/env node | ||
const fs = require("fs"); | ||
const execSync = require("child_process").execSync; | ||
|
||
const PKG = process.argv[2]; | ||
|
||
const BUCKET = "s3://docs.thi.ng"; | ||
const PREFIX = "/umbrella"; | ||
const S3_OPTS = `--profile thing-umbrella --acl public-read`; | ||
const SYNC_OPTS = `${S3_OPTS} --include "*" --exclude "*.sass" --exclude "*.ts"`; | ||
|
||
const MINIFY_OPTS = | ||
"--file-ext html --collapse-whitespace --remove-comments --remove-optional-tags --remove-redundant-attributes --remove-script-type-attributes --remove-tag-whitespace --use-short-doctype --minify-css true"; | ||
|
||
function* files(dir, ext) { | ||
for (let f of fs.readdirSync(dir)) { | ||
const curr = dir + "/" + f; | ||
if (f.endsWith(ext)) { | ||
yield curr; | ||
} else if (fs.statSync(curr).isDirectory()) { | ||
yield* files(curr, ext); | ||
} | ||
} | ||
} | ||
|
||
const sanitizeFile = (f) => { | ||
let updated = false; | ||
const src = fs | ||
.readFileSync(f, "utf-8") | ||
.replace( | ||
/\{@link @thi\.ng\/([a-z0-9-]+)(#(\w+))?\s*\|\s*([^\}]+)\}/g, | ||
(_, id, label) => { | ||
updated = true; | ||
return `<a href="${PREFIX}/${id}/">${label}</a>`; | ||
} | ||
) | ||
.replace( | ||
/\{@link @thi\.ng\/([a-z0-9-]+)#(\w+)?\s*\}/g, | ||
(_, id, sym) => { | ||
updated = true; | ||
let path = `${PREFIX}/${id}/`; | ||
if (sym.startsWith("I")) { | ||
path += `interfaces/${sym.toLowerCase()}.html`; | ||
} else if (/^[a-z]/.test(sym)) { | ||
path += `modules.html#${sym.toLowerCase()}`; | ||
} | ||
return `<a href="${path}">${sym}</a>`; | ||
} | ||
) | ||
.replace(/\{@link @thi\.ng\/([a-z0-9-]+)#?\s*\}/g, (_, id) => { | ||
updated = true; | ||
return `<a href="${PREFIX}/${id}/">@thi.ng/${id}</a>`; | ||
}); | ||
if (updated) { | ||
console.log("sanitizing:", f); | ||
fs.writeFileSync(f, src, "utf-8"); | ||
} | ||
}; | ||
|
||
const sanitizePackage = (root) => { | ||
for (let f of files(root, ".html")) { | ||
sanitizeFile(f); | ||
} | ||
}; | ||
|
||
const minifyPackage = (root) => { | ||
console.log("minifying", root); | ||
execSync( | ||
`node_modules/.bin/html-minifier-terser ${MINIFY_OPTS} --input-dir ${root} --output-dir ${root}` | ||
); | ||
}; | ||
|
||
const syncPackage = (id, root) => { | ||
console.log("syncing", root); | ||
console.log( | ||
execSync( | ||
`aws s3 sync ${root} ${BUCKET}${PREFIX}/${id} ${SYNC_OPTS}` | ||
).toString() | ||
); | ||
}; | ||
|
||
const processPackage = (id) => { | ||
console.log("processing", id); | ||
const root = `packages/${id}/doc`; | ||
try { | ||
sanitizePackage(root); | ||
minifyPackage(root); | ||
syncPackage(id, root); | ||
} catch (e) { | ||
console.warn(e); | ||
} | ||
}; | ||
|
||
if (PKG) { | ||
processPackage(PKG); | ||
} else { | ||
for (let pkg of fs.readdirSync("packages")) { | ||
if (fs.statSync(`packages/${pkg}`).isDirectory()) { | ||
processPackage(pkg); | ||
} | ||
} | ||
} | ||
|
||
execSync( | ||
`node_modules/.bin/ts-node -P tools/tsconfig.json tools/src/doc-table.ts` | ||
); | ||
|
||
execSync(`aws s3 cp docs.html ${BUCKET}/index.html ${S3_OPTS}`); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
#!/bin/sh | ||
aws cloudfront create-invalidation \ | ||
--distribution-id EL2F1HMDPZ2RL \ | ||
--paths "/umbrella/$1/*" \ | ||
--profile thing-umbrella |
This file was deleted.
Oops, something went wrong.