diff options
Diffstat (limited to 'build')
-rwxr-xr-x | build/generate-images.js | 57 |
1 files changed, 18 insertions, 39 deletions
diff --git a/build/generate-images.js b/build/generate-images.js index 9bd40641e4..c9108ce713 100755 --- a/build/generate-images.js +++ b/build/generate-images.js @@ -2,10 +2,10 @@ 'use strict'; const imageminZopfli = require('imagemin-zopfli'); +const Svgo = require('svgo'); const {fabric} = require('fabric'); const {readFile, writeFile} = require('fs').promises; const {resolve} = require('path'); -const Svgo = require('svgo'); const logoFile = resolve(__dirname, '../assets/logo.svg'); @@ -22,32 +22,20 @@ function loadSvg(svg) { }); } -async function generateSvgFavicon(svg, outputFile) { - const svgo = new Svgo({ - plugins: [ - {removeDimensions: true}, - { - addAttributesToSVGElement: { - attributes: [ - {'width': '32'}, - {'height': '32'}, - ], - }, - }, - ], - }); - - const {data} = await svgo.optimize(svg); - await writeFile(outputFile, data); -} +async function generate(svg, outputFile, {size, bg}) { + if (outputFile.endsWith('.svg')) { + const svgo = new Svgo({ + plugins: [ + {removeDimensions: true}, + {addAttributesToSVGElement: {attributes: [{width: size}, {height: size}]}}, + ], + }); -async function generateSvg(svg, outputFile) { - const svgo = new Svgo(); - const {data} = await svgo.optimize(svg); - await writeFile(outputFile, data); -} + const {data} = await svgo.optimize(svg); + await writeFile(outputFile, data); + return; + } -async function generate(svg, outputFile, {size, bg}) { const {objects, options} = await loadSvg(svg); const canvas = new fabric.Canvas(); canvas.setDimensions({width: size, height: size}); @@ -78,25 +66,16 @@ async function generate(svg, outputFile, {size, bg}) { async function main() { const gitea = process.argv.slice(2).includes('gitea'); - const svg = await readFile(logoFile, 'utf8'); + await Promise.all([ - generateSvgFavicon(svg, resolve(__dirname, '../public/img/favicon.svg')), - generateSvg(svg, resolve(__dirname, '../public/img/logo.svg')), - generate(svg, resolve(__dirname, '../public/img/logo-lg.png'), {size: 880}), - generate(svg, resolve(__dirname, '../public/img/logo-512.png'), {size: 512}), - generate(svg, resolve(__dirname, '../public/img/logo-192.png'), {size: 192}), - generate(svg, resolve(__dirname, '../public/img/logo-sm.png'), {size: 120}), - generate(svg, resolve(__dirname, '../public/img/avatar_default.png'), {size: 200}), + generate(svg, resolve(__dirname, '../public/img/logo.svg'), {size: 32}), + generate(svg, resolve(__dirname, '../public/img/logo.png'), {size: 512}), generate(svg, resolve(__dirname, '../public/img/favicon.png'), {size: 180}), + generate(svg, resolve(__dirname, '../public/img/avatar_default.png'), {size: 200}), generate(svg, resolve(__dirname, '../public/img/apple-touch-icon.png'), {size: 180, bg: true}), + gitea && generate(svg, resolve(__dirname, '../public/img/gitea.svg'), {size: 32}), ]); - if (gitea) { - await Promise.all([ - generateSvg(svg, resolve(__dirname, '../public/img/gitea.svg')), - generate(svg, resolve(__dirname, '../public/img/gitea-192.png'), {size: 192}), - ]); - } } main().then(exit).catch(exit); |