This repository has been archived by the owner on Dec 5, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 31
/
gulpfile.js
163 lines (138 loc) · 4.92 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
/* ---------------------------------------------------------
* Copyright (C) Microsoft Corporation. All rights reserved.
* --------------------------------------------------------*/
const gulp = require('gulp');
const fs = require('fs');
const path = require('path');
const gutil = require('gulp-util');
const log = gutil.log;
const colors = gutil.colors;
const mocha = require('gulp-mocha');
const msbuild = require('gulp-msbuild');
const argv = require('yargs').argv;
const exec = require('child_process').exec;
const gulpSequence = require('gulp-sequence');
const sources = [
'src',
'lib',
'test',
'typings'
].map(function (tsFolder) {
return tsFolder + '/**/*.ts';
});
function logExec(stdout, stderr) {
if (stdout) {
stdout.toString().trim()
.split(/\r?\n/)
.forEach((line) => {
log(line);
});
}
if (stderr) {
stderr.toString().trim()
.split(/\r?\n/)
.forEach((line) => {
log(colors.red(line));
});
}
}
function getNativeBuildOptions() {
// const target = (argv.rebuild ? 'Rebuild' : 'Build');
const config = 'Release';
const arch = process.arch === 'x64' ? 'x64' : 'Win32';
// const verbose = (argv.verbose ? '' : 'ErrorsOnly;WarningsOnly')
const outDir = 'out/native/' + config + '/' + arch + '/';
const networkOutDir = 'out/native/network/' + config + '/' + arch + '/';
const outArch = arch === 'x64' ? '64' : '';
return {
target: 'Build',
config: config,
arch: arch,
verbose: 'ErrorsOnly;WarningsOnly',
outDir: outDir,
networkOutDir: networkOutDir,
outArch: outArch
};
}
gulp.task('buildnativeproxy', function () {
const opts = getNativeBuildOptions();
return gulp.src('native/Proxy/Proxy.vcxproj', { base: '.' })
.pipe(msbuild({
targets: [opts.target],
configuration: opts.config,
properties: { Platform: opts.arch },
stdout: true,
stderr: true,
logCommand: true,
toolsVersion: 14,
consoleLoggerParameters: opts.verbose
}));
});
gulp.task('buildnativenetworkproxy', function () {
const opts = getNativeBuildOptions();
return gulp.src('native/NetworkProxy/NetworkProxy.vcxproj', { base: '.' })
.pipe(msbuild({
targets: [opts.target],
configuration: opts.config,
properties: { Platform: opts.arch },
stdout: true,
stderr: true,
logCommand: true,
toolsVersion: 14,
consoleLoggerParameters: opts.verbose
}));
});
gulp.task('buildnativeprojects', ['buildnativeproxy', 'buildnativenetworkproxy']);
gulp.task('buildnativeaddon', ['buildnativeprojects'], function (done) {
const opts = getNativeBuildOptions();
const arch = opts.arch === 'Win32' ? 'ia32' : 'x64';
const gypPath = path.join(__dirname, '/node_modules/.bin/node-gyp');
return exec('cd native/Addon && ' + gypPath + ' clean configure build --arch=' + arch, function (err, stdout, stderr) {
logExec(stdout);
logExec(stderr); // node-gyp sends info through stderr and we don't want to treat it as error
done(err);
});
});
gulp.task('buildnative', gulpSequence(['buildnativeaddon'], ['copyproxy', 'copynetworkproxy']));
gulp.task('copyproxy', function () {
const opts = getNativeBuildOptions();
return gulp.src([
opts.outDir + 'Proxy.dll',
opts.outDir + 'Proxy.pdb'
])
.pipe(gulp.dest('out/lib'));
});
gulp.task('copynetworkproxy', function () {
const opts = getNativeBuildOptions();
return gulp.src(
[
opts.networkOutDir + 'NetworkProxy.exe',
opts.networkOutDir + 'NetworkProxy.pdb'
])
.pipe(gulp.dest('out/lib'));
});
gulp.task('default', ['buildnative']);
function test() {
return gulp.src('out/test/**/*.test.js', { read: false })
.pipe(mocha({ ui: 'tdd' }))
.on('error', function (e) {
log(e ? e.toString() : 'error in test task!');
this.emit('end'); // eslint-disable-line no-invalid-this
});
}
gulp.task('build-test', ['build'], test);
gulp.task('test', test);
gulp.task('watch-build-test', ['build', 'build-test'], function () {
return gulp.watch(sources, ['build', 'build-test']);
});
gulp.task('copypasta', function (done) {
// Recursively copy out folder to another folder
if (!argv.outDir || !fs.existsSync(argv.outDir)) { // eslint-disable-line no-sync
log(colors.red('Usage: gulp copypasta --outDir <path>'));
return;
}
exec(`xcopy out ${argv.outDir} /S /Y /D`, function (err, stdout, stderr) {
logExec(stdout, stderr);
done(err);
});
});