aboutsummaryrefslogtreecommitdiff
path: root/scripts/update_manifest.js
diff options
context:
space:
mode:
authoroldmud0 <oldmud0@users.noreply.github.com>2019-03-29 21:03:43 -0500
committeroldmud0 <oldmud0@users.noreply.github.com>2019-03-29 21:03:43 -0500
commit5d0044b93cfd5ada490c7c1b296bdd0f1602a8f2 (patch)
tree5786bebd21748987d0481f4f79505aa482214e5e /scripts/update_manifest.js
parent9a32aa6e849cab35710aaddd5e2323276e8eccfb (diff)
Add a bunch of scripts
Diffstat (limited to 'scripts/update_manifest.js')
-rwxr-xr-xscripts/update_manifest.js84
1 files changed, 84 insertions, 0 deletions
diff --git a/scripts/update_manifest.js b/scripts/update_manifest.js
new file mode 100755
index 00000000..5f64cfb4
--- /dev/null
+++ b/scripts/update_manifest.js
@@ -0,0 +1,84 @@
+#!/usr/bin/env node
+
+const fs = require("fs");
+const crypto = require("crypto");
+const ArgumentParser = require("argparse").ArgumentParser;
+
+function isFile(file) {
+ if (!fs.existsSync(file)) {
+ console.error(`File '${file}' not found. Try again.`);
+ throw Error();
+ }
+ return file;
+}
+
+const argParser = new ArgumentParser({
+ addHelp: true,
+ description: "Adds a new latest version to the manifest file based on the " +
+ "provided zip file, including an incremental update."
+});
+argParser.addArgument("manifestFile", {
+ metavar: "<manifest file>", type: isFile
+});
+argParser.addArgument("version", {
+ metavar: "<version>"
+});
+argParser.addArgument([ "-f", "--full" ], {
+ metavar: "<full zip file>", type: isFile, nargs: 1,
+ dest: "fullZipFile"
+});
+argParser.addArgument([ "-i", "--incremental" ], {
+ type: isFile, nargs: 2, dest: "incremental",
+ metavar: ["<incremental zip file>", "<file containing list of deleted files>"]
+});
+argParser.addArgument([ "-e", "--executable" ], {
+ metavar: "[executable file]", nargs: 1,
+ dest: "executable"
+});
+
+const {
+ manifestFile,
+ version,
+ fullZipFile,
+ incremental: [incrementalZipFile, deletionsFile],
+ executable
+} = argParser.parseArgs();
+
+const manifest = JSON.parse(fs.readFileSync(manifestFile));
+
+const deleteActions = deletionsFile ? fs.readFileSync(deletionsFile)
+ .split("\n").map(file => {
+ // XXX: This does not delete empty directories. Finding them would
+ // actually be a substantial amount of work because Git does not
+ // give us a good way of finding directories that were deleted.
+ return { action: "delete", target: file };
+ }) : [];
+
+const urlBase = "https://s3.wasabisys.com/ao-downloads/";
+
+manifest.versions = [{
+ version,
+ executable,
+ prev: manifest.version[0] ? manifest.version[0].version : undefined,
+ full: fullZipFile ? [
+ {
+ action: "dl",
+ url: urlBase + encodeURIComponent(fullZipFile),
+ hash: crypto.createHash("sha1")
+ .update(fs.readFileSync(fullZipFile))
+ .digest("hex")
+ }
+ ] : undefined,
+ update: incremental ? [
+ ...deleteActions,
+ {
+ action: "dl",
+ url: urlBase + encodeURIComponent(incrementalZipFile),
+ hash: crypto.createHash("sha1")
+ .update(fs.readFileSync(incrementalZipFile))
+ .digest("hex")
+ }
+ ] : undefined
+}, ...manifest.versions];
+
+fs.writeFileSync(manifestFile, JSON.stringify(manifest, null, 4));