This repository has been archived by the owner on Sep 8, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 257
/
gulpfile.js
196 lines (172 loc) · 5.59 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
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
var fs = require('fs');
var gulp = require('gulp');
var Server = require('karma').Server;
var concat = require('gulp-concat');
var jshint = require('gulp-jshint');
var header = require('gulp-header');
var footer = require('gulp-footer');
var rename = require('gulp-rename');
var es = require('event-stream');
var del = require('del');
var uglify = require('gulp-uglify');
var plumber = require('gulp-plumber');//To prevent pipe breaking caused by errors at 'watch'
var git = require('gulp-git');
var bump = require('gulp-bump');
var runSequence = require('run-sequence');
var geSaLaKaCuLa = require('gesalakacula');
var reKaLa = geSaLaKaCuLa.recursiveKarmaLauncher;
var connect = require('gulp-connect');
var angularProtractor = require('gulp-angular-protractor');
var sauceConnectLauncher = require('sauce-connect-launcher');
var versionAfterBump, sauceConnectProcess;
gulp.task('default', ['build', 'test']);
gulp.task('build', ['scripts']);
gulp.task('test', ['build', 'protractor', 'karma']);
gulp.task('ci', ['protractor-sauce','karma-sauce'], function() {
closeSauceConnect();
});
gulp.task('watch', ['build', 'karma-watch'], function() {
gulp.watch(['src/**/*.{js,html}'], ['build']);
});
gulp.task('clean', function(cb) {
del(['dist'], cb);
});
gulp.task('scripts', ['clean'], function() {
var buildLib = function() {
return gulp.src(['src/*.js'])
.pipe(plumber({
errorHandler: handleError
}))
.pipe(header('(function () { \n\'use strict\';\n'))
.pipe(footer('\n}());'))
.pipe(jshint())
.pipe(jshint.reporter('jshint-stylish'))
.pipe(jshint.reporter('fail'));
};
var config = {
pkg: JSON.parse(fs.readFileSync('./package.json')),
banner:
'/*!\n' +
' * <%= pkg.name %>\n' +
' * <%= pkg.homepage %>\n' +
' * Version: <%= pkg.version %> - <%= timestamp %>\n' +
' * License: <%= pkg.license %>\n' +
' */\n\n\n'
};
return es.merge(buildLib())
.pipe(plumber({
errorHandler: handleError
}))
.pipe(concat('mask.js'))
.pipe(header(config.banner, {
timestamp: (new Date()).toISOString(), pkg: config.pkg
}))
.pipe(gulp.dest('dist'))
.pipe(uglify({preserveComments: 'some'}))
.pipe(rename({extname: '.min.js'}))
.pipe(gulp.dest('dist'));
});
gulp.task('karma', ['build'], function(callback) {
runKarma(true, callback);
});
gulp.task('karma-watch', ['build'], function(callback) {
runKarma(false, callback);
});
function runKarma(singleRun, callback) {
var server = new Server({configFile: __dirname + '/karma.conf.js', singleRun: singleRun}, function(exitCode) {
callback();
});
server.start();
}
gulp.task('start-sauce-connect', function(callback) {
sauceConnectLauncher({
username: process.env.SAUCE_USERNAME,
accessKey: process.env.SAUCE_ACCESS_KEY,
tunnelIdentifier: process.env.TRAVIS_JOB_NUMBER
}, function(err, sauceProcess) {
if (err) {
callback(err);
}
sauceConnectProcess = sauceProcess;
callback();
});
});
function closeSauceConnect() {
sauceConnectProcess.close(function() {
console.log("Closed Sauce Connect process");
});
}
gulp.task('karma-sauce', ['build', 'start-sauce-connect'], function(callback) {
var customLaunchers = geSaLaKaCuLa({
'Windows 7': {
'internet explorer': '10..11'
},
'Windows 10': {
'MicrosoftEdge': '13'
},
'OS X 10.10': {
'chrome': '43..44',
'firefox': '39..40',
'safari': '8'
}
});
reKaLa({
karma: Server,
customLaunchers: customLaunchers
}, function(code) {
if (code) {
closeSauceConnect();
}
callback(code);
});
});
gulp.task('protractor', ['build'], function(callback) {
runProtractor('protractor.config.js', callback);
});
gulp.task('protractor-sauce', ['build', 'start-sauce-connect'], function(callback) {
runProtractor('protractor.travis.config.js', callback);
});
var runProtractor = function(configFile, callback) {
connect.server({
port: 8000
});
gulp.src(['test/maskSpec.protractor.js'])
.pipe(angularProtractor({
'configFile': configFile,
'debug': false,
'autoStartStopServer': true
}))
.on('error', function(e) {
closeSauceConnect();
callback(e);
})
.on('end', function() {
connect.serverClose();
callback();
});
};
var handleError = function(err) {
console.log(err.toString());
this.emit('end');
};
gulp.task('release:bump', function() {
var type = process.argv[3] ? process.argv[3].substr(2) : 'patch';
return gulp.src(['./package.json'])
.pipe(bump({type: type}))
.pipe(gulp.dest('./'))
.on('end', function() {
versionAfterBump = require('./package.json').version;
});
});
gulp.task('release:rebuild', function(cb) {
runSequence('release:bump', 'build', cb); // bump will here be executed before build
});
gulp.task('release:commit', ['release:rebuild'], function() {
return gulp.src(['./package.json', 'dist/**/*'])
.pipe(git.add())
.pipe(git.commit(versionAfterBump));
});
gulp.task('release:tag', ['release:commit'], function() {
git.tag(versionAfterBump, versionAfterBump);
});
gulp.task('release', ['release:tag']);