|
| 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`) |
0 commit comments