diff options
author | silverwind <me@silverwind.io> | 2022-06-06 05:27:25 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-06-06 11:27:25 +0800 |
commit | df0fb17d041b34854c5a0bdd4a14ad50807ded4a (patch) | |
tree | b42e06afa668ba74dd6d79467c053c537e02f1f8 /build/generate-svg.js | |
parent | 0a8c0306004382263ba86610ba4111c569b99f14 (diff) | |
download | gitea-df0fb17d041b34854c5a0bdd4a14ad50807ded4a.tar.gz gitea-df0fb17d041b34854c5a0bdd4a14ad50807ded4a.zip |
Modernize JS build scripts (#19824)
- Remove __dirname, use file URLs instead
- Upgrade fabric dependency
- Use fs/promises syntax, this breaks node 12 but we require 14 already
The change in public/img/favicon.svg is not caused by the fabric
upgrade, but it seems it was not properly generated when introduced.
Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com>
Diffstat (limited to 'build/generate-svg.js')
-rwxr-xr-x | build/generate-svg.js | 26 |
1 files changed, 13 insertions, 13 deletions
diff --git a/build/generate-svg.js b/build/generate-svg.js index 29b7d47693..c4f3d5a7f9 100755 --- a/build/generate-svg.js +++ b/build/generate-svg.js @@ -1,13 +1,14 @@ +#!/usr/bin/env node import fastGlob from 'fast-glob'; import {optimize} from 'svgo'; -import {resolve, parse, dirname} from 'path'; -import fs from 'fs'; +import {parse} from 'path'; +import {readFile, writeFile, mkdir} from 'fs/promises'; import {fileURLToPath} from 'url'; -const {readFile, writeFile, mkdir} = fs.promises; -const __dirname = dirname(fileURLToPath(import.meta.url)); -const glob = (pattern) => fastGlob.sync(pattern, {cwd: resolve(__dirname), absolute: true}); -const outputDir = resolve(__dirname, '../public/img/svg'); +const glob = (pattern) => fastGlob.sync(pattern, { + cwd: fileURLToPath(new URL('..', import.meta.url)), + absolute: true, +}); function exit(err) { if (err) console.error(err); @@ -16,7 +17,6 @@ function exit(err) { async function processFile(file, {prefix, fullName} = {}) { let name; - if (fullName) { name = fullName; } else { @@ -35,7 +35,8 @@ async function processFile(file, {prefix, fullName} = {}) { {name: 'addAttributesToSVGElement', params: {attributes: [{'width': '16'}, {'height': '16'}, {'aria-hidden': 'true'}]}}, ], }); - await writeFile(resolve(outputDir, `${name}.svg`), data); + + await writeFile(fileURLToPath(new URL(`../public/img/svg/${name}.svg`, import.meta.url)), data); } function processFiles(pattern, opts) { @@ -44,15 +45,14 @@ function processFiles(pattern, opts) { async function main() { try { - await mkdir(outputDir); + await mkdir(fileURLToPath(new URL('../public/img/svg', import.meta.url)), {recursive: true}); } catch {} await Promise.all([ - ...processFiles('../node_modules/@primer/octicons/build/svg/*-16.svg', {prefix: 'octicon'}), - ...processFiles('../web_src/svg/*.svg'), - ...processFiles('../public/img/gitea.svg', {fullName: 'gitea-gitea'}), + ...processFiles('node_modules/@primer/octicons/build/svg/*-16.svg', {prefix: 'octicon'}), + ...processFiles('web_src/svg/*.svg'), + ...processFiles('public/img/gitea.svg', {fullName: 'gitea-gitea'}), ]); } main().then(exit).catch(exit); - |