This repository has been archived by the owner on Jan 31, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
gulpfile.js
197 lines (159 loc) · 5.15 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
187
188
189
190
191
192
193
194
195
196
197
'use strict';
// load plugins
var $ = require('gulp-load-plugins')();
// manually require modules that won"t get picked up by gulp-load-plugins
var gulp = require('gulp'),
del = require('del'),
pkg = require('./package.json'),
browser = require('browser-sync');
// handle errors
var onError = function(error) {
$.util.log('');
$.util.log($.util.colors.red('You fucked up:', error.message, 'on line' , error.lineNumber));
$.util.log('');
this.emit('end');
}
// 'development' is just default, production overrides are triggered
// by adding the production flag to the gulp command e.g. `gulp build --production`
var isProduction = ($.util.env.production === true ? true : false);
// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
// Terminal Banner
// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
console.log("");
console.log($.util.colors.gray(" <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>>>>>>>>>>>>>"));
console.log($.util.colors.cyan(" __ __ __ "));
console.log($.util.colors.cyan(" |__). _ _|_ _ . _ | \ |__) "));
console.log($.util.colors.cyan(" |__)|(_)(_| )(_||| )|__/|__) "));
console.log($.util.colors.cyan(" _/ "));
console.log($.util.colors.gray(" <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>>>>>>>>>>>>>"));
console.log("");
// code banner
var BANNER = [
'/**',
' ** <%= pkg.name %> v<%= pkg.version %>',
' ** <%= pkg.description %>',
' ** <%= pkg.homepage %>',
' **',
' ** <%= pkg.author.name %> <<%= pkg.author.email %>>',
' **',
' ** ',
' ** <%= pkg.repository.url %> ',
' **/',
''
].join('\n');
// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
// Config
// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
// paths
var SRC = 'src/',
DIST = 'dist/bigchaindb-blog/';
// Port to use for the development server
var PORT = 1337,
GHOSTURL = 'localhost:2368';
// Browsers to target when prefixing CSS
var COMPATIBILITY = ['Chrome >= 30', 'Safari >= 6.1', 'Firefox >= 35', 'Opera >= 32', 'iOS >= 8', 'Android >= 4', 'ie >= 10'];
// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
// Tasks
// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
//
// Delete build artifacts
//
gulp.task('clean', function(done) {
return del([
DIST + '**/*',
DIST + '.*' // delete all hidden files
], done)
});
//
// Styles
//
gulp.task('css', ['clean'], function() {
return gulp.src(SRC + 'assets/scss/bigchaindb-blog.scss')
.pipe($.sourcemaps.init())
.pipe($.sass().on('error', $.sass.logError))
.pipe($.autoprefixer({ browsers: COMPATIBILITY }))
.pipe($.if(isProduction, $.cssmin()))
.pipe($.if(!isProduction, $.sourcemaps.write()))
.pipe($.if(isProduction, $.header(BANNER, { pkg: pkg })))
.pipe($.rename({ suffix: '.min' }))
.pipe(gulp.dest(DIST + 'assets/css/'))
.pipe(browser.stream())
});
//
// JavaScript
//
gulp.task('js', ['clean'], function() {
return gulp.src(SRC + 'assets/js/bigchaindb-blog.js')
.pipe($.sourcemaps.init())
.pipe($.include())
.pipe($.if(isProduction, $.uglify())).on('error', onError)
.pipe($.if(!isProduction, $.sourcemaps.write()))
.pipe($.if(isProduction, $.header(BANNER, { pkg: pkg })))
.pipe($.rename({suffix: '.min'}))
.pipe(gulp.dest(DIST + 'assets/js/'))
});
//
// Copy Images
//
gulp.task('img', ['clean'], function() {
return gulp.src(SRC + 'assets/img/**/*')
.pipe($.if(isProduction, $.imagemin({
optimizationLevel: 3, // png
progressive: true, // jpg
interlaced: true, // gif
multipass: true, // svg
svgoPlugins: [{ removeViewBox: false }]
})))
.pipe(gulp.dest(DIST + 'assets/img/'))
});
//
// Copy all the rest
//
gulp.task('copy', ['clean'], function() {
gulp.src([
SRC + '*.hbs',
'./README.md',
'./package.json'
])
.pipe(gulp.dest(DIST))
gulp.src(SRC + 'partials/*.hbs')
.pipe(gulp.dest(DIST + 'partials/'))
gulp.src(SRC + 'assets/fonts/**/*')
.pipe(gulp.dest(DIST + 'assets/fonts/'))
});
//
// Create zip package for upload
//
gulp.task('zip', ['clean', 'copy', 'css', 'js', 'img'], function() {
if (isProduction) {
return gulp.src(DIST + '/**/*')
.pipe($.zip('bigchaindb-blog.zip'))
.pipe(gulp.dest('dist'))
}
});
//
// Dev Server
//
gulp.task('server', ['build'], function() {
browser.init({
proxy: GHOSTURL,
port: PORT,
reloadDebounce: 2000
});
});
// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
// Task sequences
// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
//
// Build site, run server, and watch for file changes
//
gulp.task('default', ['build', 'server'], function() {
gulp.watch([SRC + '**/*'], ['build', browser.reload])
});
//
// Full build
//
// `gulp build` is the development build
// `gulp build --production` is the production build
//
gulp.task('build', ['clean', 'copy', 'css', 'js', 'img', 'zip'])