-
Notifications
You must be signed in to change notification settings - Fork 23
/
Copy pathgulpfile.js
109 lines (91 loc) · 3.26 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
'use strict';
var gulp = require('gulp');
var $ = require('gulp-load-plugins')();
var jeet = require('jeet');
var pngquant = require('pngquant');
var jpegtran = require('imagemin-jpegtran');
var webpack = require('webpack-stream');
var wp = require('webpack');
var theme = 'themes/overpass_doc/';
gulp.task('styles', function () {
return gulp.src('themes/src/styles/main.styl')
//stylus
.pipe($.plumber())
.pipe($.sourcemaps.init())
.pipe($.stylus({use: [jeet()]}))
.pipe($.autoprefixer({browsers: ['last 1 version']}))
.pipe($.minifyCss())
.pipe($.sourcemaps.write())
.pipe(gulp.dest(theme + 'static/css'));
});
gulp.task('scripts', [], function() {
var config = require('./webpack.config.js');
config.devtool = "inline-source-map";
return gulp.src('themes/src/scripts/main.js')
.pipe(webpack(config))
.pipe(gulp.dest(theme + 'static/js/'));
});
gulp.task('scripts-deploy', [], function() {
var config = require('./webpack.config.js');
config.plugins.push(
new wp.optimize.UglifyJsPlugin({minimize:true})
);
return gulp.src('themes/src/scripts/main.js')
.pipe(webpack(config))
.pipe(gulp.dest(theme + 'static/js/'));
});
gulp.task('jshint', function () {
return gulp.src('themes/src/scripts/**/*.js')
.pipe($.jshint())
.pipe($.jshint.reporter('jshint-stylish'))
.pipe($.jshint.reporter('fail'));
});
gulp.task('html', ['styles'], function () {
var assets = $.useref.assets({searchPath: '{.tmp,themes/src}'});
return gulp.src('themes/src/layouts/*.html')
.pipe(assets)
.pipe($.if('*.js', $.uglify()))
.pipe($.if('*.css', $.csso()))
.pipe(assets.restore())
.pipe($.useref())
.pipe($.if('*.html', $.htmlclean()))
.pipe(gulp.dest(theme + 'layouts'));
});
gulp.task('partials', ['styles'], function () {
var assets = $.useref.assets({searchPath: '{.tmp,themes/src}'});
return gulp.src('themes/src/layouts/**/*.html')
.pipe(assets)
.pipe($.if('*.js', $.uglify()))
.pipe($.if('*.css', $.csso()))
.pipe(assets.restore())
.pipe($.useref())
.pipe($.if('*.html', $.htmlclean()))
.pipe(gulp.dest(theme + 'layouts/'));
});
gulp.task('clean', require('del').bind(null, [theme + 'layouts', theme + 'static/assets/css/*.css', theme + 'static/assets/*.js']));
gulp.task('watch', function () {
// watch for changes
gulp.watch([
'*.html',
theme + 'static/css/**/*.css',
'scripts/**/*.js',
]).on('change', $.livereload.changed);
gulp.watch('themes/src/styles/**/*.styl', ['styles']);
gulp.watch('themes/src/scripts/**/*.js', ['scripts']);
gulp.watch('themes/src/**/*.html', ['html']);
gulp.watch('themes/src/**/*.html', ['partials']);
});
gulp.task('clearcache', function() {
$.cache.clearAll();
});
gulp.task('build', ['jshint', 'html', 'partials'], function () {
return gulp.src(theme + '**/*').pipe($.size({title: 'build', gzip: true}));
});
gulp.task('deploy', ['clean', 'build', 'scripts-deploy'], function(){
gulp.src('').pipe($.shell(['node_modules/.bin/hugo --theme=overpass_doc --baseUrl=//osmlab.github.io/learnoverpass/']));
});
gulp.task('default', ['clean', 'build'], function () {
gulp.start('scripts');
gulp.start('watch');
gulp.src('').pipe($.shell(['node_modules/.bin/hugo server --watch --theme=overpass_doc --buildDrafts']));
});