Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 83d7728

Browse files
committed
build: store in same format in src/
1 parent 1d4aaeb commit 83d7728

File tree

6 files changed

+12493
-10
lines changed

6 files changed

+12493
-10
lines changed

scripts/build.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,20 +12,20 @@ Object.keys(mime).forEach(function (type) {
1212
// add the mime extensions from Apache
1313
var mime = require('../src/mime.json')
1414
Object.keys(mime).forEach(function (type) {
15-
var e = mime[type]
15+
var d = mime[type]
1616
var t = type.toLowerCase()
1717
var o = db[t] = db[t] || {source: 'apache'}
18-
if (e.length) o.extensions = (o.extensions || []).concat(e)
18+
if (d.extensions && d.extensions.length) o.extensions = (o.extensions || []).concat(d.extensions)
1919
})
2020

2121
// add all of node mime's mime extensions
2222
// though i think we should just put this in `types.json`
2323
var mime = require('../src/node.json')
2424
Object.keys(mime).forEach(function (type) {
25-
var e = mime[type]
25+
var d = mime[type]
2626
var t = type.toLowerCase()
2727
var o = db[t] = db[t] || {}
28-
if (e.length) o.extensions = (o.extensions || []).concat(e)
28+
if (d.extensions && d.extensions.length) o.extensions = (o.extensions || []).concat(d.extensions)
2929
})
3030

3131
// now add all our custom extensions

scripts/extensions.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ var co = require('co')
77
var fs = require('fs')
88
var path = require('path')
99
var cogent = require('cogent')
10+
var writedb = require('./lib/write-db')
1011

1112
co(function* () {
1213
yield [
@@ -47,9 +48,11 @@ function* get(url) {
4748
var mime = match[1]
4849
if (mime.substr(-8) === '/example') return
4950
// remove the leading # and <type> and return all the <ext>s
50-
json[mime] = line.replace(/^(?:# )?([\w-]+\/[\w\+\.-]+)/, '')
51+
var extensions = line.replace(/^(?:# )?([\w-]+\/[\w\+\.-]+)/, '')
5152
.split(/\s+/)
5253
.filter(Boolean)
54+
var o = json[mime] = {}
55+
if (extensions.length) o.extensions = extensions
5356
})
54-
fs.writeFileSync('src/' + path.basename(url).split('.')[0] + '.json', JSON.stringify(json))
57+
writedb('src/' + path.basename(url).split('.')[0] + '.json', json)
5558
}

scripts/types.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ var getRawBody = require('raw-body')
99
var cogent = require('cogent')
1010
var parser = require('csv-parse')
1111
var toArray = require('stream-to-array')
12+
var writedb = require('./lib/write-db')
1213

1314
var leadingSpacesRegExp = /^\s+/
1415
var listColonRegExp = /:(?:\s|$)/m
@@ -53,7 +54,7 @@ co(function* () {
5354
json[mime] = result
5455
})
5556

56-
fs.writeFileSync('src/iana.json', JSON.stringify(json))
57+
writedb('src/iana.json', json)
5758
})()
5859

5960
function addTemplateData(data) {

src/iana.json

Lines changed: 8532 additions & 1 deletion
Large diffs are not rendered by default.

src/mime.json

Lines changed: 3891 additions & 1 deletion
Large diffs are not rendered by default.

src/node.json

Lines changed: 59 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,59 @@
1-
{"text/vtt":["vtt"],"application/x-chrome-extension":["crx"],"text/x-component":["htc"],"text/cache-manifest":["manifest"],"application/octet-stream":["buffer"],"application/mp4":["m4p"],"audio/mp4":["m4a"],"video/MP2T":["ts"],"application/x-web-app-manifest+json":["webapp"],"text/x-lua":["lua"],"application/x-lua-bytecode":["luac"],"text/x-markdown":["markdown","md","mkd"],"text/plain":["ini"],"application/dash+xml":["mdp"],"font/opentype":["otf"],"application/json":["map"],"application/xml":["xsd"],"application/font-woff2":["woff2"],"text/yaml":["yaml","yml"]}
1+
{
2+
"application/dash+xml": {
3+
"extensions": ["mdp"]
4+
},
5+
"application/font-woff2": {
6+
"extensions": ["woff2"]
7+
},
8+
"application/json": {
9+
"extensions": ["map"]
10+
},
11+
"application/mp4": {
12+
"extensions": ["m4p"]
13+
},
14+
"application/octet-stream": {
15+
"extensions": ["buffer"]
16+
},
17+
"application/x-chrome-extension": {
18+
"extensions": ["crx"]
19+
},
20+
"application/x-lua-bytecode": {
21+
"extensions": ["luac"]
22+
},
23+
"application/x-web-app-manifest+json": {
24+
"extensions": ["webapp"]
25+
},
26+
"application/xml": {
27+
"extensions": ["xsd"]
28+
},
29+
"audio/mp4": {
30+
"extensions": ["m4a"]
31+
},
32+
"font/opentype": {
33+
"extensions": ["otf"]
34+
},
35+
"text/cache-manifest": {
36+
"extensions": ["manifest"]
37+
},
38+
"text/plain": {
39+
"extensions": ["ini"]
40+
},
41+
"text/vtt": {
42+
"extensions": ["vtt"]
43+
},
44+
"text/x-component": {
45+
"extensions": ["htc"]
46+
},
47+
"text/x-lua": {
48+
"extensions": ["lua"]
49+
},
50+
"text/x-markdown": {
51+
"extensions": ["markdown","md","mkd"]
52+
},
53+
"text/yaml": {
54+
"extensions": ["yaml","yml"]
55+
},
56+
"video/MP2T": {
57+
"extensions": ["ts"]
58+
}
59+
}

0 commit comments

Comments
 (0)