update icons

This commit is contained in:
codecalm 2024-02-17 20:26:51 +01:00
parent 8391b90880
commit ad4f8659b0
6 changed files with 81 additions and 64 deletions

View File

@ -507,3 +507,25 @@ export const convertIconsToImages = async (dir, extension, size = 240) => {
})
})
}
export const getMaxUnicode = () => {
const files = globSync(path.join(ICONS_SRC_DIR, '**/*.svg'))
let maxUnicode = 0
files.forEach(function (file) {
const svgFile = fs.readFileSync(file).toString()
svgFile.replace(/unicode: "([a-f0-9.]+)"/i, function (m, unicode) {
const newUnicode = parseInt(unicode, 16)
if (newUnicode) {
maxUnicode = Math.max(maxUnicode, newUnicode)
}
})
})
console.log(`Max unicode: ${maxUnicode}`)
return maxUnicode
}

View File

@ -1,47 +0,0 @@
import { globSync, glob } from 'glob'
import fs from 'fs'
import path from 'path'
import { ICONS_SRC_DIR } from './helpers.mjs'
const getMaxUnicode = () => {
const files = globSync(path.join(ICONS_SRC_DIR, '**/*.svg'))
let maxUnicode = 0
files.forEach(function(file) {
const svgFile = fs.readFileSync(file).toString()
svgFile.replace(/unicode: "([a-f0-9.]+)"/i, function(m, unicode) {
const newUnicode = parseInt(unicode, 16)
if (newUnicode) {
maxUnicode = Math.max(maxUnicode, newUnicode)
}
})
})
return maxUnicode
}
let maxUnicode = getMaxUnicode()
console.log(`Max unicode: ${maxUnicode}`)
const files = globSync(path.join(ICONS_SRC_DIR, '**/*.svg'))
files.forEach(function(file) {
let svgFile = fs.readFileSync(file).toString()
if (!svgFile.match(/\nunicode: "?([a-f0-9.]+)"?/i)) {
maxUnicode++
const unicode = maxUnicode.toString(16)
if (unicode) {
svgFile = svgFile.replace(/-->\n<svg/i, function(m) {
return `unicode: "${unicode}"\n${m}`
})
console.log(`Add unicode "${unicode}" to "${file}"`)
fs.writeFileSync(file, svgFile, 'utf8')
}
}
})

View File

@ -5,9 +5,7 @@ import { getArgvs, getPackageJson, ICONS_SRC_DIR } from './helpers.mjs'
const p = getPackageJson()
const argv = getArgvs(),
version = argv['latest-version'] || `${p.version}`,
newVersion = argv['new-version'] || `${p.version}`
const setVersions = function(version, files) {
for (const i in files) {
@ -18,7 +16,7 @@ const setVersions = function(version, files) {
let svgFile = fs.readFileSync(filePath).toString()
if (!svgFile.match(/version: ([0-9.]+)/i)) {
svgFile = svgFile.replace(/---\n<svg>/i, function(m) {
svgFile = svgFile.replace(/-->\n<svg/i, function(m) {
return `version: "${version}"\n${m}`
})
@ -26,7 +24,6 @@ const setVersions = function(version, files) {
} else {
console.log(`File ${file} already has version`)
}
} else {
console.log(`File ${file} doesn't exists`)
}
@ -34,7 +31,7 @@ const setVersions = function(version, files) {
}
if (version) {
cp.exec(`grep -RiL "version: " ${ICONS_SRC_DIR}/*.svg`, function(err, ret) {
cp.exec(`grep -RiL "version: " ${ICONS_SRC_DIR}/**/*.svg`, function(err, ret) {
let newIcons = []
ret.replace(/src\/_icons\/([a-z0-9-]+)\.svg/g, function(m, fileName) {

46
.build/update-icons.mjs Normal file
View File

@ -0,0 +1,46 @@
import { globSync, glob } from 'glob'
import fs from 'fs'
import path from 'path'
import { ICONS_SRC_DIR, getMaxUnicode, getArgvs, getPackageJson } from './helpers.mjs'
const p = getPackageJson(),
argv = getArgvs(),
lastVersion = argv['latest-version'] || `${p.version}`,
newVersion = argv['new-version']
console.log(argv);
const files = globSync(path.join(ICONS_SRC_DIR, '**/*.svg'))
let maxUnicode = getMaxUnicode()
files.forEach(function (file) {
let svgFile = fs.readFileSync(file).toString()
// Add unicode to svg files
if (!svgFile.match(/\nunicode: "?([a-f0-9.]+)"?/i)) {
maxUnicode++
const unicode = maxUnicode.toString(16)
if (unicode) {
svgFile = svgFile.replace(/-->\n<svg/i, function (m) {
return `unicode: "${unicode}"\n${m}`
})
console.log(`Add unicode "${unicode}" to "${file}"`)
fs.writeFileSync(file, svgFile, 'utf8')
}
}
if (newVersion) {
// Add version to svg files
if (!svgFile.match(/\nversion: "?([a-f0-9.]+)"?/i)) {
svgFile = svgFile.replace(/-->\n<svg/i, function (m) {
return `version: "${newVersion}"\n${m}`
})
console.log(`Add version "${newVersion}" to "${file}"`)
fs.writeFileSync(file, svgFile, 'utf8')
}
}
})

16
.vscode/settings.json vendored
View File

@ -1,12 +1,12 @@
{
"files.exclude": {
"**/.git": true,
"**/.svn": true,
"**/.hg": true,
"**/CVS": true,
"**/.DS_Store": true,
"**/Thumbs.db": true,
"**/.idea/": true
},
"**/.git": true,
"**/.svn": true,
"**/.hg": true,
"**/CVS": true,
"**/.DS_Store": true,
"**/Thumbs.db": true,
"**/.idea/": true
},
"explorerExclude.backup": {}
}

View File

@ -19,9 +19,8 @@
"changelog": "node ./.build/changelog.mjs",
"changelog-commit": "git add . && node ./.build/changelog-commit.mjs",
"changelog-image": "node ./.build/changelog-image.mjs",
"update": "pnpm run update:icons-version && pnpm run update:icons-unicode && pnpm run check-unicodes",
"update:icons-version": "node ./.build/update-icons-version.mjs",
"update:icons-unicode": "node ./.build/update-icons-unicode.mjs",
"update": "pnpm run update:icons",
"update:icons": "node ./.build/update-icons.mjs",
"optimize": "node ./.build/optimize.mjs",
"import": "node ./.build/import.mjs && pnpm run optimize",
"import-tags": "node ./.build/import-tags.mjs",