This repository has been archived by the owner on Apr 12, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 125
/
gulpfile.js
210 lines (195 loc) · 6.34 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
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
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
var path = require('path');
var gulp = require('gulp');
var sass = require('gulp-sass');
var process = require('process');
var gutil = require('gulp-util');
var webpack = require('webpack');
var clean = require('gulp-clean');
var packager = require('electron-packager');
var childProcess = require('child_process');
var convertNewline = require("gulp-convert-newline");
var packageInfo = require('./package.json');
var webpackConfig = require('./webpack.config.js');
var APP_NAME = packageInfo.name;
gulp.task('clean', function (callback) {
gulp.src(['./app', './build'], {read: false})
.pipe(clean());
callback();
});
gulp.task('copy', function () {
gulp.src(['./src/browser.js', './src/app.config.js', './src/*.html'])
.pipe(gulp.dest('./app'));
gulp.src(['./src/assets/*', './src/assets/*/**', '!./src/assets/scripts/*.sh'])
.pipe(gulp.dest('./app/assets'));
gulp.src(['./package.json']).pipe(gulp.dest('./app'));
gulp.src(['./node_modules/electron-sudo/src/bin/*', './node_modules/electron-sudo/src/bin/*/**'])
.pipe(gulp.dest('./app/bin'));
gulp.src('./src/assets/scripts/*.sh')
.pipe(convertNewline())
.pipe(gulp.dest('./app/assets/scripts'));
});
gulp.task('webpack', function (callback) {
webpack(webpackConfig, function (err, stats) {
if (err) {
throw new gutil.PluginError('webpack', err);
}
gutil.log('[webpack]', stats.toString({ modules: false, colors: true }));
callback();
});
});
gulp.task('sass', function () {
gulp.src('./src/sass/main.scss')
.pipe(
sass({
includePaths: [path.join(__dirname, './src/sass')],
outputStyle: 'compressed'
})
.on('error', sass.logError))
.pipe(gulp.dest('./app'));
});
gulp.task('build', ['copy', 'sass', 'webpack']);
var deleteUselessFiles = function (platform, distPath) {
var filesToBeRemoved = [];
switch (platform) {
case 'win32':
filesToBeRemoved = [
'*.html',
'LICENSE',
'version',
'pdf.dll',
'locales/*.*',
'xinput1_3.dll',
'd3dcompiler.dll',
'vccorlib120.dll',
'snapshot_blob.bin',
'd3dcompiler_47.dll',
'./resources/default_app',
'ui_resources_200_percent.pak',
'content_resources_200_percent.pak',
];
break;
case 'darwin':
filesToBeRemoved = [
'*.html',
'LICENSE',
'version',
'/' + APP_NAME + '.app/Contents/Frameworks/Electron Framework.framework/Versions/A/Resources/snapshot_blob.bin',
];
break;
case 'linux':
filesToBeRemoved = [
'*.html',
'LICENSE',
'version',
'locales/*.*',
'snapshot_blob.bin',
'./resources/default_app',
];
break;
}
filesToBeRemoved = filesToBeRemoved.map((file) => {
return path.join(distPath, file);
});
console.log('Removed unnecessary files.');
return gulp.src(filesToBeRemoved).pipe(clean());
}
var compressFiles = function (platform, distPath, callback) {
var upx = '';
var filesToBeCompressed = [];
switch (platform) {
case 'win32':
upx = path.join(__dirname, 'tools/upx.exe')
filesToBeCompressed = [
'node.dll',
'libEGL.dll',
'msvcr120.dll',
'msvcp120.dll',
'libGLESv2.dll',
APP_NAME + '.exe',
];
break;
case 'darwin':
upx = path.join(__dirname, 'tools/upx');
break;
case 'linux':
upx = path.join(__dirname, 'tools/upx-' + process.arch);
filesToBeCompressed = [
APP_NAME,
'libnode.so',
];
break;
}
console.log('Compressing executables...');
filesToBeCompressed.forEach((file) => {
var fullPath = path.join(distPath, file);
childProcess.exec(upx + ' -9 ' + fullPath, function (error, stdout, stderr) {
if (error) {
gutil.log(error);
}
gutil.log(stdout, stderr);
});
});
}
var buildPackage = function (platform, arch, callback) {
var icon;
switch (platform) {
case 'win32':
icon = './app/assets/images/icon.ico';
break;
case 'darwin':
icon = './app/assets/images/icon.icns';
break;
default:
icon = './app/assets/images/icon.png';
break;
}
packager({
arch: arch,
icon: icon,
dir: './app',
out: './build',
name: APP_NAME,
version: '0.36.2',
platform: platform,
}, function (err, appPath) {
if (appPath) {
var distPath = appPath[0];
console.log(distPath)
callback && callback(platform, arch, distPath);
}
});
}
var afterPackage = function (platform, arch, distPath) {
deleteUselessFiles(platform, distPath);
compressFiles(platform, distPath);
}
gulp.task('package', ['build'], function (callback) {
gulp.src('./app/*.map').pipe(clean());
if (process.arch !== 'ia32') {
buildPackage(process.platform, process.arch, afterPackage);
}
if (process.platform !== 'darwin') {
buildPackage(process.platform, 'ia32', afterPackage);
}
});
gulp.task('package-uncompressed', ['build'], function (callback) {
gulp.src('./app/*.map').pipe(clean());
if (process.arch !== 'ia32') {
buildPackage(process.platform, process.arch);
}
if (process.platform !== 'darwin') {
buildPackage(process.platform, 'ia32');
}
});
gulp.task('watch', ['build'], function () {
gulp.watch('./src/sass/**/*.scss', ['sass']);
gulp.watch(['./src/js/**/*.*',
'./src/app.config.js'], ['webpack']);
gulp.watch(['./src/*.html',
'./package.json',
'./src/browser.js',
'./src/assets/**/*.*',
'./src/app.config.js',
'./node_modules/electron-sudo/**'], ['copy']);
});
gulp.task('default', ['build']);