This repository has been archived by the owner on Nov 11, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 41
/
gulpfile.js
161 lines (143 loc) · 3.72 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
var gulp = require('gulp');
var jshint = require('gulp-jshint');
var concat = require('gulp-concat');
var minifyCSS = require('gulp-minify-css');
var uglify = require('gulp-uglify');
var rename = require('gulp-rename');
var header = require('gulp-header');
var sass = require('gulp-sass');
var livereload = require('gulp-livereload');
var protractor = require("gulp-protractor").protractor;
var del = require('del');
var runSequence = require('run-sequence');
var stylish = require('jshint-stylish');
var http = require('http');
var st = require('st');
var path = require('path');
var karma = require('karma').server;
var pkg = require('./package');
var jshintConfig = pkg.jshintConfig;
var BANNER = [
'/**',
' * <%= pkg.name %> v<%= pkg.version %> (<%= pkg.homepage %>)',
' * Copyright <%= new Date().getFullYear() %> <%= pkg.author %>',
' * Licensed under <%= pkg.license %>',
' */',
''
].join('\n');
var PATH = {
SOURCE: './src/',
TEST: './test/',
DIST: './dist/'
};
var SOURCE = {
SCRIPTS: PATH.SOURCE + 'scripts/',
STYLES: PATH.SOURCE + 'styles/',
};
var handleErr = function(err) {
console.error('ERROR' + (err.fileName ? ' in ' + err.fileName : ':'));
console.error(err.message);
this.end();
};
gulp.task('clean', function(cb) {
del([PATH.DIST], cb);
});
jshintConfig.lookup = false;
gulp.task('jshint', function() {
return gulp.src(SOURCE.SCRIPTS + '*.js')
.pipe(jshint(jshintConfig))
.pipe(jshint.reporter(stylish))
.pipe(livereload());
});
gulp.task('sass', function() {
return gulp.src(SOURCE.STYLES + '*.scss')
.pipe(sass()).on('error', handleErr)
.pipe(gulp.dest(PATH.DIST))
.pipe(livereload());
});
gulp.task('concat', function() {
return gulp.src([
SOURCE.SCRIPTS + 'providers.js',
SOURCE.SCRIPTS + 'controllers.js',
SOURCE.SCRIPTS + 'directives.js',
SOURCE.SCRIPTS + 'module.js'
])
.pipe(concat(pkg.name + '.js'))
.pipe(gulp.dest(PATH.DIST));
});
gulp.task('uglify', function() {
return gulp.src(PATH.DIST + pkg.name + '.js')
.pipe(uglify()).on('error', handleErr)
.pipe(rename({
basename: pkg.name,
suffix: '.min'
}))
.pipe(gulp.dest(PATH.DIST));
});
gulp.task('minify', function() {
return gulp.src(PATH.DIST + pkg.name + '.css')
.pipe(minifyCSS())
.pipe(rename({
basename: pkg.name,
suffix: '.min'
}))
.pipe(gulp.dest(PATH.DIST));
});
gulp.task('banner', function() {
return gulp.src(PATH.DIST + '*')
.pipe(header(BANNER, {
pkg: pkg
}))
.pipe(gulp.dest(PATH.DIST));
});
gulp.task('watch', ['server'], function() {
livereload.listen({
basePath: './',
reloadPage: 'demo/index.html'
});
gulp.watch(SOURCE.SCRIPTS + '*.js', ['jshint']);
gulp.watch(SOURCE.STYLES + '*.scss', ['sass']);
});
var server;
gulp.task('server', function(cb) {
server = http.createServer(
st({
path: __dirname,
index: 'index.html',
cache: false
})
).listen(8080, cb);
});
gulp.task('test-unit', function(cb) {
var config = {
configFile: path.join(__dirname, '/test/karma.conf.js')
};
karma.start(config, function() {
cb();
});
});
gulp.task('test-e2e', ['server'], function() {
return gulp.src([PATH.TEST + 'specs/e2e/*.js'])
.pipe(protractor({
configFile: path.join(__dirname, (process.env.TRAVIS) ?
'/test/e2e.travis.conf.js' : '/test/e2e.conf.js'),
args: ['--baseUrl', 'http://127.0.0.1:8000']
})).on('error', function(e) {
server.close();
throw e;
}).on('end', function() {
server.close();
});
});
gulp.task('build', ['clean'], function(cb) {
runSequence(
'sass',
'concat',
'uglify',
'minify',
'banner',
'test-unit',
'test-e2e',
cb);
});
gulp.task('default', ['build']);