1
0
mirror of https://github.com/coreui/coreui-icons.git synced 2025-08-18 06:21:17 +02:00

feat: add symbols definitions

This commit is contained in:
mrholek
2019-11-10 15:48:48 +01:00
parent 6af9b02abd
commit ecf009a7f4
4 changed files with 4639 additions and 0 deletions

46
build/build-defs.js Normal file
View File

@@ -0,0 +1,46 @@
const fs = require('fs')
const dirnames = process.mainModule.filename.includes('pro') ?
['solid', 'linear']
: ['free', 'brand', 'flag']
const prefixes = {
brand: 'cib-',
flag: 'cif-',
free: 'cil-',
linear: 'cil-',
solid: 'cis-'
}
const getAttributeValue = (string, attribute) => {
const regex = new RegExp(`${attribute}="([^"]+)"`, 'g')
return string.match(regex, '')[0]
.match(/"(.*?)"/ig, '')[0]
.replace(/"/g, '')
}
// let allNames = {}
dirnames.forEach(setName => {
const dirname = `svg/${setName}/`
const svgs = fs.readdirSync(dirname)
let symbols = []
svgs.forEach((svg, idx, svgs) => {
let symbol = {}
const file = dirname + svg
const content = fs.readFileSync(file, 'utf8')
const viewBox = getAttributeValue(content, 'viewBox')
const computedContent = content.replace(/(<svg([^>]+)>)|(<\/svg>)/ig, '')
.replace(/\n/g, '').replace(/"/g, '\'')
.replace('<!-- Generated by IcoMoon.io -->', '')
symbol = `<symbol id="${prefixes[setName]}${svg.replace('.svg', '').toLowerCase()}" viewBox="${viewBox}">\n${computedContent}\n</symbol>`
idx === svgs.length - 1 ? symbols.push(symbol) : symbols.push(`${symbol}\n`)
})
fs.writeFile(
`symbols/${setName}-defs.svg`,
`<svg aria-hidden="true" style="position: absolute; width: 0; height: 0; overflow: hidden;" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
<defs>
${symbols.join('')}
</defs>
</svg>`,
() => ''
)
})

2491
symbols/brand-defs.svg Normal file

File diff suppressed because one or more lines are too long

After

Width:  |  Height:  |  Size: 1.4 MiB

592
symbols/flag-defs.svg Normal file

File diff suppressed because one or more lines are too long

After

Width:  |  Height:  |  Size: 3.3 MiB

1510
symbols/free-defs.svg Normal file

File diff suppressed because it is too large Load Diff

After

Width:  |  Height:  |  Size: 248 KiB