-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathcreateManifest.js
More file actions
36 lines (31 loc) · 947 Bytes
/
createManifest.js
File metadata and controls
36 lines (31 loc) · 947 Bytes
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
const glob = require('glob').sync;
const size = require('image-size');
const fs = require('fs');
// Icons glob
const allIcons = glob('build/img/icons/*.png');
// Prepare img arr
const parsedIcons = allIcons.reduce((arr, img) => {
arr.push(readImage(img));
return arr;
}, []);
// Create entry in manifest file
function readImage(img) {
const dimensions = size(img);
return {
src: img.replace('build', ''),
sizes: `${dimensions.width}x${dimensions.height}`,
type: `image/${dimensions.type}`,
};
}
// Manifest
const manifest = {
name: 'Algolia Community',
short_name: 'Algolia', // eslint-disable-line camelcase
theme_color: '#00aeff', // eslint-disable-line camelcase
background_color: '#f7f7ff', // eslint-disable-line camelcase
display: 'standalone',
start_url: '/', // eslint-disable-line camelcase
icons: parsedIcons,
};
// Write to dir
fs.writeFileSync('build/manifest.json', JSON.stringify(manifest));