2021-04-16 18:07:11 +03:00
|
|
|
#!/usr/bin/env node
|
|
|
|
|
|
|
|
'use strict'
|
|
|
|
|
|
|
|
// Usage:
|
|
|
|
// yarn add -D @iconify/json-tools @iconify/json
|
|
|
|
// node bundle_icons.js
|
|
|
|
// https://iconify.design/docs/icon-bundles/
|
|
|
|
|
|
|
|
const fs = require('fs')
|
|
|
|
const path = require('path')
|
|
|
|
const { Collection } = require('@iconify/json-tools')
|
|
|
|
|
|
|
|
let icons = [
|
|
|
|
'fxemoji:key',
|
|
|
|
'fxemoji:rocket',
|
|
|
|
'fxemoji:satelliteantenna',
|
|
|
|
'fxemoji:lockandkey',
|
|
|
|
'fxemoji:clipboard',
|
|
|
|
'flat-color-icons:donate',
|
|
|
|
'flat-color-icons:clock',
|
|
|
|
'codicon:github-inverted',
|
|
|
|
'ant-design:check-square-filled',
|
|
|
|
'emojione-v1:white-heavy-check-mark',
|
|
|
|
'emojione-v1:alarm-clock',
|
|
|
|
'emojione-v1:warning',
|
|
|
|
'emojione-v1:backhand-index-pointing-right',
|
|
|
|
'twemoji:light-bulb',
|
|
|
|
'noto:play-button',
|
|
|
|
'noto:stop-button',
|
|
|
|
'noto:lock',
|
|
|
|
'twemoji:gear',
|
|
|
|
'eva:corner-right-down-fill',
|
|
|
|
'bi:heart-fill',
|
2021-10-14 13:01:06 +03:00
|
|
|
'fxemoji:running',
|
2021-12-16 00:46:02 +03:00
|
|
|
'ic:round-person',
|
|
|
|
'bx:bxs-bar-chart-alt-2',
|
|
|
|
'bi:people-fill',
|
|
|
|
'fluent:data-bar-horizontal-24-filled',
|
|
|
|
'ic:round-dashboard',
|
|
|
|
'ci:settings-filled',
|
|
|
|
'akar-icons:chevron-down',
|
|
|
|
'ls:logout',
|
|
|
|
'fluent:key-32-filled',
|
|
|
|
'majesticons:clipboard-copy',
|
|
|
|
'fa-regular:calendar-alt',
|
2021-12-16 01:59:40 +03:00
|
|
|
'ph:books-bold',
|
|
|
|
'fa-solid:external-link-alt',
|
|
|
|
'bx:bx-code-curly',
|
|
|
|
'simple-icons:wakatime',
|
|
|
|
'bx:bxs-heart',
|
|
|
|
'heroicons-solid:light-bulb',
|
|
|
|
'ion:rocket',
|
|
|
|
'heroicons-solid:server',
|
|
|
|
'eva:checkmark-circle-2-fill',
|
2022-10-06 00:36:57 +03:00
|
|
|
'fluent:key-24-filled',
|
|
|
|
'mdi:language-c',
|
|
|
|
'mdi:language-cpp',
|
|
|
|
'mdi:language-go',
|
|
|
|
'mdi:language-haskell',
|
|
|
|
'mdi:language-html5',
|
|
|
|
'mdi:language-java',
|
|
|
|
'mdi:language-javascript',
|
|
|
|
'mdi:language-kotlin',
|
|
|
|
'mdi:language-lua',
|
|
|
|
'mdi:language-php',
|
|
|
|
'mdi:language-python',
|
|
|
|
'mdi:language-r',
|
|
|
|
'mdi:language-ruby',
|
|
|
|
'mdi:language-rust',
|
|
|
|
'mdi:language-swift',
|
|
|
|
'mdi:language-typescript',
|
2021-04-16 18:07:11 +03:00
|
|
|
]
|
|
|
|
|
2021-12-19 15:04:00 +03:00
|
|
|
const output = path.normalize(path.join(__dirname, '../static/assets/js/icons.dist.js'))
|
2021-04-16 18:07:11 +03:00
|
|
|
const pretty = false
|
|
|
|
|
|
|
|
// Sort icons by collections: filtered[prefix][array of icons]
|
|
|
|
let filtered = {}
|
|
|
|
icons.forEach(icon => {
|
|
|
|
let parts = icon.split(':'),
|
|
|
|
prefix
|
|
|
|
|
|
|
|
if (parts.length > 1) {
|
|
|
|
prefix = parts.shift()
|
|
|
|
icon = parts.join(':')
|
|
|
|
} else {
|
|
|
|
parts = icon.split('-')
|
|
|
|
prefix = parts.shift()
|
|
|
|
icon = parts.join('-')
|
|
|
|
}
|
|
|
|
if (filtered[prefix] === void 0) {
|
|
|
|
filtered[prefix] = []
|
|
|
|
}
|
|
|
|
if (filtered[prefix].indexOf(icon) === -1) {
|
|
|
|
filtered[prefix].push(icon)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
// Parse each collection
|
|
|
|
let code = ''
|
|
|
|
Object.keys(filtered).forEach(prefix => {
|
|
|
|
let collection = new Collection()
|
|
|
|
if (!collection.loadIconifyCollection(prefix)) {
|
|
|
|
console.error('Error loading collection', prefix)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
code += collection.scriptify({
|
|
|
|
icons: filtered[prefix],
|
|
|
|
optimize: true,
|
|
|
|
pretty: pretty
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
// Save code
|
|
|
|
fs.writeFileSync(output, code, 'utf8')
|
|
|
|
console.log('Saved bundle to', output, ' (' + code.length + ' bytes)')
|