-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
88 lines (72 loc) · 2.2 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
const path = require('path');
const chalk = require('chalk');
const gulp = require('gulp');
const prefixer = require('gulp-autoprefixer');
const concat = require('gulp-concat');
const plumber = require('gulp-plumber');
const sass = require('gulp-sass');
const sourcemaps = require('gulp-sourcemaps');
/**
* ---------------------------------------------------------------------
* Constants and utils.
* ---------------------------------------------------------------------
*/
const SRC_PATHS = {
sass: path.join(__dirname, 'resources/assets/sass/*.scss'),
js: path.join(__dirname, 'resources/assets/js/**/*.js')
};
const WATCH_PATHS = {
sass: [
path.join(__dirname, 'resources/assets/sass/**/**/*.scss'),
path.join(__dirname, 'resources/assets/sass/**/**/**/*.scss')
],
js: path.join(__dirname, 'resources', 'assets', 'js', '**', '*.js')
};
const DEST_PATHS = {
sass: path.join(__dirname, 'public/css'),
js: path.join(__dirname, 'public/js')
};
const countTask = (() => {
let taskNumber = 1;
return (taskName, color = 'yellow') => {
const title = chalk.bgWhite.black('[ TASK ]');
const task = chalk[color](`[${taskName}]`);
const number = chalk.blue(`${taskNumber++}`.padStart(4, '0'));
console.log(chalk.bold(`${title} ${task}: ${number}`));
};
})();
/**
* ---------------------------------------------------------------------
* Tasks.
* ---------------------------------------------------------------------
*/
function sassTask(done) {
countTask('Sass', 'magenta');
gulp
.src(SRC_PATHS.sass)
.pipe(plumber())
.pipe(sourcemaps.init())
.pipe(sass({ outputStyle: 'compressed' }))
.pipe(prefixer())
.pipe(sourcemaps.write('.'))
.pipe(gulp.dest(DEST_PATHS.sass));
done();
}
function jsTask(done) {
countTask('JS', 'yellow');
gulp
.src(SRC_PATHS.js)
.pipe(concat('index.js'))
.pipe(gulp.dest(DEST_PATHS.js));
done();
}
function watchTask(done) {
gulp.watch(WATCH_PATHS.js, jsTask);
gulp.watch(WATCH_PATHS.sass, sassTask);
done();
}
exports.__js = jsTask;
exports.__sass = sassTask;
exports.__watch = watchTask;
exports.build = gulp.series(jsTask, sassTask);
exports.default = exports.dev = gulp.series(jsTask, sassTask, watchTask);