-
Notifications
You must be signed in to change notification settings - Fork 1
/
gulpfile.js
125 lines (106 loc) · 3.18 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
var gulp = require('gulp');
var clean = require('gulp-clean');
var concat = require('gulp-concat');
var uglify = require('gulp-uglify')
var rename = require('gulp-rename');
var karma = require('gulp-karma');
var coveralls = require('gulp-coveralls');
var jshint = require('gulp-jshint');
var stylish = require('jshint-stylish');
var ts = require('gulp-typescript');
var merge = require('merge2');
var browserify = require('browserify');
var source = require('vinyl-source-stream');
var buffer = require('vinyl-buffer');
var paths = {
scripts: inDirectory('src/', [
'Utilities.js',
'ThrottleMixin.js',
'EventingMixin.js',
'DashlingEnums.js',
'Dashling.js',
'Settings.js',
'ManifestParser.js',
'StreamController.js',
'Stream.js',
'RequestManager.js'
]),
testFiles: ['test/src/*.js']
};
paths.wrappedScripts = ['src/Start.js'].concat(paths.scripts, ['src/End.js']);
// Comment!
function inDirectory(dir, files) {
var newSet = [];
for (var i = 0; i < files.length; i++) {
newSet.push(dir + files[i]);
}
return newSet;
}
gulp.task('clean', function() {
gulp.src(['coverage', 'dist'])
.pipe(clean());
});
gulp.task('jshint', function() {
return gulp.src(paths.scripts)
.pipe(jshint())
.pipe(jshint.reporter(stylish))
.pipe(jshint.reporter('fail'));
});
gulp.task('typescript', ['clean'], function(cb) {
var tsResult = gulp.src('src/*.ts')
.pipe(ts({
typescript: require('typescript'),
module: 'amd',
declaration: true,
target: 'ES5'
}));
return merge([
tsResult.dts.pipe(gulp.dest('dist/amd')),
tsResult.js.pipe(gulp.dest('dist/amd'))
]);
});
gulp.task('browserify', ['typescript'], function() {
var b = browserify({
entries: './dist/amd/Dashling.js',
debug: true
});
b.require('./dist/amd/Dashling.js', { expose: 'Dashling'});
return b.bundle()
.pipe(source('dashling.js'))
.pipe(buffer())
.pipe(gulp.dest('./dist/'));
});
gulp.task('scripts', ['clean', 'jshint', 'testscripts'], function(cb) {
return gulp.src(paths.wrappedScripts)
.pipe(concat('dashling.full.js', {
newLine: '\r\n'
}))
.pipe(gulp.dest('dist'))
.pipe(uglify())
.pipe(rename('dashling.min.js'))
.pipe(gulp.dest('dist'));
});
gulp.task('testscripts', ['clean', 'jshint'], function() {
return gulp.src(paths.scripts)
.pipe(concat('dashling.test.js'))
.pipe(gulp.dest('dist'));
});
gulp.task('test', ['clean', 'scripts'], function(cb) {
return gulp.src(paths.wrappedScripts.concat(paths.testFiles))
.pipe(karma({
configFile: 'karma.config.js',
action: 'run'
}));
});
gulp.task('covertest', ['scripts', 'test'], function() {
gulp.src('coverage/**/lcov.info')
.pipe(coveralls());
});
// Rerun the task when a file changes
gulp.task('watch', function() {
gulp.watch(paths.scripts, ['scripts']);
gulp.watch(paths.testFiles, ['scripts']);
});
// gulp.task('default', ['jshint', 'scripts', 'test'], function() {
gulp.task('default', ['typescript'], function() {
});