makeIcons.js 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. const sharp = require("sharp");
  2. const fs = require("fs");
  3. const path = require("path");
  4. const iconPath = path.resolve(__dirname, "res", "icon", "ios");
  5. if (!fs.existsSync(iconPath)) {
  6. if (fs.mkdirSync(iconPath, { recursive: true })) {
  7. return;
  8. }
  9. }
  10. var sizeList = [
  11. 20, 29, 40, 50, 57, 58, 60, 72, 76, 80, 87, 100, 114, 120, 144, 152, 167,
  12. 180, 1024,
  13. ];
  14. var config = "";
  15. sizeList.forEach((size) => {
  16. config += `<icon height="${size}" src="res/icon/ios/icon-${size}.png" width="${size}" />\n`;
  17. sharp("icon.png")
  18. .resize(size)
  19. .toBuffer()
  20. .then((data) => {
  21. var file = fs.open(
  22. path.resolve(iconPath, `icon-${size}.png`),
  23. "w",
  24. (err, fd) => {
  25. if (err) {
  26. return console.error(err);
  27. }
  28. fs.writeFile(fd, data, (err) => {
  29. if (err) {
  30. return console.error(err);
  31. }
  32. });
  33. }
  34. );
  35. })
  36. .catch((e) => {
  37. console.log(e);
  38. });
  39. });
  40. fs.writeFile(path.resolve(iconPath, "config"), config, (err) => {});