Skip to content

Commit 3b2ce4e

Browse files
committed
Use environment methods in favicon build script, refactor to use BuildError
1 parent 26ba943 commit 3b2ce4e

1 file changed

Lines changed: 6 additions & 5 deletions

File tree

‎scripts/build/favicon.ts‎

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,16 @@
2121
import sharp, { type Metadata } from 'sharp'
2222
import toIco from 'to-ico'
2323
import { writeFile, mkdir } from 'fs/promises'
24-
import { ClientScriptError } from '@components/scripts/errors'
24+
import { isTest } from '@lib/config'
25+
import { BuildError } from '@lib/errors'
2526

2627
type IconGenerator = (_options: Metadata) => Promise<Buffer>
2728

2829
const faviconPath = `src/assets/favicon.svg`
2930
const generateIcoFavicon: IconGenerator = async ({ width, height, density }) => {
3031
if (!width || !height || !density) {
3132
const message = `Required option not passed to generateIcoFavicon`
32-
throw new ClientScriptError({ message })
33+
throw new BuildError({ message })
3334
}
3435
const faviconDimensions = [32, 64]
3536
// Create buffer for each size
@@ -47,7 +48,7 @@ const generateIcoFavicon: IconGenerator = async ({ width, height, density }) =>
4748
const generatePngFavicon: IconGenerator = ({ density, width, height }) => {
4849
if (!width || !height || !density) {
4950
const message = `Required option not passed to generatePngFavicon`
50-
throw new ClientScriptError({ message })
51+
throw new BuildError({ message })
5152
}
5253
return sharp(faviconPath, {
5354
density: (180 / Math.max(width, height)) * density,
@@ -60,7 +61,7 @@ const generatePngFavicon: IconGenerator = ({ density, width, height }) => {
6061
const generatePwaIcon = (size: number): IconGenerator => ({ density, width, height }) => {
6162
if (!width || !height || !density) {
6263
const message = `Required option not passed to generatePwaIcon`
63-
throw new ClientScriptError({ message })
64+
throw new BuildError({ message })
6465
}
6566
return sharp(faviconPath, {
6667
density: (size / Math.max(width, height)) * density,
@@ -102,7 +103,7 @@ export const buildFavicons = async () => {
102103
}
103104

104105
// Execute when run directly (ES module), but not during tests
105-
if (process.env['NODE_ENV'] !== 'test') {
106+
if (!isTest()) {
106107
buildFavicons().catch((error) => {
107108
console.error('❌ Failed to generate favicons:', error)
108109
process.exit(1)

0 commit comments

Comments
 (0)