forked from hainproject/hain
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
114 lines (100 loc) · 3.23 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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
'use strict';
const gulp = require('gulp');
const babel = require('gulp-babel');
const sourcemaps = require('gulp-sourcemaps');
const packager = require('electron-packager');
const path = require('path');
const install = require('gulp-install');
const zip = require('gulp-zip');
const electronInstaller = require('electron-winstaller');
const fs = require('fs');
const del = require('del');
const replace = require('gulp-replace');
const appPkg = require('./app/package.json');
gulp.task('deps', () => {
return gulp.src('./app/package.json')
.pipe(install({ production: true }));
});
gulp.task('clean:renderer', () => {
return del(['./app/renderer']);
});
gulp.task('renderer', ['deps', 'clean:renderer'], () => {
const js = gulp.src('./app/renderer-jsx/**/*.js*')
.pipe(sourcemaps.init())
.pipe(babel({
presets: ['es2015', 'react']
}))
.pipe(sourcemaps.write())
.pipe(gulp.dest('./app/renderer'));
return js;
});
function build(arch) {
return new Promise((resolve, reject) => {
packager({
arch,
dir: path.join(__dirname, 'app'),
platform: 'win32',
asar: true,
ignore: /(renderer-jsx|__tests__)/gi,
overwrite: true,
out: path.join(__dirname, 'out'),
icon: path.join(__dirname, 'build', 'icon.ico'),
'version-string': {
ProductName: 'Hain',
CompanyName: 'Heejin Lee'
}
}, (err, appPath) => {
if (err) {
console.log(err);
return reject(err);
}
return resolve();
});
});
}
function buildZip(arch) {
const filename = `Hain-${arch}-v${appPkg.version}.zip`;
return gulp.src(`./out/Hain-win32-${arch}/**/*`)
.pipe(zip(filename))
.pipe(gulp.dest('./out/'));
}
function buildInstaller(arch) {
const filename = `HainSetup-${arch}-v${appPkg.version}.exe`;
return electronInstaller.createWindowsInstaller({
appDirectory: path.resolve(`./out/hain-win32-${arch}`),
outputDirectory: `./out/${arch}`,
authors: 'Heejin Lee',
title: 'Hain',
iconUrl: 'https://raw.githubusercontent.com/appetizermonster/Hain/master/build/icon.ico',
setupIcon: path.resolve('./build/icon.ico'),
loadingGif: path.resolve('./build/installer.gif'),
skipUpdateIcon: true, // HACK to resolve rcedit error (electron-winstaller)
noMsi: true
}).then(() => {
fs.renameSync(`./out/${arch}/Setup.exe`, `./out/${filename}`);
});
}
gulp.task('build', ['renderer', 'deps'], () => {
return build('ia32')
.then(() => build('x64'));
});
gulp.task('build-zip-ia32', ['build'], () => buildZip('ia32'));
gulp.task('build-zip-x64', ['build'], () => buildZip('x64'));
gulp.task('build-zip', ['build-zip-ia32', 'build-zip-x64']);
gulp.task('build-installer', ['build', 'build-zip'], () => {
return buildInstaller('ia32')
.then(() => buildInstaller('x64'));
});
gulp.task('build-chocolatey', () => {
return gulp.src('./chocolatey/**/*')
.pipe(replace('${version}', appPkg.version))
.pipe(gulp.dest('./out/chocolatey/'));
});
gulp.task('build-all', ['build-zip', 'build-installer', 'build-chocolatey']);
gulp.task('watch', ['renderer'], () => {
const opts = {
debounceDelay: 2000
};
gulp.watch('./app/renderer-jsx/**/*', opts, ['renderer']);
});
gulp.task('default', ['renderer']);