Skip to content

Commit

Permalink
data: automatically create data/*/VERSION.json for latest
Browse files Browse the repository at this point in the history
Commited files under data/ folder contain metadata, packed and unpacked
data for all released versions. Releases are normally done with `grunt
release` which calls `grunt data` which uses version latest, so a manual
copy of `data/*/latest.json` to the actual latest version was required
(or forgotten).

So change the pipeline to automatically generate the correctly-versioned
files in addition to latest.

Also move version parsing to data-meta, where it belongs.
  • Loading branch information
ichernev committed Aug 25, 2022
1 parent e551fde commit f13e22b
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 12 deletions.
15 changes: 4 additions & 11 deletions tasks/data-dedupe.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [];

Expand All @@ -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);
});
Expand Down
23 changes: 22 additions & 1 deletion tasks/data-meta.js
Original file line number Diff line number Diff line change
@@ -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,
Expand Down Expand Up @@ -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 : ''));
});
};
3 changes: 3 additions & 0 deletions tasks/data-pack.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
Expand Down

0 comments on commit f13e22b

Please sign in to comment.