-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
executable file
·352 lines (328 loc) · 11.8 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
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
'use strict';
var gulp = require('gulp');
var sequence = require('gulp-sequence');
var clean = require('gulp-clean');
var fs = require('fs-extra');
var argv = require('yargs')
.option('platform', {
alias: 'p',
describe: 'choose a platform',
choices: ['mac', 'darwin', 'windows','win', 'win32', 'win64', 'linux'],
default: 'darwin'
})
.argv;
var path = require('path');
var packager = require('electron-packager');
var builder = require('electron-builder');
var packageJSON = require('./package.json');
var config = require('./config.js');
var CURRENT_ENVIRONMENT = 'development';
var finalAppPaths = [];
var childProcess = require('child_process');
gulp.task('cleanup:build', function() {
var osInfo = getOSInfo();
var arch = osInfo.arch;
var platform = osInfo.platform;
var src = './build/' + config.PACKAGE.PRODUCTNAME + '-' + platform + '-' + arch;
src = './build';
return gulp
.src([src], {
read: false
})
.pipe(clean());
});
gulp.task('package', function(done) {
//var devDependencies = packageJSON.devDependencies;
//var devDependenciesKeys = Object.keys(devDependencies);
var ignoreFiles = [
'dist',
'script',
'notice.txt',
'gulpfile.js',
'builder.json',
'gruntfile.js',
'.npminstall',
'index1.html',
'配置说明.txt',
'desktop_setup.iss',
'screencapture.node_debug',
'screencapture.node_pkg',
'.vscode',
'.gitignore',
// 'node_modules/.bin',
'.gitignore',
'platforms',
'ronglib'
];
var supportPlatforms = ['darwin', 'win32', 'linux'];
var osInfo = getOSInfo();
var arch = osInfo.arch;
var platform = osInfo.platform;
// We will keep all stuffs in dist/ instead of src/ for production
var iconFolderPath = './res';
var iconPath;
var productName = config.PACKAGE.PRODUCTNAME;
productName += '-' + platform + '-' + arch;
if (platform === 'darwin') {
iconPath = path.join(iconFolderPath, config.PACKAGE.MAC.APPICON);
}
else {
iconPath = path.join(iconFolderPath, config.PACKAGE.WIN.APPICON);
}
supportPlatforms.forEach(function(_platform) {
if(_platform !== platform){
ignoreFiles.push('modules/screenshot' + _platform);
}
});
var ignorePath = ignoreFiles.join('|');
var ignoreRegexp = new RegExp(ignorePath);
// var unpackRegexp = new RegExp(['screenshot.framework','RongIMLib.node'], 'ig');
// var unpackRegexp = new RegExp(['*.node'], 'ig');
packager({
'dir': './',
//'name': config.PACKAGE.PRODUCTNAME,
'name': config.PACKAGE.APPNAME,
'platform': platform,
'asar': false,
//'asar' : {
//'unpack': 'modules/screenshot/*',
//'unpackDir': 'modules/screenshot/'
//},
'arch': arch,
'electronVersion': config.PACKAGE.RUNTIMEVERSION,
'out': './build',
'icon': iconPath,
'appBundleId': config.APP_ID, // OS X only
'appVersion': config.PACKAGE.VERSION,
//'build-version': config.MAC.CF_BUNDLE_VERSION,
//'helper-bundle-id': config.MAC.HELPER_BUNDLE_ID, // OS X only
'ignore': ignoreRegexp,
'overwrite': true,
'packageManager': 'npm',
'prune': true,
'appCopyright': config.PACKAGE.COPYRIGHT,
'osxSign': {
'identity': 'Developer ID Application: Beijing Rong Cloud Network Technology CO., LTD (CQJSB93Y3D)'
},
//'extendInfo': './assets/info.plist'
// 'all': true,
'protocols': [{
name: config.PROTOCAL,
schemes: [config.PROTOCAL]
}],
'win32metadata': {
'CompanyName': config.PACKAGE.AUTHOR,
'FileDescription': config.PACKAGE.DESCRIPTION,
'OriginalFilename': 'atom.exe',
'ProductName': config.PACKAGE.PRODUCTNAME,
'InternalName': config.PACKAGE.PRODUCTNAME
}
//'required': {
//'darwin': darwinResources
//}
}, function(error, appPaths) {
if (error) {
console.log(error);
process.exit(1);
}
else {
// TODO
// we should support to build all platforms at once later !
// something like [ 'build/Kaku-darwin-x64' ]
finalAppPaths = appPaths;
done();
}
});
});
gulp.task('post-package', function(done) {
var currentLicenseFile = path.join(__dirname, 'LICENSE');
var promises = finalAppPaths.map(function(appPath) {
var targetLicenseFile = path.join(appPath, 'LICENSE');
var promise = new Promise(function(resolve, reject) {
fs.copy(currentLicenseFile, targetLicenseFile, function(error) {
if (error) {
reject(error);
}
else {
resolve();
}
});
});
return promise;
});
Promise.all(promises).then(function() {
done();
}).catch(function(error) {
console.log(error)
process.exit(1);
});
});
gulp.task('build', function(callback) {
var osInfo = getOSInfo();
var tasks = [
'cleanup:build',
'package',
'post-package'
];
// if(osInfo.platform == 'darwin'){
// tasks.push('zip')
// }
sequence(
tasks
)(callback);
});
function getOSInfo(){
var arch = process.arch || 'ia32';
var platform = argv.platform || process.platform;
platform = platform.toLowerCase();
// platform = argv.p;
switch (platform) {
case 'mac':
case 'darwin':
platform = 'darwin';
arch = 'x64';
break;
case 'freebsd':
case 'linux':
platform = 'linux';
break;
case 'linux32':
platform = 'linux';
arch = 'ia32';
break;
case 'linux64':
platform = 'linux';
arch = 'x64';
break;
case 'win':
case 'win32':
case 'windows':
platform = 'win32';
arch = 'ia32';
break;
case 'win64':
platform = 'win32';
arch = 'x64';
break;
default:
console.log('We don\'t support your platform ' + platform);
process.exit(1);
break;
}
return {platform:platform, arch:arch};
}
//未用
function installerMac () {
return new Promise((resolve, reject) => {
console.log('begin make installerMac')
var cmd = 'rm -rf ./dist/osx/SealTalk_Ent.dmg && electron-builder \"build/SealTalk_Ent-darwin-x64/SealTalk_Ent.app\" --platform=osx --out=\"dist/osx\" --config=builder.json --overwrite'
childProcess.exec(cmd, (error, stdout, stderr) => {
if (error) {
reject('installerMac failed' + error)
} else {
resolve()
}
})
})
}
//未用
gulp.task('installerMac', function (cb) {
var cmd = 'rm -rf ./dist/osx/SealTalk_Ent.dmg && electron-builder \"build/SealTalk_Ent-darwin-x64/SealTalk_Ent.app\" --platform=osx --out=\"dist/osx\" --config=builder.json --overwrite'
childProcess.exec(cmd, (err, stdout, stderr) => {
console.log(stdout);
console.log(stderr);
cb(err);
});
})
gulp.task('copyScreencapture', function (cb) {
var osInfo = getOSInfo();
var arch = osInfo.arch;
var platform = osInfo.platform;
var targetPlatform = path.join(__dirname, 'build', config.PACKAGE.PRODUCTNAME + '-' + platform + '-' + arch);
targetPlatform = path.join(targetPlatform, config.PACKAGE.PRODUCTNAME + '.app', 'Contents', 'Resources', 'app', 'node_modules', 'screencapture.node');
var currentPlatform = path.join(__dirname, 'node_modules', 'screencapture.node');
fs.copy(currentPlatform, targetPlatform, function(error) {
if (error) {
console.log(error);
}
else {
console.log('copy screencapture finished');
}
});
})
gulp.task('copyPlatforms', function (cb) {
var osInfo = getOSInfo();
var arch = osInfo.arch;
var platform = osInfo.platform;
var currentPlatform;
var targetPlatform = path.join(__dirname, 'build', config.PACKAGE.PRODUCTNAME + '-' + platform + '-' + arch);
if(platform == 'darwin'){
currentPlatform = path.join(__dirname, 'modules', 'screenshot', 'darwin', 'platforms');
targetPlatform = path.join(targetPlatform, config.PACKAGE.PRODUCTNAME + '.app', 'Contents', 'MacOS', 'platforms');
} else if(platform == 'win32'){
currentPlatform = path.join(__dirname, 'modules', 'screenshot', 'win32', 'platforms');
targetPlatform = path.join(targetPlatform, 'platforms');
}
fs.copy(currentPlatform, targetPlatform, function(error) {
if (error) {
console.log(error);
}
else {
console.log('copy platforms finished');
}
});
})
gulp.task('copyLib', function (cb) {
var osInfo = getOSInfo();
var arch = osInfo.arch;
var platform = osInfo.platform;
var currentPlatform;
var targetPlatform = path.join(__dirname, 'build', config.PACKAGE.PRODUCTNAME + '-' + platform + '-' + arch);
if(platform == 'darwin'){
currentPlatform = path.join(__dirname, 'modules', 'screenshot', 'darwin', 'ronglib');
targetPlatform = path.join(targetPlatform, config.PACKAGE.PRODUCTNAME + '.app', 'Contents', 'Resources', 'ronglib');
} else if(platform == 'win32'){
currentPlatform = path.join(__dirname, 'modules', 'screenshot', 'win32', 'ronglib');
}
fs.copy(currentPlatform, targetPlatform, function(error) {
if (error) {
console.log(error);
}
else {
console.log('copy ronglib finished');
}
});
})
gulp.task('modifylibPath', function(callback) {
var osInfo = getOSInfo();
var arch = osInfo.arch;
var platform = osInfo.platform;
var basePath = '';
if(platform == 'darwin'){
basePath = path.join(__dirname, 'build', config.PACKAGE.PRODUCTNAME + '-' + platform + '-' + arch,
config.PACKAGE.PRODUCTNAME + '.app', 'Contents', 'Resources', 'app', 'modules', 'screenshot', platform, 'screencapture.node');
}
childProcess.spawnSync('install_name_tool', ['-change', './modules/screenshot/darwin/lib/QtCore', '@executable_path/../Resources/app/modules/screenshot/darwin/lib/QtCore', basePath])
childProcess.spawnSync('install_name_tool', ['-change', './modules/screenshot/darwin/lib/QtGui', '@executable_path/../Resources/app/modules/screenshot/darwin/lib/QtGui', basePath])
childProcess.spawnSync('install_name_tool', ['-change', './modules/screenshot/darwin/lib/QtWidgets', '@executable_path/../Resources/app/modules/screenshot/darwin/lib/QtWidgets', basePath])
childProcess.spawnSync('install_name_tool', ['-change', './modules/screenshot/darwin/lib/QtDBus', '@executable_path/../Resources/app/modules/screenshot/darwin/lib/QtDBus', basePath])
childProcess.spawnSync('install_name_tool', ['-change', './modules/screenshot/darwin/lib/QtPrintSupport', '@executable_path/../Resources/app/modules/screenshot/darwin/lib/QtPrintSupport', basePath])
childProcess.spawnSync('install_name_tool', ['-change', './modules/screenshot/darwin/lib/QtMacExtras', '@executable_path/../Resources/app/modules/screenshot/darwin/lib/QtMacExtras', basePath])
childProcess.spawnSync('otool', ['-L', basePath])
});
gulp.task('modifylibPathDebug', function(callback) {
var osInfo = getOSInfo();
var arch = osInfo.arch;
var platform = osInfo.platform;
var basePath = '';
if(platform == 'darwin'){
basePath = path.join(__dirname, 'modules', 'screenshot', platform, 'screencapture.node');
}
childProcess.spawnSync('install_name_tool', ['-change', './dynamiclibrary/darwin/lib/QtCore', './modules/screenshot/darwin/lib/QtCore', basePath])
childProcess.spawnSync('install_name_tool', ['-change', './dynamiclibrary/darwin/lib/QtGui', './modules/screenshot/darwin/lib/QtGui', basePath])
childProcess.spawnSync('install_name_tool', ['-change', './dynamiclibrary/darwin/lib/QtWidgets', './modules/screenshot/darwin/lib/QtWidgets', basePath])
childProcess.spawnSync('install_name_tool', ['-change', './dynamiclibrary/darwin/lib/QtDBus', './modules/screenshot/darwin/lib/QtDBus', basePath])
childProcess.spawnSync('install_name_tool', ['-change', './dynamiclibrary/darwin/lib/QtPrintSupport', './modules/screenshot/darwin/lib/QtPrintSupport', basePath])
childProcess.spawnSync('install_name_tool', ['-change', './dynamiclibrary/darwin/lib/QtMacExtras', './modules/screenshot/darwin/lib/QtMacExtras', basePath])
childProcess.spawnSync('otool', ['-L', basePath])
});