This repository has been archived by the owner on Jun 27, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 33
/
gulpfile.js
186 lines (171 loc) · 4.8 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
184
185
186
/*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')();
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('scss/**/*.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('styles'))
.pipe(browserSync.reload({
stream: true
}));
});
// process JS files and return the stream.
gulp.task('js', function () {
return gulp.src('scripts/**/*.js')
.pipe(gulp.dest('scripts'));
});
// 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('scripts/*.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('scripts/*.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('scripts/*.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 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 = [
'styles/main.css',
'scripts/**/*.js',
'images/**/*',
'templates/**/*.twig'
];
//initialize browsersync
browserSync.init(files, {
proxy: "mysite.dev" // 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('scss/**/*.scss')
.pipe(styleguide.generate({
title: 'Monoset Styleguide',
overviewPath: 'README.md',
server: true,
port: 3010,
// customColors: '/scss/utils/_styleguide_custom_variables.scss',
// For static style guide. Generat relative to your environment:
// appRoot: '/themes/monoset/styleguide',
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('styleguide/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("scss/**/*.scss", ['sass', 'styleguide']);
// gulp.watch("scripts/**/*.js", ['js']);
// });
// Default task to be run with `gulp`
gulp.task('default', ['sass', 'browser-sync'], function() {
gulp.watch("scss/**/*.scss", ['sass']);
gulp.watch("scripts/**/*.js", ['js']);
});