v / vlib / net / http / mime / build.vsh
38 lines · 31 sloc · 849 bytes · fbdc992b3029d53354c05454eb1ad25c84e4b979
Raw
1import net.http
2import json
3
4struct MimeType {
5 source string
6 extensions []string
7 compressible bool
8 charset string
9}
10
11fn main() {
12 mime_folder := dir(executable())
13 chdir(mime_folder)!
14 //
15 mt_json := http.get('https://raw.githubusercontent.com/jshttp/mime-db/master/db.json')!
16 mt_map := json.decode(map[string]MimeType, mt_json.body)!
17
18 mut ext_to_mt_str := map[string]string{}
19 for mt_str, mt in mt_map {
20 for ext in mt.extensions {
21 ext_to_mt_str[ext] = mt_str
22 }
23 }
24 ext_to_mt_str['v'] = 'text/x-vlang'
25 ext_to_mt_str['vsh'] = 'text/x-vlang'
26
27 write_file('db.v', '
28 module mime
29
30 // FILE AUTOGENERATED BY `build.vsh` - DO NOT MANUALLY EDIT
31
32 const db = ${mt_map}
33
34 const ext_to_mt_str = ${ext_to_mt_str}
35 ')!
36 execute('${@VEXE} fmt -w db.v')
37 println('db.v was regenerated. New file size: ${file_size('db.v')} bytes .')
38}
39