-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
148 lines (123 loc) · 3.81 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
var gulp = require('gulp');
var sourcemaps = require('gulp-sourcemaps');
var source = require('vinyl-source-stream');
var buffer = require('vinyl-buffer');
var browserify = require('browserify');
var watchify = require('watchify');
var babelify = require('babelify');
var uglify = require('gulp-uglify');
var del = require('del');
var htmlmin = require('gulp-htmlmin');
var Server = require('karma').Server;
var isparta = require('isparta');
var istanbul = require('istanbul');
var browserifyIstanbul = require('browserify-istanbul');
function compile(watch) {
var bundler = watchify(browserify({
entries: 'src/ng-on-http-stable.js',
debug: true
}).transform(babelify));
function rebundle() {
bundler.bundle()
.on('error', function (err) {
console.error(err);
this.emit('end');
})
.pipe(source('ng-on-http-stable.js'))
.pipe(buffer())
.pipe(uglify())
.pipe(sourcemaps.init({ loadMaps: true }))
.pipe(sourcemaps.write('./'))
.pipe(gulp.dest('./dist'));
}
if (watch) {
bundler.on('update', function () {
console.log('-> bundling...');
rebundle();
});
}
rebundle();
}
function watch() {
return compile(true);
}
function clean() {
return del(['dist/**/*']);
}
function test(done) {
var options = {
basePath: process.cwd(),
// enable / disable watching file and executing tests whenever any file changes
autoWatch: true,
// testing framework to use (jasmine/mocha/qunit/...)
frameworks: ['jasmine', 'browserify'],
// reporters
reporters: ['mocha', 'coverage'],
// list of files / patterns to load in the browser
files: [
{ pattern: 'node_modules/angular/angular.js'},
{ pattern: 'node_modules/angular-mocks/angular-mocks.js'},
{ pattern: 'src/**/*.js'},
{ pattern: 'tests/**/*.js'}
],
preprocessors: {
'src/**/*.js': ['browserify'],
'tests/**/*.js': ['browserify']
},
browserify: {
debug: true,
transform: [
babelify,
browserifyIstanbul({
instrumenter: isparta,
instrumenterConfig: {
noCompact: true
}
})
]
},
coverageReporter: {
dir: 'reports',
reporters: [{ type: 'html', subdir: 'html' }]
},
proxies: {},
// list of files / patterns to exclude
exclude: [],
// web server port
port: 8080,
captureTimeout: 20000,
// Start these browsers, currently available:
// - Chrome
// - ChromeCanary
// - Firefox
// - Opera
// - Safari (only Mac)
// - PhantomJS
// - IE (only Windows)
browsers: [
'PhantomJS2'
],
// Which plugins to enable
plugins: [
'karma-jasmine',
'karma-phantomjs2-launcher',
'karma-chrome-launcher',
'karma-coverage',
'karma-browserify',
'karma-mocha-reporter'
],
// Continuous Integration mode
// if true, it capture browsers, run tests and exit
singleRun: true,
colors: true,
// logLevel: 'LOG_DEBUG'
};
return new Server(options, function (exitStatus) {
exitStatus ? process.exit(0) : done && done();
}).start();
}
gulp.task('clean', clean);
gulp.task('build', function () { return compile(); });
gulp.task('watch', function () { return watch(); });
gulp.task('default', ['watch']);
gulp.task('test', function (done) { return test(done); });