This repository has been archived by the owner on Jun 29, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 157
/
gulpfile.babel.js
169 lines (150 loc) · 4.49 KB
/
gulpfile.babel.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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
'use strict';
const cp = require('child_process');
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 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, platform, icon) {
return new Promise((resolve, reject) => {
packager(
{
arch,
name: 'Hain',
dir: path.join(__dirname, 'app'),
platform: platform || 'win32',
asar: true,
ignore: /(renderer-jsx|__tests__)/gi,
overwrite: true,
out: path.join(__dirname, 'out'),
icon: path.join(__dirname, 'build', icon || 'icon.ico'),
'version-string': {
ProductName: 'Hain',
CompanyName: 'Heejin Lee'
}
},
(err) => {
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/'));
}
// Workaround to build zip file which is including symlinks
function buildZipUsingExec(arch, platform, filesToCompress) {
const filename = `hain-${platform}-${arch}-v${appPkg.version}.zip`;
const targetDir = `Hain-${platform}-${arch}`;
const workingDir = path.join(__dirname, 'out', targetDir);
return new Promise((resolve, reject) => {
cp.exec(
`zip --symlinks -r ../${filename} ${filesToCompress}`,
{
cwd: workingDir
},
(err, stdout, stderr) => {
if (err) {
console.log(stdout);
console.log(stderr);
return reject(err);
}
return resolve();
}
);
});
}
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/hainproject/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}`);
});
}
function buildDebianPkg() {
const electronDebianPkg = require('electron-installer-debian');
const options = {
src: 'out/hain-linux-x64/',
dest: 'out/installers/',
arch: 'amd64'
};
return new Promise((resolve, reject) => {
electronDebianPkg(options, (err) => {
if (err) {
console.log(err);
return reject(err);
}
return resolve();
});
});
}
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-debian', ['renderer'], () => {
return build('x64', 'linux').then(() => buildDebianPkg());
});
gulp.task('build-darwin', ['renderer', 'deps'], () => {
return build('x64', 'darwin', 'icon.icns').then(() =>
buildZipUsingExec('x64', 'darwin', '*.app')
);
});
gulp.task('build-installer', ['build', 'build-zip'], () => {
return buildInstaller('ia32').then(() => buildInstaller('x64'));
});
gulp.task('build-all', ['build-zip', 'build-installer']);
gulp.task('watch', ['renderer'], () => {
const opts = {
debounceDelay: 2000
};
gulp.watch('./app/renderer-jsx/**/*', opts, ['renderer']);
});
gulp.task('default', ['renderer']);