forked from salomvary/soundcleod
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
92 lines (82 loc) · 2.41 KB
/
gulpfile.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
'use strict'
const { execFile } = require('child_process')
const gulp = require('gulp')
const { name } = require('./app/package.json')
const rename = require('gulp-rename')
const svg2png = require('svg2png')
const through = require('through2')
const toIco = require('gulp-to-ico')
const Vinyl = require('vinyl')
/* eslint no-multi-spaces: off */
gulp.task(
'iconset',
gulp.parallel(
() => generateIcon(`${name}-lo.svg`, 'icon_16x16.png', 16),
() => generateIcon(`${name}-lo.svg`, '[email protected]', 32),
() => generateIcon(`${name}-lo.svg`, 'icon_32x32.png', 32),
() => generateIcon(`${name}.svg`, '[email protected]', 64),
() => generateIcon(`${name}.svg`, 'icon_128x128.png', 128),
() => generateIcon(`${name}.svg`, '[email protected]', 256),
() => generateIcon(`${name}.svg`, 'icon_256x256.png', 256),
() => generateIcon(`${name}.svg`, '[email protected]', 512),
() => generateIcon(`${name}.svg`, 'icon_512x512.png', 512),
() => generateIcon(`${name}.svg`, '[email protected]', 1024)
)
)
gulp.task('macos-icon', (cb) => {
if (process.platform == 'darwin') {
execFile(
'iconutil',
['-c', 'icns', '-o', 'build/icon.icns', 'build/icon.iconset'],
cb
)
} else {
cb()
}
})
gulp.task('windows-icon', () =>
gulp
.src([
'build/icon.iconset/icon_16x16.png',
'build/icon.iconset/icon_32x32.png',
'build/icon.iconset/[email protected]',
'build/icon.iconset/icon_128x128.png',
'build/icon.iconset/icon_256x256.png'
])
.pipe(toIco('icon.ico'))
.pipe(gulp.dest('build'))
)
gulp.task(
'icons',
gulp.series('iconset', gulp.parallel('macos-icon', 'windows-icon'))
)
gulp.task('background', () =>
gulp
.src('background.svg')
.pipe(svg2pngPlugin())
.pipe(rename('background.png'))
.pipe(gulp.dest('build'))
)
gulp.task('images', gulp.parallel('icons', 'background'))
function generateIcon(inputFile, outputFile, size) {
return gulp
.src(inputFile)
.pipe(svg2pngPlugin({ width: size, height: size }))
.pipe(rename(outputFile))
.pipe(gulp.dest('build/icon.iconset'))
}
function svg2pngPlugin(options) {
return through.obj((file, encoding, callback) => {
svg2png(file.contents, options)
.then((buffer) => {
callback(
null,
new Vinyl({
path: file.path,
contents: buffer
})
)
})
.catch(callback)
})
}