-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
gulpfile.js
117 lines (101 loc) · 2.41 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
/* eslint-env node */
'use strict';
const beeper = require('beeper');
const chalk = require('chalk');
const Fiber = require('fibers');
const gulp = require('gulp');
const log = require('fancy-log');
const sass = require('gulp-sass');
const sasslint = require("gulp-stylelint");
const autoprefixer = require('gulp-autoprefixer');
const sourcemaps = require('gulp-sourcemaps');
const { spawn } = require('child_process');
sass.compiler = require('sass');
const paths = {
SASS_DIR: './assets/scss/',
CSS_DIR: './assets/css/',
IGNORE: [
'!**/.#*',
'!**/flycheck_*'
],
init: function () {
this.SASS = [
this.SASS_DIR + '**/*.scss'
].concat(this.IGNORE);
this.ALL_SASS = [
this.SASS_DIR + '**/*.scss'
].concat(this.IGNORE);
return this;
}
}.init();
// Try to ensure that all processes are killed on exit
const spawned = [];
process.on('exit', () => {
spawned.forEach(pcs => {
pcs.kill();
});
});
const spawnTask = function(command, args, cb) {
spawned.push(
spawn(command, args, { stdio: 'inherit' })
.on('error', err => {
beeper();
return cb(err);
})
.on('exit', cb),
);
};
gulp.task('sass', () => {
return gulp.src(paths.SASS_DIR + '**/*.scss')
.pipe(sourcemaps.init())
.pipe(sass({fiber: Fiber}))
.pipe(autoprefixer({
browsers: ['last 2 versions'],
cascade: false
}))
.pipe(sourcemaps.write('.'))
.pipe(gulp.dest(paths.CSS_DIR));
});
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('watch', (cb) => {
gulp.watch(paths.SASS, gulp.parallel(['sasslint', 'sass']));
// lint all scss when rules change
gulp.watch('**/.stylelintrc.yml', gulp.parallel('sasslint-nofail'));
cb();
});
gulp.task(
'serve',
(cb) => spawnTask('yarn', ['serve'], cb)
);
gulp.task(
'default',
gulp.parallel('watch', 'serve'),
);