forked from reselect/Reselect
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgulpfile.js
More file actions
180 lines (154 loc) · 5.06 KB
/
Copy pathgulpfile.js
File metadata and controls
180 lines (154 loc) · 5.06 KB
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
var fs = require('fs');
var gulp = require('gulp');
var es = require('event-stream');
var del = require('del');
var map = require('map-stream');
var events = require('events');
var emitter = new events.EventEmitter();
var path = require('path');
var karma = require('karma').server;
var notifier = require('node-notifier');
var $ = require('gulp-load-plugins')();
var connect = require('gulp-connect');
var bourbon = require('node-bourbon');
var config = {
pkg: JSON.parse(fs.readFileSync('./package.json')),
banner: '/*!\n' +
' * <%= pkg.name %>\n' +
' * <%= pkg.homepage %>\n' +
' * Version: <%= pkg.version %> - <%= timestamp %>\n' +
' * License: <%= pkg.license %>\n' +
' */\n\n\n'
};
gulp.task('default', ['build', 'test']);
gulp.task('test', ['karma']);
gulp.task('clean-build', ['clean'], function() {
return gulp.start(['build']);
});
gulp.task('build', ['scripts', 'styles'], function() {
$.util.log('Reselect Built');
});
gulp.task('dev', ['watch', 'dev-watch', 'dev-karma'], function() {
connect.server({
root: 'examples'
});
});
gulp.task('dev-watch', function() {
gulp.watch(['examples/**/*.{js,html}']).on('change', $.livereload.changed);
});
gulp.task('watch', function() {
$.livereload.listen();
gulp.watch(['src/**/*.{js,html}'], ['scripts']);
gulp.watch(['src/**/*.scss'], ['styles']);
gulp.watch(['dist/**/*.min.{css,js}']).on('change', $.livereload.changed);
});
gulp.task('clean', function(cb) {
return del(['dist'], cb);
});
gulp.task('scripts', function() {
var buildTemplates = function() {
return gulp.src('src/**/*.html')
.pipe($.plumber({
errorHandler: handleError
}))
.pipe($.minifyHtml({
empty: true,
spare: true,
quotes: true
}))
.pipe($.angularTemplatecache({
module: 'reselect.templates',
standalone: true
}));
};
var buildLib = function() {
// Custom linting reporter used for error notify
var jsHintErrorReporter = map(function(file, cb) {
if (!file.jshint.success) {
file.jshint.results.forEach(function(err) {
if (err) {
//console.log(err);
// Error message
var msg = [
path.basename(file.path),
'Line: ' + err.error.line,
'Reason: ' + err.error.reason
];
// Emit this error event
emitter.emit('error', new Error(msg.join('\n')));
}
});
}
cb(null, file);
});
return gulp.src(['src/reselect.js', 'src/reselect*.js', 'src/filters/reselect*.js', 'src/common.js'])
.pipe($.plumber({
errorHandler: handleError
}))
// .pipe($.jshint())
// .pipe($.jshint.reporter('jshint-stylish'))
// .pipe(jsHintErrorReporter) // If error pop up a notify alert
.on('error', $.notify.onError(function(error) {
return error.message;
}));
};
return es.merge(gulp.src(['src/libs/*.js']), buildLib(), buildTemplates())
.pipe($.plumber({
errorHandler: handleError
}))
.pipe($.concat('reselect.js'))
.pipe($.header('(function () { \n\'use strict\';\n'))
.pipe($.header(config.banner, {
timestamp: (new Date()).toISOString(),
pkg: config.pkg
}))
.pipe($.footer('\n}).apply(this);'))
.pipe(gulp.dest('examples/libs'))
.pipe(gulp.dest('dist'))
.pipe($.uglify({
preserveComments: 'some'
}))
.pipe($.rename({
ext: '.min.js'
}))
.pipe(gulp.dest('examples/libs'))
.pipe(gulp.dest('dist'));
});
gulp.task('styles', function() {
return gulp.src('src/scss/reselect.scss')
.pipe($.plumber({
errorHandler: handleError
}))
.pipe($.sass({
includePaths: bourbon.includePaths
}))
.pipe($.header(config.banner, {
timestamp: (new Date()).toISOString(),
pkg: config.pkg
}))
.pipe($.rename('reselect.css'))
.pipe(gulp.dest('examples/libs'))
.pipe(gulp.dest('dist'))
.pipe($.minifyCss())
.pipe($.rename({
ext: '.min.css'
}))
.pipe(gulp.dest('examples/libs'))
.pipe(gulp.dest('dist'));
});
gulp.task('karma', ['build'], function() {
karma.start({
configFile: __dirname + '/test/karma.conf.js',
singleRun: true
});
});
gulp.task('dev-karma', ['build'], function() {
karma.start({
configFile: __dirname + '/test/karma.conf.js',
singleRun: false
});
});
var handleError = function(err) {
console.log(err.toString());
this.emit('end');
};