forked from MissingMaps/missingmaps.github.io
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgulpfile.js
More file actions
194 lines (174 loc) · 5.76 KB
/
gulpfile.js
File metadata and controls
194 lines (174 loc) · 5.76 KB
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
const gulp = require('gulp');
const autoprefixer = require('gulp-autoprefixer');
const browserSync = require('browser-sync');
const cleaner = require('gulp-clean');
const concat = require('gulp-concat');
const cp = require('child_process');
const fs = require('fs');
const git = require('gulp-git');
const markdownpdf = require("markdown-pdf");
const plumber = require('gulp-plumber');
const request = require('request');
const runSequence = require('run-sequence').use(gulp);
const sass = require('gulp-sass');
const sourcemaps = require('gulp-sourcemaps');
const uglify = require('gulp-uglify');
const zip = require('gulp-zip');
function clean() {
return gulp.src(['_site', '.tmp', 'app/_data/events', 'app/_posts'], {read: false, allowEmpty: true})
.pipe(cleaner());
}
exports.clean = clean;
function copyAssets() {
return gulp.src('.tmp/assets/**')
.pipe(gulp.dest('_site/assets'));
}
exports.copyAssets = copyAssets;
function styles() {
const sassInput = 'app/assets/styles/*.scss';
const sassOptions = {
includePaths: ['node_modules/foundation-sites/scss','node_modules/@fortawesome/fontawesome-free/scss','.tmp/assets/styles' ],
errLogToConsole: true,
outputStyle: 'expanded'
};
return gulp.src(sassInput)
.pipe(plumber())
.pipe(sourcemaps.init())
.pipe(sass(sassOptions).on('error', sass.logError))
.pipe(autoprefixer())
.pipe(sourcemaps.write('.'))
.pipe(browserSync.reload({stream:true}))
.pipe(gulp.dest('.tmp/assets/styles'));
}
exports.styles = styles;
function icons() {
return gulp.src('node_modules/@fortawesome/fontawesome-free/webfonts/**.*')
.pipe(gulp.dest('.tmp/assets/fonts'));
}
exports.icons = icons
function javascripts() {
const javascriptPaths = [
// the order of these matter
'app/assets/scripts/*.js',
'node_modules/@fortawesome/fontawesome-free/js/all.min.js'
]
/* https://github.com/Foundation-for-Jekyll-sites/jekyll-foundation/blob/master/gulp/tasks/javascript.js */
return gulp.src(javascriptPaths)
.pipe(concat('main.min.js'))
// .pipe(uglify({ mangle: false }))
.pipe(gulp.dest('.tmp/assets/scripts'))
}
exports.javascripts = javascripts;
function zipMaterials() {
return gulp.src('app/assets/downloads/mapathon-materials/**', { base : "app/assets/downloads/" })
.pipe(zip('mapathon-materials.zip'))
.pipe(gulp.dest('.tmp/assets/downloads'))
}
exports.zipMaterials = zipMaterials;
function validationPdf(cb) {
markdownpdf({
cssPath: 'app/assets/styles/github-markdown.css',
paperFormat: 'Letter'})
.from('app/assets/sources/MissingMaps_validation_josm_en.md')
.to(".tmp/assets/downloads/MissingMaps_validation_josm_en.pdf", function () {
console.log("Done converting MissingMaps_validation_josm_en.md to PDF.")
cb();
})
}
exports.validationPdf = validationPdf;
function cloneEvents(cb) {
git.clone('https://github.com/MissingMaps/events', {args: './app/_data/events'}, function(err) {
// handle err
cb();
});
}
exports.cloneEvents = cloneEvents
function cloneBlog(cb) {
git.clone('https://github.com/MissingMaps/blog', {args: './app/_posts'}, function(err) {
// handle err
cb();
});
}
exports.cloneBlog = cloneBlog
/* Build the jekyll website. */
function jekyll(done) {
const args = ['exec', 'jekyll', 'build'];
switch (environment) {
case 'development':
args.push('--config=_config.yml,_config-dev.yml');
break;
case 'production':
args.push('--config=_config.yml');
break;
}
return cp.spawn('bundle', args, {stdio: 'inherit'})
.on('close', done);
}
exports.jekyll = jekyll;
/* different build options */
/* ======================= */
function watching() {
function browserReload(cb) { browserSync.reload(); cb(); }
browserSync({
server: '_site'
});
gulp.watch(['./app', './_config*'], gulp.series(
jekyll,
gulp.parallel(javascripts, styles, icons),
copyAssets,
browserReload));
}
exports.serve = gulp.series(
clean,
gulp.parallel(cloneEvents, cloneBlog),
jekyll,
gulp.parallel(javascripts, styles, icons, zipMaterials, validationPdf),
copyAssets,
watching);
var environment = 'development';
function setProd(cb) { environment = 'production'; cb(); }
exports.prod = gulp.series(
clean,
gulp.parallel(cloneEvents, cloneBlog),
setProd,
jekyll,
gulp.parallel(javascripts, styles, icons, zipMaterials, validationPdf),
copyAssets);
///////////////////////////////////////////////////////////////////////////////
//--------------------------- Humans task -----------------------------------//
//---------------------------------------------------------------------------//
// gulp.task('get-humans', function(){
//
// var getHumans = function(callback){
// var options = {
// url: 'https://api.github.com/repos/MissingMaps/missingmaps.github.io/contributors',
// headers: {
// 'User-Agent': 'request'
// }
// };
//
// request(options, function (err, res) {
// var humans = JSON.parse(res.body).map(function(human){
// return {login: human.login, html_url: human.html_url, contributions: human.contributions}
// });
// humans.sort(function(a,b){
// return b.contributions - a.contributions;
// })
// callback(humans);
// });
// }
//
// getHumans(function(humans){
// fs.readFile('./docs/humans-tmpl.txt', 'utf8', function (err, doc) {
// if (err) throw err;
// //Do your processing, MD5, send a satellite to the moon, etc.
// for (i = 0; i < humans.length; i++) {
// doc = doc + '\nContributor: '+humans[i].login + '\nGithub: '+humans[i].html_url +'\n';
// }
// fs.writeFile('./app/humans.txt', doc, function(err) {
// if (err) throw err;
// console.log('complete');
// });
// });
// });
// });