Merging upstream version 1.10.5+dfsg.
Signed-off-by: Daniel Baumann <daniel@debian.org>
This commit is contained in:
parent
b34f263e6c
commit
eb7be08aac
20 changed files with 494 additions and 1175 deletions
57
build/build-svgs.mjs
Normal file
57
build/build-svgs.mjs
Normal file
|
@ -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)
|
||||
}
|
||||
})()
|
Loading…
Add table
Add a link
Reference in a new issue