Skip to content

Commit

Permalink
Update build script
Browse files Browse the repository at this point in the history
  • Loading branch information
wooorm committed Apr 28, 2018
1 parent 870ca5f commit 46fa1ae
Showing 1 changed file with 16 additions and 5 deletions.
21 changes: 16 additions & 5 deletions build.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@

var fs = require('fs');
var path = require('path');
var http = require('http');
var https = require('https');
var concat = require('concat-stream');
var unzip = require('unzip');
var dsv = require('d3-dsv');
var bail = require('bail');

var found;

var SCOPES = {
I: 'individual',
M: 'macrolanguage',
Expand All @@ -23,26 +25,35 @@ var TYPES = {
S: 'special'
};

http
.request('http://www-01.sil.org/iso639-3/iso-639-3_Code_Tables_20160115.zip', onrequest)
https
.request('https://iso639-3.sil.org/sites/iso639-3/files/downloads/iso-639-3_Code_Tables_20180123.zip', onrequest)
.end();

process.on('exit', onexit);

function onexit() {
if (!found) {
throw new Error('Could not find expected file');
}
}

function onrequest(response) {
response
.pipe(new unzip.Parse())
.on('entry', onentry);
}

function onentry(entry) {
if (path.basename(entry.path) === 'iso-639-3_20160115.tab') {
if (path.basename(entry.path) === 'iso-639-3_20180123.tab') {
found = true;
entry.pipe(concat(onconcat));
} else {
entry.autodrain();
}
}

function onconcat(body) {
var data = dsv.tsvParse(body.toString()).map(function (language) {
var data = dsv.tsvParse(String(body)).map(function (language) {
return {
name: language.Ref_Name || null,
type: TYPES[language.Language_Type],
Expand Down

0 comments on commit 46fa1ae

Please sign in to comment.