This repository has been archived by the owner on Jul 31, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathgulpfile.js
122 lines (107 loc) · 4 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
var gulp = require('gulp');
const noop = require('gulp-noop');
const htmlmin = require('gulp-htmlmin');
let cleanCSS = require('gulp-clean-css');
var concat = require('gulp-concat');
var nunjucksRender = require('gulp-nunjucks-render');
var compiler = require('webpack');
var webpack = require('webpack-stream');
var webpack_config = require('./webpack.config.js');
var webpack_config_prod = require('./webpack.config.prod.js');
var browserSync = require('browser-sync').create();
var sitemap = require('gulp-sitemap');
var save = require('gulp-save');
var cachebust = require('gulp-cache-bust');
const minifyInlineJSON = require('gulp-minify-inline-json');
const isProd = process.env.NODE_ENV === 'production';
/* Read JSON data */
var fs = require('fs');
var read_data = function(name) {
return JSON.parse(fs.readFileSync(`./src/data/${name}.json`))
}
/* Custom nunjucks filters */
var manageEnvironment = function(environment) {
environment.addFilter('mititle', function(str) {
const title = "Mood Indigo | Asia's Largest College Cultural Festival"
if (str && str.length > 0) { return str + " | " + title; }
return title;
});
environment.addFilter('midescription', function(str) {
if (str && str.length > 0) { return str; }
return "Mood Indigo, 27th to 30th December 2018, A Montage of Dreams. IIT Bombay brings you Asia's Largest College Cultural Festival";
});
environment.addFilter('micta', function(str) {
if (str && str.length > 0) { return str; }
return "https://2018.moodi.org/images/CTA.jpg";
});
environment.addFilter('miurl', function(str) {
if (str && str.length > 0) { return str; }
return "https://2018.moodi.org/";
});
environment.addFilter('filexists', function(str) {
return (fs.existsSync('./src' + str)) ? str : false;
});
}
/* Gulp tasks */
gulp.task('webpack', function() {
return gulp.src('src/script/main.js')
.pipe(webpack(isProd ? webpack_config_prod : webpack_config, compiler, function(err, stats) {}))
.pipe(gulp.dest('build/'));
});
gulp.task('webpack-watch', ['webpack'], function (done) { browserSync.reload(); done(); });
gulp.task('assets', function() {
gulp.src(['src/images/**/*']).pipe(gulp.dest('build/images/'));
gulp.src(['src/assets/**/*']).pipe(gulp.dest('build/assets/'));
gulp.src(['src/favicon.ico']).pipe(gulp.dest('build/'));
});
gulp.task('styles', function() {
gulp.src(['src/styles/*.css'])
.pipe(concat('styles.css'))
.pipe(cleanCSS())
.pipe(gulp.dest('build/'));
});
gulp.task('css-watch', ['styles'], function (done) { browserSync.reload(); done(); });
gulp.task('nunjucks', function() {
return gulp.src('src/pages/*.html')
.pipe(save('before-sitemap'))
.pipe(sitemap({ siteUrl: 'https://moodi.org' }))
.pipe(gulp.dest('build/'))
.pipe(save.restore('before-sitemap'))
.pipe(nunjucksRender({
path: ['src/templates'],
data: {
acco_faqs: read_data('acco_faqs'),
people: read_data('people'),
experience: read_data('experience'),
social: read_data('social'),
depts: read_data('depts')
},
manageEnv: manageEnvironment
}))
.pipe(cachebust({
type: 'timestamp'
}))
.pipe(minifyInlineJSON())
.pipe(isProd ? htmlmin({
collapseWhitespace: true,
minifyCSS: true,
minifyJS: true,
removeComments: true,
}) : noop())
.pipe(gulp.dest('build/'))
});
gulp.task('nunjucks-watch', ['nunjucks'], function (done) { browserSync.reload(); done(); });
gulp.task('build', ['webpack', 'styles', 'nunjucks', 'assets'], function(){});
gulp.task('serve', ['build'], function () {
browserSync.init({
server: {
baseDir: "./build/",
serveStaticOptions: {
extensions: ['html']
}
}
});
gulp.watch("src/**/*.html", ['nunjucks-watch']);
gulp.watch("src/**/*.js", ['webpack-watch']);
gulp.watch("src/**/*.css", ['css-watch']);
});