-
Notifications
You must be signed in to change notification settings - Fork 5
/
gulpfile.js
187 lines (167 loc) · 4.32 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
var gulp = require('gulp');
var jshint = require('gulp-jshint');
var concat = require('gulp-concat');
var babel = require('gulp-babel');
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 webpack = require('gulp-webpack');
var wait = require('gulp-wait');
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/',
DEMO: './demo/',
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(wait(1000))
.pipe(livereload());
});
gulp.task('sass', function() {
return gulp.src(SOURCE.STYLES + '*.scss')
.pipe(sass()).on('error', handleErr)
.pipe(gulp.dest(PATH.DIST))
.pipe(wait(500))
.pipe(livereload());
});
gulp.task('convert-and-concat', function() {
return gulp.src([
SOURCE.SCRIPTS + '*.js'
])
.pipe(babel())
.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('webpack', function() {
return gulp.src(SOURCE.SCRIPTS + '*.js')
.pipe(webpack({
output: {
path: __dirname + PATH.DEMO.substr(1),
filename: 'bundle.js'
},
module: {
loaders: [{
loader: 'babel-loader'
}]
}
}))
.pipe(gulp.dest(PATH.DEMO));
});
gulp.task('reloadDemo', function() {
return gulp.src(PATH.DEMO + '*.*')
.pipe(livereload());
});
gulp.task('watch', ['server', 'webpack'], function() {
livereload.listen({
basePath: './',
reloadPage: 'demo/index.html'
});
gulp.watch(SOURCE.SCRIPTS + '*.js', ['jshint', 'webpack']);
gulp.watch(SOURCE.STYLES + '*.scss', ['sass']);
gulp.watch(PATH.DEMO + '*.*', ['reloadDemo']);
});
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', 'webpack'], 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',
'convert-and-concat',
'uglify',
'minify',
'banner',
'test-unit',
'test-e2e',
cb);
});
gulp.task('default', ['build']);