forked from michaeltaranto/angular-feature-flags
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathgulpfile.js
115 lines (105 loc) · 2.86 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
//--------------------------------
// MODULES
//--------------------------------
var gulp = require('gulp'),
eslint = require('gulp-eslint'),
connect = require('gulp-connect'),
open = require('open'),
rename = require('gulp-rename'),
uglify = require('gulp-uglify'),
header = require('gulp-header'),
wrap = require('gulp-wrap'),
concat = require('gulp-concat'),
ngannotate = require('gulp-ng-annotate'),
karma = require('gulp-karma'),
pkg = require('./package.json'),
//--------------------------------
// HELPERS
//--------------------------------
karmaConfig = function(action) {
return {
frameworks: ['jasmine'],
browsers: ['PhantomJS'],
reporters: ['progress'],
action: action
};
},
TEST_FILES = 'test/**/*.spec.js',
SRC_FILES = 'src/*.js',
KARMA_FILES = [
'demo/vendor/angular.min.js',
'test/vendor/angular-mocks.js',
SRC_FILES,
TEST_FILES
],
PORT = 9999;
//--------------------------------
// TASKS
//--------------------------------
gulp.task('lint', function() {
return gulp.src([
'demo/scripts/directives.js',
SRC_FILES,
TEST_FILES
])
.pipe(eslint({
configFile: '.eslintrc.js'
}))
.pipe(eslint.format())
.pipe(eslint.failOnError());
});
gulp.task('test', function() {
return gulp.src(KARMA_FILES)
.pipe(karma(karmaConfig('run')))
.on('error', function(err) {
throw err;
});
});
gulp.task('connect', function() {
connect.server({
root: 'demo',
port: PORT,
livereload: true
});
});
gulp.task('server', gulp.series('connect', function() {
open("http://localhost:" + PORT);
}));
gulp.task('reload', function() {
return gulp.src('demo/**/*.*')
.pipe(connect.reload());
});
gulp.task('build', function() {
return gulp.src(SRC_FILES)
.pipe(concat('featureFlags.js'))
.pipe(wrap('(function(){\n<%= contents %>\n}());'))
.pipe(header([
'/*!',
' * <%= title %> v<%= version %>',
' *',
' * © <%= new Date().getFullYear() %>, <%= author.name %>',
' */\n\n'
].join('\n'), pkg))
.pipe(ngannotate({
add: true,
single_quotes: true
}))
.pipe(gulp.dest('dist/'))
.pipe(rename('featureFlags.min.js'))
.pipe(uglify())
.pipe(header([
'/*! <%= title %> v<%= version %> © <%= new Date().getFullYear() %> <%= author.name %> */\n'
].join(''), pkg))
.pipe(gulp.dest('dist/'))
.pipe(gulp.dest('demo/scripts'));
});
gulp.task('dev', gulp.series('build', 'server', function() {
gulp.watch(['demo/**/*.*'], ['reload']);
gulp.watch(['demo/scripts/*.js', TEST_FILES], ['lint']);
gulp.watch(SRC_FILES, ['lint', 'build']);
gulp.src(KARMA_FILES)
.pipe(karma(karmaConfig('watch')));
}));
gulp.task('precommit', gulp.series('lint', 'test', 'build'));
gulp.task('demo', gulp.series('build', 'server'));
gulp.task('default', gulp.parallel('precommit'));