-
Notifications
You must be signed in to change notification settings - Fork 9
/
gulpfile.js
129 lines (115 loc) · 3.32 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
'use strict';
const gulp = require('gulp');
const plumber = require('gulp-plumber');
const stylus = require('gulp-stylus');
const cssnano = require('gulp-cssnano');
const gcmq = require('gulp-group-css-media-queries');
const sourcemaps = require('gulp-sourcemaps');
const jeet = require('jeet');
const rupture = require('rupture');
const koutoSwiss = require('kouto-swiss');
const prefixer = require('autoprefixer-stylus');
const rollup = require('gulp-rollup');
const uglify = require('gulp-uglify');
const pug = require('gulp-pug');
const imagemin = require('gulp-imagemin');
const browserSync = require('browser-sync');
const ghPages = require('gulp-gh-pages');
const sitespeedio = require('gulp-sitespeedio');
const plato = require('gulp-plato');
const rollupConfig = require('./rollup.config');
const eslintConfig = require('./.eslintrc');
const srcPaths = {
js: 'src/js/main.js',
css: 'src/styl/**/*.styl',
mainStyl: 'src/styl/main.styl',
pug: 'src/templates/**/!(_)*.pug',
img: 'src/img/**/*'
};
const buildPaths = {
build: 'build/**/*',
js: 'build/js/',
css: 'build/css/',
pug: 'build/',
img: 'build/img',
tests: {
perf: 'tests/perf',
complexity: 'tests/complexity'
}
};
gulp.task('css', () => {
gulp.src(srcPaths.mainStyl)
.pipe(plumber())
.pipe(sourcemaps.init())
.pipe(stylus({
use: [koutoSwiss(), prefixer(), jeet(), rupture()],
compress: true
}))
.pipe(gcmq())
.pipe(cssnano())
.pipe(sourcemaps.write('./'))
.pipe(gulp.dest(buildPaths.css));
});
gulp.task('js', () => {
gulp.src(srcPaths.js)
.pipe(plumber())
.pipe(rollup(rollupConfig))
.pipe(uglify())
.pipe(gulp.dest(buildPaths.js));
});
gulp.task('pug', () => {
gulp.src(srcPaths.pug)
.pipe(plumber())
.pipe(pug())
.pipe(gulp.dest(buildPaths.pug));
});
gulp.task('images', () => {
gulp.src(srcPaths.img)
.pipe(plumber())
.pipe(imagemin({
optimizationLevel: 3,
progressive: true,
interlaced: true
}))
.pipe(gulp.dest(buildPaths.img));
});
gulp.task('watch', () => {
gulp.watch(srcPaths.pug, ['pug']);
gulp.watch(srcPaths.css, ['css']);
gulp.watch(srcPaths.js, ['js']);
gulp.watch(srcPaths.img, ['images']);
});
gulp.task('browser-sync', () => {
let files = [
buildPaths.build
];
browserSync.init(files, {
server: {
baseDir: './build/'
},
});
});
gulp.task('pages', () => {
gulp.src([buildPaths.build, `!${buildPaths.build}.map`])
.pipe(ghPages());
});
gulp.task('test:perf', sitespeedio({
url: 'http://localhost:3000',
resultBaseDir: buildPaths.tests.perf,
suppressDomainFolder: true,
html: true
}));
gulp.task('test:complexity', () => gulp.src(srcPaths.js)
.pipe(plato(buildPaths.tests.complexity, {
eslint: eslintConfig,
complexity: {
errorsOnly : false,
cyclomatic : 3,
halstead : 10,
maintainability : 90,
trycatch : true
}
})));
gulp.task('default', ['css', 'pug', 'js', 'images', 'watch', 'browser-sync']);
gulp.task('test', ['browser-sync', 'test:perf', 'test:complexity']);
gulp.task('deploy', ['css', 'pug', 'js', 'images', 'pages']);