forked from slively/ng-context-menu
-
Notifications
You must be signed in to change notification settings - Fork 3
/
gulpfile.js
119 lines (103 loc) · 3.08 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
var gulp = require('gulp'),
concat = require('gulp-concat'),
uglify = require('gulp-uglify'),
jshint = require('gulp-jshint'),
rename = require('gulp-rename'),
connect = require('gulp-connect'),
protractor = require("gulp-protractor").protractor,
program = require('commander'),
stylish = require('jshint-stylish'),
path = require('path'),
child_process = require('child_process'),
debug = false,
WATCH_MODE = 'watch',
RUN_MODE = 'run';
var mode = RUN_MODE;
function list(val) {
return val.split(',');
}
function getProtractorBinary(binaryName){
var winExt = /^win/.test(process.platform)? '.cmd' : '';
var pkgPath = require.resolve('protractor');
var protractorDir = path.resolve(path.join(path.dirname(pkgPath), '..', 'bin'));
return path.join(protractorDir, '/'+binaryName+winExt);
}
program
.version('0.0.1')
.option('-t, --tests [glob]', 'Specify which tests to run')
.option('-b, --browsers <items>', 'Specify which browsers to run on', list)
.option('-r, --reporters <items>', 'Specify which reporters to use', list)
.option('-p, --port [port]', 'Specify which port to use', 8080)
.parse(process.argv);
gulp.task('lint', function () {
gulp.src('src/**/*.js')
.pipe(jshint('.jshintrc'))
.pipe(jshint.reporter(stylish));
});
gulp.task('js', function() {
var jsTask = gulp.src('src/**/*.js')
.pipe(concat('ng-context-menu.js'))
.pipe(gulp.dest('dist'));
if (!debug) {
jsTask.pipe(uglify());
}
jsTask
.pipe(rename('ng-context-menu.min.js'))
.pipe(gulp.dest('dist'))
.pipe(connect.reload());
});
gulp.task('connect', function() {
if (mode === WATCH_MODE) {
gulp.watch(['index.html'], function() {
gulp.src(['index.html'])
.pipe(connect.reload());
});
}
connect.server({
livereload: mode === WATCH_MODE,
port: program.port
});
});
gulp.task('protractor-install', function(done){
child_process.spawn(getProtractorBinary('webdriver-manager'), ['update'], {
stdio: 'inherit'
}).once('close', done);
});
gulp.task('protractor', function(done) {
gulp.src(["./src/tests/*.js"])
.pipe(protractor({
configFile: 'protractor.conf.js',
args: [
'--baseUrl', 'http://127.0.0.1:' + program.port,
'--browser', program.browsers ? program.browsers[0] : 'chrome'
]
}))
.on('end', function() {
if (mode === RUN_MODE) {
connect.serverClose();
}
done();
})
.on('error', function() {
if (mode === RUN_MODE) {
connect.serverClose();
}
done();
});
});
gulp.task('debug', function() {
debug = true;
});
gulp.task('watch-mode', function() {
mode = WATCH_MODE;
});
function watch() {
var jsWatcher = gulp.watch('src/**/*.js', ['js', 'lint']);
function changeNotification(event) {
console.log('File', event.path, 'was', event.type, ', running tasks...');
}
jsWatcher.on('change', changeNotification);
}
gulp.task('default', ['watch-mode', 'js', 'lint', 'protractor-install'], watch);
gulp.task('server', ['connect', 'default']);
gulp.task('test', ['connect', 'protractor']);