forked from jshjohnson/Animate
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
128 lines (115 loc) · 3.16 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
var gulp = require('gulp'),
plugins = require('gulp-load-plugins')(),
package = require('./package.json'),
sass = require('gulp-sass'),
Server = require('karma').Server;
opn = require('opn');
var paths = {
output : 'assets/scripts/dist/',
scripts : [
'assets/js/src/**/*.js',
'test/spec/*.js',
],
styles : [
'assets/scss/**/*.scss'
],
html : [
'*.html'
]
};
var banner = [
'/*! ',
'<%= package.name %> ',
'v<%= package.version %> | ',
'(c) ' + new Date().getFullYear() + ' <%= package.author %> |',
' <%= package.homepage %>',
' */',
'\n'
].join('');
/**
* Create local server to let us see what we are doing
*/
gulp.task('connect', function() {
plugins.connect.server({
root: [__dirname],
port: 8000,
livereload: true
});
opn('http://localhost:8000/test/results/unit-tests.html');
opn('http://localhost:8000');
});
/**
* Fire browser reload on html change
*/
gulp.task('html', function () {
gulp.src(paths.html)
.pipe(plugins.connect.reload());
});
/**
* Compile our styles, prefix the result, rename and move
*/
gulp.task('styles', function () {
gulp.src(paths.styles)
.pipe(plugins.sass().on('error', sass.logError))
.pipe(plugins.autoprefixer('last 2 versions', '> 1%', 'ie 8'))
.pipe(plugins.header(banner, { package : package }))
.pipe(gulp.dest('assets/css/'))
.pipe(plugins.csso())
.pipe(plugins.rename({suffix: '.min'}))
.pipe(plugins.header(banner, { package : package }))
.pipe(gulp.dest('assets/css/'))
.pipe(plugins.connect.reload());
});
/**
* Add nice banner comment to script file, move it, rename it, uglify it
*/
gulp.task('scripts', function() {
return gulp.src(paths.scripts[0])
.pipe(plugins.plumber())
.pipe(plugins.header(banner, { package : package }))
.pipe(gulp.dest('assets/js/dist/'))
.pipe(plugins.rename({ suffix: '.min' }))
.pipe(plugins.uglify())
.pipe(plugins.header(banner, { package : package }))
.pipe(gulp.dest('assets/js/dist/'))
.pipe(plugins.connect.reload());
});
/**
* Make sure our JS doesn't suck balls
*/
gulp.task('lint', function () {
return gulp.src(paths.scripts[0])
.pipe(plugins.plumber())
.pipe(plugins.eslint({
configFile: '.eslintrc'
}))
.pipe(plugins.eslint.format());
});
/**
* Run test once and exit
*/
gulp.task('test', function (done) {
new Server({
configFile: __dirname + '/test/karma.conf.js',
singleRun: true
}, done).start();
});
/**
* Watch for file changes and re-run tests on each change
*/
gulp.task('tdd', function (done) {
new Server({
configFile: __dirname + '/test/karma.conf.js'
}, done).start();
});
/**
* Watch our JS and SCSS files
*/
gulp.task('watch', function() {
gulp.watch(paths.scripts, ['scripts', 'lint', 'tdd']);
gulp.watch(paths.styles, ['styles']);
gulp.watch(paths.html, ['html']);
});
gulp.task('dev', ['lint', 'test', 'connect', 'watch']);
gulp.task('build', ['lint', 'scripts', 'test']);
gulp.task('default', ['dev']);