forked from aleksip/shila-drupal-theme
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgulpfile.js
More file actions
155 lines (137 loc) · 3.23 KB
/
gulpfile.js
File metadata and controls
155 lines (137 loc) · 3.23 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
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
/* eslint-env node */
'use strict';
// Configuration.
var config = {};
config.browserSync = {
proxyTarget: 'localhost:8080',
proxyReqHeaders: {
host: 'www.shila.dev'
}
};
config.drush = {
alias: '@local.d8.shila'
};
config.sass = {
srcFiles: [
'./dist/sass/*.scss'
],
watchFiles: [
'./dist/sass/**/*.scss',
'./dist/_patterns/**/*.scss',
'./node_modules/shila-css/**/*.scss'
],
options: {
includePaths: [
'./dist/sass',
'./node_modules/shila-css',
'./node_modules/breakpoint-sass/stylesheets',
'./node_modules/sass-toolkit/stylesheets',
'./node_modules/singularitygs/stylesheets'
],
outputStyle: 'expanded'
},
destDir: './dist/css'
};
config.patternsDir = './dist/_patterns';
config.imageFiles = './dist/images/**/*';
config.patternLab = {
dir: './pattern-lab'
};
config.drupal = {
templatesDir: './templates'
};
// Load Gulp and other tools.
var gulp = require('gulp');
var run = require('gulp-run');
var runSequence = require('run-sequence');
var sass = require('gulp-sass');
var sourcemaps = require('gulp-sourcemaps');
var browserSync = require('browser-sync').create();
var fs = require('fs');
var sassLint = require('gulp-sass-lint');
var sassGlob = require('gulp-sass-glob');
// Helper functions.
function isDirectory(dir) {
try {
return fs.statSync(dir).isDirectory();
}
catch (err) {
return false;
}
}
// Gulp tasks.
/**
* Sets up BrowserSync and watchers.
*/
gulp.task('watch', ['sass-change'], function () {
browserSync.init({
proxy: {
target: config.browserSync.proxyTarget,
reqHeaders: config.browserSync.proxyReqHeaders
}
});
gulp.watch(config.sass.watchFiles, ['sass-change']);
gulp.watch(config.patternsDir + '/**/*.twig', ['patterns-change']);
});
/**
* Compiles Sass files.
*/
gulp.task('sass', function () {
return gulp.src(config.sass.srcFiles)
.pipe(sassGlob())
.pipe(sourcemaps.init())
.pipe(sass(config.sass.options).on('error', sass.logError))
.pipe(sourcemaps.write('./'))
.pipe(gulp.dest(config.sass.destDir))
.pipe(browserSync.stream({match: '**/*.css'}));
});
/**
* Task sequence to run when Sass files have changed.
*/
gulp.task('sass-change', function () {
runSequence('sass', 'pl:generate');
});
/**
* Task sequence to run when StarterKit pattern files have changed.
*/
gulp.task('patterns-change', function () {
runSequence('pl:generate', 'bs:reload');
});
/**
* Task sequence to run when Drupal theme templates have changed.
*/
gulp.task('templates-change', function () {
runSequence('drush:cr', 'bs:reload');
});
/**
* Generates Pattern Lab front-end.
*/
gulp.task('pl:generate', function () {
if (isDirectory(config.patternLab.dir)) {
return run('php ' + config.patternLab.dir + '/core/console --generate').exec();
}
});
/**
* Runs drush cr.
*/
gulp.task('drush:cr', function () {
return run('drush ' + config.drush.alias + ' cr').exec();
});
/**
* Calls BrowserSync reload.
*/
gulp.task('bs:reload', function () {
browserSync.reload();
});
/**
* Lints Sass files.
*/
gulp.task('lint:sass', function () {
return gulp.src(config.sass.srcFiles)
.pipe(sassLint())
.pipe(sassLint.format());
});
/**
* Gulp default task.
*/
gulp.task('default', ['watch']);