This repository has been archived by the owner on Jul 20, 2021. It is now read-only.
forked from oddbird/accoutrement
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
83 lines (71 loc) · 1.68 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
/* eslint-env node */
'use strict';
const beeper = require('beeper');
const chalk = require('chalk');
const gulp = require('gulp');
const log = require('fancy-log');
const sassdoc = require('sassdoc');
const sasslint = require("gulp-stylelint");
const paths = {
TEST_DIR: 'test/',
SASS_DIR: 'sass/',
IGNORE: [
'!**/.#*',
'!**/flycheck_*'
],
init: function () {
this.SASS = [
this.SASS_DIR + '**/*.scss'
].concat(this.IGNORE);
this.ALL_SASS = [
this.SASS_DIR + '**/*.scss',
this.TEST_DIR + '**/*.scss'
].concat(this.IGNORE);
return this;
}
}.init();
const onError = function (err) {
log.error(chalk.red(err.message));
beeper();
this.emit('end');
};
const sasslintTask = (src, failOnError, shouldLog) => {
if (shouldLog) {
const cmd = `sasslint ${src}`;
log("Running", `'${chalk.cyan(cmd)}'...`);
}
const stream = gulp.src(src).pipe(
sasslint({
reporters: [{ formatter: "string", console: true }],
failAfterError: failOnError
})
);
if (!failOnError) {
stream.on("error", onError);
}
return stream;
};
gulp.task(
"sasslint",
() => sasslintTask(paths.SASS, true)
);
gulp.task(
"sasslint-nofail",
() => sasslintTask(paths.SASS)
);
gulp.task(
'sassdoc',
() => gulp.src(paths.SASS).pipe(sassdoc())
);
gulp.task('watch', (cb) => {
gulp.watch(paths.SASS, gulp.parallel('sassdoc'));
// lint scss on changes
gulp.watch(paths.ALL_SASS).on('all', (event, filepath) => {
if (event === 'add' || event === 'change') {
sasslintTask(filepath, false, true);
}
});
// lint all scss when rules change
gulp.watch('**/.stylelintrc.yml', gulp.parallel('sasslint-nofail'));
cb();
});