diff --git a/tasks/data-dedupe.js b/tasks/data-dedupe.js index b521af48..eaae9f0f 100644 --- a/tasks/data-dedupe.js +++ b/tasks/data-dedupe.js @@ -26,15 +26,6 @@ function dedupe(zone) { }; } -function findVersion (source) { - var matches = source.match(/\nRelease (\d{4}[a-z]) /); - - if (matches && matches[1]) { - return matches[1]; - } - throw new Error("Could not find version from temp/download/latest/NEWS."); -} - function addCountries(countries) { var result = []; @@ -55,14 +46,16 @@ module.exports = function (grunt) { var zones = grunt.file.readJSON('temp/collect/' + version + '.json'), meta = grunt.file.readJSON('data/meta/' + version + '.json'), output = { - version : version === 'latest' ? - findVersion(grunt.file.read('temp/download/latest/NEWS')) : version, + version : meta.version, zones : zones.map(dedupe), links : [], countries : addCountries(meta.countries) }; grunt.file.write('data/unpacked/' + version + '.json', JSON.stringify(output, null, 2)); + if (version === 'latest') { + grunt.file.copy('data/unpacked/' + version + '.json', 'data/unpacked/' + output.version + '.json'); + } grunt.log.ok('Deduped data for ' + version); }); diff --git a/tasks/data-meta.js b/tasks/data-meta.js index 2f1fcdaf..e76d5ae8 100644 --- a/tasks/data-meta.js +++ b/tasks/data-meta.js @@ -1,5 +1,22 @@ "use strict"; +var path = require('path'); + +function parseVersion (grunt, version) { + var newsPath = path.join('temp/download', version, 'NEWS'), + input = grunt.file.read(newsPath), + matches = input.match(/\nRelease (\d{4}[a-z]) /); + + if (matches && matches[1]) { + if (version !== 'latest' && version !== matches[1]) { + throw new Error("Parsed version " + matches[1] + + " differs from specified version " + version) + } + return matches[1]; + } + throw new Error("Could not find version from " + newsPath); +} + function parseLatLong (input, isLong) { var sign = input[0] === '+' ? 1 : -1, deg = ~~input.substr(1, 2 + isLong) * sign, @@ -127,12 +144,16 @@ module.exports = function (grunt) { var validCountries = filterCountries(countries); var output = { + version: parseVersion(grunt, version), countries: validCountries, zones: zones }; grunt.file.write('data/meta/' + version + '.json', JSON.stringify(output, null, '\t')); + if (version === 'latest') { + grunt.file.copy('data/meta/latest.json', 'data/meta/' + output.version + '.json'); + } - grunt.log.ok('Added metadata for ' + version); + grunt.log.ok('Added metadata for ' + version + (version === 'latest' ? ': ' + output.version : '')); }); }; diff --git a/tasks/data-pack.js b/tasks/data-pack.js index 37ca6560..c9fbbbab 100644 --- a/tasks/data-pack.js +++ b/tasks/data-pack.js @@ -19,6 +19,9 @@ module.exports = function (grunt) { }); grunt.file.write('data/packed/' + version + '.json', JSON.stringify(output, null, '\t')); + if (version === 'latest') { + grunt.file.copy('data/packed/latest.json', 'data/packed/' + unpacked.version + '.json'); + } grunt.log.ok('Packed data for ' + version); });