Skip to content

Commit f13e22b

Browse files
committed
data: automatically create data/*/VERSION.json for latest
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.
1 parent e551fde commit f13e22b

File tree

3 files changed

+29
-12
lines changed

3 files changed

+29
-12
lines changed

tasks/data-dedupe.js

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,6 @@ function dedupe(zone) {
2626
};
2727
}
2828

29-
function findVersion (source) {
30-
var matches = source.match(/\nRelease (\d{4}[a-z]) /);
31-
32-
if (matches && matches[1]) {
33-
return matches[1];
34-
}
35-
throw new Error("Could not find version from temp/download/latest/NEWS.");
36-
}
37-
3829
function addCountries(countries) {
3930
var result = [];
4031

@@ -55,14 +46,16 @@ module.exports = function (grunt) {
5546
var zones = grunt.file.readJSON('temp/collect/' + version + '.json'),
5647
meta = grunt.file.readJSON('data/meta/' + version + '.json'),
5748
output = {
58-
version : version === 'latest' ?
59-
findVersion(grunt.file.read('temp/download/latest/NEWS')) : version,
49+
version : meta.version,
6050
zones : zones.map(dedupe),
6151
links : [],
6252
countries : addCountries(meta.countries)
6353
};
6454

6555
grunt.file.write('data/unpacked/' + version + '.json', JSON.stringify(output, null, 2));
56+
if (version === 'latest') {
57+
grunt.file.copy('data/unpacked/' + version + '.json', 'data/unpacked/' + output.version + '.json');
58+
}
6659

6760
grunt.log.ok('Deduped data for ' + version);
6861
});

tasks/data-meta.js

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,22 @@
11
"use strict";
22

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+
320
function parseLatLong (input, isLong) {
421
var sign = input[0] === '+' ? 1 : -1,
522
deg = ~~input.substr(1, 2 + isLong) * sign,
@@ -127,12 +144,16 @@ module.exports = function (grunt) {
127144
var validCountries = filterCountries(countries);
128145

129146
var output = {
147+
version: parseVersion(grunt, version),
130148
countries: validCountries,
131149
zones: zones
132150
};
133151

134152
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+
}
135156

136-
grunt.log.ok('Added metadata for ' + version);
157+
grunt.log.ok('Added metadata for ' + version + (version === 'latest' ? ': ' + output.version : ''));
137158
});
138159
};

tasks/data-pack.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@ module.exports = function (grunt) {
1919
});
2020

2121
grunt.file.write('data/packed/' + version + '.json', JSON.stringify(output, null, '\t'));
22+
if (version === 'latest') {
23+
grunt.file.copy('data/packed/latest.json', 'data/packed/' + unpacked.version + '.json');
24+
}
2225

2326
grunt.log.ok('Packed data for ' + version);
2427
});

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy