-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
192 lines (171 loc) · 4.85 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
/* Config settings - Update this when you clone the repo */
var eventRepo = {
remoteUrl: "https://github.com/HackTJ/2018.git",
branch: "gh-pages",
cacheDir: '.page'
}
var homepageRepo = {
remoteUrl: "https://github.com/HackTJ/hacktj.github.io.git",
branch: "master",
cacheDir: '.homepage'
}
/* ----------------------------------------------------- */
var concat = require('gulp-concat');
var githubPages = require("gulp-gh-pages");
var gulp = require('gulp');
var http = require('node-static');
var pug = require('gulp-pug');
var livereload = require('gulp-livereload');
var minifyIMG = require('gulp-imagemin')
var minifyJS = require('gulp-uglify')
var rmdir = require('rimraf');
var sass = require('gulp-sass');
var when = require('when');
/**** Compiler tasks ****/
var compiler = {};
// Clean /out directory
compiler.clean = function(cb) {
rmdir('./out/**/*', function(){
console.log('done cleaning')
return cb();
});
}
// Compile HTML
compiler.html = function() {
console.log('Compiling HTML...');
var deferred = when.defer();
gulp.src('./pug/[!_]*.pug')
.pipe(pug())
.pipe(gulp.dest('./out'))
.pipe(livereload())
.on('end', function(){
deferred.resolve();
});
return deferred.promise;
}
// Compile CSS
compiler.css = function() {
console.log('Compiling CSS...');
var deferred = when.defer()
gulp.src('./scss/[!_]*.scss')
.pipe(sass({outputStyle: 'compressed'}))
.on('error', function (err) { console.log(err.message); })
.pipe(gulp.dest('./out/css'))
.pipe(livereload())
.on('end', function(){
deferred.resolve();
});
return deferred.promise;
}
// Compile JS
compiler.js = function() {
console.log('Compiling JS...');
var main = when.defer();
gulp.src(['./js/image.js','./js/__*.js', './js/_*.js', './js/main.js'])
.pipe(concat('main.js'))
.pipe(minifyJS())
.pipe(gulp.dest('./out/js'))
.on('end', function(){
main.resolve();
});
var upload = when.defer();
gulp.src('./js/upload.js')
.pipe(minifyJS())
.pipe(gulp.dest('./out/js'))
.on('end', function(){
upload.resolve();
});
var hackathon = when.defer();
gulp.src(['./js/moment.js','./js/hackathonsList.js','./js/hackathons.js'])
.pipe(minifyJS())
.pipe(gulp.dest('./out/js'))
.on('end', function(){
hackathon.resolve();
});
var register = when.defer();
gulp.src(['./js/register.js'])
.pipe(minifyJS())
.pipe(gulp.dest('./out/js'))
.on('end', function(){
hackathon.resolve();
});
return when.all([main, upload, hackathon, register]).promise;
}
// Compile static resources
compiler.static = function(){
console.log('Compiling static...');
var deferred = when.defer();
gulp.src('./static/**')
.pipe(gulp.dest('./out'))
.on('end', function(){
deferred.resolve();
});
return deferred.promise;
}
// Add gulp tasks for each compiler
Object.keys(compiler).forEach(function(name){
gulp.task(name, compiler[name]);
})
// Clear directory and compile all
var compileAll = function(cb){
when.all([
compiler.html(),
compiler.css(),
compiler.js(),
compiler.static()
]).then(function(stuff){
console.log("Compiled all files.")
return cb();
});
}
gulp.task('compile', ['clean'], compileAll)
/**** Deploy tasks ****/
var deploy = {}
// Deploy to hacktj.org/year
deploy.event = function(){
var deferred = when.defer();
gulp.src("./out/**/*")
.pipe( githubPages( eventRepo ) )
.on('end', function(){
deferred.resolve();
});
return deferred.promise;
}
// Deploy to hacktj.org
deploy.homepage = function() {
var deferred = when.defer();
return gulp.src("./out/**/*")
.pipe( githubPages( homepageRepo ) )
.on('end', function(){
deferred.resolve();
});
return deferred.promise;
}
// Deploy to both targets
deploy.all = function(cb){
when.all([
deploy.event(),
deploy.homepage()
]).then(function(){
return cb();
})
}
// Add gulp tasks for each deploy target
Object.keys(deploy).forEach(function(target){
gulp.task('deploy-'+target, ['compile'], deploy[target]);
});
gulp.task('watch', ['default'], 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('./static/**', ['static']);
gulp.watch('./scss/**/*.scss', ['css']);
gulp.watch('./js/**/*.js', ['js'])
gulp.watch('./pug/*.pug', ['html']);
console.log("Server listening on port %s", port)
});
gulp.task('default', ['compile'])