-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
executable file
·158 lines (140 loc) · 4.28 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
'use strict';
var browserify = require('browserify')
, del = require('del')
, source = require('vinyl-source-stream')
, vinylPaths = require('vinyl-paths')
, glob = require('glob')
, Server = require('karma').Server
, gulp = require('gulp');
// Load all gulp plugins listed in package.json
var gulpPlugins = require('gulp-load-plugins')({
pattern: ['gulp-*', 'gulp.*'],
replaceString: /\bgulp[\-.]/
});
// Define file path variables
var paths = {
root: 'app/', // App root path
src: 'app/features/', // Source path
dist: 'app/dist/', // Distribution path
test: 'test/' // Test path
};
/*
* Useful tasks:
* - gulp fast:
* - linting
* - unit tests
* - browserification
* - no minification, does not start server.
* - gulp watch:
* - starts server with live reload enabled
* - lints, unit tests, browserifies and live-reloads changes in browser
* - no minification
* - gulp:
* - linting
* - unit tests
* - browserification
* - minification and browserification of minified sources
* - start server for e2e tests
* - run Protractor End-to-end tests
* - stop server immediately when e2e tests have finished
*
* At development time, you should usually just have 'gulp watch' running in the
* background all the time. Use 'gulp' before releases.
*/
var liveReload = true;
gulp.task('clean', function () {
return gulp
.src([paths.root + 'ngAnnotate', paths.dist], {read: false})
.pipe(vinylPaths(del));
});
gulp.task('lint', function () {
return gulp
.src(['gulpfile.js',
paths.src + '**/*.js',
paths.test + '**/*.js',
'!' + paths.src + 'third-party/**',
'!' + paths.test + 'browserified/**'
])
.pipe(gulpPlugins.eslint())
.pipe(gulpPlugins.eslint.format());
});
gulp.task('unit', function () {
return gulp.src([
paths.test + 'unit/**/*.js'
])
.pipe(gulpPlugins.mocha({reporter: 'dot'}));
});
gulp.task('browserify', /*['lint', 'unit'],*/ function () {
return browserify(paths.src + 'app.js', {debug: true})
.bundle()
.pipe(source('app.js'))
.pipe(gulp.dest(paths.dist))
.pipe(gulpPlugins.connect.reload());
});
gulp.task('ngAnnotate', ['lint', 'unit'], function () {
return gulp.src([
paths.src + '**/*.js',
'!' + paths.src + 'third-party/**'
])
.pipe(gulpPlugins.ngAnnotate())
.pipe(gulp.dest(paths.root + 'ngAnnotate'));
});
gulp.task('browserify-min', ['ngAnnotate'], function () {
return browserify(paths.root + 'ngAnnotate/app.js')
.bundle()
.pipe(source('app.min.js'))
.pipe(gulpPlugins.streamify(gulpPlugins.uglify({mangle: false})))
.pipe(gulp.dest(paths.dist));
});
gulp.task('browserify-tests', function () {
var bundler = browserify({debug: true});
glob
.sync(paths.test + 'unit/**/*.js')
.forEach(function (file) {
bundler.add(file);
});
return bundler
.bundle()
.pipe(source('browserified_tests.js'))
.pipe(gulp.dest(paths.test + 'browserified'));
});
gulp.task('karma', ['browserify-tests'], function (done) {
new Server({
configFile: __dirname + '/karma.conf.js',
singleRun: true
}, done).start();
});
gulp.task('server', ['browserify'], function () {
gulpPlugins.connect.server({
root: 'app',
livereload: liveReload
});
});
gulp.task('e2e', ['server'], function () {
return gulp.src([paths.test + 'e2e/**/*.js'])
.pipe(gulpPlugins.protractor.protractor({
configFile: 'protractor.conf.js',
args: ['--baseUrl', 'http://127.0.0.1:8080']
}))
.on('error', function (e) {
throw e;
})
.on('end', function () {
gulpPlugins.connect.serverClose();
});
});
gulp.task('watch', function () {
gulp.start('server');
gulp.watch([
paths.src + '**/*.js',
'!' + paths.src + 'third-party/**',
paths.test + '**/*.js'
], ['fast']);
});
gulp.task('fast', ['clean'], function () {
gulp.start('browserify');
});
gulp.task('default', ['clean'], function () {
liveReload = false;
gulp.start('karma', 'browserify', 'browserify-min', 'e2e');
});