Skip to content

Commit

Permalink
feat: allow generate PWA assets in subfolders (#13)
Browse files Browse the repository at this point in the history
* feat: use path in name

* feat: change function resolveTempPngAssetName

* feat: import mkdir

---------

Co-authored-by: liningzhu <[email protected]>
  • Loading branch information
Barba828 and liningzhu authored Aug 21, 2023
1 parent 878493d commit 9fe4636
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions src/build.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { existsSync } from 'node:fs'
import { rm, writeFile } from 'node:fs/promises'
import { mkdir, rm, writeFile } from 'node:fs/promises'
import { dirname, resolve } from 'node:path'
import { consola } from 'consola'
import { green, yellow } from 'colorette'
Expand Down Expand Up @@ -184,7 +184,8 @@ async function optimizePng(filePath: string, png: PngOptions) {
}
}

function resolveTempPngAssetName(name: string) {
async function resolveTempPngAssetName(name: string) {
await mkdir(dirname(name), { recursive: true })
return name.replace(/\.png$/, '-temp.png')
}

Expand All @@ -205,7 +206,7 @@ async function generateTransparentAssets(
return
}

filePath = resolveTempPngAssetName(filePath)
filePath = await resolveTempPngAssetName(filePath)
const { width, height } = extractAssetSize(size, padding)
await sharp({
create: {
Expand Down Expand Up @@ -248,7 +249,7 @@ async function generateMaskableAssets(
return
}

filePath = resolveTempPngAssetName(filePath)
filePath = await resolveTempPngAssetName(filePath)
const { width, height } = extractAssetSize(size, padding)
await sharp({
create: {
Expand Down Expand Up @@ -374,7 +375,7 @@ async function generateAppleSplashScreens(
return
}

filePath = resolveTempPngAssetName(filePath)
filePath = await resolveTempPngAssetName(filePath)
const { width, height } = extractAppleDeviceSize(size.size, size.padding)
await sharp({
create: {
Expand Down

0 comments on commit 9fe4636

Please sign in to comment.