template/cordova/lib/build.js
function parseAndValidateArgs (options) {
    // parse and validate args
    var args = nopt({
        'archs': [String],
        'appx': String,
        'phone': Boolean,
        'win': Boolean,
        'bundle': Boolean,
        'packageCertificateKeyFile': String,
        'packageThumbprint': String,
        'publisherId': String,
        'buildConfig': String,
        'buildFlag': [String, Array]
    }, {}, options.argv, 0);

    var config = {};
    var buildConfig = {};

    // Validate args
    if (options.debug && options.release) {
        throw new CordovaError('Cannot specify "debug" and "release" options together.');
    }

    if (args.phone && args.win) {
        throw new CordovaError('Cannot specify "phone" and "win" options together.');
    }

    // get build options/defaults
    config.buildType = options.release ? 'release' : 'debug';

    var archs = options.archs || args.archs;
    config.buildArchs = archs ? archs.toLowerCase().split(' ') : ['anycpu'];

    config.phone = !!args.phone;
    config.win = !!args.win;
    config.projVerOverride = args.appx;
    // only set config.bundle if architecture is not anycpu
    if (args.bundle) {
        if (config.buildArchs.length > 1 && (config.buildArchs.indexOf('anycpu') > -1 || config.buildArchs.indexOf('any cpu') > -1)) {
            // Not valid to bundle anycpu with cpu-specific architectures.  warn, then don't bundle
            events.emit('warn', '"anycpu" and CPU-specific architectures were selected. ' +
                'This is not valid when enabling bundling with --bundle. Disabling bundling for this build.');
        } else {
            config.bundle = true;
        }
    }

    // if build.json is provided, parse it
    var buildConfigPath = options.buildConfig || args.buildConfig;
    if (buildConfigPath) {
        buildConfig = parseBuildConfig(buildConfigPath, config.buildType);
        for (var prop in buildConfig) { config[prop] = buildConfig[prop]; }
    }

    // Merge buildFlags from build config and CLI arguments into
    // single array ensuring that ones from CLI take a precedence
    config.buildFlags = [].concat(buildConfig.buildFlag || [], args.buildFlag || []);

    // CLI arguments override build.json config
    if (args.packageCertificateKeyFile) {
        args.packageCertificateKeyFile = path.resolve(process.cwd(), args.packageCertificateKeyFile);
        config.packageCertificateKeyFile = args.packageCertificateKeyFile;
    }

    config.packageThumbprint = config.packageThumbprint || args.packageThumbprint;
    config.publisherId = config.publisherId || args.publisherId;

    return config;
}
function parseAndValidateArgs (options) {
    // parse and validate args
    var args = nopt({
        'archs': [String],
        'appx': String,
        'phone': Boolean,
        'win': Boolean,
        'bundle': Boolean,
        'packageCertificateKeyFile': String,
        'packageThumbprint': String,
        'publisherId': String,
        'buildConfig': String,
        'buildFlag': [String, Array]
    }, {}, options.argv, 0);

    var config = {};
    var buildConfig = {};

    // Validate args
    if (options.debug && options.release) {
        throw new CordovaError('Cannot specify "debug" and "release" options together.');
    }

    if (args.phone && args.win) {
        throw new CordovaError('Cannot specify "phone" and "win" options together.');
    }

    // get build options/defaults
    config.buildType = options.release ? 'release' : 'debug';

    var archs = options.archs || args.archs;
    config.buildArchs = archs ? archs.toLowerCase().split(' ') : ['anycpu'];

    config.phone = !!args.phone;
    config.win = !!args.win;
    config.projVerOverride = args.appx;
    // only set config.bundle if architecture is not anycpu
    if (args.bundle) {
        if (config.buildArchs.length > 1 && (config.buildArchs.indexOf('anycpu') > -1 || config.buildArchs.indexOf('any cpu') > -1)) {
            // Not valid to bundle anycpu with cpu-specific architectures.  warn, then don't bundle
            events.emit('warn', '"anycpu" and CPU-specific architectures were selected. ' +
                'This is not valid when enabling bundling with --bundle. Disabling bundling for this build.');
        } else {
            config.bundle = true;
        }
    }

    // if build.json is provided, parse it
    var buildConfigPath = options.buildConfig || args.buildConfig;
    if (buildConfigPath) {
        buildConfig = parseBuildConfig(buildConfigPath, config.buildType);
        for (var prop in buildConfig) { config[prop] = buildConfig[prop]; }
    }

    // Merge buildFlags from build config and CLI arguments into
    // single array ensuring that ones from CLI take a precedence
    config.buildFlags = [].concat(buildConfig.buildFlag || [], args.buildFlag || []);

    // CLI arguments override build.json config
    if (args.packageCertificateKeyFile) {
        args.packageCertificateKeyFile = path.resolve(process.cwd(), args.packageCertificateKeyFile);
        config.packageCertificateKeyFile = args.packageCertificateKeyFile;
    }

    config.packageThumbprint = config.packageThumbprint || args.packageThumbprint;
    config.publisherId = config.publisherId || args.publisherId;

    return config;
}
function parseAndValidateArgs ( options ) { // parse and validate args var args = nopt ( { 'archs' : [ String ] , 'appx' : String , 'phone' : Boolean , 'win' : Boolean , 'bundle' : Boolean , 'packageCertificateKeyFile' : String , 'packageThumbprint' : String , 'publisherId' : String , 'buildConfig' : String , 'buildFlag' : [ String , Array ] } , { } , options . argv , 0 ) ; var config = { } ; var buildConfig = { } ; // Validate args if ( options . debug && options . release ) { throw new CordovaError ( 'Cannot specify "debug" and "release" options together.' ) ; } if ( args . phone && args . win ) { throw new CordovaError ( 'Cannot specify "phone" and "win" options together.' ) ; } // get build options/defaults config . buildType = options . release ? 'release' : 'debug' ; var archs = options . archs || args . archs ; config . buildArchs = archs ? archs . toLowerCase ( ) . split ( ' ' ) : [ 'anycpu' ] ; config . phone = ! ! args . phone ; config . win = ! ! args . win ; config . projVerOverride = args . appx ; // only set config.bundle if architecture is not anycpu if ( args . bundle ) { if ( config . buildArchs . length > 1 && ( config . buildArchs . indexOf ( 'anycpu' ) > - 1 || config . buildArchs . indexOf ( 'any cpu' ) > - 1 ) ) { // Not valid to bundle anycpu with cpu-specific architectures.  warn, then don't bundle events . emit ( 'warn' , '"anycpu" and CPU-specific architectures were selected. ' + 'This is not valid when enabling bundling with --bundle. Disabling bundling for this build.' ) ; } else { config . bundle = true ; } } // if build.json is provided, parse it var buildConfigPath = options . buildConfig || args . buildConfig ; if ( buildConfigPath ) { buildConfig = parseBuildConfig ( buildConfigPath , config . buildType ) ; for ( var prop in buildConfig ) { config [ prop ] = buildConfig [ prop ] ; } } // Merge buildFlags from build config and CLI arguments into // single array ensuring that ones from CLI take a precedence config . buildFlags = [ ] . concat ( buildConfig . buildFlag || [ ] , args . buildFlag || [ ] ) ; // CLI arguments override build.json config if ( args . packageCertificateKeyFile ) { args . packageCertificateKeyFile = path . resolve ( process . cwd ( ) , args . packageCertificateKeyFile ) ; config . packageCertificateKeyFile = args . packageCertificateKeyFile ; } config . packageThumbprint = config . packageThumbprint || args . packageThumbprint ; config . publisherId = config . publisherId || args . publisherId ; return config ; }
Parses and validates buildOptions object and platform-specific CLI arguments,
provided via argv field

@param   {Object}  [options]  An options object. If not specified, result
will be populated with default values.

@return  {Object}             Build configuration, used by other methods
Parses and validates buildOptions object and platform - specific CLI arguments provided via argv field