-
Notifications
You must be signed in to change notification settings - Fork 0
/
sharp.js
96 lines (81 loc) · 3.06 KB
/
sharp.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
const sharp = require('sharp');
const fs = require('fs');
const path = require('path');
// Root Images
const targetRoot = path.resolve(__dirname, 'src/public/images');
const destinationRoot = path.resolve(__dirname, 'dist/assets/images');
if (!fs.existsSync(destinationRoot)) {
fs.mkdirSync(destinationRoot);
}
fs.readdirSync(targetRoot)
.forEach((image) => {
const extension = image.split('.')[1] === 'png' ? 'png' : 'jpg';
const ignore = ['app-icon.png', 'app-logo.png', 'avatar-image.png', 'empty-favorite.png', 'loading.gif'];
if (!ignore.includes(image)) {
sharp(`${targetRoot}/${image}`)
.resize(800)
.toFile(path.resolve(__dirname, `${destinationRoot}/${image.split('.')
.slice(0, -1)
.join('.')}-large.${extension}`));
sharp(`${targetRoot}/${image}`)
.resize(600)
.toFile(path.resolve(__dirname, `${destinationRoot}/${image.split('.')
.slice(0, -1)
.join('.')}-medium.${extension}`));
sharp(`${targetRoot}/${image}`)
.resize(480)
.toFile(path.resolve(__dirname, `${destinationRoot}/${image.split('.')
.slice(0, -1)
.join('.')}-small.${extension}`));
}
});
// Food Images
const targetFood = path.resolve(__dirname, 'src/public/images/foods');
const destinationFood = path.resolve(__dirname, 'dist/assets/images/foods');
if (!fs.existsSync(destinationFood)) {
fs.mkdirSync(destinationFood);
}
fs.readdirSync(targetFood)
.forEach((image) => {
const extension = image.split('.')[1] === 'png' ? 'png' : 'jpg';
sharp(`${targetFood}/${image}`)
.resize(800)
.toFile(path.resolve(__dirname, `${destinationFood}/${image.split('.')
.slice(0, -1)
.join('.')}-large.${extension}`));
sharp(`${targetFood}/${image}`)
.resize(600)
.toFile(path.resolve(__dirname, `${destinationFood}/${image.split('.')
.slice(0, -1)
.join('.')}-medium.${extension}`));
sharp(`${targetFood}/${image}`)
.resize(480)
.toFile(path.resolve(__dirname, `${destinationFood}/${image.split('.')
.slice(0, -1)
.join('.')}-small.${extension}`));
});
// Menu Images
const targetMenu = path.resolve(__dirname, 'src/public/images/menus');
const destinationMenu = path.resolve(__dirname, 'dist/assets/images/menus');
if (!fs.existsSync(destinationMenu)) {
fs.mkdirSync(destinationMenu);
}
fs.readdirSync(targetMenu)
.forEach((image) => {
const extension = image.split('.')[1] === 'png' ? 'png' : 'jpg';
sharp(`${targetMenu}/${image}`)
.resize(800)
.toFile(path.resolve(__dirname, `${destinationMenu}/${image.split('.')
.slice(0, -1)
.join('.')}-large.${extension}`));
sharp(`${targetMenu}/${image}`)
.resize(600)
.toFile(path.resolve(__dirname, `${destinationMenu}/${image.split('.')
.slice(0, -1)
.join('.')}-medium.${extension}`));
sharp(`${targetMenu}/${image}`)
.resize(480)
.toFile(path.resolve(__dirname, `${destinationMenu}/${image.split('.')
.slice(0, -1)
.join('.')}-small.${extension}`));
});