Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

tools app.json: initial commit

  • Loading branch information...
commit 06d0e4866af645df499294e4cb1ceb29f76a10f4 1 parent 8bafce7
@4z3 authored
View
24 tools/app.json/json-query
@@ -0,0 +1,24 @@
+#! /usr/bin/env node
+//
+// usage: json-query filename [--json] [keys...]
+//
+
+var args = process.argv.slice(2);
+var filename = args.shift();
+var x = JSON.parse(require('fs').readFileSync(filename));
+
+var filter = function (x) {
+ return x;
+};
+
+args.forEach(function (key) {
+ if (key === '--json') {
+ filter = function (x) {
+ return JSON.stringify(x, null, 2);
+ };
+ } else {
+ x = x[key];
+ };
+});
+
+console.log(filter(x));
View
23 tools/app.json/make-app
@@ -0,0 +1,23 @@
+#! /bin/sh
+#
+# usage: make-app [build_dir]
+#
+set -euf
+
+PATH="$(dirname $(readlink -f $0))${PATH+:$PATH}"
+
+app_name="`json-query $config_json name`"
+
+{
+ make-app-files $app_name $1 | sed '
+ 1s/^/"files": /
+ $s/$/,/
+ '
+ make-app-proxies $config_json | sed '
+ 1s/^/"proxies": /
+ '
+} | sed '
+ s/^/ /
+ 1s/^/{\n/
+ $s/$/\n}/
+'
View
51 tools/app.json/make-app-files
@@ -0,0 +1,51 @@
+#! /bin/sh
+#
+# usage: make-app-files app_name build_dir
+#
+set -euf
+
+app_name="$1"
+build_dir="$2"
+
+typeof() {
+ # TODO use file; ensure that file works everywhere...lol
+ echo "$1" | sed '
+ s:^.*\.css$:text/css:
+ s:^.*\.gif$:image/gif:
+ s:^.*\.html$:text/html:
+ s:^.*\.jpg$:image/jpeg:
+ s:^.*\.js$:application/javascript:
+ s:^.*\.json$:application/json:
+ s:^.*\.manifest$:text/cache-manifest:
+ s:^.*\.png$:image/png:
+ s:^.*\.svg$:image/svg+xml:
+ '
+}
+
+cd "$build_dir"
+find . -type f | sed "s:^\./::" |
+while read filename; do
+ if test "$filename" = "index.html"; then
+ signal='"signal": "SIGSTOP"'
+ else
+ unset signal
+ fi
+ url="/$app_name/$filename"
+ type="`typeof $filename`"
+ content="`base64 -w 0 $filename`"
+ encoding='"Content-Transfer-Encoding": "base64"'
+
+ cat<<EOF
+"$url": {
+ "type": "$type",
+ "content": "$content"${encoding+,
+ $encoding}${signal+,
+ $signal}
+}
+EOF
+done | sed '
+ $!s/^}$/&,/
+ s/^/ /
+ 1s/^/{\n/
+ $s/$/\n}/
+'
View
18 tools/app.json/make-app-proxies
@@ -0,0 +1,18 @@
+#! /usr/bin/env node
+//
+// usage: make-app-proxies config_json
+//
+
+var args = process.argv.slice(2);
+var filename = args.shift();
+var x = JSON.parse(require('fs').readFileSync(filename));
+
+var proxies = {};
+
+x.proxies.forEach(function (proxy) {
+ proxies['/' + proxy.proxyAlias] = {
+ baseURL: proxy.baseUrl
+ };
+});
+
+console.log(JSON.stringify(proxies, null, 2));
Please sign in to comment.
Something went wrong with that request. Please try again.