Skip to content

Commit 35183a6

Browse files
committed
Update build script
1 parent e0f27bc commit 35183a6

File tree

4 files changed

+61
-32
lines changed

4 files changed

+61
-32
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
.DS_Store
22
*.log
33
node_modules/
4+
archive.zip
45
iso-639-3.js
56
iso-639-3.min.js
67
yarn.lock

build.js

+55-27
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,19 @@ var fs = require('fs')
44
var path = require('path')
55
var https = require('https')
66
var concat = require('concat-stream')
7-
var unzip = require('unzip')
7+
var yauzl = require('yauzl')
88
var dsv = require('d3-dsv')
99
var bail = require('bail')
1010

11-
var found
11+
var found = false
1212

13-
var SCOPES = {
13+
var scopes = {
1414
I: 'individual',
1515
M: 'macrolanguage',
1616
S: 'special'
1717
}
1818

19-
var TYPES = {
19+
var types = {
2020
A: 'ancient',
2121
C: 'constructed',
2222
E: 'extinct',
@@ -25,31 +25,60 @@ var TYPES = {
2525
S: 'special'
2626
}
2727

28+
// Note:
29+
// You can find download links here:
30+
// <https://iso639-3.sil.org/code_tables/download_tables>
31+
// Just get the complete code tables in UTF-8.
32+
2833
https
2934
.request(
30-
'https://iso639-3.sil.org/sites/iso639-3/files/downloads/iso-639-3_Code_Tables_20180123.zip',
35+
'https://iso639-3.sil.org/sites/iso639-3/files/downloads/iso-639-3_Code_Tables_20190408.zip',
3136
onrequest
3237
)
3338
.end()
3439

35-
process.on('exit', onexit)
36-
37-
function onexit() {
38-
if (!found) {
39-
throw new Error('Could not find expected file')
40-
}
40+
function onrequest(res) {
41+
res
42+
.pipe(fs.createWriteStream('archive.zip'))
43+
.on('close', onclose)
44+
.on('error', bail)
4145
}
4246

43-
function onrequest(response) {
44-
response.pipe(new unzip.Parse()).on('entry', onentry)
47+
function onclose() {
48+
yauzl.open('archive.zip', {lazyEntries: true}, onopen)
4549
}
4650

47-
function onentry(entry) {
48-
if (path.basename(entry.path) === 'iso-639-3_20180123.tab') {
51+
function onopen(err, archive) {
52+
bail(err)
53+
54+
read()
55+
56+
archive.on('entry', onentry)
57+
archive.on('end', onend)
58+
59+
function onentry(entry) {
60+
if (path.basename(entry.fileName) !== 'iso-639-3_20190408.tab') {
61+
return read()
62+
}
63+
4964
found = true
50-
entry.pipe(concat(onconcat))
51-
} else {
52-
entry.autodrain()
65+
archive.openReadStream(entry, onreadstream)
66+
}
67+
68+
function onreadstream(err, rs) {
69+
bail(err)
70+
rs.pipe(concat(onconcat)).on('error', bail)
71+
rs.on('end', read)
72+
}
73+
74+
function read() {
75+
archive.readEntry()
76+
}
77+
}
78+
79+
function onend() {
80+
if (!found) {
81+
throw new Error('File not found')
5382
}
5483
}
5584

@@ -59,15 +88,14 @@ function onconcat(body) {
5988
fs.writeFile('index.json', JSON.stringify(data, 0, 2) + '\n', bail)
6089
}
6190

62-
function mapper(language) {
91+
function mapper(d) {
6392
return {
64-
name: language.Ref_Name || null,
65-
type: TYPES[language.Language_Type],
66-
scope: SCOPES[language.Scope],
67-
iso6393: language['Id'], // There’s a `<U+FEFF>`
68-
// in there, I don’t know why, but meh.
69-
iso6392B: language.Part2B || null,
70-
iso6392T: language.Part2T || null,
71-
iso6391: language.Part1 || null
93+
name: d.Ref_Name || null,
94+
type: types[d.d_Type],
95+
scope: scopes[d.Scope],
96+
iso6393: d.Id,
97+
iso6392B: d.Part2B || null,
98+
iso6392T: d.Part2T || null,
99+
iso6391: d.Part1 || null
72100
}
73101
}

package.json

+4-4
Original file line numberDiff line numberDiff line change
@@ -34,14 +34,14 @@
3434
"remark-preset-wooorm": "^4.0.0",
3535
"tape": "^4.4.0",
3636
"tinyify": "^2.5.0",
37-
"unzip": "^0.1.11",
38-
"xo": "^0.24.0"
37+
"xo": "^0.24.0",
38+
"yauzl": "^2.10.0"
3939
},
4040
"scripts": {
4141
"generate": "node build",
4242
"format": "remark . -qfo && prettier --write \"**/*.js\" && xo --fix",
43-
"build-bundle": "browserify . -s iso6393 -o iso-639-3.js",
44-
"build-mangle": "browserify . -s iso6393 -p tinyify -o iso-639-3.min.js",
43+
"build-bundle": "browserify index.json -s iso6393 -o iso-639-3.js",
44+
"build-mangle": "browserify index.json -s iso6393 -p tinyify -o iso-639-3.min.js",
4545
"build": "npm run build-bundle && npm run build-mangle",
4646
"test-api": "node test",
4747
"test": "npm run format && npm run build && npm run test-api"

readme.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ Normal, single language (example: `eng` for `English`).
168168

169169
[author]: https://wooorm.com
170170

171-
[iso]: http://www-01.sil.org/iso639-3
171+
[iso]: https://iso639-3.sil.org
172172

173173
[type]: #type
174174

0 commit comments

Comments
 (0)