aboutsummaryrefslogtreecommitdiffstats
path: root/scripts/prepare_index_html.js
blob: f1aa5c5199ba6805967f65bcb8a166c89447f030 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
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/app/src/main/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);
        }
    });
}