️ Multithreaded image processing

This commit is contained in:
trickypr 2022-03-27 15:52:49 +11:00
parent ffbe6bbacc
commit 2bdcbb0736
4 changed files with 25 additions and 4 deletions

View file

@ -47,6 +47,7 @@
"glob": "^7.1.7", "glob": "^7.1.7",
"linus": "^0.0.6", "linus": "^0.0.6",
"listr": "^0.14.3", "listr": "^0.14.3",
"modern-async": "^1.1.2",
"prompts": "^2.4.1", "prompts": "^2.4.1",
"rimraf": "^3.0.2", "rimraf": "^3.0.2",
"rustic": "^1.2.1", "rustic": "^1.2.1",

View file

@ -9,6 +9,7 @@ import {
copyFileSync, copyFileSync,
} from 'fs' } from 'fs'
import { copyFile, readFile, writeFile } from 'fs/promises' import { copyFile, readFile, writeFile } from 'fs/promises'
import { every } from 'modern-async'
import { dirname, extname, join } from 'path' import { dirname, extname, join } from 'path'
import sharp from 'sharp' import sharp from 'sharp'
@ -73,8 +74,7 @@ function constructConfig(name: string) {
async function setupImages(configPath: string, outputPath: string) { async function setupImages(configPath: string, outputPath: string) {
log.info('Generating icons') log.info('Generating icons')
// TODO: This can be made parallel to avoid problems with cpu vs disk access await every([16, 22, 24, 32, 48, 64, 128, 256], async (size) => {
for (const size of [16, 22, 24, 32, 48, 64, 128, 256]) {
await sharp(join(configPath, 'logo.png')) await sharp(join(configPath, 'logo.png'))
.resize(size, size) .resize(size, size)
.toFile(join(outputPath, `default${size}.png`)) .toFile(join(outputPath, `default${size}.png`))
@ -83,7 +83,9 @@ async function setupImages(configPath: string, outputPath: string) {
join(outputPath, `default${size}.png`), join(outputPath, `default${size}.png`),
join(configPath, `logo${size}.png`) join(configPath, `logo${size}.png`)
) )
}
return true
})
await sharp(join(configPath, 'logo.png')) await sharp(join(configPath, 'logo.png'))
.resize(512, 512) .resize(512, 512)

View file

@ -5,7 +5,7 @@ import { ENGINE_DIR, SRC_DIR } from '../../constants'
import * as gitPatch from './gitPatch' import * as gitPatch from './gitPatch'
import * as copyPatch from './copyPatches' import * as copyPatch from './copyPatches'
import * as brandingPatch from './brandingPatch' import * as brandingPatch from './brandingPatch'
import path, { join } from 'path' import { join } from 'path'
import { existsSync, writeFileSync } from 'fs' import { existsSync, writeFileSync } from 'fs'
import { patchCountFile } from '../../middleware/patch-check' import { patchCountFile } from '../../middleware/patch-check'
import { checkHash } from '../../utils' import { checkHash } from '../../utils'

View file

@ -1460,6 +1460,11 @@ core-js-pure@^3.16.0:
resolved "https://registry.yarnpkg.com/core-js-pure/-/core-js-pure-3.18.1.tgz#097d34d24484be45cea700a448d1e74622646c80" resolved "https://registry.yarnpkg.com/core-js-pure/-/core-js-pure-3.18.1.tgz#097d34d24484be45cea700a448d1e74622646c80"
integrity sha512-kmW/k8MaSuqpvA1xm2l3TVlBuvW+XBkcaOroFUpO3D4lsTGQWBTb/tBDCf/PNkkPLrwgrkQRIYNPB0CeqGJWGQ== integrity sha512-kmW/k8MaSuqpvA1xm2l3TVlBuvW+XBkcaOroFUpO3D4lsTGQWBTb/tBDCf/PNkkPLrwgrkQRIYNPB0CeqGJWGQ==
core-js-pure@^3.19.1:
version "3.21.1"
resolved "https://registry.yarnpkg.com/core-js-pure/-/core-js-pure-3.21.1.tgz#8c4d1e78839f5f46208de7230cebfb72bc3bdb51"
integrity sha512-12VZfFIu+wyVbBebyHmRTuEE/tZrB4tJToWcwAMcsp3h4+sHR+fMJWbKpYiCRWlhFBq+KNyO8rIV9rTkeVmznQ==
core-util-is@~1.0.0: core-util-is@~1.0.0:
version "1.0.3" version "1.0.3"
resolved "https://registry.yarnpkg.com/core-util-is/-/core-util-is-1.0.3.tgz#a6042d3634c2b27e9328f837b965fac83808db85" resolved "https://registry.yarnpkg.com/core-util-is/-/core-util-is-1.0.3.tgz#a6042d3634c2b27e9328f837b965fac83808db85"
@ -3422,6 +3427,14 @@ mkdirp-classic@^0.5.2, mkdirp-classic@^0.5.3:
resolved "https://registry.yarnpkg.com/mkdirp-classic/-/mkdirp-classic-0.5.3.tgz#fa10c9115cc6d8865be221ba47ee9bed78601113" resolved "https://registry.yarnpkg.com/mkdirp-classic/-/mkdirp-classic-0.5.3.tgz#fa10c9115cc6d8865be221ba47ee9bed78601113"
integrity sha512-gKLcREMhtuZRwRAfqP3RFW+TK4JqApVBtOIftVgjuABpAtpxhPGaDcfvbhNvD0B8iD1oUr/txX35NjcaY6Ns/A== integrity sha512-gKLcREMhtuZRwRAfqP3RFW+TK4JqApVBtOIftVgjuABpAtpxhPGaDcfvbhNvD0B8iD1oUr/txX35NjcaY6Ns/A==
modern-async@^1.1.2:
version "1.1.2"
resolved "https://registry.yarnpkg.com/modern-async/-/modern-async-1.1.2.tgz#8625664f279a2f8d479f13cbf818234777b0f0d4"
integrity sha512-bgDB0Lg9u86SCDiBlkJGRbAAuArvQLiTwZKEjwL2DtZJMunnNYXS9GWyVBzcbKFnw/XmMpr19NkM/FHX3ce0VA==
dependencies:
core-js-pure "^3.19.1"
nanoassert "^2.0.0"
ms@2.0.0: ms@2.0.0:
version "2.0.0" version "2.0.0"
resolved "https://registry.yarnpkg.com/ms/-/ms-2.0.0.tgz#5608aeadfc00be6c2901df5f9861788de0d597c8" resolved "https://registry.yarnpkg.com/ms/-/ms-2.0.0.tgz#5608aeadfc00be6c2901df5f9861788de0d597c8"
@ -3437,6 +3450,11 @@ ms@^2.1.1:
resolved "https://registry.yarnpkg.com/ms/-/ms-2.1.3.tgz#574c8138ce1d2b5861f0b44579dbadd60c6615b2" resolved "https://registry.yarnpkg.com/ms/-/ms-2.1.3.tgz#574c8138ce1d2b5861f0b44579dbadd60c6615b2"
integrity sha512-6FlzubTLZG3J2a/NVCAleEhjzq5oxgHyaCU9yYXvcLsvoVaHJq/s5xXI6/XXP6tz7R9xAOtHnSO/tXtF3WRTlA== integrity sha512-6FlzubTLZG3J2a/NVCAleEhjzq5oxgHyaCU9yYXvcLsvoVaHJq/s5xXI6/XXP6tz7R9xAOtHnSO/tXtF3WRTlA==
nanoassert@^2.0.0:
version "2.0.0"
resolved "https://registry.yarnpkg.com/nanoassert/-/nanoassert-2.0.0.tgz#a05f86de6c7a51618038a620f88878ed1e490c09"
integrity sha512-7vO7n28+aYO4J+8w96AzhmU8G+Y/xpPDJz/se19ICsqj/momRbb9mh9ZUtkoJ5X3nTnPdhEJyc0qnM6yAsHBaA==
napi-build-utils@^1.0.1: napi-build-utils@^1.0.1:
version "1.0.2" version "1.0.2"
resolved "https://registry.yarnpkg.com/napi-build-utils/-/napi-build-utils-1.0.2.tgz#b1fddc0b2c46e380a0b7a76f984dd47c41a13806" resolved "https://registry.yarnpkg.com/napi-build-utils/-/napi-build-utils-1.0.2.tgz#b1fddc0b2c46e380a0b7a76f984dd47c41a13806"