aboutsummaryrefslogtreecommitdiffstats
path: root/scripts/prepare_index_html.js
diff options
context:
space:
mode:
authorDave Arter <davea@mysociety.org>2017-06-16 17:24:59 +0100
committerDave Arter <davea@mysociety.org>2017-06-22 16:31:00 +0100
commit88b724b8bc7aa4932c1ddc03c580152dc6aaf492 (patch)
treeafa117cdae90219eeda24d9ccdf215aa11fa5c1a /scripts/prepare_index_html.js
parentf19ac095f0c589bff68d4629576bc958ecdab1b3 (diff)
Process index.html as template at build time
There are a few places in index.html that depend on CONFIG in order to load the right cobrand stylesheet/language/map etc. This commit removes the run time script loading and instead processes index.html as a lodash template at build time to pull in the correct stylesheets and scripts.
Diffstat (limited to 'scripts/prepare_index_html.js')
-rwxr-xr-xscripts/prepare_index_html.js33
1 files changed, 33 insertions, 0 deletions
diff --git a/scripts/prepare_index_html.js b/scripts/prepare_index_html.js
new file mode 100755
index 0000000..379b0d9
--- /dev/null
+++ b/scripts/prepare_index_html.js
@@ -0,0 +1,33 @@
+#!/usr/bin/env node
+
+// This script is run as a hook by Cordova, it's not intended for manual
+// execution.
+
+var fs = require('fs');
+var path = require('path');
+var _ = require("../www/jslib/lodash.min.js");
+
+function processTemplate(filename, context) {
+ // Reads a file, processes it as a lodash template with the given context,
+ // and writes the result back to the original file.
+ var data = fs.readFileSync(filename, 'utf8');
+ var template = _.template(data);
+ var result = template(context);
+ fs.writeFileSync(filename, result, 'utf8');
+}
+
+module.exports = function(context) {
+ var CONFIG = require("../www/js/config.js");
+
+ var files = [
+ "platforms/android/assets/www/index.html",
+ "platforms/ios/www/index.html",
+ ];
+ files.forEach(function(file) {
+ if (fs.existsSync(file)) {
+ processTemplate(file, {CONFIG: CONFIG});
+ } else {
+ console.log("file didn't exist: ", file);
+ }
+ });
+}