{"size": 1209, "ext": "js", "max_stars_repo_path": "scripts/downloadOpenTokJS.js", "max_stars_repo_name": "jlorente/cordova-plugin-opentok-variant", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "scripts/downloadOpenTokJS.js", "max_issues_repo_name": "jlorente/cordova-plugin-opentok-variant", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "scripts/downloadOpenTokJS.js", "max_forks_repo_name": "jlorente/cordova-plugin-opentok-variant", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 32.6756756757, "max_line_length": 123, "alphanum_fraction": 0.5343258892}
#!/usr/bin/env node

module.exports = function (context) {
    /**
     *
     * Change to correct version
     */
    var openTokJSClientVersion = "v2";

    /**
     *
     * Do not change anything below this
     */
    var downloadFile = require('./downloadFile.js'),
        exec = require('./exec/exec.js'),
        Q = context.requireCordovaModule('q'),
        fs = require('fs'),
        deferral = new Q.defer();
    console.log('Downloading OpenTok JS SDK');
    downloadFile('https://static.opentok.com/' + openTokJSClientVersion +'/js/opentok.js', './opentok.js', function (err) {
        if (!err) {
            console.log('downloaded');
            fs.appendFile('./opentok.js', 'module.exports = window.OT;', function (err) {
                if (err) throw err;
                console.log('Module export added to opentok.js!');

                var frameworkDir = context.opts.plugin.dir + '/src/browser/';
                exec('mv ./opentok.js ' + frameworkDir, function (err, out, code) {
                    console.log('moved openTok.js into ' + frameworkDir);
                    deferral.resolve();
                });
            });
        }
    });
    return deferral.promise;
};
