forked from 2braincells2go/previewer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
114 lines (99 loc) · 2.63 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
'use strict';
var gulp = require('gulp'),
plugins = require('gulp-load-plugins')(),
pkg = require('./package'),
scripts = {
all: [
'gulpfile.js',
'src/*.js',
'docs/js/*.js'
],
src: 'src/*.js',
docs: 'docs/js',
dest: 'dist'
},
styles = {
all: [
'src/*.css',
'docs/css/*.css'
],
src: 'src/*.less',
docs: 'docs/css',
main: 'dist/previewer.css',
dest: 'dist'
},
replacement = {
regexp: /@\w+/g,
filter: function (placeholder) {
switch (placeholder) {
case '@VERSION':
placeholder = pkg.version;
break;
case '@YEAR':
placeholder = (new Date()).getFullYear();
break;
case '@DATE':
placeholder = (new Date()).toISOString();
break;
}
return placeholder;
}
};
gulp.task('jshint', function () {
return gulp.src(scripts.all)
.pipe(plugins.jshint('src/.jshintrc'))
.pipe(plugins.jshint.reporter('default'));
});
gulp.task('jscs', function () {
return gulp.src(scripts.all)
.pipe(plugins.jscs('src/.jscsrc'));
});
gulp.task('js', ['jshint', 'jscs'], function () {
return gulp.src(scripts.src)
.pipe(plugins.replace(replacement.regexp, replacement.filter))
.pipe(gulp.dest(scripts.docs))
.pipe(gulp.dest(scripts.dest))
.pipe(plugins.rename('previewer.min.js'))
.pipe(plugins.uglify({
preserveComments: 'some'
}))
.pipe(gulp.dest(scripts.dest));
});
gulp.task('jscopy', function () {
return gulp.src(scripts.src)
.pipe(gulp.dest(scripts.dest));
});
gulp.task('less', function () {
return gulp.src(styles.src)
.pipe(plugins.less())
.pipe(gulp.dest(styles.dest));
});
gulp.task('csslint', ['less'], function () {
return gulp.src(styles.main)
.pipe(plugins.csslint('src/.csslintrc'))
.pipe(plugins.csslint.reporter());
});
gulp.task('css', ['csslint'], function () {
return gulp.src(styles.main)
.pipe(plugins.replace(replacement.regexp, replacement.filter))
.pipe(plugins.autoprefixer())
.pipe(plugins.csscomb())
.pipe(gulp.dest(styles.docs))
.pipe(gulp.dest(styles.dest))
.pipe(plugins.rename('previewer.min.css'))
.pipe(plugins.minifyCss())
.pipe(gulp.dest(styles.dest));
});
gulp.task('docs', function () {
return gulp.src('docs/**')
.pipe(gulp.dest('_gh_pages'));
});
gulp.task('release', ['js', 'css'], function () {
return gulp.src('dist/*')
.pipe(gulp.dest('_releases/' + pkg.version));
});
gulp.task('watch', function () {
gulp.watch(scripts.src, ['jscopy']);
gulp.watch(styles.src, ['less']);
});
gulp.task('default', ['watch']);