forked from strawdynamics/drift
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
97 lines (81 loc) · 2.61 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
const gulp = require('gulp');
const browserify = require('browserify');
const babelify = require('babelify');
const concat = require('gulp-concat');
const rename = require('gulp-rename');
const uglify = require('gulp-uglify');
const gutil = require('gulp-util');
const source = require('vinyl-source-stream');
const buffer = require('vinyl-buffer');
const Server = require('karma').Server;
const cssnano = require('gulp-cssnano');
const runSequence = require('run-sequence');
const karmaConfig = require('./karmaConfig');
const Config = require('karma/lib/config').Config;
const paths = {
test: __dirname + '/test/**/*.js',
js: __dirname + '/src/js/**/*.js',
jsEntry: __dirname + '/src/js/Drift.js',
css: __dirname + '/src/css/**/*.css'
};
function runKarmaTests(configObj, done, singleRun) {
var config = new Config();
config.set(configObj);
if (singleRun !== null) {
config.singleRun = singleRun;
}
new Server(config, function(exitCode) {
if (exitCode !== 0) {
throw new gutil.PluginError({plugin: 'karma', message: 'Karma tests failed'});
}
done();
}).start();
}
gulp.task('default', ['build', 'test-headless']);
gulp.task('build', ['build-js', 'build-css']);
// When actually setting up CI stuff, this will need to run in sequence.
// https://www.npmjs.com/package/run-sequence
gulp.task('build-ci', function() {
runSequence(['build', 'test-headless']);
});
gulp.task('test-local', function(done) {
runKarmaTests(karmaConfig.local, done, true);
});
gulp.task('test-headless', function(done) {
runKarmaTests(karmaConfig.headless, done, true);
});
gulp.task('test-full', function(done) {
if (!process.env.SAUCE_USERNAME || !process.env.SAUCE_ACCESS_KEY) {
throw new gutil.PluginError({
plugin: 'test-full',
message: 'Unable to run full tests. Please make sure both SAUCE_USERNAME and SAUCE_ACCESS_KEY are defined in the environment.'
});
}
runKarmaTests(karmaConfig.full, done, true);
});
gulp.task('build-js', function() {
var b = browserify({
standalone: 'Drift',
entries: paths.jsEntry,
transform: [babelify]
}).bundle();
return b.pipe(source('Drift.js'))
.pipe(buffer())
.pipe(gulp.dest('dist'))
.pipe(uglify())
.pipe(rename({ suffix: '.min' }))
.pipe(gulp.dest('dist'));
});
gulp.task('build-css', function() {
return gulp.src(paths.css)
.pipe(gulp.dest('dist'))
.pipe(cssnano())
.pipe(rename({ suffix: '.min' }))
.pipe(gulp.dest('dist'))
});
gulp.task('watch', function() {
gulp.watch([paths.js, paths.test], function() {
runSequence(['build-js', 'test-headless']);
});
gulp.watch(paths.css, ['build-css']);
});