forked from art-bazhin/medlakor
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
159 lines (142 loc) · 3.76 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
'use strict';
var gulp = require('gulp');
var concat = require('gulp-concat');
var webserver = require('gulp-server-livereload');
var stylus = require('gulp-stylus');
var pug = require('gulp-pug');
var autoprefixer = require('gulp-autoprefixer');
var htmlmin = require('gulp-htmlmin');
var imagemin = require('gulp-imagemin');
var cssmin = require('gulp-cssmin');
var rename = require('gulp-rename');
var runSequence = require('run-sequence');
var uglify = require('gulp-uglify');
var plumber = require('gulp-plumber');
var watch = require('gulp-watch');
var clean = require('gulp-clean');
var typograf = require('gulp-typograf');
var ts = Math.floor(Date.now()/1000);
//Build markup
gulp.task('html', function() {
gulp.src(['src/pug/**/*.pug', '!src/pug/partials/**/*.pug', '!src/pug/404/404.pug'])
.pipe(plumber())
.pipe(pug({
pretty: true,
locals: {timestamp: ts}
}))
.pipe(typograf({
lang: 'ru',
disable: ['ru/other/phone-number']
}))
.pipe(rename({
basename: "index"
}))
.pipe(htmlmin({
collapseWhitespace: true
}))
.pipe(gulp.dest('build/'));
});
//Build 404 page
gulp.task('notfound', function() {
gulp.src('src/pug/404/404.pug')
.pipe(plumber())
.pipe(pug({
pretty: true,
}))
.pipe(htmlmin({
collapseWhitespace: true
}))
.pipe(gulp.dest('build/'));
});
//Build styles
gulp.task('css', function() {
gulp.src('src/stylus/style.styl')
.pipe(plumber())
.pipe(stylus())
.pipe(autoprefixer({
browsers: ['last 2 versions'],
cascade: false
}))
.pipe(cssmin())
.pipe(gulp.dest('build/css/'));
});
//Build scripts
gulp.task('js', ['js.menu', 'js.home', 'js.configurator']);
//Build menu scripts
gulp.task('js.menu', function() {
gulp.src('src/js/menu.js')
.pipe(plumber())
.pipe(uglify())
.pipe(gulp.dest('build/js/'));
});
//Build home page scripts
gulp.task('js.home', function() {
gulp.src('src/js/home/*.js')
.pipe(plumber())
.pipe(concat(
'home.js'))
.pipe(uglify())
.pipe(gulp.dest('build/js/'));
});
//Build configurator page scripts
gulp.task('js.configurator', function() {
gulp.src('src/js/configurator/*.js')
.pipe(plumber())
.pipe(concat(
'configurator.js'))
//.pipe(uglify())
.pipe(gulp.dest('build/js/'));
});
//Run webserver with livereload
gulp.task('webserver', function() {
gulp.src('build')
.pipe(webserver({
livereload: true,
fallback: "index.html",
port: 8080,
open: true
}));
});
//Clean build directory
gulp.task('clean', function() {
return gulp.src('build', {
read: false
}).pipe(clean());
});
//Minify inline images
gulp.task('min-inline', function() {
return gulp.src(['src/img/inline/**/*'])
.pipe(imagemin())
.pipe(gulp.dest('src/img/inline/'));
});
//Build & copy assets
gulp.task('assets', function() {
//gulp.src('src/assets/fonts/*').pipe(gulp.dest('build/assets/fonts'));
gulp.src(['src/img/**/*', '!src/img/inline/**/*', '!src/img/inline'])
.pipe(imagemin())
.pipe(gulp.dest('build/img/'));
});
//Copy reg documents
gulp.task('reg', function() {
gulp.src(['src/reg/**/*'])
.pipe(gulp.dest('build/reg/'));
});
//Copy instructions
gulp.task('instr', function() {
gulp.src(['src/instr/**/*'])
.pipe(gulp.dest('build/instr/'));
});
//Watch task
gulp.task('watch', function() {
gulp.watch('src/stylus/**/*.styl', ['css']);
gulp.watch('src/pug/**/*.pug', ['html']);
gulp.watch('src/reg/**/*', ['reg']);
//gulp.watch('src/pug/404/404.pug', ['notfound']);
gulp.watch('src/js/**/*.js', ['js']);
});
//Development task
gulp.task('default', ['watch', 'webserver']);
//Build task
gulp.task('build', function() {
runSequence('clean', 'min-inline', ['html', 'css', 'js', 'reg', 'instr', 'assets', 'notfound']);
});