-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
197 lines (168 loc) · 4.86 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
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
//modules
const browserSync = require('browser-sync'),
del = require('del'),
gulp = require('gulp'),
autoprefixer = require('gulp-autoprefixer'),
cleanCSS = require('gulp-clean-css'),
csslint = require('gulp-csslint'),
gulpif = require('gulp-if'),
imagemin = require('gulp-imagemin'),
jshint = require('gulp-jshint'),
newer = require('gulp-newer'),
run = require('gulp-run'),
sourcemaps = require('gulp-sourcemaps'),
uglify = require('gulp-uglify-es').default,
useref = require('gulp-useref'),
watch = require('gulp-watch'),
pipe = require('multipipe');
//variables
const srcPath = {
'src': './src',
'html': './src/**/*.html',
'img': './src/**/*.+(jpg|jpeg|png|svg|gif|ico)',
'css': ['./src/!(css|js)*/**/*.css'],
'cssLint': './src/**/*.css',
'js': './src/!(js|completed)*/**/*.js',
'jsLint': ['./src/**/*.js', '!./**/node_modules/**', '!./src/**/*.min.js'],
'font': './src/font/**/*.*',
'analysis': './code-analysis/',
'task': './src/task/**/*.+(pdf|тых|html|css)',
'cmpl': ['./src/completed/**/*.*', '!./**/node_modules/**'],
'print': './src/css/print/*.css'
};
const distPath = {
'dist': './dist/',
'html': './dist/',
'img': './dist/',
'css': './dist/css/',
'print': './dist/css/print',
'js': './dist/',
'font': './dist/font/',
'task': './dist/task/',
'cmpl': './dist/completed/'
};
const pluginSettings = {
autoprefixer: {
browsers: ['last 2 versions', 'ie 9', 'ie 10']
},
cleanCSS: {
compatibility: '*'
},
csslint: {
filename: 'index.html',
directory: srcPath.analysis + '/css/'
},
jshint: {
filename: srcPath.analysis + '/js/index.html',
createMissingFolders: true
}
};
//tasks
const cleanDist = function () {
return del([srcPath.analysis, distPath.dist]);
}
const parseHtml = function () {
return gulp.src(srcPath.html)
.pipe(newer(distPath.html))
.pipe(useref({}, pipe(sourcemaps.init)))
.pipe(gulpif("*.js", pipe(
uglify()
)))
.pipe(gulpif("*.css",
pipe(
autoprefixer(pluginSettings.autoprefixer),
cleanCSS(pluginSettings.cleanCSS)
)
))
.pipe(sourcemaps.write())
.pipe(gulp.dest(distPath.html));
}
const parseCss = function () {
return gulp.src(srcPath.css)
.pipe(sourcemaps.init())
.pipe(autoprefixer(pluginSettings.autoprefixer))
.pipe(cleanCSS(pluginSettings.cleanCSS))
.pipe(sourcemaps.write())
.pipe(gulp.dest(distPath.css));
}
const lintCss = function () {
return gulp.src(srcPath.cssLint)
.pipe(csslint(".csslintrc"));
}
const copyJs = function () {
return gulp.src(srcPath.js)
.pipe(gulp.dest(distPath.js));
}
const lintJs = function () {
return gulp.src(srcPath.jsLint)
.pipe(jshint(".jshintrc"));
}
const parseImages = function () {
return gulp.src(srcPath.img)
.pipe(newer(distPath.img))
.pipe(imagemin())
.pipe(gulp.dest(distPath.img));
}
const copyFonts = function () {
return gulp.src(srcPath.font)
.pipe(gulp.dest(distPath.font));
}
const copyTaskFiles = function () {
return gulp.src(srcPath.task)
.pipe(gulp.dest(distPath.task));
}
const copyCompletedFiles = function () {
return gulp.src(srcPath.cmpl)
.pipe(gulp.dest(distPath.cmpl));
}
const copyPrintJsFiles = function () {
return gulp.src(srcPath.print)
.pipe(gulp.dest(distPath.print));
}
const copyThemeCssFiles = function () {
return gulp.src('./src/css/theme/*.css')
.pipe(gulp.dest('./dist/css/theme/'));
}
const copyHlJsFiles = function () {
return gulp.src('./src/js/highlight/*.js')
.pipe(gulp.dest('./dist/js/'));
}
const copyCustomCss = function () {
return gulp.src('./src/css/custom.css')
.pipe(gulp.dest('./dist/css/'));
}
const lint = gulp.parallel(lintJs, lintCss);
const translate = gulp.parallel(parseHtml, parseCss, copyJs, parseImages, copyFonts, copyCustomCss, copyTaskFiles, copyCompletedFiles, copyPrintJsFiles, copyThemeCssFiles, copyHlJsFiles);
const build = gulp.series(cleanDist, lint, translate);
const watchServ = function () {
watch(srcPath.css, parseCss);
watch(srcPath.html, parseHtml);
watch(srcPath.js, copyJs);
watch(srcPath.img, parseImages);
watch(srcPath.font, copyFonts);
watch(srcPath.task, copyTaskFiles);
watch(srcPath.cmpl, copyCompletedFiles);
watch(srcPath.print, copyPrintJsFiles);
watch('./src/js/highlight/*.js', copyHlJsFiles);
watch('./src/css/custom.css', copyCustomCss);
}
const serveDir = function () {
browserSync.init({
server: distPath.dist,
port: 4000
});
browserSync.watch(distPath.dist).on("change", browserSync.reload);
}
const serverWatch = gulp.parallel(watchServ, serveDir);
const default_task = gulp.series(build, serverWatch);
const ya = function (cb) {
run(`npx yaspeller .\\`).exec()
.on("error", function (err) {
console.error(err.message);
cb();
})
.on("finish", cb);
}
module.exports.default = default_task;
module.exports.build = build;
module.exports.ya = ya;