-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
119 lines (99 loc) · 2.82 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
var gulp = require('gulp');
var ts = require('gulp-typescript');
var nodeunit = require('gulp-nodeunit');
var browserify = require('browserify');
var reactify = require('reactify');
var source = require("vinyl-source-stream");
var istanbul = require("gulp-istanbul");
var webdriver = require("gulp-webdriver");
var selenium = require('selenium-standalone');
var child_process = require("child_process");
var connect = require('connect');
var serveStatic = require('serve-static');
var http = require('http');
seleniumServer = null;
gulp.task('default', ['bundleClient']);
gulp.task('serve', ['default'], function(cb) {
var app = connect().use(serveStatic('./bin/client/static'));
appServer = http.createServer(app).listen(1337, cb);
console.log('Listening on 1337...');
});
gulp.task('webdriver', ['selenium', 'serve'], function(cb) {
var tests = gulp.src('webdriver/config.js');
var p = tests.pipe(webdriver());
p.on('error', function() {
seleniumServer.close();
appServer.close();
process.exit(1);
});
p.on('finish', function() {
seleniumServer.kill();
appServer.close();
cb();
});
});
gulp.task('selenium', function(cb) {
selenium.install({logger: console.log}, function() {
selenium.start(function(err, child) {
seleniumServer = child;
cb();
});
});
});
gulp.task('compileTS', function() {
var tsResult = gulp
.src('src/**/*.ts')
.pipe(ts({
noEmitOnError : true,
module: 'commonjs',
outDir: 'bin'
}));
return tsResult.js.pipe(gulp.dest('./bin'));
});
gulp.task('bundleClient', ['compileTS', 'move'], function() {
var b = browserify();
// USING THE REACT TRANSFORM
b.transform(reactify);
// Grab the file to build the dependency graph from
b.add('./bin/client/main.js');
b.bundle()
.on('error', function(err) {
console.error(err.message);
this.emit('end');
})
.pipe(source('main.js'))
.pipe(gulp.dest('./bin/client/static/js'));
});
gulp.task('move', ['move-component', 'move-statics']);
gulp.task('move-component', function(cb) {
// move components
var jsx = gulp.src('src/client/component/**/*')
.pipe(gulp.dest('./bin/client/component'));
jsx.on('end', function() {
cb();
});
});
gulp.task('move-statics', function() {
var vendors = gulp
.src('src/client/static/**/*');
return vendors.pipe(gulp.dest('./bin/client/static'));
});
gulp.task('pre-test', function () {
return gulp.src('bin/common/*.js')
// Covering files
.pipe(istanbul())
// Force `require` to return covered files
.pipe(istanbul.hookRequire());
});
gulp.task('test', ['pre-test'], function() {
var tests = gulp.src('bin/**/*.test.js');
tests
.pipe(nodeunit())
.on('error', function() {
process.exit(1);
})
.pipe(istanbul.writeReports())
.on('end', function() {
process.exit(0);
});
});