forked from tinderjs/tinder-desktop
-
Notifications
You must be signed in to change notification settings - Fork 1
/
gulpfile.js
203 lines (175 loc) · 6.77 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
var gulp = require('gulp');
var appPkg = require('./desktop-app/package.json');
var electron = require('electron-prebuilt');
var mergeStream = require('merge-stream');
var proc = require('child_process');
var removeNPMAbsolutePaths = require('removeNPMAbsolutePaths');
var runSequence = require('run-sequence');
var shelljs = require('shelljs');
var packager = require('electron-packager');
var $ = require('gulp-load-plugins')();
var buildDir = './build';
// File paths to various assets are defined here.
var PATHS = {
javascript: [
'bower_components/angular/angular.min.js',
'bower_components/angular-cookies/angular-cookies.min.js',
'bower_components/angular-route/angular-route.min.js',
'bower_components/angular-sanitize/angular-sanitize.min.js',
'bower_components/angular-translate/angular-translate.min.js',
'bower_components/angular-translate-loader-static-files/angular-translate-loader-static-files.min.js',
'bower_components/jquery/dist/jquery.min.js',
'bower_components/moment/min/moment-with-locales.min.js',
'bower_components/mousetrap/mousetrap.min.js',
'bower_components/ngAutocomplete/src/ngAutocomplete.js',
'bower_components/ng-range-slider/dist/ng-range-slider.min.js'
],
stylesheets: [
'bower_components/font-awesome/css/font-awesome.min.css'
],
fonts: [
'bower_components/font-awesome/fonts/*.{eot,svg,ttf,woff,woff2}'
]
};
// JavaScript assets handler
gulp.task('compile:scripts', function() {
shelljs.rm('-rf', './desktop-app/js/vendor');
return gulp.src(PATHS.javascript)
.pipe(gulp.dest('desktop-app/js/vendor'));
});
// Stylesheet assets handler
gulp.task('compile:stylesheets', function() {
return gulp.src(PATHS.stylesheets)
.pipe(gulp.dest('desktop-app/css'));
});
// Fonts assets handler
gulp.task('compile:fonts', function() {
return gulp.src(PATHS.fonts)
.pipe(gulp.dest('desktop-app/fonts'));
});
// Assets handler
gulp.task('compile:all', ['compile:scripts', 'compile:stylesheets',
'compile:fonts']);
// Remove build output directories
gulp.task('clean', function() {
shelljs.rm('-rf', buildDir);
shelljs.rm('-rf', './dist');
removeNPMAbsolutePaths('./desktop-app/node_modules');
});
// Build for all platforms
['darwin', 'linux', 'win32'].forEach(function(platform) {
var arch = ['ia32', 'x64'];
// Only x64 on darwin
if(platform == 'darwin') arch = ['x64'];
arch.forEach(function(arch) {
return gulp.task('build:' + platform + ':' + arch, function(callback) {
var icon = null;
if(platform == 'darwin') {
icon = './assets-osx/icon.icns';
} else if(platform == 'win32') {
icon = './assets-windows/icon.ico';
};
var opts = {
platform: platform,
arch: arch,
asar: true,
download: {
cache: './cache'
},
dir: './desktop-app',
icon: icon,
out: buildDir,
overwrite: true,
'app-version': appPkg.version
};
packager(opts, function done_callback (err, appPaths) {
if(err) { return console.log(err); }
callback();
});
});
});
});
// Package .dmg for OS X
gulp.task('pack:darwin:x64', ['build:darwin:x64'], function(callback) {
if(process.platform !== 'darwin') {
console.warn('Skipping darwin x64 packaging: must be on OS X.');
return callback();
}
shelljs.mkdir('-p', './dist/darwin');
shelljs.rm('-f', './dist/darwin/Tinder Desktop.dmg');
return gulp.src([]).pipe($.appdmg({
source: './assets-osx/dmg.json',
target: './dist/darwin/Tinder Desktop.dmg'
}));
});
// Package installer .exe for Windows
['ia32', 'x64'].forEach(function(arch) {
gulp.task('pack:win32:' + arch, function(callback) {
return gulp.src('./assets-windows/installer-script-' + arch + '.iss')
.pipe($.inno());
});
});
// Package for Linux
['ia32', 'x64'].forEach(function(arch) {
return ['deb', 'rpm'].forEach(function(target) {
return gulp.task('pack:linux:' + arch + ':' + target, function() {
var move_opt;
shelljs.rm('-rf', buildDir + '/linux');
shelljs.mkdir('-p', buildDir + '/linux');
move_opt = gulp.src(['./assets-linux/after-install.sh', './assets-linux/after-remove.sh', buildDir + '/tinder-desktop/linux' + arch + '/**']).pipe(gulp.dest(buildDir + '/linux/opt/tinder-desktop'));
return mergeStream(move_opt).on('end', function() {
var output, port;
shelljs.cd(buildDir + '/linux');
port = arch === 'ia32' ? 'i386' : 'x86_64';
output = "../../dist/linux/tinder-desktop-" + arch + "." + target;
shelljs.mkdir('-p', '../../dist/linux');
shelljs.rm('-f', output);
shelljs.exec("fpm -s dir -t " + target + " -a " + port + " --rpm-os linux -n tinder-desktop --after-install ./opt/tinder-desktop/after-install.sh --after-remove ./opt/tinder-desktop/after-remove.sh --vendor \"tinderjs\" --license ISC --category Chat --url \"https://github.com/tinderjs/tinder-desktop\" --description \"A cross-platform desktop Tinder client\" -m \"Stuart Williams <[email protected]>\" -p " + output + " -v " + appPkg.version + " .");
return shelljs.cd('../..');
});
});
});
});
// Build all platforms
gulp.task('build:all', ['clean'], function(callback) {
runSequence('build:darwin:x64', 'build:win32:all', 'build:linux:all',
callback);
});
// Build all Windows archs
gulp.task('build:win32:all', function(callback) {
runSequence('build:win32:ia32', 'build:win32:x64', callback);
});
// Build all Linux archs
gulp.task('build:linux:all', function(callback) {
runSequence('build:linux:ia32', 'build:linux:x64', callback);
});
// Build and package all Linux archs
gulp.task('pack:linux:all', ['build:linux:all'], function(callback) {
runSequence('pack:linux:ia32:deb', 'pack:linux:ia32:rpm',
'pack:linux:x64:deb', 'pack:linux:x64:rpm', callback);
})
// Build and package all Windows archs
gulp.task('pack:win32:all', ['build:win32:all'], function(callback) {
runSequence('pack:win32:ia32', 'pack:win32:x64', callback);
})
// Build and package all platforms
gulp.task('pack:all', ['compile:all'], function(callback) {
runSequence('pack:darwin:x64', 'pack:win32:all',
'pack:linux:all', callback);
});
// Run Tinder Desktop in debug mode
gulp.task('run', ['compile:all'], function(callback) {
var child = proc.spawn(electron, ['--enable-logging', '--debug=5858', './desktop-app']);
child.stdout.on('data', function(data) {
console.log('stdout: ' + data);
});
child.stderr.on('data', function(data) {
console.log('stderr: ' + data);
});
child.on('exit', function(exitCode) {
console.log('Exited with code: ' + exitCode);
return callback(exitCode === 1 ? new Error('Error running run task') : null);
});
});
// Default task is to run Tinder Desktop in debug mode
gulp.task('default', ['run']);