-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.babel.js
220 lines (197 loc) · 7.63 KB
/
gulpfile.babel.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
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
// Include config
import config from './config';
// Plugins
import gulp from 'gulp';
import del from 'del';
import plugins from 'gulp-load-plugins';
import browser from 'browser-sync';
import yargs from 'yargs';
import named from 'vinyl-named';
import webpack from 'webpack-stream';
// Variables
const globalConfig = config();
const $ = plugins();
const PRODUCTION = !!(yargs.argv.production);
const TEST = !!(yargs.argv.devtest);
function cleanStyles () {
return del([globalConfig.outputPath + globalConfig.outputFolders.styles + '**/*.css'], {force: true});
}
function cleanScriptsVendor () {
return del([globalConfig.outputPath + globalConfig.outputFolders.scripts + 'vendor.js'], {force: true});
}
function cleanScripts () {
return del([
globalConfig.outputPath + globalConfig.outputFolders.scripts + '**/*.{js, map}',
'!' + globalConfig.outputPath + globalConfig.outputFolders.scripts + 'drupal/',
'!' + globalConfig.outputPath + globalConfig.outputFolders.scripts + 'drupal/**/*.js',
'!' + globalConfig.outputPath + globalConfig.outputFolders.scripts + '**/*.behaviors.js',
'!' + globalConfig.outputPath + globalConfig.outputFolders.scripts + 'vendor.js'
], {force: true});
}
function cleanImages () {
return del([globalConfig.outputPath + globalConfig.outputFolders.images + '**/*.{png,gif,jpg}'], {force: true});
}
function cleanFonts () {
return del([globalConfig.outputPath + globalConfig.outputFolders.fonts + '**/*.{eot,otf,svg,ttf,woff,woff2}'], {force: true});
}
function cleanHtml () {
return del([globalConfig.outputPath + globalConfig.outputFolders.templates + '*.html'], {force: true});
}
function sasslint () {
return gulp.src(globalConfig.assetsToLoad.styles)
.pipe($.if(!TEST, $.plumber()))
.pipe($.sassLint())
.pipe($.sassLint.format())
.pipe($.sassLint.failOnError())
.on('end', () => {
$.util.log($.util.colors.green('Sass Lint compiled'));
});
}
function style () {
return gulp.src(globalConfig.assetsToLoad.styles)
.pipe($.if(!PRODUCTION, $.sourcemaps.init()))
.pipe($.sass.sync({
outputStyle: 'compressed',
includePaths: [globalConfig.sourcePath + globalConfig.sourceFolders.styles, './node_modules']
}).on('error', $.sass.logError))
.pipe($.autoprefixer({
browsers: ['last 2 version', 'safari 5', 'ie 9', 'ff 17', 'opera 12.1', 'ios 6', 'android 4'],
cascade: false
}))
.pipe($.if(!PRODUCTION, $.sourcemaps.write()))
.pipe(gulp.dest(globalConfig.outputPath + globalConfig.outputFolders.styles))
.pipe(browser.stream())
.on('end', () => {
$.util.log($.util.colors.green('Styles compiled'));
});
}
function vendorScripts () {
return gulp.src(globalConfig.assetsToLoad.vendorScripts)
.pipe($.plumber())
.pipe($.concat('vendor.js'))
.pipe($.babel({presets: ['es2015']}))
.pipe($.if(PRODUCTION, $.uglify()))
.pipe(gulp.dest(globalConfig.outputPath + globalConfig.outputFolders.scripts))
.on('end', function () {
$.util.log($.util.colors.green('Scripts compiled'));
});
}
function scripts (done) {
if (!PRODUCTION) {
globalConfig.webpackConfig['devtool'] = 'eval-source-map';
globalConfig.webpackConfig['watch'] = true;
}
return gulp.src(globalConfig.assetsToLoad.scripts)
.pipe(named())
.pipe(webpack(globalConfig.webpackConfig, null, function (err, stats) {
$.util.log($.util.colors.green(stats.toString({
chunks: false, // Makes the build much quieter
colors: true
})));
browser.reload();
done();
}))
.pipe($.if(PRODUCTION, $.uglify()))
.pipe(gulp.dest(globalConfig.outputPath + globalConfig.outputFolders.scripts))
.on('end', function () {
$.util.log($.util.colors.green('Scripts compiled'));
});
}
function eslint () {
return gulp.src(globalConfig.sourcePath + globalConfig.sourceFolders.scripts + '**/*')
.pipe($.if(!TEST, $.plumber()))
.pipe($.eslint())
.pipe($.eslint.format())
.on('end', () => {
$.util.log($.util.colors.green('ES Lint compiled'));
});
}
function images () {
return gulp.src(globalConfig.assetsToLoad.images)
.pipe($.newer(globalConfig.outputPath + globalConfig.outputFolders.images))
.pipe(gulp.dest(globalConfig.outputPath + globalConfig.outputFolders.images))
.on('end', function () {
$.util.log($.util.colors.green('Images compiled'));
});
}
function fonts () {
return gulp.src(globalConfig.assetsToLoad.fonts)
.pipe($.newer(globalConfig.outputPath + globalConfig.outputFolders.fonts))
.pipe(gulp.dest(globalConfig.outputPath + globalConfig.outputFolders.fonts))
.on('end', function () {
$.util.log($.util.colors.green('Fonts compiled'));
});
}
function svgFont () {
return gulp.src([globalConfig.sourcePath + globalConfig.sourceFolders.svg + '*.svg'])
.pipe($.iconfontCss({
fontName: globalConfig.svgFontName,
path: globalConfig.sourcePath + globalConfig.sourceFolders.styles + 'base/_icons.scss',
targetPath: '../' + globalConfig.sourceFolders.styles + 'base/_icons-rendered.scss',
fontPath: '../' + globalConfig.sourceFolders.fonts
}))
.pipe($.iconfont({
fontName: globalConfig.svgFontName,
formats: ['svg', 'ttf', 'eot', 'woff', 'woff2']
}))
.pipe(gulp.dest(globalConfig.sourcePath + globalConfig.outputFolders.fonts))
.on('end', () => {
$.util.log($.util.colors.green('Icon font compiled'));
});
}
function html () {
return gulp.src(globalConfig.assetsToLoad.templates + '.html')
.pipe($.plumber())
.pipe(gulp.dest(globalConfig.outputPath + globalConfig.outputFolders.templates))
.on('end', function () {
$.util.log($.util.colors.green('Html compiled'));
});
}
function pug () {
return gulp.src(globalConfig.assetsToLoad.templates + '.pug')
.pipe($.plumber())
.pipe($.pug({pretty: true}))
.pipe(gulp.dest(globalConfig.outputPath + globalConfig.outputFolders.templates))
.on('end', function () {
$.util.log($.util.colors.green('Pug compiled'));
});
}
function webServer (done) {
browser.init({
server: globalConfig.outputPath,
startPath: globalConfig.outputFolders.templates
});
done();
}
function watch () {
gulp.watch(globalConfig.sourcePath + globalConfig.sourceFolders.scripts + '**/*').on('change', eslint);
gulp.watch(globalConfig.assetsToLoad.styles).on('change', gulp.series(cleanStyles, sasslint, style));
gulp.watch(globalConfig.assetsToLoad.images).on('change', gulp.series(cleanImages, images, browser.reload));
gulp.watch(globalConfig.assetsToLoad.fonts).on('change', gulp.series(cleanFonts, fonts, browser.reload));
gulp.watch(globalConfig.sourcePath + globalConfig.sourceFolders.styles + 'svg/*.svg', gulp.series(cleanFonts, svgFont, fonts, browser.reload));
gulp.watch(globalConfig.assetsToLoad.templates + '.html').on('change', gulp.series(cleanHtml, html, browser.reload));
gulp.watch(globalConfig.assetsToLoad.templates + '.pug').on('change', gulp.series(cleanHtml, pug, browser.reload));
}
// Default task
gulp.task('default',
gulp.series(
gulp.parallel(cleanStyles, cleanScriptsVendor, cleanScripts, cleanImages, cleanFonts, cleanHtml),
gulp.parallel(sasslint, eslint),
svgFont, style, vendorScripts, eslint, scripts, images, fonts, html, pug, webServer, watch
)
);
// Build task
gulp.task('build',
gulp.series(
gulp.parallel(cleanStyles, cleanScriptsVendor, cleanScripts, cleanImages, cleanFonts, cleanHtml),
gulp.parallel(sasslint, eslint),
svgFont, style, vendorScripts, scripts, images, fonts, html, pug)
);
// Build dev
gulp.task('build-dev',
gulp.series(svgFont, style, vendorScripts, scripts, images, fonts)
);
// Lint Test task
gulp.task('linttest',
gulp.parallel(sasslint, eslint)
);