/
gulpfile.babel.js
95 lines (78 loc) · 2.12 KB
/
gulpfile.babel.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
import browserSync from 'browser-sync';
import del from 'del';
import fs from 'fs';
import gulp from 'gulp';
import gulpLoadPlugins from 'gulp-load-plugins';
import sassdoc from 'sassdoc';
import runSequence from 'run-sequence';
// postCss plugins
import autoprefixer from 'autoprefixer';
import mdcss from 'mdcss';
import reporter from 'postcss-reporter';
import scssSyntax from 'postcss-scss';
import stylelint from 'stylelint';
import jigsassMdcss from 'mdcss-theme-jigsass';
const $ = gulpLoadPlugins();
const reload = browserSync.reload;
gulp.task('sass:lint', () =>
gulp.src('scss/**/*.scss')
.pipe($.plumber())
.pipe($.postcss([
stylelint(),
reporter({
clearMessages: true,
throwError: true,
}),
],
{ syntax: scssSyntax }))
);
gulp.task('sass:sg', ['sass:lint', 'clean'], () => {
if (genDocs()) {
runSequence(
['sass:lint', 'clean'],
generateSg);
}
function generateSg() {
return gulp.src('sgSrc/sg.scss')
.pipe($.plumber())
.pipe($.sass.sync({
outputStyle: 'expanded',
precision: 10,
includePaths: ['scss'],
}).on('error', $.sass.logError))
.pipe($.postcss([
autoprefixer({ browsers: ['> 1%', 'last 2 versions', 'ie > 7'] }),
mdcss({
theme: jigsassMdcss({
title: 'jigsass-objects-grid',
examples: {
css: ['assets/sg.css'],
},
}),
assets: ['sgSrc/assets'],
}),
]))
.pipe(gulp.dest('./styleguide/assets'));
}
function genDocs() {
try {
fs.accessSync('noStyleguide', fs.F_OK); return false;
}
catch (e) { return true; }
}
});
gulp.task('serve:sg', ['sass:sg'], () => {
browserSync({
notify: true,
port: 9001,
reloadDelay: 4000,
server: {
baseDir: 'styleguide',
},
});
gulp.watch(['./styleguide/**/*']).on('change', reload);
gulp.watch(['scss/**/*.scss', 'sgSrc/**/*', 'DOCS.md'], ['sass:sg']);
});
gulp.task('clean', del.bind(null, ['styleguide']));
gulp.task('prepublish', ['sass:lint']);
gulp.task('default', () => { gulp.start('serve:sg'); });