-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
183 lines (168 loc) · 5.02 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
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
/*global -$ */
'use strict';
if (!this.Promise) {
//require('es6-promise').polyfill();
var Promise = require('es6-promise').Promise;
}
var gulp = require('gulp');
var $ = require('gulp-load-plugins')(); //postRequireTransforms
var browserSync = require('browser-sync');
var reload = browserSync.reload;
var styleguide = require('sc5-styleguide');
var sass = require('gulp-sass');
var outputPath = 'styleguide';
// Error notifications
var reportError = function(error) {
$.notify({
title: 'Gulp Task Error',
message: 'Check the console.'
}).write(error);
console.log(error.toString());
this.emit('end');
}
// Sass processing
gulp.task('sass', function() {
return gulp.src('src/sass/**/*.scss')
.pipe($.sourcemaps.init())
// Convert sass into css
.pipe($.sass({
outputStyle: 'nested', // libsass doesn't support expanded yet
precision: 10
}))
// 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
}));
});
// 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('img/**/*')
.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 cr css-js',
]))
.pipe($.notify({
title: "Caches cleared",
message: "Drupal CSS/JS caches cleared.",
onLast: true
}));
});
// BrowserSync
gulp.task('browser-sync', function() {
//watch files
var files = [
'css/main.css',
'js/**/*.js',
'img/**/*',
'templates/**/*.twig'
];
//initialize browsersync
browserSync.init(files, {
proxy: "drupalvm.test" // BrowserSync proxy, change to match your local environment
});
});
// Styleguide Generator with SC5: https://github.com/SC5/sc5-styleguide
gulp.task('styleguide:generate', function() {
return gulp.src('src/sass/**/*.scss')
.pipe(styleguide.generate({
title: 'My Styleguide',
overviewPath: 'README.md',
server: true,
port: 3010,
extraHead: [
'<link href="https://fonts.googleapis.com/css?family=Roboto:400,100,300,500,700,900">',
],
rootPath: outputPath,
disableEncapsulation: true,
// disableHtml5Mode: true
}))
.pipe(gulp.dest(outputPath));
});
gulp.task('styleguide:applystyles', function() {
return gulp.src('src/sass/main.scss')
.pipe(sass({
errLogToConsole: true
}))
.pipe(styleguide.applyStyles())
.pipe(gulp.dest(outputPath));
});
// Style guide generator incorporated into default gulp task (Experimental).
// Uncomment and replace the current task bellow if you need a style guide generated when you run 'gulp'.
// Style guide will be served on port: 3010.
gulp.task('styleguide', ['styleguide:generate', 'styleguide:applystyles']);
// Default tasks with styleguide.
// gulp.task('default', ['sass', 'browser-sync', 'styleguide'], function() {
// gulp.watch("src/scss/**/*.scss", ['sass', 'styleguide']);
// gulp.watch("js/**/*.js", ['js']);
// });
// Default task to be run with `gulp`
gulp.task('default', ['sass', 'browser-sync'], function() {
gulp.watch("src/sass/**/*.scss", ['sass']);
gulp.watch("js/**/*.js", ['js']);
});