loading up the forgejo repo on tangled to test page performance
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

move some scripts from 'build' to 'tools' directory, misc refactors (#29844)

- Move some scripts from `build` to new `tools` dir. Eventually i would
like to move all but let's do it step-by-step.
- Add dir to eslint and move the files into vars.
- Update docs accordingly.
- While updating docs I noticed we were incorrectly having `public/img`
path still in a few places. Replace those with the current
`public/assets/img`.

---------

Co-authored-by: Nanguan Lin <nanguanlin6@gmail.com>
Co-authored-by: Giteabot <teabot@gitea.io>
(cherry picked from commit 095fdd691dd1a7d7748372cc73e7708278c80933)

authored by

silverwind
Nanguan Lin
Giteabot
and committed by
Earl Warren
6eb576c3 a2f4ab60

+95 -97
+1 -1
.dockerignore
··· 62 62 /data 63 63 /indexers 64 64 /log 65 - /public/img/avatar 66 65 /tests/integration/gitea-integration-* 67 66 /tests/integration/indexers-* 68 67 /tests/e2e/gitea-e2e-* ··· 77 76 /public/assets/js 78 77 /public/assets/css 79 78 /public/assets/fonts 79 + /public/assets/img/avatar 80 80 /public/assets/img/webpack 81 81 /vendor 82 82 /web_src/fomantic/node_modules
-4
.eslintrc.yaml
··· 42 42 worker: true 43 43 rules: 44 44 no-restricted-globals: [2, addEventListener, blur, close, closed, confirm, defaultStatus, defaultstatus, error, event, external, find, focus, frameElement, frames, history, innerHeight, innerWidth, isFinite, isNaN, length, locationbar, menubar, moveBy, moveTo, name, onblur, onerror, onfocus, onload, onresize, onunload, open, opener, opera, outerHeight, outerWidth, pageXOffset, pageYOffset, parent, print, removeEventListener, resizeBy, resizeTo, screen, screenLeft, screenTop, screenX, screenY, scroll, scrollbars, scrollBy, scrollTo, scrollX, scrollY, status, statusbar, stop, toolbar, top] 45 - - files: ["build/generate-images.js"] 46 - rules: 47 - i/no-unresolved: [0] 48 - i/no-extraneous-dependencies: [0] 49 45 - files: ["*.config.*"] 50 46 rules: 51 47 i/no-unused-modules: [0]
+1 -1
.gitignore
··· 64 64 /data 65 65 /indexers 66 66 /log 67 - /public/img/avatar 67 + /public/assets/img/avatar 68 68 /tests/integration/gitea-integration-* 69 69 /tests/integration/indexers-* 70 70 /tests/e2e/gitea-e2e-*
+9 -7
Makefile
··· 148 148 GO_DIRS := build cmd models modules routers services tests 149 149 WEB_DIRS := web_src/js web_src/css 150 150 151 + ESLINT_FILES := web_src/js tools *.config.js tests/e2e 152 + STYLELINT_FILES := web_src/css web_src/js/components/*.vue 151 153 SPELLCHECK_FILES := $(GO_DIRS) $(WEB_DIRS) docs/content templates options/locale/locale_en-US.ini .github 152 154 153 155 GO_SOURCES := $(wildcard *.go) ··· 396 398 397 399 .PHONY: lint-js 398 400 lint-js: node_modules 399 - npx eslint --color --max-warnings=0 --ext js,vue web_src/js build *.config.js tests/e2e 401 + npx eslint --color --max-warnings=0 --ext js,vue $(ESLINT_FILES) 400 402 401 403 .PHONY: lint-js-fix 402 404 lint-js-fix: node_modules 403 - npx eslint --color --max-warnings=0 --ext js,vue web_src/js build *.config.js tests/e2e --fix 405 + npx eslint --color --max-warnings=0 --ext js,vue $(ESLINT_FILES) --fix 404 406 405 407 .PHONY: lint-css 406 408 lint-css: node_modules 407 - npx stylelint --color --max-warnings=0 web_src/css web_src/js/components/*.vue 409 + npx stylelint --color --max-warnings=0 $(STYLELINT_FILES) 408 410 409 411 .PHONY: lint-css-fix 410 412 lint-css-fix: node_modules 411 - npx stylelint --color --max-warnings=0 web_src/css web_src/js/components/*.vue --fix 413 + npx stylelint --color --max-warnings=0 $(STYLELINT_FILES) --fix 412 414 413 415 .PHONY: lint-swagger 414 416 lint-swagger: node_modules ··· 468 470 469 471 .PHONY: watch 470 472 watch: 471 - @bash build/watch.sh 473 + @bash tools/watch.sh 472 474 473 475 .PHONY: watch-frontend 474 476 watch-frontend: node-check node_modules ··· 962 964 .PHONY: svg 963 965 svg: node-check | node_modules 964 966 rm -rf $(SVG_DEST_DIR) 965 - node build/generate-svg.js 967 + node tools/generate-svg.js 966 968 967 969 .PHONY: svg-check 968 970 svg-check: svg ··· 997 999 .PHONY: generate-images 998 1000 generate-images: | node_modules 999 1001 npm install --no-save fabric@6.0.0-beta19 imagemin-zopfli@7 1000 - node build/generate-images.js $(TAGS) 1002 + node tools/generate-images.js $(TAGS) 1001 1003 1002 1004 .PHONY: generate-manpage 1003 1005 generate-manpage:
-79
build/generate-images.js
··· 1 - #!/usr/bin/env node 2 - import imageminZopfli from 'imagemin-zopfli'; 3 - import {optimize} from 'svgo'; 4 - import {loadSVGFromString, Canvas, Rect, util} from 'fabric/node'; 5 - import {readFile, writeFile} from 'node:fs/promises'; 6 - import {argv, exit} from 'node:process'; 7 - 8 - function doExit(err) { 9 - if (err) console.error(err); 10 - exit(err ? 1 : 0); 11 - } 12 - 13 - async function generate(svg, path, {size, bg}) { 14 - const outputFile = new URL(path, import.meta.url); 15 - 16 - if (String(outputFile).endsWith('.svg')) { 17 - const {data} = optimize(svg, { 18 - plugins: [ 19 - 'preset-default', 20 - 'removeDimensions', 21 - { 22 - name: 'addAttributesToSVGElement', 23 - params: {attributes: [{width: size}, {height: size}]} 24 - }, 25 - ], 26 - }); 27 - await writeFile(outputFile, data); 28 - return; 29 - } 30 - 31 - const {objects, options} = await loadSVGFromString(svg); 32 - const canvas = new Canvas(); 33 - canvas.setDimensions({width: size, height: size}); 34 - const ctx = canvas.getContext('2d'); 35 - ctx.scale(options.width ? (size / options.width) : 1, options.height ? (size / options.height) : 1); 36 - 37 - if (bg) { 38 - canvas.add(new Rect({ 39 - left: 0, 40 - top: 0, 41 - height: size * (1 / (size / options.height)), 42 - width: size * (1 / (size / options.width)), 43 - fill: 'white', 44 - })); 45 - } 46 - 47 - canvas.add(util.groupSVGElements(objects, options)); 48 - canvas.renderAll(); 49 - 50 - let png = Buffer.from([]); 51 - for await (const chunk of canvas.createPNGStream()) { 52 - png = Buffer.concat([png, chunk]); 53 - } 54 - 55 - png = await imageminZopfli({more: true})(png); 56 - await writeFile(outputFile, png); 57 - } 58 - 59 - async function main() { 60 - const gitea = argv.slice(2).includes('gitea'); 61 - const logoSvg = await readFile(new URL('../assets/logo.svg', import.meta.url), 'utf8'); 62 - const faviconSvg = await readFile(new URL('../assets/favicon.svg', import.meta.url), 'utf8'); 63 - 64 - await Promise.all([ 65 - generate(logoSvg, '../public/assets/img/logo.svg', {size: 32}), 66 - generate(logoSvg, '../public/assets/img/logo.png', {size: 512}), 67 - generate(faviconSvg, '../public/assets/img/favicon.svg', {size: 32}), 68 - generate(faviconSvg, '../public/assets/img/favicon.png', {size: 180}), 69 - generate(logoSvg, '../public/assets/img/avatar_default.png', {size: 200}), 70 - generate(logoSvg, '../public/assets/img/apple-touch-icon.png', {size: 180, bg: true}), 71 - gitea && generate(logoSvg, '../public/assets/img/gitea.svg', {size: 32}), 72 - ]); 73 - } 74 - 75 - try { 76 - doExit(await main()); 77 - } catch (err) { 78 - doExit(err); 79 - }
build/generate-svg.js tools/generate-svg.js
build/watch.sh tools/watch.sh
+3 -3
docs/content/administration/cmd-embedded.zh-cn.md
··· 37 37 38 38 - 列出所有模板文件,无论在哪个虚拟目录下:`**.tmpl` 39 39 - 列出所有邮件模板文件:`templates/mail/**.tmpl` 40 - - 列出 `public/img` 目录下的所有文件:`public/img/**` 40 + 列出 `public/assets/img` 目录下的所有文件:`public/assets/img/**` 41 41 42 42 不要忘记为模式使用引号,因为空格、`*` 和其他字符可能对命令行解释器有特殊含义。 43 43 ··· 49 49 50 50 ```sh 51 51 $ gitea embedded list '**openid**' 52 - public/img/auth/openid_connect.svg 53 - public/img/openid-16x16.png 52 + public/assets/img/auth/openid_connect.svg 53 + public/assets/img/openid-16x16.png 54 54 templates/user/auth/finalize_openid.tmpl 55 55 templates/user/auth/signin_openid.tmpl 56 56 templates/user/auth/signup_openid_connect.tmpl
+1 -1
docs/content/development/hacking-on-gitea.en-us.md
··· 214 214 215 215 ### Building and adding SVGs 216 216 217 - SVG icons are built using the `make svg` target which compiles the icon sources defined in `build/generate-svg.js` into the output directory `public/assets/img/svg`. Custom icons can be added in the `web_src/svg` directory. 217 + SVG icons are built using the `make svg` target which compiles the icon sources into the output directory `public/assets/img/svg`. Custom icons can be added in the `web_src/svg` directory. 218 218 219 219 ### Building the Logo 220 220
+1 -1
docs/content/development/hacking-on-gitea.zh-cn.md
··· 201 201 202 202 ### 构建和添加 SVGs 203 203 204 - SVG 图标是使用 `make svg` 目标构建的,该目标将 `build/generate-svg.js` 中定义的图标源编译到输出目录 `public/img/svg` 中。可以在 `web_src/svg` 目录中添加自定义图标。 204 + SVG 图标是使用 `make svg` 命令构建的,该命令将图标资源编译到输出目录 `public/assets/img/svg` 中。可以在 `web_src/svg` 目录中添加自定义图标。 205 205 206 206 ### 构建 Logo 207 207
+79
tools/generate-images.js
··· 1 + #!/usr/bin/env node 2 + import imageminZopfli from 'imagemin-zopfli'; // eslint-disable-line i/no-unresolved 3 + import {loadSVGFromString, Canvas, Rect, util} from 'fabric/node'; // eslint-disable-line i/no-unresolved 4 + import {optimize} from 'svgo'; 5 + import {readFile, writeFile} from 'node:fs/promises'; 6 + import {argv, exit} from 'node:process'; 7 + 8 + function doExit(err) { 9 + if (err) console.error(err); 10 + exit(err ? 1 : 0); 11 + } 12 + 13 + async function generate(svg, path, {size, bg}) { 14 + const outputFile = new URL(path, import.meta.url); 15 + 16 + if (String(outputFile).endsWith('.svg')) { 17 + const {data} = optimize(svg, { 18 + plugins: [ 19 + 'preset-default', 20 + 'removeDimensions', 21 + { 22 + name: 'addAttributesToSVGElement', 23 + params: {attributes: [{width: size}, {height: size}]} 24 + }, 25 + ], 26 + }); 27 + await writeFile(outputFile, data); 28 + return; 29 + } 30 + 31 + const {objects, options} = await loadSVGFromString(svg); 32 + const canvas = new Canvas(); 33 + canvas.setDimensions({width: size, height: size}); 34 + const ctx = canvas.getContext('2d'); 35 + ctx.scale(options.width ? (size / options.width) : 1, options.height ? (size / options.height) : 1); 36 + 37 + if (bg) { 38 + canvas.add(new Rect({ 39 + left: 0, 40 + top: 0, 41 + height: size * (1 / (size / options.height)), 42 + width: size * (1 / (size / options.width)), 43 + fill: 'white', 44 + })); 45 + } 46 + 47 + canvas.add(util.groupSVGElements(objects, options)); 48 + canvas.renderAll(); 49 + 50 + let png = Buffer.from([]); 51 + for await (const chunk of canvas.createPNGStream()) { 52 + png = Buffer.concat([png, chunk]); 53 + } 54 + 55 + png = await imageminZopfli({more: true})(png); 56 + await writeFile(outputFile, png); 57 + } 58 + 59 + async function main() { 60 + const gitea = argv.slice(2).includes('gitea'); 61 + const logoSvg = await readFile(new URL('../assets/logo.svg', import.meta.url), 'utf8'); 62 + const faviconSvg = await readFile(new URL('../assets/favicon.svg', import.meta.url), 'utf8'); 63 + 64 + await Promise.all([ 65 + generate(logoSvg, '../public/assets/img/logo.svg', {size: 32}), 66 + generate(logoSvg, '../public/assets/img/logo.png', {size: 512}), 67 + generate(faviconSvg, '../public/assets/img/favicon.svg', {size: 32}), 68 + generate(faviconSvg, '../public/assets/img/favicon.png', {size: 180}), 69 + generate(logoSvg, '../public/assets/img/avatar_default.png', {size: 200}), 70 + generate(logoSvg, '../public/assets/img/apple-touch-icon.png', {size: 180, bg: true}), 71 + gitea && generate(logoSvg, '../public/assets/img/gitea.svg', {size: 32}), 72 + ]); 73 + } 74 + 75 + try { 76 + doExit(await main()); 77 + } catch (err) { 78 + doExit(err); 79 + }