-
-
Save OMGZui/63af5292050f959a567475f8be08a278 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
process.on('message', (tasks: imageType[]) => { | |
;(async () => { | |
const data = tasks | |
.filter(({ path }: { path: string }) => /\.(jpe?g|png)$/.test(path)) | |
.map(ele => { | |
return compressImg({ ...ele, file: Buffer.from(ele.file) }) | |
}) | |
const svgaData = tasks | |
.filter(({ path }: { path: string }) => /\.(svga)$/.test(path)) | |
.map(ele => { | |
return compressSvga(ele.path, Buffer.from(ele.file)) | |
}) | |
const details = await Promise.all([ | |
...data.map(fn => fn()), | |
...svgaData.map(fn => fn()) | |
]) | |
await Promise.all( | |
details.map( | |
({ path, file }) => | |
new Promise((resolve, reject) => { | |
fs.writeFile(path, file, err => { | |
if (err) reject(err) | |
resolve(true) | |
}) | |
}) | |
) | |
) | |
if (process.send) { | |
process.send(details) | |
} | |
})() | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment