forked from liamtoo/Base
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgulpfile.js
More file actions
102 lines (91 loc) · 2.85 KB
/
Copy pathgulpfile.js
File metadata and controls
102 lines (91 loc) · 2.85 KB
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
// Set domain to your local development domain or 'auto' to use BrowserSync.
// Set domain to null to disable BrowserSync.
var domain = 'auto';
var gulp = require('gulp');
var sass = require('gulp-sass');
var sassLint = require('gulp-sass-lint');
var autoprefixer = require('gulp-autoprefixer');
var browserSync = require('browser-sync').create();
var cache = require('gulp-cache');
var sourcemaps = require('gulp-sourcemaps');
var plumber = require('gulp-plumber');
var log = require('fancy-log');
var colors = require('ansi-colors');
var notify = require('gulp-notify');
var exec = require('child_process').exec;
if (domain == 'auto') {
// Attempt to automatically get the domain name from Dev Desktop's config files.
domain = require('gulp-getdevdesktopdomain');
if (domain == null) {
log.error(colors.red.bold('Error: Could not set BrowserSync domain name automatically.'));
log.error(colors.red.bold('Manually set a domain name in gulpfile.js to use BrowserSync.'));
} else {
log.info('Found Dev Desktop domain: ' + colors.magenta(domain));
}
}
gulp.task('serve', function() {
// Skip BrowserSync init if no domain is provided.
if (domain) {
browserSync.init({
proxy: domain
// browser: "google chrome"
});
}
gulp.watch("sass/**/*.scss", gulp.series(['sass']));
gulp.watch("templates/**/*.twig").on('change', gulp.series(['clearDrupalCache', 'browserSyncReload']));
gulp.watch('js/*.js').on('change', gulp.series(['browserSyncReload']));
});
gulp.task('browserSyncReload', function() {
return browserSync.reload();
});
gulp.task('sass', function() {
stream = gulp.src("sass/**/*.scss")
.pipe(plumber(function(error) {
log.error(colors.red.bold('Error (' + error.plugin + '): ' + error.message));
this.emit('end');
}))
.pipe(plumber({errorHandler: notify.onError("Error : <%= error.message %>")}))
.pipe(sourcemaps.init())
.pipe(sourcemaps.identityMap())
.pipe(sass({
outputStyle: 'expanded'
}))
.pipe(sassLint({
configFile: '.sass-lint.yml'
}))
.pipe(sassLint.format())
.pipe(sassLint.failOnError())
.pipe(sass().on('error', sass.logError))
.pipe(autoprefixer([
'ie >= 10',
'ie_mob >= 10',
'ff >= 30',
'chrome >= 28',
'safari >= 5',
'opera >= 23',
'ios >= 6',
'android >= 4.2'
]))
.pipe(sourcemaps.write())
.pipe(gulp.dest("css"));
// Only add BrowserSync to the stream if a domain name is provided.
if (domain) {
stream = stream.pipe(
browserSync.stream({
stream: true
})
);
}
return stream;
});
gulp.task('clearDrupalCache', function(done) {
drushCmd = 'drush cc render';
if (drushCmd) {
exec(drushCmd, function (err, stdout, stderr) {
log(stdout);
log(stderr);
done();
});
}
});
gulp.task('default', gulp.series(['sass', 'serve']));