-
Notifications
You must be signed in to change notification settings - Fork 6
/
gulpfile.js
executable file
·165 lines (152 loc) · 3.95 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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
/rest//*global -$ */
'use strict';
var gulp = require('gulp');
var sass = require('gulp-sass');
var mainBowerFiles = require('main-bower-files');
var $ = require('gulp-load-plugins')();
var browserSync = require('browser-sync');
var reload = browserSync.reload;
// Error notifications
var reportError = function(error) {
$.notify({
title: 'Gulp Task Error',
message: 'Check the console.'
}).write(error);
console.log(error.toString());
this.emit('end');
}
var config = {
bootstrapDir: './bower_components/bootstrap-sass',
};
// Sass processing
gulp.task('sass', function() {
return gulp.src('scss/**/*.scss')
.pipe($.sourcemaps.init())
// Convert sass into css
.pipe($.sass({
outputStyle: 'nested', // libsass doesn't support expanded yet
precision: 10,
includePaths: [config.bootstrapDir + 'assets/stylesheets/bootstrap']
}))
// Show errors
.on('error', reportError)
// Autoprefix properties
.pipe($.autoprefixer({
browsers: ['last 2 versions']
}))
// Write sourcemaps
.pipe($.sourcemaps.write())
// Save css
.pipe(gulp.dest('css'))
.pipe(browserSync.reload({
stream: true
}))
.pipe($.notify({
title: "SASS Compiled",
message: "Your CSS files are ready sir.",
onLast: true
}));
});
// process JS files and return the stream.
gulp.task('js', function () {
return gulp.src('js/**/*.js')
.pipe(gulp.dest('js'));
});
// Optimize Images
gulp.task('images', function() {
return gulp.src('images/**/*')
.pipe($.imagemin({
progressive: true,
interlaced: true,
svgoPlugins: [{
cleanupIDs: false
}]
}))
.pipe(gulp.dest('images'));
});
// JS hint
gulp.task('jshint', function() {
return gulp.src('js/*.js')
.pipe(reload({
stream: true,
once: true
}))
.pipe($.jshint())
.pipe($.jshint.reporter('jshint-stylish'))
.pipe($.notify({
title: "JS Hint",
message: "JS Hint says all is good.",
onLast: true
}));
});
// Beautify JS
gulp.task('beautify', function() {
gulp.src('js/*.js')
.pipe($.beautify({indentSize: 2}))
.pipe(gulp.dest('scripts'))
.pipe($.notify({
title: "JS Beautified",
message: "JS files in the theme have been beautified.",
onLast: true
}));
});
// Compress JS
gulp.task('compress', function() {
return gulp.src('js/*.js')
.pipe($.sourcemaps.init())
.pipe($.uglify())
.pipe($.sourcemaps.write())
.pipe(gulp.dest('scripts'))
.pipe($.notify({
title: "JS Minified",
message: "JS files in the theme have been minified.",
onLast: true
}));
});
// Run drush to clear the theme registry
gulp.task('drush', function() {
return gulp.src('', {
read: false
})
.pipe($.shell([
'drush cc views',
]))
.pipe($.notify({
title: "Caches cleared",
message: "Drupal caches cleared.",
onLast: true
}));
});
// BrowserSync
gulp.task('browser-sync', function() {
//watch files
var files = [
'styles/main.css',
'js/**/*.js',
'images/**/*',
'templates/**/*.twig'
];
browserSync.init({
proxy: "p4p.dev:8080" ,
online: true
});
//initialize browsersync
});
// gulp.task('bower', function() {
// // mainBowerFiles is used as a src for the task,
// // usually you pipe stuff through a task
// return gulp.src(mainBowerFiles())
// // Then pipe it to wanted directory, I use
// // dist/lib but it could be anything really
// .pipe(gulp.dest('dist/lib'))
// });
// Default task to be run with `gulp`
gulp.task('default', ['sass', 'browser-sync', 'js', 'drush'], function() {
gulp.watch("scss/**/*.scss", ['sass']);
gulp.watch("bower_components/bootstrap-sass/assets/stylesheets/**/*.scss", ['sass']);
gulp.watch("js/**/*.js", ['js']);
gulp.watch("templates/*.twig", ['drush']);
gulp.watch("**/*.yml", ['drush']);
gulp.watch("**/*.theme", ['drush']);
gulp.watch("src/*.php", ['drush']);
});