gruntfile.js
function getCountryList() {
        var countries = grunt.option("countries");
        if (!countries) {
            grunt.fail.fatal("Country list not passed. Example usage: `grunt customBuild --countries=Canada,United States`");
        }

        // countries may contain commas in their names. Bit ugly, but simple. This swiches out those escaped commas
        // and replaces them later
        var commaReplaced = countries.replace(/\\,/g, '{COMMA}');
        var targetCountries = _.map(commaReplaced.split(","), function (country) {
            return country.replace(/\{COMMA\}/, ',').trim();
        });

        var countryData = [];
        var foundCountryNames = [];

        var formattedData = minifyJSON(countriesJSON);
        _.each(formattedData, function (countryInfo) {
            var countryName = countryInfo[0];
            if (_.contains(targetCountries, countryName)) {
                countryData.push(countryInfo);
                foundCountryNames.push(countryName);
            }
        });

        // if one or more of the countries wasn't found, they probably made a typo: throw a warning but continue
        if (targetCountries.length !== countryData.length) {
            grunt.log.error("The following countries weren't found (check the source/data.json file to ensure you entered the exact country string):");
            var missing = _.difference(targetCountries, foundCountryNames);
            _.each(missing, function (countryName) {
                grunt.log.error("--", countryName);
            });

            // all good! Let the user know what bundle is being created, just to remove any ambiguity
        } else {
            grunt.log.writeln("");
            grunt.log.writeln("Creating bundle with following countries:");
            _.each(targetCountries, function (country) {
                grunt.log.writeln("* " + country);
            });
        }

        config.template.customBuild.options.data.__DATA__ = "\nvar _data = " + JSON.stringify(countryData);
    }
function getCountryList() {
        var countries = grunt.option("countries");
        if (!countries) {
            grunt.fail.fatal("Country list not passed. Example usage: `grunt customBuild --countries=Canada,United States`");
        }

        // countries may contain commas in their names. Bit ugly, but simple. This swiches out those escaped commas
        // and replaces them later
        var commaReplaced = countries.replace(/\\,/g, '{COMMA}');
        var targetCountries = _.map(commaReplaced.split(","), function (country) {
            return country.replace(/\{COMMA\}/, ',').trim();
        });

        var countryData = [];
        var foundCountryNames = [];

        var formattedData = minifyJSON(countriesJSON);
        _.each(formattedData, function (countryInfo) {
            var countryName = countryInfo[0];
            if (_.contains(targetCountries, countryName)) {
                countryData.push(countryInfo);
                foundCountryNames.push(countryName);
            }
        });

        // if one or more of the countries wasn't found, they probably made a typo: throw a warning but continue
        if (targetCountries.length !== countryData.length) {
            grunt.log.error("The following countries weren't found (check the source/data.json file to ensure you entered the exact country string):");
            var missing = _.difference(targetCountries, foundCountryNames);
            _.each(missing, function (countryName) {
                grunt.log.error("--", countryName);
            });

            // all good! Let the user know what bundle is being created, just to remove any ambiguity
        } else {
            grunt.log.writeln("");
            grunt.log.writeln("Creating bundle with following countries:");
            _.each(targetCountries, function (country) {
                grunt.log.writeln("* " + country);
            });
        }

        config.template.customBuild.options.data.__DATA__ = "\nvar _data = " + JSON.stringify(countryData);
    }
function getCountryList ( ) { var countries = grunt . option ( "countries" ) ; if ( ! countries ) { grunt . fail . fatal ( "Country list not passed. Example usage: `grunt customBuild --countries=Canada,United States`" ) ; } // countries may contain commas in their names. Bit ugly, but simple. This swiches out those escaped commas // and replaces them later var commaReplaced = countries . replace ( / \\, / g , '{COMMA}' ) ; var targetCountries = _ . map ( commaReplaced . split ( "," ) , function ( country ) { return country . replace ( / \{COMMA\} / , ',' ) . trim ( ) ; } ) ; var countryData = [ ] ; var foundCountryNames = [ ] ; var formattedData = minifyJSON ( countriesJSON ) ; _ . each ( formattedData , function ( countryInfo ) { var countryName = countryInfo [ 0 ] ; if ( _ . contains ( targetCountries , countryName ) ) { countryData . push ( countryInfo ) ; foundCountryNames . push ( countryName ) ; } } ) ; // if one or more of the countries wasn't found, they probably made a typo: throw a warning but continue if ( targetCountries . length !== countryData . length ) { grunt . log . error ( "The following countries weren't found (check the source/data.json file to ensure you entered the exact country string):" ) ; var missing = _ . difference ( targetCountries , foundCountryNames ) ; _ . each ( missing , function ( countryName ) { grunt . log . error ( "--" , countryName ) ; } ) ; // all good! Let the user know what bundle is being created, just to remove any ambiguity } else { grunt . log . writeln ( "" ) ; grunt . log . writeln ( "Creating bundle with following countries:" ) ; _ . each ( targetCountries , function ( country ) { grunt . log . writeln ( "* " + country ) ; } ) ; } config . template . customBuild . options . data . __DATA__ = "\nvar _data = " + JSON . stringify ( countryData ) ; }
used for the customBuild target. This generates a custom build of CRS with the list of countries specified by the user
used for the customBuild target . This generates a custom build of CRS with the list of countries specified by the user