-
Notifications
You must be signed in to change notification settings - Fork 2
/
gulpfile.js
160 lines (127 loc) · 4.2 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
'use strict';
var gulp = require('gulp');
var plugins = require('gulp-load-plugins')();
var browserifyShare = function(opts) {
var bundle, cache;
var browserify = require('browserify');
var watchify = require('watchify');
var source = require('vinyl-source-stream');
var buffer = require('vinyl-buffer');
var watch = opts.watch || false;
var minify = opts.minify || false;
var bundler = function() {
var b;
if (cache) {
return cache.bundle();
}
b = browserify(
'js/points-center/index.js',
{
basedir: __dirname,
debug: true
}
);
if (watch) {
b = watchify(b);
b.on('update', bundle);
cache = b;
}
return b.bundle();
};
bundle = function() {
var stream = bundler()
.pipe(source('points-center.js'))
.pipe(buffer())
.pipe(plugins.sourcemaps.init({ loadMaps: true }))
.pipe(plugins.sourcemaps.write('./', {
includeContent: false,
sourceRoot: '../'
}))
.pipe(gulp.dest('./build'));
if (minify) {
stream = stream.pipe(plugins.ignore('*.map'))
.pipe(plugins.uglify())
.pipe(plugins.rename({
extname: '.min.js'
}))
.pipe(gulp.dest('./build'));
}
if (watch) {
stream = stream.pipe(plugins.livereload());
}
return stream;
};
return bundle();
};
var stylesheetsShare = function(opts) {
var watch = opts.watch || false;
var minify = opts.minify || false;
var stream = gulp.src('css/points-center.scss')
.pipe(plugins.sourcemaps.init())
.pipe(plugins.sass({
precision: 9
}).on('error', plugins.sass.logError))
.pipe(plugins.sourcemaps.write('./', {
includeContent: false,
sourceRoot: '../'
}))
.pipe(gulp.dest('./build'));
if (minify) {
stream = stream.pipe(plugins.ignore('*.map'))
.pipe(plugins.cleanCss({ keepSpecialComments: 0 }))
.pipe(plugins.rename({
extname: '.min.css'
}))
.pipe(gulp.dest('./build'));
}
if (watch) {
stream = stream.pipe(plugins.livereload());
}
return stream;
};
gulp.task('javascript-clean', function() {
var del = require('del');
return del(['build/*.js', 'build/*.js.map']);
});
gulp.task('javascript-lint', function() {
return gulp.src(['gulpfile.js', 'js/**/*.js'])
.pipe(plugins.cached('scripts'))
.pipe(plugins.eslint())
.pipe(plugins.eslint.format());
});
gulp.task('javascript', function() {
return browserifyShare({ watch: false, minify: false });
});
gulp.task('javascript-watch', ['javascript-lint'], function() {
return browserifyShare({ watch: true, minify: false });
});
gulp.task('javascript-build', ['clean'], function() {
return browserifyShare({ watch: false, minify: true });
});
gulp.task('stylesheets-clean', function() {
var del = require('del');
return del(['build/*.css', 'build/*.css.map']);
});
gulp.task('stylesheets-lint', function() {
return gulp.src(['css/points-center.scss', 'css/points-table.scss'])
.pipe(plugins.sassLint())
.pipe(plugins.sassLint.format());
});
gulp.task('stylesheets', function() {
return stylesheetsShare({ watch: false, minify: false });
});
gulp.task('stylesheets-watch', ['stylesheets-lint'], function() {
return stylesheetsShare({ watch: true, minify: false });
});
gulp.task('stylesheets-build', ['stylesheets-clean'], function() {
return stylesheetsShare({ watch: false, minify: true });
});
gulp.task('clean', ['javascript-clean', 'stylesheets-clean']);
gulp.task('watch', ['clean', 'javascript-watch', 'stylesheets-watch'], function() {
plugins.livereload.listen();
gulp.watch('js/**/*.js', ['javascript-lint']);
gulp.watch('css/*.scss', ['stylesheets-watch']);
});
gulp.task('build', ['clean', 'javascript-build', 'stylesheets-build']);
gulp.task('lint', ['javascript-lint']);
gulp.task('default', ['build']);