-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathgulpfile.js
144 lines (129 loc) · 3.71 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
var concat = require('gulp-concat'),
githubPages = require('gulp-gh-pages'),
gulp = require('gulp'),
http = require('node-static'),
jade = require('gulp-jade'),
livereload = require('gulp-livereload'),
minifyImg = require('gulp-imagemin'),
minifyJS = require('gulp-uglify'),
rimraf = require('rimraf'),
sass = require('gulp-ruby-sass'),
util = require('gulp-util'),
when = require('when'),
markdown = require('gulp-markdown')
/**** Compiler tasks ****/
var compiler = {}
// Clean /out directory
compiler.clean = function(done) {
rimraf('./out/**/*', function(){
done()
});
}
// Compile Jade -> HTML
compiler.jade = function() {
console.log("Compiling Jade -> HTML...")
var deferred = when.defer()
gulp.src('./jade/[!_]*.jade')
.pipe(jade())
.pipe(gulp.dest('./out'))
.pipe(livereload())
.on('end', deferred.resolve)
return deferred.promise
}
// Compile SCSS -> CSS
compiler.scss = function() {
console.log("Compiling SCSS -> CSS...")
var deferred = when.defer()
sass('./scss/*.scss', {style: 'compressed'})
.on('error', util.log)
.pipe(gulp.dest('./out/css'))
.pipe(livereload())
.on('end', deferred.resolve)
return deferred.promise
}
// Compile Coffeescript -> JS
compiler.js = function() {
var deferred = when.defer();
console.log("Compiling JS...")
gulp.src(['./js/__*.js', './js/_*.js', './js/main.js'])
.pipe(concat('main.js'))
.pipe(minifyJS())
.pipe(gulp.dest('./out/js'))
.pipe(livereload())
.on('end', deferred.resolve)
return deferred.promise;
}
compiler.images = function(){
console.log("Compiling images...")
var deferred = when.defer()
gulp.src('./img/**/*')
.pipe(minifyImg())
.pipe(gulp.dest('./out/img'))
.on('end', deferred.resolve)
return deferred.promise
}
// Compile static resources
compiler.static = function(){
console.log("Compiling static assets...")
var deferred = when.defer()
gulp.src('./static/**')
.pipe(gulp.dest('./out'))
.on('end', deferred.resolve)
return deferred.promise
}
// Compile markdown
compiler.md = function(){
console.log("Compiling markdown assets...")
var deferred = when.defer()
gulp.src('./jade/markdown/*.md')
.pipe(markdown())
.pipe(gulp.dest('./jade/markdown_out'))
.pipe(livereload())
.on('end', deferred.resolve)
return deferred.promise
}
// Clear directory and compile all
compiler.all = function(done){
when.all([
compiler.md(),
compiler.jade(),
compiler.scss(),
compiler.js(),
compiler.images(),
compiler.static()
]).then(function(){
done()
});
}
// Deploy to gh-pages branch
var deploy = function(){
return gulp.src('./out/**/*')
.pipe( githubPages() )
}
// Start a HTTP server on --port (defaults to 8000) and watch for changes
var watch = function() {
livereload.listen()
port = (process.argv.length > 4 && process.argv[3] == '--port') ? parseInt(process.argv[4]) : 8000
require('http').createServer(function (request, response) {
request.addListener('end', function () {
new http.Server('./out').serve(request, response)
}).resume()
}).listen(port)
gulp.watch('./jade/**/*', ['jade'])
gulp.watch('./scss/**/*', ['scss'])
gulp.watch('./js/**/*', ['js'])
gulp.watch('./img/**/*', ['images'])
gulp.watch('./static/**', ['static'])
console.log('Server listening on port %s', port)
}
// Build gulp tasks
gulp.task('clean', compiler.clean)
gulp.task('jade', compiler.jade)
gulp.task('scss', compiler.scss)
gulp.task('js', compiler.js)
gulp.task('img', compiler.img)
gulp.task('static', compiler.static)
gulp.task('compile', ['clean'], compiler.all)
gulp.task('deploy', ['compile'], deploy)
gulp.task('watch', ['compile'], watch)
gulp.task('default', ['compile'])