forked from jmhobbs/cultofthepartyparrot.com
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
147 lines (130 loc) · 4.43 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
var gulp = require('gulp'),
mocha = require('gulp-mocha'),
mustache = require("gulp-mustache"),
data = require('gulp-data'),
imagemin = require('gulp-imagemin'),
uglifycss = require('gulp-uglifycss'),
rev = require('gulp-rev'),
exec = require('child_process').exec,
fs = require('fs');
gulp.task('test', function() {
return gulp.src(['test/*.js'], { read: false })
.pipe(mocha());
});
gulp.task('render-readme', function () {
return gulp.src('templates/README.md')
.pipe(data(function(file) {
return {
contributors: JSON.parse(fs.readFileSync('contributors.json')).map(function (contributor) {
var len = contributor.contributions.length;
contributor.contributions.forEach(function(v) { v.comma = true; v.and = false; });
contributor.contributions[len-1].comma = false;
if(len > 1) {
contributor.contributions[len-1].and = true;
contributor.contributions[len-2].comma = false;
}
return contributor;
})
};
}))
.pipe(mustache())
.pipe(gulp.dest("."));
});
gulp.task('render-humans', function () {
var d = new Date();
function pad(s) {
if (s.toString().length == 1) {
return "0" + s;
}
return s;
}
return gulp.src('templates/humans.txt')
.pipe(data(function(file) {
return {
contributors: JSON.parse(fs.readFileSync('contributors.json')),
last_update: d.getFullYear() + "/" + pad(d.getMonth()) + "/" + pad(d.getDay())
};
}))
.pipe(mustache())
.pipe(gulp.dest("dist/"));
});
function ParrotObjectAddSlackName (parrot) {
parrot.slack_name = (parrot.gif || parrot.hd).replace(/\.gif$/, '').toLowerCase().replace(/[^a-z0-9-_]/g, '-').replace(/-+/g, '-').replace(/^hd-/,'');
return parrot;
}
// Depends on zip and css for the asset manifest
gulp.task('render', ['test', 'zip', 'css'], function () {
return gulp.src(['templates/index.html', 'templates/parrotparty.yaml'])
.pipe(data(function(file) {
// Mustache doesn't handle dots in keys...
var assets = {};
var json = JSON.parse(fs.readFileSync('dist/assets/rev-manifest.json'));
for(var key in json) {
assets[key.replace('.', '_')] = json[key];
}
return {
parrots: JSON.parse(fs.readFileSync('parrots.json')).map(ParrotObjectAddSlackName),
guests: JSON.parse(fs.readFileSync('guests.json')).map(ParrotObjectAddSlackName),
assets: assets,
zip: JSON.parse(fs.readFileSync('dist/rev-manifest.json'))['parrots.zip'],
guests_zip: JSON.parse(fs.readFileSync('dist/rev-manifest.json'))['guests.zip']
};
}))
.pipe(mustache())
.pipe(gulp.dest("dist/"));
});
gulp.task('zip', ['compress', 'guests-compress'], function () {
return gulp.src('*.zip')
.pipe(rev())
.pipe(gulp.dest('dist/'))
.pipe(rev.manifest())
.pipe(gulp.dest('dist/'));
});
gulp.task('compress', ['test'], function (cb) {
exec('rm -f ./parrots.zip', function (err, stdout, stderr) {
console.log(stderr);
if(err != null) { cb(err); }
exec("echo \" ~= Party or Die =~\n~= cultofthepartyparrot.com =~\" | zip -o -r -z ./parrots.zip ./parrots/*", function(err, stdout, stderr) {
console.log(stderr);
cb(err);
});
});
});
gulp.task('guests-compress', ['test'], function (cb) {
exec('rm -f ./guests.zip', function (err, stdout, stderr) {
console.log(stderr);
if(err != null) { cb(err); }
exec("echo \" ~= Party or Die =~\n~= cultofthepartyparrot.com =~\" | zip -o -r -z ./guests.zip ./guests/*", function(err, stdout, stderr) {
console.log(stderr);
cb(err);
});
});
});
gulp.task('images', function () {
gulp.src('src/favicon.ico')
.pipe(gulp.dest('dist/'));
gulp.src('parrots/**/*')
.pipe(gulp.dest('dist/parrots/'));
gulp.src('guests/**/*')
.pipe(gulp.dest('dist/guests/'));
return gulp.src('src/*.{svg,png,jpg,gif}')
.pipe(imagemin())
.pipe(gulp.dest('dist/assets/'));
});
gulp.task('css', function () {
return gulp.src('src/parrot.css')
.pipe(uglifycss())
.pipe(rev())
.pipe(gulp.dest('dist/assets/'))
.pipe(rev.manifest())
.pipe(gulp.dest('dist/assets/'));
});
gulp.task('clean', function (cb) {
exec('rm -rf dist/*', function (err, stdout, stderr) {
console.log(stdout);
console.log(stderr);
cb(err);
});
});
gulp.task('build', ['test', 'css', 'images', 'render', 'render-humans', 'zip']);
gulp.task('default', ['test']);