-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathgulpfile.js
81 lines (72 loc) · 2.5 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
var gulp = require('gulp'),
jshint = require('gulp-jshint'),
uglify = require('gulp-uglify'),
rename = require('gulp-rename'),
zip = require('gulp-zip'),
less = require('gulp-less'),
jshint_stylish = require('jshint-stylish'),
sequence = require('run-sequence'),
header = require('gulp-header'),
pkg = require('./package.json'),
banner = [
'/*!',
' * <%= pkg.name %> - <%= pkg.description %>',
' * @version v<%= pkg.version %>',
' * @link <%= pkg.homepage %>',
' *',
' * Copyright 2014-2017 <%= pkg.author %>',
' * Released under the MIT license',
' * @license https://github.com/hoxxep/Snarl/blob/master/LICENSE ',
' */',
'',
''
].join('\n');
gulp.task('less-src', function () {
return gulp.src('src/less/snarl.less')
.pipe(header(banner, {pkg: pkg}))
.pipe(gulp.dest('./dist'))
.pipe(less())
.pipe(gulp.dest('./dist'))
.pipe(less({compress: true}))
.pipe(rename({extname: '.min.css'}))
.pipe(gulp.dest('./dist'))
.pipe(gulp.dest('./docs/static'));
});
gulp.task('less-homepage', function () {
return gulp.src('docs/static/style.less')
.pipe(less({compress: true}))
.pipe(gulp.dest('./docs/static'));
});
gulp.task('less', ['less-src', 'less-homepage']);
gulp.task('jshint', function () {
return gulp.src(['src/js/snarl.js', 'gulpfile.js'])
.pipe(jshint())
.pipe(jshint.reporter(jshint_stylish))
.pipe(jshint.reporter('fail'));
});
//TODO: sourcemaps
gulp.task('uglify', function () {
return gulp.src('src/js/snarl.js')
.pipe(header(banner, {pkg: pkg}))
.pipe(gulp.dest('./dist'))
.pipe(gulp.dest('./docs/static'))
.pipe(uglify({mangle: true, preserveComments: 'some'}))
.pipe(rename({extname: '.min.js'}))
.pipe(gulp.dest('./dist'))
.pipe(gulp.dest('./docs/static'));
});
// Fail if jshint fails to stop gulp & uglify crashing
gulp.task('js', function () {
sequence('jshint', 'uglify');
});
gulp.task('zip', function () {
return gulp.src(['./dist/*', 'LICENSE', 'README.md'])
.pipe(rename({dirname: 'snarl'}))
.pipe(zip('snarl.zip'))
.pipe(gulp.dest('./dist'));
});
gulp.task('build', ['less', 'less-homepage', 'js', 'zip']);
gulp.task('default', ['build', 'watch']);
gulp.task('watch', ['build'], function () {
gulp.watch(['src/js/*.js', 'src/less/*.less', 'docs/static/style.less'], ['build']);
});