summaryrefslogtreecommitdiffstats
path: root/build/build-svgs.js
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2022-07-22 19:27:36 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2022-07-23 08:52:25 +0000
commit78edec0e2d8a3e1216d99234554276cb05505ac4 (patch)
tree6f1a3cfda8731ef3a19f5ae57c928054a0c5624f /build/build-svgs.js
parentInitial commit. (diff)
downloadbootstrap-icons-78edec0e2d8a3e1216d99234554276cb05505ac4.tar.xz
bootstrap-icons-78edec0e2d8a3e1216d99234554276cb05505ac4.zip
Adding upstream version 1.9.1+dfsg.upstream/1.9.1+dfsg
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'build/build-svgs.js')
-rw-r--r--build/build-svgs.js55
1 files changed, 55 insertions, 0 deletions
diff --git a/build/build-svgs.js b/build/build-svgs.js
new file mode 100644
index 0000000..c889ce5
--- /dev/null
+++ b/build/build-svgs.js
@@ -0,0 +1,55 @@
+#!/usr/bin/env node
+
+'use strict'
+
+const fs = require('fs').promises
+const path = require('path')
+const process = require('process')
+const picocolors = require('picocolors')
+const { loadConfig, optimize } = require('svgo')
+
+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.js'))
+
+ 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)
+ }
+})()