forked from YouTransfer/YouTransfer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
175 lines (151 loc) · 5.05 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
'use strict';
// ------------------------------------------------------------------------------------------ Configuration
var paths = {
src: 'src',
dist: 'dist',
bootstrap: 'node_modules/bootstrap/dist'
};
// ------------------------------------------------------------------------------------------ Dependencies
var gulp = require('gulp');
var filter = require('gulp-filter');
var uglify = require('gulp-uglify');
var cssmin = require('gulp-cssmin');
var less = require('gulp-less');
var gutil = require('gulp-util');
var karma = require('gulp-karma');
var mocha = require('gulp-mocha');
var istanbul = require('gulp-istanbul');
var webdriver = require('gulp-webdriver');
var del = require('del');
var browserify = require('browserify');
var buffer = require('vinyl-buffer');
var source = require('vinyl-source-stream');
var vinylPaths = require('vinyl-paths');
var selenium = require('selenium-standalone');
var runSequence = require('run-sequence');
// ------------------------------------------------------------------------------------------ Tasks
gulp.task('cleanTask', cleanTask);
gulp.task('browserifyAppTask', browserifyAppTask);
gulp.task('browserifyVendorTask', browserifyVendorTask);
gulp.task('copyStaticTask', copyStaticTask);
gulp.task('lessTask', lessTask);
gulp.task('testComponentsTask', testComponentsTask);
gulp.task('testModulesTask', testModulesTask);
gulp.task('testViewsTask', ['testWebdriverTask'], testViewsTask);
gulp.task('testWebdriverTask', ['build'], testWebdriverTask);
gulp.task('testTerminationTask', testTerminationTask);
gulp.task('clean', ['cleanTask']);
gulp.task('build', ['browserifyAppTask', 'browserifyVendorTask', 'copyStaticTask', 'lessTask']);
gulp.task('dist', ['build']);
gulp.task('test', function(callback) {
runSequence('testModulesTask', 'testComponentsTask', 'testViewsTask', 'testTerminationTask', callback);
});
gulp.task('watch', ['dist'], function() {
gulp.watch([paths.src + '/**/js/**', '!**/*.less'], ['browserifyAppTask', 'browserifyVendorTask']);
gulp.watch(paths.src + '/**/*.less', ['lessTask']);
gulp.watch([paths.src + '/**/*','!**/js/**', '!**/*.less'], ['copyStaticTask']);
});
// ------------------------------------------------------------------------------------------ Task Definitions
function cleanTask() {
return gulp.src('dist/*', {read: false})
.pipe(vinylPaths(del));
}
function browserifyAppTask() {
var bundler = browserify({ entries: paths.src + '/js/index.js' });
bundler.external(require('./src/js/vendor.js'));
return browserifyTask(bundler, 'app.js');
}
function browserifyVendorTask() {
var bundler = browserify();
bundler.require(require('./src/js/vendor.js'));
return browserifyTask(bundler, 'vendor.js');
}
function browserifyTask(bundler, src) {
return bundler.bundle()
.on('error', log)
.pipe(source(src))
.pipe(buffer())
.pipe(uglify())
.pipe(gulp.dest(paths.dist + '/js'));
}
function copyStaticTask() {
gulp.src(paths.bootstrap + '/**/*', {base: paths.bootstrap})
.pipe(filter(['**/fonts/**']))
.on('error', log)
.pipe(gulp.dest(paths.dist));
return gulp.src(paths.src + '/**/*', {base: paths.src})
.pipe(filter(['**/*', '!**/js/**', '!**/css/**']))
.on('error', log)
.pipe(gulp.dest(paths.dist));
}
function lessTask() {
return gulp.src(paths.src + '/css/styles.less')
.pipe(less())
.pipe(cssmin())
.on('error', log)
.pipe(gulp.dest(paths.dist + '/css'));
}
function testModulesTask() {
return gulp.src(['./lib/*.js'])
.pipe(istanbul({includeUntested: true}))
.pipe(istanbul.hookRequire())
.on('finish', function () {
gulp.src(['./test/modules/**/*.test.js'])
.pipe(mocha({reporter: 'spec'}))
.pipe(istanbul.writeReports({
dir: './test/unit-test-coverage',
reporters: [ 'lcov' ],
reportOpts: {
dir: './test/unit-test-coverage'
}
}))
.on('error', log);
})
.on('error', log);
}
function testComponentsTask() {
return gulp.src([])
.pipe(karma({ configFile: './test/components/karma.conf.js', action: 'run'}))
.on('error', function (err) {
throw err;
});
}
function testViewsTask() {
return gulp.src('./test/views/wdio.conf.js')
.pipe(webdriver())
.on('error', log)
.on('finish', function() {
selenium.app.close();
selenium.server.kill();
});
}
function testWebdriverTask(callback) {
selenium.install({
version: '3.5.3'
}, function(err) {
if(!err) {
selenium.start({
version: '3.5.3'
}, function(err, child) {
if(!err) {
selenium.app = require('./app');
selenium.server = child;
callback();
} else {
callback(err);
}
});
} else {
callback(err);
}
});
}
// Workaround for issue with gulp WebdriverIO task not ending the browser session correctly
// This means that the test should be run stand-alone
function testTerminationTask() {
process.exit(0);
}
// ------------------------------------------------------------------------------------------ Functions
function log(err) {
gutil.log(gutil.colors.red('Error'), err.message);
}