From c5f37af8cd7815d3a2602b0a55c80d28667f96ea Mon Sep 17 00:00:00 2001 From: silverwind Date: Thu, 25 Apr 2024 18:30:33 +0200 Subject: [PATCH] Update generate-images dependencies and rebuild (#30689) This upgrades `generate-images.js` on v1.21 to the latest version from main branch and I ran it which generated some minor diff in the SVGs. It fixes one issue mentioned in https://github.com/go-gitea/gitea/issues/30596#issuecomment-2075483451 by removing `--no-package-lock`. --- Makefile | 2 +- build/generate-images.js | 33 +++++++++++++++------------------ public/assets/img/favicon.svg | 2 +- public/assets/img/logo.svg | 2 +- 4 files changed, 18 insertions(+), 21 deletions(-) diff --git a/Makefile b/Makefile index ece95d2ad4..8960dc7e3e 100644 --- a/Makefile +++ b/Makefile @@ -1009,7 +1009,7 @@ generate-gitignore: .PHONY: generate-images generate-images: | node_modules - npm install --no-save --no-package-lock fabric@5 imagemin-zopfli@7 + npm install --no-save fabric@6.0.0-rc1 imagemin-zopfli@7 node build/generate-images.js $(TAGS) .PHONY: generate-manpage diff --git a/build/generate-images.js b/build/generate-images.js index a3a0f8d8f3..9b584efcf8 100755 --- a/build/generate-images.js +++ b/build/generate-images.js @@ -1,20 +1,13 @@ #!/usr/bin/env node import imageminZopfli from 'imagemin-zopfli'; +import {loadSVGFromString, Canvas, Rect, util} from 'fabric/node'; import {optimize} from 'svgo'; -import {fabric} from 'fabric'; import {readFile, writeFile} from 'node:fs/promises'; +import {argv, exit} from 'node:process'; -function exit(err) { +function doExit(err) { if (err) console.error(err); - process.exit(err ? 1 : 0); -} - -function loadSvg(svg) { - return new Promise((resolve) => { - fabric.loadSVGFromString(svg, (objects, options) => { - resolve({objects, options}); - }); - }); + exit(err ? 1 : 0); } async function generate(svg, path, {size, bg}) { @@ -27,7 +20,7 @@ async function generate(svg, path, {size, bg}) { 'removeDimensions', { name: 'addAttributesToSVGElement', - params: {attributes: [{width: size}, {height: size}]} + params: {attributes: [{width: size}, {height: size}]}, }, ], }); @@ -35,14 +28,14 @@ async function generate(svg, path, {size, bg}) { return; } - const {objects, options} = await loadSvg(svg); - const canvas = new fabric.Canvas(); + const {objects, options} = await loadSVGFromString(svg); + const canvas = new Canvas(); canvas.setDimensions({width: size, height: size}); const ctx = canvas.getContext('2d'); ctx.scale(options.width ? (size / options.width) : 1, options.height ? (size / options.height) : 1); if (bg) { - canvas.add(new fabric.Rect({ + canvas.add(new Rect({ left: 0, top: 0, height: size * (1 / (size / options.height)), @@ -51,7 +44,7 @@ async function generate(svg, path, {size, bg}) { })); } - canvas.add(fabric.util.groupSVGElements(objects, options)); + canvas.add(util.groupSVGElements(objects, options)); canvas.renderAll(); let png = Buffer.from([]); @@ -64,7 +57,7 @@ async function generate(svg, path, {size, bg}) { } async function main() { - const gitea = process.argv.slice(2).includes('gitea'); + const gitea = argv.slice(2).includes('gitea'); const logoSvg = await readFile(new URL('../assets/logo.svg', import.meta.url), 'utf8'); const faviconSvg = await readFile(new URL('../assets/favicon.svg', import.meta.url), 'utf8'); @@ -79,4 +72,8 @@ async function main() { ]); } -main().then(exit).catch(exit); +try { + doExit(await main()); +} catch (err) { + doExit(err); +} diff --git a/public/assets/img/favicon.svg b/public/assets/img/favicon.svg index afeeacb77c..9556545002 100644 --- a/public/assets/img/favicon.svg +++ b/public/assets/img/favicon.svg @@ -1 +1 @@ - \ No newline at end of file + \ No newline at end of file diff --git a/public/assets/img/logo.svg b/public/assets/img/logo.svg index afeeacb77c..9556545002 100644 --- a/public/assets/img/logo.svg +++ b/public/assets/img/logo.svg @@ -1 +1 @@ - \ No newline at end of file + \ No newline at end of file