-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathupdate_db.js
54 lines (47 loc) · 1.18 KB
/
update_db.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#!/usr/bin/env node
'use strict';
/*
This checks every icon file in icons/res against
the metadata and prints out all necessary JSON
if new icons are found.
*/
var mime = require('mime')
, sizeOf = require('image-size')
, filewalker = require('filewalker')
, icons = require('./icons/icons.json')
, urls = require('./icons/urls.json');
var parseIconFile = function(p) {
var fp = 'icons/res/' + p;
var fname = p.split(".");
var meta = {}
fname.pop();
fname = fname.join(".");
fname = fname.split("-")[0];
if (fname in icons) return false; // return early
try {
var d = sizeOf(fp);
}
catch(e) {
console.log(e);
console.log(fp)
}
return {
"canonical_url": fname,
"content_type": mime.lookup(fp),
"path": fp,
"w": d.width,
"h": d.height
}
}
var newMetadata = {}
filewalker('./icons/res')
.on('file', function(p, s) {
// console.log('file: %s, %d bytes', p, s.size);
var metadata = parseIconFile(p);
if (metadata) newMetadata[metadata.canonical_url] = metadata;
})
.on('done', function() {
console.log('done parsing %d icon files.', this.files);
console.log(JSON.stringify(newMetadata, null, 2))
})
.walk();