mirror of
				https://github.com/go-gitea/gitea
				synced 2025-11-04 05:18:25 +00:00 
			
		
		
		
	Migrate all JS config and tools to TS and fix a number of type issues. This required Node.js 22.18.0 or greater where [type-stripping was enabled](https://nodejs.org/en/blog/release/v22.18.0) by default. Given that Node 22 is the current LTS, I think it's ok to assume that the user has a recent version of it. Webpack currently requires the `--disable-interpret` flag to work, should be fixed eventually with https://github.com/webpack/webpack-cli/issues/4525. `fast-glob` is replaced by `fs.globSync`, available in Node 22.0.0 or greater.
		
			
				
	
	
		
			62 lines
		
	
	
		
			2.0 KiB
		
	
	
	
		
			JavaScript
		
	
	
		
			Executable File
		
	
	
	
	
			
		
		
	
	
			62 lines
		
	
	
		
			2.0 KiB
		
	
	
	
		
			JavaScript
		
	
	
		
			Executable File
		
	
	
	
	
#!/usr/bin/env node
 | 
						|
import {initWasm, Resvg} from '@resvg/resvg-wasm';
 | 
						|
import {optimize} from 'svgo';
 | 
						|
import {readFile, writeFile} from 'node:fs/promises';
 | 
						|
import {argv, exit} from 'node:process';
 | 
						|
 | 
						|
async function generate(svg: string, path: string, {size, bg}: {size: number, bg?: boolean}) {
 | 
						|
  const outputFile = new URL(path, import.meta.url);
 | 
						|
 | 
						|
  if (String(outputFile).endsWith('.svg')) {
 | 
						|
    const {data} = optimize(svg, {
 | 
						|
      plugins: [
 | 
						|
        'preset-default',
 | 
						|
        'removeDimensions',
 | 
						|
        {
 | 
						|
          name: 'addAttributesToSVGElement',
 | 
						|
          params: {
 | 
						|
            attributes: [{width: String(size)}, {height: String(size)}],
 | 
						|
          },
 | 
						|
        },
 | 
						|
      ],
 | 
						|
    });
 | 
						|
    await writeFile(outputFile, data);
 | 
						|
    return;
 | 
						|
  }
 | 
						|
 | 
						|
  const resvgJS = new Resvg(svg, {
 | 
						|
    fitTo: {
 | 
						|
      mode: 'width',
 | 
						|
      value: size,
 | 
						|
    },
 | 
						|
    ...(bg && {background: 'white'}),
 | 
						|
  });
 | 
						|
  const renderedImage = resvgJS.render();
 | 
						|
  const pngBytes = renderedImage.asPng();
 | 
						|
  await writeFile(outputFile, Buffer.from(pngBytes));
 | 
						|
}
 | 
						|
 | 
						|
async function main() {
 | 
						|
  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');
 | 
						|
  await initWasm(await readFile(new URL(import.meta.resolve('@resvg/resvg-wasm/index_bg.wasm'))));
 | 
						|
 | 
						|
  await Promise.all([
 | 
						|
    generate(logoSvg, '../public/assets/img/logo.svg', {size: 32}),
 | 
						|
    generate(logoSvg, '../public/assets/img/logo.png', {size: 512}),
 | 
						|
    generate(faviconSvg, '../public/assets/img/favicon.svg', {size: 32}),
 | 
						|
    generate(faviconSvg, '../public/assets/img/favicon.png', {size: 180}),
 | 
						|
    generate(logoSvg, '../public/assets/img/avatar_default.png', {size: 200}),
 | 
						|
    generate(logoSvg, '../public/assets/img/apple-touch-icon.png', {size: 180, bg: true}),
 | 
						|
    gitea && generate(logoSvg, '../public/assets/img/gitea.svg', {size: 32}),
 | 
						|
  ]);
 | 
						|
}
 | 
						|
 | 
						|
try {
 | 
						|
  await main();
 | 
						|
} catch (err) {
 | 
						|
  console.error(err);
 | 
						|
  exit(1);
 | 
						|
}
 |