|
1 | 1 | import fs from 'fs/promises' |
2 | | -import pixelfix from '@proicons/pixelfix'; |
3 | | -import sharp from 'sharp'; |
| 2 | +import pixelfix from '@proicons/pixelfix' |
| 3 | +import sharp from 'sharp' |
4 | 4 | import path from 'path' |
5 | 5 |
|
6 | | -/** |
7 | | - * @param {string} file |
8 | | - * @param {string} root |
9 | | - */ |
10 | | -export default async ({ file, root }) => { |
11 | | - const pngSizes = [24, 72, 120]; |
12 | | - const outDir = path.resolve(root, 'icons/svg'); |
| 6 | +export default async ({ file, root }: {file: string, root: string}) => { |
| 7 | + const pngSizes = [24, 72, 120] |
| 8 | + const outDir = path.resolve(root, 'icons/svg') |
13 | 9 |
|
14 | 10 | for (const size of pngSizes) { |
15 | | - const colors = ['black', 'white']; |
16 | | - const scale = size / 24; |
17 | | - const newFolder = path.resolve(root, `icons/png${scale == 1 ? '' : `@${scale}x`}`); |
| 11 | + const colors = ['black', 'white'] |
| 12 | + const scale = size / 24 |
| 13 | + const newFolder = path.resolve(root, `icons/png${scale == 1 ? '' : `@${scale}x`}`) |
18 | 14 |
|
19 | 15 | for (const color of colors) { |
20 | | - const newColorFolder = path.join(newFolder, color); |
| 16 | + const newColorFolder = path.join(newFolder, color) |
21 | 17 |
|
22 | | - await fs.mkdir(newColorFolder, { recursive: true }); |
| 18 | + await fs.mkdir(newColorFolder, { recursive: true }) |
23 | 19 |
|
24 | 20 | const fileCt = await fs.readFile(path.join(outDir, file), 'utf-8') |
25 | | - const fileStr = fileCt.replaceAll('currentColor', color); |
| 21 | + const fileStr = fileCt.replaceAll('currentColor', color) |
26 | 22 |
|
27 | | - const newFilePath = path.resolve(newFolder, color, `${file.slice(0, -4)}.png`); |
| 23 | + const newFilePath = path.resolve(newFolder, color, `${file.slice(0, -4)}.png`) |
28 | 24 |
|
29 | 25 | try { |
30 | | - await sharp(Buffer.from(fileStr)).resize(size, size).png().toFile(newFilePath); |
31 | | - await pixelfix(newFilePath); |
| 26 | + await sharp(Buffer.from(fileStr)).resize(size, size).png().toFile(newFilePath) |
| 27 | + await pixelfix(newFilePath) |
32 | 28 | } catch (error) { |
33 | | - console.error(`Failed to generate ${file}`, error); |
| 29 | + console.error(`Failed to generate ${file}`, error) |
34 | 30 | } |
35 | 31 | } |
36 | 32 | } |
|
0 commit comments