automatically download vendored libraries when tagged

Daniel Pittman [08-26-18 - 19:45]
automatically download vendored libraries when tagged

The `X-VendorAddon: <name> <esoui id>` tag can be used to specify
that an addon should be downloaded and extracted when building the
release package.

This helps avoid manually updating remote packages when we need to
update them, and works smoothly with the model of shipping a version
that is seen by ESO, not manually vendored internally.
Filename
LibStub/LibStub.txt
LibStub/LibStub/LibStub.lua
SlippyCheezeReadItOnce.txt
release.sh
diff --git a/LibStub/LibStub.txt b/LibStub/LibStub.txt
deleted file mode 100644
index df3488c..0000000
--- a/LibStub/LibStub.txt
+++ /dev/null
@@ -1,7 +0,0 @@
-## APIVersion: 100007
-## Title: LibStub
-## Description: Universal Library Stub
-## Credits: Kaelten, Cladhaire, ckknight, Mikk, Ammo, Nevcairiel, ported to ESO by Seerah
-## Version: 1.0 r4
-
-LibStub\LibStub.lua
\ No newline at end of file
diff --git a/LibStub/LibStub/LibStub.lua b/LibStub/LibStub/LibStub.lua
deleted file mode 100644
index 4c35014..0000000
--- a/LibStub/LibStub/LibStub.lua
+++ /dev/null
@@ -1,38 +0,0 @@
--- LibStub is a simple versioning stub meant for use in Libraries.  http://www.wowace.com/wiki/LibStub for more info
--- LibStub is hereby placed in the Public Domain Credits: Kaelten, Cladhaire, ckknight, Mikk, Ammo, Nevcairiel, joshborke
--- LibStub developed for World of Warcraft by above members of the WowAce community.
--- Ported to Elder Scrolls Online by Seerah
-
-local LIBSTUB_MAJOR, LIBSTUB_MINOR = "LibStub", 4
-local LibStub = _G[LIBSTUB_MAJOR]
-
-local strformat = string.format
-if not LibStub or LibStub.minor < LIBSTUB_MINOR then
-	LibStub = LibStub or {libs = {}, minors = {} }
-	_G[LIBSTUB_MAJOR] = LibStub
-	LibStub.minor = LIBSTUB_MINOR
-
-	function LibStub:NewLibrary(major, minor)
-		assert(type(major) == "string", "Bad argument #2 to `NewLibrary' (string expected)")
-		if type(minor) ~= "number" then
-			minor = assert(tonumber(zo_strmatch(minor, "%d+%.?%d*")), "Minor version must either be a number or contain a number.")
-		end
-
-		local oldminor = self.minors[major]
-		if oldminor and oldminor >= minor then return nil end
-		self.minors[major], self.libs[major] = minor, self.libs[major] or {}
-		return self.libs[major], oldminor
-	end
-
-	function LibStub:GetLibrary(major, silent)
-		if not self.libs[major] and not silent then
-			error(strformat("Cannot find a library instance of %q.", tostring(major)), 2)
-		end
-		return self.libs[major], self.minors[major]
-	end
-
-	function LibStub:IterateLibraries() return pairs(self.libs) end
-	setmetatable(LibStub, { __call = LibStub.GetLibrary })
-end
-
-LibStub.SILENT = true
\ No newline at end of file
diff --git a/SlippyCheezeReadItOnce.txt b/SlippyCheezeReadItOnce.txt
index e37133a..c376c5a 100644
--- a/SlippyCheezeReadItOnce.txt
+++ b/SlippyCheezeReadItOnce.txt
@@ -6,6 +6,9 @@
 ## APIVersion: 100024
 ## SavedVariables: SlippyCheezeReadItOnceData
 ## DependsOn: LibStub LibAsync
+##
+## X-VendorAddon: LibStub 44
+## Sadly, can't vendor LibAsync, no upstream ESOUI location for it. :/

 SlippyCheezeReadItOnce.lua

diff --git a/release.sh b/release.sh
index 78f18c9..56072f5 100644
--- a/release.sh
+++ b/release.sh
@@ -1,6 +1,9 @@
 #!/usr/bin/env zsh
 #
 # Create a release zip file ready for pushing to esoui
+set -e
+set +u
+set WARN_CREATE_GLOBAL

 function log() {echo "release: $*"; }
 function die() { log "$@" >&2;  exit 1; }
@@ -8,6 +11,15 @@ function die() { log "$@" >&2;  exit 1; }
 # check we have the tools we need
 [[ -x =git-chglog ]] || die "the (golang) git-chglog tool is missing"
 [[ -x =md2bbcode ]] || die "the md2bbcode script is missing"
+[[ -x =jq ]] || die "the jq utility is missing"
+[[ -x =curl ]] || die "curl is missing"
+
+# grab the ESOUI token from the git config
+token="X-API-Token: $(git config esoui.token)"
+if [[ $? > 0 || ${token} == 'X-API-Token: ' ]]; then
+  die "git config esoui.token failed: '${esoui_token:-not found in config file}'"
+fi
+

 IS_RELEASE_VERSION='true'
 if [[ $1 == test ]]; then
@@ -108,12 +120,44 @@ perl -p -e 'BEGIN { $v=shift; } s/^## (AddOn)?Version:.*$/## \1Version: $v/' \
 done

 # add any embedded libraries wholesale!
-log "shipping embedded libraries"
+log "shipping local embedded libraries"
 for embed in [lL]ib*/**/*(.); do
   log "embed ${embed}"
   cp --parents ${embed} ${build}
 done

+log "fetching remote embedded libraries"
+< ${manifest} while read _ tag name id _; do
+  if [[ ${tag:l} == x-vendoraddon: ]]; then
+    if [[ -z ${name} || -z ${id} ]]; then
+      die "missing name or id for vendoring from esoui: [${name}] [${id}]"
+    fi
+
+    log "fetching release information for ${id}:${name}"
+    data=$(curl -sSLH ${token} https://api.esoui.com/addons/details/${id}.json)
+
+    json_id=$(jq -M -r '.[0].id' <<<${data})
+    if [[ ${id} != ${json_id} ]]; then
+      die "vendoring ${id}:${name} - remote {id: '${json_id}'} does not match"
+    fi
+
+    json_name=$(jq -M -r '.[0].title' <<<${data})
+    if [[ ${name} != ${json_name} ]]; then
+      die "vendoring ${id}:${name} - remote {title: '${json_name}'} does not match"
+    fi
+
+    json_filename=$(jq -M -r '.[0].filename' <<<${data})
+    if [[ ${json_filename} != ${name}*.zip ]]; then
+      die "vendoring ${id}:${name} - remote {filename: '${json_filename}'} does not match expectations"
+    fi
+
+    # we actually have a validated set of data, and a filename, fetch it down
+    # and unpack into the build directory!
+    log "downloading ${json_id}:${json_name} from ${json_filename} and unpacking"
+    unzip -bD =(curl -L -H ${token} http://www.esoui.com/downloads/dl${id}/${json_filename}) -d ${build}
+  fi
+done
+
 # generate the changelog and description files
 if [[ -f README.md ]]; then
   ship README.md