Skip to content

Commit 74f3398

Browse files
committed
feat: Support MDI v5 icon set from @quasar/extras (#55)
1 parent 168c8f7 commit 74f3398

File tree

5 files changed

+5150
-2
lines changed

5 files changed

+5150
-2
lines changed

ui/build/icons/build.all.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
require('./build.mdi.js')
1+
require('./build.mdi-v4.js')
2+
require('./build.mdi-v5.js')
23
require('./build.ion.js')
34
require('./build.eva.js')
45
require('./build.fontawesome.js')
File renamed without changes.

ui/build/icons/build.mdi-v5.js

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
const path = require('path')
2+
const { green, blue } = require('chalk')
3+
const { readFile, writeFile } = require('../utils')
4+
5+
const name = 'mdi-v5'
6+
const inputLocation = `../../src/components/icon-set/${name}.js`
7+
const outputLocation = `../../src/components/icon-set/${name}.js`
8+
let oldIcons = {}
9+
let icons = []
10+
let blacklisted = [
11+
'md',
12+
'mdi-blank',
13+
'mdi-18px.mdi-set, .mdi-18px.md',
14+
'mdi-24px.mdi-set, .mdi-24px.md',
15+
'mdi-36px.mdi-set, .mdi-36px.md',
16+
'mdi-48px.mdi-set, .mdi-48px.md',
17+
'mdi-dar',
18+
'mdi-dark.mdi-inactiv',
19+
'mdi-ligh',
20+
'mdi-light.mdi-inactiv',
21+
'mdi-rotate-4',
22+
'mdi-rotate-9',
23+
'mdi-rotate-13',
24+
'mdi-rotate-18',
25+
'mdi-rotate-22',
26+
'mdi-rotate-27',
27+
'mdi-rotate-31',
28+
'mdi-flip-',
29+
'mdi-spi'
30+
]
31+
32+
let fa = readFile(path.resolve(__dirname, inputLocation))
33+
fa = fa.split('\n')
34+
fa.shift()
35+
fa.shift()
36+
fa.shift()
37+
fa.pop()
38+
fa.pop()
39+
fa.pop()
40+
fa = '[\n' + fa.join(',\n') + '\n]\n'
41+
// eslint-disable-next-line no-eval
42+
fa = eval(fa)
43+
fa.forEach(f => {
44+
const name = f.name
45+
const tags = f.tags
46+
oldIcons[name] = { tags: Array(tags).join(',') }
47+
})
48+
49+
const location = require.resolve('@quasar/extras/mdi-v5/mdi-v5.css')
50+
const fileContents = readFile(location)
51+
52+
fileContents
53+
.split('\n')
54+
.forEach(line => {
55+
line = line.trim()
56+
if (line.startsWith('.')) {
57+
const pos = line.indexOf(':before')
58+
if (pos > 0) {
59+
line = line.slice(1, pos - 1)
60+
if (blacklisted.includes(line) === false) {
61+
if (oldIcons[line]) {
62+
const tags = oldIcons[line].tags.split(',').map(tag => {
63+
if (tag === '') return tag
64+
return "'" + tag + "'"
65+
}).join(', ')
66+
icons.push(`{ name: '${line}', tags: [${tags}] }`)
67+
} else {
68+
icons.push(`{ name: '${line}', tags: [] }`)
69+
}
70+
}
71+
}
72+
}
73+
})
74+
75+
if (icons.length === 0) {
76+
console.log(`${red('[error]')} MDI icons parsed 0 icons...exiting`)
77+
process.exit(1)
78+
}
79+
80+
let output = 'export default {\n'
81+
output += ` name: '${name}',\n`
82+
output += ' icons: [\n'
83+
84+
icons.forEach((icon, index) => {
85+
if (index !== 0) {
86+
output += ',\n'
87+
}
88+
89+
output += ` ${icon}`
90+
})
91+
92+
output += '\n ]\n'
93+
output += '}\n'
94+
95+
writeFile(path.resolve(__dirname, outputLocation), output)
96+
console.log(`${blue('[icon]')} ${green(name + ':')} ${icons.length} generated`)

ui/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@
1818
"build": "node build/index.js",
1919
"build:js": "node build/script.javascript.js",
2020
"build:css": "node build/script.css.js",
21-
"icons:mdi": "node build/icons/build.mdi.js",
21+
"icons:mdi-v4": "node build/icons/build.mdi-v4.js",
22+
"icons:mdi-v5": "node build/icons/build.mdi-v5.js",
2223
"icons:ion": "node build/icons/build.ion.js",
2324
"icons:eva": "node build/icons/build.eva.js",
2425
"icons:fontawesome": "node build/icons/build.fontawesome.js",

0 commit comments

Comments
 (0)