-
Notifications
You must be signed in to change notification settings - Fork 31
/
gulpfile.js
95 lines (85 loc) · 2.5 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
/* eslint-env node */
/* eslint-disable unicorn/prefer-module */
/* eslint-disable unicorn/prefer-node-protocol */
/* eslint no-unused-vars: ["error", { "varsIgnorePattern": "debug" }] */
let child_process = require('child_process');
let gulp = require('gulp');
let log = require('fancy-log');
let rename = require('gulp-rename');
let sass = require('gulp-sass')(require('sass'));
let sourcemaps = require('gulp-sourcemaps');
let Transform = require('stream').Transform;
let paths = {
styles: ['*/static/scss/**/*.scss'],
scripts: ['*/static/js/src/**/*.js'],
};
function debug() {
var transformStream = new Transform({objectMode: true});
transformStream._transform = function (file, encoding, callback) {
console.log('Path is:', file.path);
callback(undefined, file);
};
return transformStream;
}
function styles() {
return (
gulp
.src(paths.styles)
//.pipe(debug())
.pipe(sourcemaps.init())
.pipe(sass({outputStyle: 'expanded'}).on('error', sass.logError))
.pipe(
rename(function (path) {
path.dirname = path.dirname.replace(
/^[^/]+\/static\/scss/,
'css',
);
}),
)
.pipe(sourcemaps.write('sourcemaps/'))
.pipe(gulp.dest('static/'))
);
}
function scripts() {
return (
gulp
.src(paths.scripts)
//.pipe(debug())
.pipe(
rename(function (path) {
path.dirname = path.dirname.replace(
/^[^/]+\/static\/js\/src/,
'js',
);
}),
)
.pipe(gulp.dest('static/'))
);
}
function watch() {
gulp.watch(paths.scripts, scripts);
gulp.watch(paths.styles, styles);
}
function clean() {
return child_process.exec(
'git clean -fdx static/',
function (error, stdout, stderr) {
if (error) {
log.error(`git clean failed: ${error}`);
}
if (stderr) {
process.stderr.write(stderr);
}
if (stdout) {
process.stdout.write(stdout);
}
},
);
}
var build = gulp.parallel(styles, scripts);
exports.build = build;
exports.clean = clean;
exports.default = gulp.series(build, watch);
exports.scripts = scripts;
exports.styles = styles;
exports.watch = watch;