-
Notifications
You must be signed in to change notification settings - Fork 0
/
createDocs.js
90 lines (81 loc) · 2.08 KB
/
createDocs.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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
var paths = require('./config').iconSets
var promisify = require('util').promisify
var { basename } = require('path')
var glob = promisify(require('glob'))
var { findIndex } = require('underscore')
var { writeFileSync } = require('fs')
var jsonminify = require('jsonminify')
var promises = []
for (let path in paths) {
promises.push(glob(paths[path]))
}
function generateObject (folderPaths) {
var icons = [
{
name: 'Font awesome',
url: 'http://typicons.com/',
folder: 'fa',
set: []
},
{
name: 'Material Design icons',
url: 'https://materialdesignicons.com/',
folder: 'mdi',
set: []
},
{
name: 'Ionicons',
url: 'http://ionicons.com/',
folder: 'ion',
set: []
},
{
name: 'Typicons',
url: 'http://typicons.com/',
folder: 'ti',
set: []
},
{
name: 'Octicons',
url: 'http://typicons.com/',
folder: 'oct',
set: []
}
] //
return new Promise(function (resolve, reject) {
for (let folder of folderPaths) {
for (let file of folder) {
var originalName = basename(file, '.svg')
var iconSetName = file.split('/')[3]
var fileIndex = findIndex(icons, { folder: iconSetName })
if (fileIndex < 0) {
reject(new Error(`Iconset not found "${iconSetName}"`))
}
var tags = originalName.split('-').join(',')
console.log(tags)
icons[fileIndex].set.push({
name: iconSetName + '-' + originalName,
tags: tags
})
} //
}
for (let iconSet of icons) {
writeFileSync(
`./static/data/${iconSet.folder}.json`,
jsonminify(JSON.stringify(iconSet))
)
}
writeFileSync(`./static/data/all.json`, jsonminify(JSON.stringify(icons)))
resolve(icons)
})
} //
Promise.all(promises)
.then(folderPaths => {
generateObject(folderPaths).then(icons => {
var fileContent = `export default ${JSON.stringify(icons)}`
writeFileSync('./docs/icons.js', fileContent)
})
})
.catch(err => {
console.log(err)
})