|
1 | 1 | "use strict";
|
2 | 2 |
|
| 3 | +var path = require('path'); |
| 4 | + |
| 5 | +function parseVersion (grunt, version) { |
| 6 | + var newsPath = path.join('temp/download', version, 'NEWS'), |
| 7 | + input = grunt.file.read(newsPath), |
| 8 | + matches = input.match(/\nRelease (\d{4}[a-z]) /); |
| 9 | + |
| 10 | + if (matches && matches[1]) { |
| 11 | + if (version !== 'latest' && version !== matches[1]) { |
| 12 | + throw new Error("Parsed version " + matches[1] + |
| 13 | + " differs from specified version " + version) |
| 14 | + } |
| 15 | + return matches[1]; |
| 16 | + } |
| 17 | + throw new Error("Could not find version from " + newsPath); |
| 18 | +} |
| 19 | + |
3 | 20 | function parseLatLong (input, isLong) {
|
4 | 21 | var sign = input[0] === '+' ? 1 : -1,
|
5 | 22 | deg = ~~input.substr(1, 2 + isLong) * sign,
|
@@ -127,12 +144,16 @@ module.exports = function (grunt) {
|
127 | 144 | var validCountries = filterCountries(countries);
|
128 | 145 |
|
129 | 146 | var output = {
|
| 147 | + version: parseVersion(grunt, version), |
130 | 148 | countries: validCountries,
|
131 | 149 | zones: zones
|
132 | 150 | };
|
133 | 151 |
|
134 | 152 | grunt.file.write('data/meta/' + version + '.json', JSON.stringify(output, null, '\t'));
|
| 153 | + if (version === 'latest') { |
| 154 | + grunt.file.copy('data/meta/latest.json', 'data/meta/' + output.version + '.json'); |
| 155 | + } |
135 | 156 |
|
136 |
| - grunt.log.ok('Added metadata for ' + version); |
| 157 | + grunt.log.ok('Added metadata for ' + version + (version === 'latest' ? ': ' + output.version : '')); |
137 | 158 | });
|
138 | 159 | };
|
0 commit comments