Skip to content

Commit c5f37af

Browse files
authored
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 #30596 (comment) by removing `--no-package-lock`.
1 parent 7aa8b8e commit c5f37af

File tree

4 files changed

+18
-21
lines changed

4 files changed

+18
-21
lines changed

Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -1009,7 +1009,7 @@ generate-gitignore:
10091009

10101010
.PHONY: generate-images
10111011
generate-images: | node_modules
1012-
npm install --no-save --no-package-lock fabric@5 imagemin-zopfli@7
1012+
npm install --no-save fabric@6.0.0-rc1 imagemin-zopfli@7
10131013
node build/generate-images.js $(TAGS)
10141014

10151015
.PHONY: generate-manpage

build/generate-images.js

+15-18
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,13 @@
11
#!/usr/bin/env node
22
import imageminZopfli from 'imagemin-zopfli';
3+
import {loadSVGFromString, Canvas, Rect, util} from 'fabric/node';
34
import {optimize} from 'svgo';
4-
import {fabric} from 'fabric';
55
import {readFile, writeFile} from 'node:fs/promises';
6+
import {argv, exit} from 'node:process';
67

7-
function exit(err) {
8+
function doExit(err) {
89
if (err) console.error(err);
9-
process.exit(err ? 1 : 0);
10-
}
11-
12-
function loadSvg(svg) {
13-
return new Promise((resolve) => {
14-
fabric.loadSVGFromString(svg, (objects, options) => {
15-
resolve({objects, options});
16-
});
17-
});
10+
exit(err ? 1 : 0);
1811
}
1912

2013
async function generate(svg, path, {size, bg}) {
@@ -27,22 +20,22 @@ async function generate(svg, path, {size, bg}) {
2720
'removeDimensions',
2821
{
2922
name: 'addAttributesToSVGElement',
30-
params: {attributes: [{width: size}, {height: size}]}
23+
params: {attributes: [{width: size}, {height: size}]},
3124
},
3225
],
3326
});
3427
await writeFile(outputFile, data);
3528
return;
3629
}
3730

38-
const {objects, options} = await loadSvg(svg);
39-
const canvas = new fabric.Canvas();
31+
const {objects, options} = await loadSVGFromString(svg);
32+
const canvas = new Canvas();
4033
canvas.setDimensions({width: size, height: size});
4134
const ctx = canvas.getContext('2d');
4235
ctx.scale(options.width ? (size / options.width) : 1, options.height ? (size / options.height) : 1);
4336

4437
if (bg) {
45-
canvas.add(new fabric.Rect({
38+
canvas.add(new Rect({
4639
left: 0,
4740
top: 0,
4841
height: size * (1 / (size / options.height)),
@@ -51,7 +44,7 @@ async function generate(svg, path, {size, bg}) {
5144
}));
5245
}
5346

54-
canvas.add(fabric.util.groupSVGElements(objects, options));
47+
canvas.add(util.groupSVGElements(objects, options));
5548
canvas.renderAll();
5649

5750
let png = Buffer.from([]);
@@ -64,7 +57,7 @@ async function generate(svg, path, {size, bg}) {
6457
}
6558

6659
async function main() {
67-
const gitea = process.argv.slice(2).includes('gitea');
60+
const gitea = argv.slice(2).includes('gitea');
6861
const logoSvg = await readFile(new URL('../assets/logo.svg', import.meta.url), 'utf8');
6962
const faviconSvg = await readFile(new URL('../assets/favicon.svg', import.meta.url), 'utf8');
7063

@@ -79,4 +72,8 @@ async function main() {
7972
]);
8073
}
8174

82-
main().then(exit).catch(exit);
75+
try {
76+
doExit(await main());
77+
} catch (err) {
78+
doExit(err);
79+
}

public/assets/img/favicon.svg

+1-1
Loading

public/assets/img/logo.svg

+1-1
Loading

0 commit comments

Comments
 (0)