summaryrefslogtreecommitdiffstats
path: root/build/build-svgs.mjs
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2023-05-03 09:10:03 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2023-05-03 09:10:03 +0000
commit9aeff034f5cdf4e22090904bf9dfecf439b34658 (patch)
tree7ed7a2f5bc0291104a79f90f547c4b250e50c21b /build/build-svgs.mjs
parentReleasing debian version 1.10.4+dfsg-1. (diff)
downloadbootstrap-icons-9aeff034f5cdf4e22090904bf9dfecf439b34658.tar.xz
bootstrap-icons-9aeff034f5cdf4e22090904bf9dfecf439b34658.zip
Merging upstream version 1.10.5+dfsg.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'build/build-svgs.mjs')
-rw-r--r--build/build-svgs.mjs57
1 files changed, 57 insertions, 0 deletions
diff --git a/build/build-svgs.mjs b/build/build-svgs.mjs
new file mode 100644
index 0000000..2927156
--- /dev/null
+++ b/build/build-svgs.mjs
@@ -0,0 +1,57 @@
+#!/usr/bin/env node
+
+import fs from 'node:fs/promises'
+import path from 'node:path'
+import process from 'node:process'
+import { fileURLToPath } from 'node:url'
+import picocolors from 'picocolors'
+import { loadConfig, optimize } from 'svgo'
+
+const __filename = fileURLToPath(import.meta.url)
+const __dirname = path.dirname(fileURLToPath(import.meta.url))
+
+const iconsDir = path.join(__dirname, '../icons/')
+
+const VERBOSE = process.argv.includes('--verbose')
+
+async function processFile(file, config) {
+ const filepath = path.join(iconsDir, file)
+ const basename = path.basename(file, '.svg')
+
+ const originalSvg = await fs.readFile(filepath, 'utf8')
+ const { data: optimizedSvg } = await optimize(originalSvg, { path: filepath, ...config })
+
+ // svgo will always add a final newline when in pretty mode
+ const resultSvg = optimizedSvg.trim()
+
+ if (resultSvg !== originalSvg) {
+ await fs.writeFile(filepath, resultSvg, 'utf8')
+ }
+
+ if (VERBOSE) {
+ console.log(`- ${basename}`)
+ }
+}
+
+(async () => {
+ try {
+ const basename = path.basename(__filename)
+ const timeLabel = picocolors.cyan(`[${basename}] finished`)
+
+ console.log(picocolors.cyan(`[${basename}] started`))
+ console.time(timeLabel)
+
+ const files = await fs.readdir(iconsDir)
+ const config = await loadConfig(path.join(__dirname, '../svgo.config.mjs'))
+
+ await Promise.all(files.map(file => processFile(file, config)))
+
+ const filesLength = files.length
+
+ console.log(picocolors.green('\nSuccess, prepared %s icon%s!'), filesLength, filesLength === 1 ? '' : 's')
+ console.timeEnd(timeLabel)
+ } catch (error) {
+ console.error(error)
+ process.exit(1)
+ }
+})()