This repository was archived by the owner on Mar 22, 2024. It is now read-only.
Repository navigation
Expand file tree
/
Copy pathgulpfile.js
More file actions
109 lines (91 loc) · 2.91 KB
/
Copy pathgulpfile.js
File metadata and controls
109 lines (91 loc) · 2.91 KB
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
var gulp = require('gulp');
var $ = require('gulp-load-plugins')();
var spawn = require('child_process').spawn;
var path = require('path');
var SMTPServer = require('smtp-server').SMTPServer;
var config = require('./config.js');
var ts = $.typescript;
var tsProject = ts.createProject(config.tsConfigFile);
var server = null;
var smtpServer = null;
var failOnErrors = false;
$.del = require('del');
$.ts = $.typescript;
var handleError = function(err) {
if (failOnErrors) {
$.util.log(err.message);
process.exit(1);
}
}
gulp.task('clean-js', function(cb) {
$.del(config.tsOutDir, cb);
});
gulp.task('transpile-ts2js', ['clean-js'], function () {
return tsProject.src()
.pipe($.ts(tsProject))
.on('error', handleError)
.js
.pipe(gulp.dest(config.tsOutDir));
});
gulp.task('restart-smtp-server', function(cb) {
var smtpOpts = {
disabledCommands: ['STARTTLS'],
logger: false,
onAuth: function (auth, session, callback) {
if (auth.username !== config.smtp.user ||
auth.password !== config.smtp.pass) {
return callback(new Error('Invalid username or password'));
}
callback(null, {user: config.smtp.user});
},
onData: function (stream, session, callback) {
stream.pipe(process.stdout);
stream.on('end', callback);
},
};
if (smtpServer) {
smtpServer.close(function() {
smtpServer = new SMTPServer(smtpOpts);
smtpServer.listen(config.smtp.port, cb);
});
} else {
smtpServer = new SMTPServer(smtpOpts);
smtpServer.listen(config.smtp.port, cb);
}
});
gulp.task('restart-app-server', ['transpile-ts2js'], function() {
if (server) server.kill()
return server = spawn('node', [config.initFilePath], {stdio: 'inherit'});
});
gulp.task('restart-servers', ['restart-app-server', 'restart-smtp-server']);
gulp.task('unit-tests', ['transpile-ts2js'], function() {
return gulp.src(config.testFiles)
.pipe($.jasmine())
.on('error', handleError);
});
gulp.task('integration-test-stg0', ['transpile-ts2js'], function() {
return gulp.src(config.integrationFiles.stg0)
.pipe($.jasmine())
.on('error', handleError);
});
gulp.task('integration-test-stg1', ['integration-test-stg0',
'transpile-ts2js'], function() {
return gulp.src(config.integrationFiles.stg1)
.pipe($.jasmine())
.on('error', handleError);
});
gulp.task('integration-tests', ['integration-test-stg0',
'integration-test-stg1']);
gulp.task('default', ['unit-tests', 'restart-servers'], function() {
var files = [config.tsFilesGlob, config.tsConfigFile];
gulp.watch(files, ['unit-tests', 'restart-servers']);
});
gulp.task('test', function() {
failOnErrors = true;
gulp.start(['unit-tests']);
});
gulp.task('integrate', function() {
failOnErrors = true;
gulp.start(['integration-tests']);
});
gulp.task('build', ['test']);