-
Notifications
You must be signed in to change notification settings - Fork 7
/
gulpfile.js
205 lines (201 loc) · 6.54 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
198
199
200
201
202
203
204
205
var gulp = require('gulp');
var fs = require('fs');
var path = require('path');
var rename = require('gulp-rename');
var less = require('gulp-less');
var async = require('async');
var minifyCSS = require('gulp-minify-css');
var concat = require('gulp-concat');
var http = require('http');
var git = require('gulp-git');
var exec = require('child_process').exec;
var uglify = require('gulp-uglify');
var sourcemaps = require('gulp-sourcemaps');
var livereload = require('gulp-livereload');
var minifyHtml = require('gulp-minify-html');
var replace = require('gulp-replace');
var nodemon = require('gulp-nodemon');
var express = require('express');
var bodyParser = require('body-parser');
var crypto = require('crypto');
// Task responsible for less
gulp.task('less', function() {
// Build it
gulp.src(['public/less/admin.less'])
.pipe(less())
.pipe(gulp.dest('public/dist'));
gulp.src(['public/less/404.less'])
.pipe(less())
.pipe(gulp.dest('public/dist'));
gulp.src(['public/less/main.less'])
.pipe(less())
.pipe(gulp.dest('public/dist'));
gulp.src(['public/less/recruiting.less'])
.pipe(less())
.pipe(gulp.dest('public/dist'));
});
gulp.task('less-prod', function() {
// Build it
gulp.src(['public/less/admin.less'])
.pipe(less())
.pipe(rename({
extname: '.min.css'
}))
.pipe(minifyCSS())
.pipe(gulp.dest('public/dist'));
gulp.src(['public/less/main.less'])
.pipe(less())
.pipe(rename({
extname: '.min.css'
}))
.pipe(minifyCSS())
.pipe(gulp.dest('public/dist'));
gulp.src(['public/less/recruiting.less'])
.pipe(less())
.pipe(rename({
extname: '.min.css'
}))
.pipe(minifyCSS())
.pipe(gulp.dest('public/dist'));
gulp.src(['public/less/404.less'])
.pipe(less())
.pipe(rename({
extname: '.min.css'
}))
.pipe(minifyCSS())
.pipe(gulp.dest('public/dist'));
});
// Task responsible for pages
gulp.task('html', function() {
gulp.src(['public/pages/*.html'])
.pipe(replace('{{.css}}', '.css'))
.pipe(replace('{{.js}}', '.js'))
.pipe(replace('{{.html}}', '.html'))
.pipe(replace('</body>', '<script src="http://localhost:35729/livereload.js"></script></body>'))
.pipe(gulp.dest('public/dist'));
gulp.src(['public/partials/*.html'])
.pipe(rename({
extname: '.partial.html'
}))
.pipe(gulp.dest('public/dist'));
});
gulp.task('html-prod', function() {
gulp.src(['public/pages/*.html'])
.pipe(replace('{{.css}}', '.min.css'))
.pipe(replace('{{.js}}', '.min.js'))
.pipe(replace('{{.html}}', '.min.html'))
.pipe(rename({
extname: '.min.html'
}))
.pipe(minifyHtml({
empty: true,
quotes: true
}))
.pipe(gulp.dest('public/dist'));
gulp.src(['public/partials/*.html'])
.pipe(rename({
extname: '.partial.min.html'
}))
.pipe(minifyHtml({
empty: true,
quotes: true
}))
.pipe(gulp.dest('public/dist'));
});
// Task responsible for running the server
gulp.task('server', function() {
nodemon({
script: 'server.js',
ext: 'js',
ignore: ['public/*'],
env: {
TUACM_DEV: 'true',
TUACM_LOGPATH: path.join(__dirname, 'logs'),
TUACM_MONGO_URL: 'mongodb://tuacm:[email protected]:10045/tuacm',
TUACM_SESSION_SECRET: 'thisIsSoSecretBro',
TUACM_GMAIL_EMAIL: '[email protected]',
TUACM_GMAIL_PASSWORD: 'TestTemple450',
TUACM_PORT: '3000'
}
});
});
// Task responsible for assembling js
gulp.task('js', function() {
// Build it
gulp.src('public/js/*.main.js')
.pipe(concat('main.js'))
.pipe(gulp.dest('public/dist'));
gulp.src('public/js/*.admin.js')
.pipe(concat('admin.js'))
.pipe(gulp.dest('public/dist'));
});
gulp.task('js-prod', function() {
// Build it
gulp.src('public/js/*.main.js')
.pipe(sourcemaps.init())
.pipe(concat('main.min.js'))
.pipe(uglify())
.pipe(sourcemaps.write())
.pipe(gulp.dest('public/dist'));
gulp.src('public/js/*.admin.js')
.pipe(sourcemaps.init())
.pipe(concat('admin.min.js'))
.pipe(uglify())
.pipe(sourcemaps.write())
.pipe(gulp.dest('public/dist'));
});
// This shit waits on the webhook
gulp.task('githook', function() {
var app = express();
app.use(bodyParser.text({'type': 'application/json'}));
app.post('/githook', function(req, res) {
xHubSig = req.headers['x-hub-signature'].substring(5);
hmac = crypto.createHmac('sha1', process.env.GITHUB_SECRET || 'thisissosecret');
hmac.write(req.body);
computedHubSig = hmac.digest('hex');
if (computedHubSig === xHubSig) {
async.series([
function(cb) {
git.pull('origin', 'revamp', {}, cb);
},
function(cb) {
exec('npm install', cb);
},
function(cb) {
exec('bower install', cb);
},
function(cb) {
gulp.start('deploy');
cb();
},
function(cb) {
exec('forever restartall', cb);
}
], function(err) {
if (err) {
res.status(500).send();
console.log(err);
} else {
res.status(200).send();
}
});
} else {
res.status(500).send();
console.log("Digests don't match");
}
});
http.createServer(app).listen(4000, '0.0.0.0')
});
// Task readies for deployment
gulp.task('build', ['less', 'js', 'html'], function() {});
gulp.task('deploy', ['less-prod', 'js-prod', 'html-prod'], function() {});
// Starts the dev server
gulp.task('watch', ['server'], function() {
livereload.listen();
gulp.watch('public/js/*.js', ['js']).on('change', livereload.changed);
gulp.watch('public/less/**/*.less', ['less']).on('change', livereload.changed);
gulp.watch('public/pages/*.html', ['html']).on('change', livereload.changed);;
gulp.watch('public/partials/*.html', ['html']).on('change', livereload.changed);;
});
// Executed on the 'gulp' command
gulp.task('default', ['build', 'watch']);