All files seymour.js

100% Statements 76/76
100% Branches 30/30
100% Functions 9/9
100% Lines 76/76

Press n or j to go to the next uncovered block, b, p or k for the previous block.

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 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173                                1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x       22x     2x   2x 2x 2x       20x 20x 1x     19x 19x   19x 19x   19x                   19x 1x     19x 1x     19x 1x     19x 1x     19x 1x 1x 1x     19x 1x   2x     19x     1x   18x     19x 1x       19x 1x       19x   15x     1x 1x     19x   15x     4x       4x   4x 4x 2x 2x     4x 4x 2x 2x 2x   4x     19x   19x   19x   19x           18x   18x 18x   18x   18x   18x     17x       1x  
/**
 * Copyright 2015 Darryl Pogue
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
 
var pkg             = require('../package.json');
var cordova         = require('cordova-lib').cordova;
var ConfigParser    = require('cordova-common').ConfigParser;
var CordovaError    = require('cordova-common').CordovaError;
var events          = require('cordova-common').events;
var CordovaLogger   = require('cordova-common').CordovaLogger;
var fs              = require('fs');
var path            = require('path');
var HooksRunner     = require('cordova-lib/src/hooks/HooksRunner');
var cordovaUtil     = require('cordova-lib/src/cordova/util');
var et              = require('elementtree');
 
function run(args, env)
{
    if (args.indexOf('-v') !== -1 ||
        args.indexOf('--version') !== -1)
    {
        var cdvVer = require('cordova-lib/package').version;
 
        console.log('Seymour ' + pkg.version);
        console.log('Cordova ' + cdvVer);
        return Promise.resolve();
    }
 
 
    var projectRoot = cordova.findProjectRoot();
    if (!projectRoot) {
        return Promise.reject(new CordovaError('Current working directory is not a Cordova-based project.'));
    }
 
    var logger = CordovaLogger.get();
    logger.subscribe(events);
 
    var configPath = path.join(projectRoot, 'config.xml');
    var config = new ConfigParser(configPath);
 
    var opts = {
        platforms: [],
        options: {device: true},
        verbose: false,
        silent: false,
        browserify: true,
        fetch: true
    };
 
 
    if (env.SEY_APP_ID) {
        config.setPackageName(env.SEY_APP_ID);
    }
 
    if (env.SEY_APP_NAME) {
        config.setName(env.SEY_APP_NAME);
    }
 
    if (env.SEY_APP_SHORTNAME) {
        config.setShortName(env.SEY_APP_SHORTNAME);
    }
 
    if (env.SEY_APP_VERSION) {
        config.setVersion(env.SEY_APP_VERSION);
    }
 
    if (env.SEY_VERBOSE) {
        opts.verbose = true;
        opts.options.verbose = true;
        logger.setLevel('verbose');
    }
 
    if (env.SEY_BUILD_PLATFORMS) {
        opts.platforms = env.SEY_BUILD_PLATFORMS
                        .split(',')
                        .map(function(p) { return p.toLowerCase(); });
    }
 
    if (env.SEY_BUILD_MODE &&
        env.SEY_BUILD_MODE.toLowerCase() === 'release')
    {
        opts.options.release = true;
    } else {
        opts.options.debug = true;
    }
 
    if (env.SEY_BUILD_CONFIG) {
        opts.options.buildConfig = env.SEY_BUILD_CONFIG;
    }
 
 
    if (env.SEY_NOBROWSERIFY) {
        opts.browserify = false;
    }
 
 
    Object.keys(env)
        .filter(function(v) {
            return v.match(/^SEY_PREFERENCE_/);
        })
        .forEach(function(envName) {
            var name = envName.replace(/^SEY_PREFERENCE_/, '');
            config.setGlobalPreference(name, env[envName]);
        });
 
    Object.keys(env)
        .filter(function(v) {
            return v.match(/^SEY_([A-Za-z]+)_PREFERENCE_/);
        })
        .forEach(function(envName) {
            var platform = envName.match(/^SEY_([A-Za-z]+)(?=_)/)[0] //e.g. SEY_IOS
                                  .replace(/^SEY_/, '') // Remove SEY_
                                  .toLowerCase();
 
            var name = envName.replace(/^SEY_([A-Za-z]+)_PREFERENCE_/, '');
 
            var plat = config.doc.find('platform[@name=\"' + platform + '\"]');
            if(!plat) {
                plat = new et.Element('platform', { name: platform });
                config.doc.getroot().append(plat);
            }
 
            var pref = plat.find('preference[@name="' + name + '"]');
            if (!pref) {
                pref = new et.Element('preference');
                pref.attrib.name = name;
                plat.append(pref);
            }
            pref.attrib.value = env[envName];
        });
 
    config.write();
 
    var base_opts = JSON.stringify(opts);
 
    var prep_opts = JSON.parse(base_opts);
 
    return cordova.prepare.call(null, prep_opts)
    .then(function() {
        // Some plugins (Crosswalk *shakefist*) add a bunch of their own stuff
        // to config.xml that overrides user-defined variables.
        // We re-save the config.xml file after installing plugins to ensure
        // we have the data that we want and not extra garbage.
        config.write();
 
        var projectRoot = cordovaUtil.cdProjectRoot();
        var build_opts = cordovaUtil.preProcessOptions(JSON.parse(base_opts));
 
        var hooksRunner = new HooksRunner(projectRoot);
 
        return hooksRunner.fire('before_build', build_opts)
        .then(function() {
            return cordova.compile.call(null, build_opts);
        })
        .then(function() {
            return hooksRunner.fire('after_build', build_opts);
        });
    });
}
module.exports = run;