Skip to content

Commit

Permalink
Removed unnecessary uuid lib
Browse files Browse the repository at this point in the history
  • Loading branch information
Filip Mösner committed May 22, 2023
1 parent 3fc4c94 commit b38556a
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 19 deletions.
4 changes: 1 addition & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,12 @@
"dependencies": {
"commander": "^8.3.0",
"pngjs": "^7.0.0",
"sharp": "^0.32.1",
"uuid": "^9.0.0"
"sharp": "^0.32.1"
},
"devDependencies": {
"@types/node": "^20.2.1",
"@types/pngjs": "^6.0.1",
"@types/sharp": "^0.32.0",
"@types/uuid": "^9.0.1",
"typescript": "^5.0.4",
"vitest": "^0.31.1"
}
Expand Down
11 changes: 2 additions & 9 deletions src/lib/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import fs from 'node:fs'
import path from 'node:path'
import os from 'node:os'
import { v4 as uuidv4 } from 'uuid'
import generatePNG, { ImageInfo } from './png'
import generateICO, { REQUIRED_IMAGE_SIZES as ICO_SIZES } from './ico'
import generateICNS, { REQUIRED_IMAGE_SIZES as ICNS_SIZES } from './icns'
Expand Down Expand Up @@ -204,11 +203,7 @@ const generateIconFromSVG = async (
logger.log(' src: ' + svgFilePath)
logger.log(' dir: ' + destDirPath)

const workDir = path.join(os.tmpdir(), uuidv4())
fs.mkdirSync(workDir)
if (!fs.existsSync(workDir)) {
throw new Error('Failed to create the working directory.')
}
const workDir = fs.mkdtempSync('tmp-xxxxxx')

try {
const images = await generatePNG(
Expand All @@ -218,11 +213,9 @@ const generateIconFromSVG = async (
logger
)
const results = await generate(images, destDirPath, options, logger)
fs.rmSync(workDir, {force: true, recursive: true})
return results
} catch (err) {
} finally {
fs.rmSync(workDir, {force: true, recursive: true})
throw err
}
}

Expand Down
11 changes: 4 additions & 7 deletions src/lib/png.test.ts
Original file line number Diff line number Diff line change
@@ -1,27 +1,24 @@
import { test, expect } from 'vitest'
import os from 'node:os'
import path from 'node:path'
import fs from 'node:fs'
import { v4 as uuidv4 } from 'uuid'
import Logger from './logger'
import generatePNG, { filterImagesBySizes } from './png'
import { REQUIRED_IMAGE_SIZES as FAV_SIZES } from './favicon'
import { REQUIRED_IMAGE_SIZES as ICNS_SIZES } from './icns'
import { REQUIRED_IMAGE_SIZES as ICO_SIZES } from './ico'

test('generatePNG', () => {
const dir = path.join(os.tmpdir(), uuidv4())
fs.mkdirSync(dir)
const dir = fs.mkdtempSync('tmp-xxxxxx')

return generatePNG('./examples/data/sample.svg', dir, [16], new Logger())
.then((results) => {
expect(results[0].size).toBe(16)
fs.rmSync(dir, { recursive: true, force: true })
})
.catch((err) => {
console.error(err)
fs.rmSync(dir, { recursive: true, force: true })
})
.finally(() => {
fs.rmSync(dir, { recursive: true, force: true })
});
})

// Test data
Expand Down

0 comments on commit b38556a

Please sign in to comment.