-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
37 lines (32 loc) · 1.21 KB
/
index.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
const fs = require('fs');
const path = require('path');
const { promisify } = require('util');
const createIcon = require('./lib/icon');
const createLogo = require('./lib/logo');
const { saveAsSVG, saveAsPNG } = require('./lib/common');
const readFile = promisify(fs.readFile);
const writeFile = promisify(fs.writeFile);
module.exports = (opts) => {
const { buildDir, iconSizes, logoSizes } = opts;
const svgIcons = iconSizes.map(createIcon);
const svgLogos = logoSizes.map(createLogo);
return Promise.all([
saveAsSVG('icon', svgIcons, path.join(buildDir, 'icons', 'svg')),
saveAsPNG('icon', svgIcons, path.join(buildDir, 'icons', 'png')),
saveAsSVG('logo', svgLogos, path.join(buildDir, 'logo', 'svg')),
saveAsPNG('logo', svgLogos, path.join(buildDir, 'logo', 'png')),
])
.then(results => results.reduce(
(memo, result) => memo.concat(result),
[],
))
.then(
flattened => writeFile(
path.join(buildDir, 'files.json'),
JSON.stringify(flattened, null, 2),
)
.then(() => readFile(path.join(__dirname, 'lib', 'index.html'), 'utf8'))
.then(html => writeFile(path.join(buildDir, 'index.html'), html))
.then(() => flattened),
);
};