-
Notifications
You must be signed in to change notification settings - Fork 1
/
gulpfile.js
executable file
·142 lines (126 loc) · 4.13 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
const gulp = require('gulp');
const cleaner = require('gulp-clean');
const gulpSass = require('gulp-sass')(require('sass'));
const jsConcat = require('gulp-concat');
const jsUglify = require('gulp-terser');
const cleanCSS = require('gulp-clean-css');
const beautify = require('gulp-beautify');
const rename = require('gulp-rename');
const jsInclude = require('gulp-include');
const cssExtend = require('gulp-autoprefixer');
const sourceMaps = require('gulp-sourcemaps');
function jquery() {
return gulp.src([
'node_modules/jquery/dist/jquery.js'
]).pipe(gulp.dest('assets/js/'));
}
function bootstrap() {
return gulp.src([
'node_modules/bootstrap-sass/assets/javascripts/bootstrap.js'
]).pipe(gulp.dest('assets/js/')) &&
gulp.src([
'node_modules/bootstrap-sass/assets/fonts/bootstrap/*'
]).pipe(gulp.dest('assets/fonts/glyphicons/'));
}
function helpers() {
return gulp.src([
'node_modules/jquery-helper/dist/jquery.helper.js',
'node_modules/jquery-helper/dist/jquery.touch.js'
]).pipe(jsConcat('helper.js')).pipe(gulp.dest('assets/js/'));
}
function sticky_sidebar() {
return gulp.src([
'node_modules/sticky-sidebar/dist/jquery.sticky-sidebar.js'
]).pipe(rename('sticky-sidebar.js')).pipe(gulp.dest('assets/js/'));
}
function roboto_fontface() {
return gulp.src([
'node_modules/roboto-fontface/fonts/**/*',
]).pipe(gulp.dest('assets/fonts'));
}
function copy() {
return jquery() &&
bootstrap() &&
helpers() &&
sticky_sidebar() &&
roboto_fontface();
}
function cleanup() {
return gulp.src([
'assets/*'
], {
read: false
}).pipe(cleaner());
}
function js_minify() {
return gulp.src(['assets/js/*.js', '!assets/js/*.min.js'])
.pipe(sourceMaps.init())
.pipe(jsUglify())
.pipe(sourceMaps.write())
.pipe(rename({ suffix: '.min' }))
.pipe(gulp.dest('assets/js'));
}
function css_minify() {
return gulp.src(['assets/css/*.css', '!assets/css/*.min.css'])
.pipe(sourceMaps.init())
.pipe(cleanCSS({debug: true}, (details) => {
console.log(`${details.name}: ${details.stats.originalSize}`);
console.log(`${details.name}: ${details.stats.minifiedSize}`);
}))
.pipe(sourceMaps.write())
.pipe(rename({ suffix: '.min' }))
.pipe(gulp.dest('assets/css'));
}
function minify() {
return js_minify() && css_minify();
}
function js() {
return gulp.src('src/js/*.js')
.pipe(sourceMaps.init())
.pipe(jsInclude({
extensions: 'js',
hardFail: true,
separateInputs: true
}))
.on('error', console.log)
.pipe(beautify.js({
indent_size: 2
}))
.pipe(jsConcat('admin.js'))
.pipe(sourceMaps.write())
.pipe(gulp.dest('assets/js'));
}
function sass() {
return gulp.src('src/scss/*.scss')
.pipe(sourceMaps.init())
.pipe(gulpSass({
includePaths: ['node_modules']
}).on('error', gulpSass.logError))
.pipe(cssExtend({
cascade: false
}))
.pipe(beautify.css({
indent_size: 2
}))
.pipe(sourceMaps.write())
.pipe(gulp.dest('assets/css'));
}
function images() {
return gulp.src('src/images/*').pipe(gulp.dest('assets/images')) &&
gulp.src(['src/favicon.png', 'src/favicon.ico']).pipe(gulp.dest('assets'));
}
function watchFiles() {
gulp.watch('src/js/**/*.js', gulp.series(js, js_minify));
gulp.watch('src/scss/**/*.scss', gulp.series(sass, css_minify));
gulp.watch('src/images/**/*.*', gulp.series(images));
return;
}
exports.js = js;
exports.sass = sass;
exports.cleanup = cleanup;
exports.js_minify = js_minify;
exports.css_minify = css_minify;
exports.minify = gulp.parallel(js_minify, css_minify);
exports.watch = gulp.parallel(sass, js, watchFiles);
exports.copy = gulp.parallel(jquery, bootstrap, helpers, sticky_sidebar, roboto_fontface);
exports.default = gulp.series(cleanup, copy, images, js, sass, minify, watchFiles);