-
Notifications
You must be signed in to change notification settings - Fork 1
/
gulpfile.js
99 lines (78 loc) · 2.65 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
"use strict";
var gulp = require('gulp');
var $ = require('gulp-load-plugins')();
var browserify = require('browserify');
var del = require('del');
var glob = require('glob');
var assign = require('lodash.assign');
var buffer = require('vinyl-buffer');
var source = require('vinyl-source-stream');
var watchify = require('watchify');
// Load tasks for web-component-tester
// Adds tasks for `gulp test:local` and `gulp test:remote`
require('web-component-tester').gulp.init(gulp, ['build-test']);
gulp.task('clean', function() {
del(['dist', 'test/build']);
});
gulp.task('lint', function() {
return gulp.src(['./src/**/*.js'])
.pipe($.jshint())
.pipe($.jshint.reporter('default'))
.pipe($.jshint.reporter('fail'));
});
gulp.task('lint-tc', function() {
return gulp.src(['./src/**/*.js', '!./src/polyfills.js'])
.pipe($.jshint())
.pipe($.jshint.reporter('default'))
.pipe($.jshint.reporter('fail'));
});
var testBundler = browserify(assign({}, watchify.args, {
entries: glob.sync('./test/src/**/test-*.js'),
debug: true
}));
function rebundleTest(bundler) {
return bundler
.bundle()
.on('error', $.util.log.bind($.util, 'Browserify Error'))
.pipe(source('test-bundle.js'))
.pipe(gulp.dest('./test/build'))
}
gulp.task('build-test', function() {
return rebundleTest(testBundler);
});
//add 'test' task when tests are fixed
gulp.task('verify', ['lint', 'test']);
gulp.task('test', ['build-test', 'test:local']);
var mainBundler = browserify(assign({}, watchify.args, {
entries: './src/dolphin-polymer-api.js',
standalone: 'dolphin',
debug: true
}));
function rebundle(bundler) {
return bundler
.on('prebundle', function(bundle) {
bundle.external('./polyfills.js');
})
.bundle()
.on('error', $.util.log.bind($.util, 'Browserify Error'))
.pipe(source('dolphin-platform-polymer.js'))
.pipe($.derequire())
.pipe(gulp.dest('./dist'))
.pipe(buffer())
.pipe($.rename({extname: '.min.js'}))
.pipe($.sourcemaps.init({loadMaps: true}))
.pipe($.uglify())
.pipe($.sourcemaps.write('./'))
.pipe(gulp.dest('./dist'));
}
gulp.task('build', function() {
return rebundle(mainBundler);
});
gulp.task('watch', function() {
gulp.watch(['src/**'], ['lint']);
var watchedMainBundler = watchify(mainBundler);
watchedMainBundler.on('update', function() {rebundle(watchedMainBundler)});
var watchedTestBundler = watchify(testBundler);
watchedTestBundler.on('update', function() {rebundle(watchedTestBundler)});
});
gulp.task('default', ['verify', 'build']);