-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
126 lines (108 loc) · 4.14 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
var gulp = require('gulp');
var elm = require('gulp-elm');
var autoprefixer = require('gulp-autoprefixer');
var rename = require('gulp-rename');
var minifyCSS = require('gulp-clean-css');
var uglifyJS = require('gulp-uglify');
var concat = require('gulp-concat');
var rimraf = require('rimraf');
var yaml = require('js-yaml');
var fs = require('fs');
var replace = require('gulp-replace');
var stripDebug = require('gulp-strip-debug');
var ifElse = require('gulp-if-else');
var gutil = require('gulp-util');
var argv = require('yargs').argv;
var exec = require('child_process').execSync;
var env = argv.prod ? "prod" : "dev";
var config = yaml.safeLoad(fs.readFileSync('config/build.yml', 'utf8'));
var generated = { buildNum : new Date().getTime() };
var envConf = config[env] || {};
console.log("Building for environment:", env);
for(key in config)
if(key !== "prod" && key !== "dev")
envConf[key] = config[key];
envConf.gen = generated;
var injectConfig = function() {
if(!config[env]) throw "Invalid environment string: \"" + env + "\"";
return replace(new RegExp("{{%(.*?)%}}","gi"), function(text) {
var propList = text.replace(new RegExp("{{%|%}}","g"),"").trim().split(".");
var replaceVal = propList.reduce(function(props,key) {
if(!props[key])
throw "Error during replacement. No such property: " + text;
else
return props[key];
}, envConf);
return replaceVal;
});
};
var buildCss = function(stylesheet) {
exec('mkdir -p public/dist/css');
exec('cabal --config-file=/dev/null run style ' + stylesheet + ' | tail -n 1 1> public/dist/css/' + stylesheet + '.min.css');
};
gulp.task('build:reader-css', function() {
console.log("Compiling Reader CSS.");
buildCss("reader");
console.log("Compiling Renderer CSS.");
buildCss("renderer");
});
gulp.task('build:reader-js', ['build:reader-elm'], function() {
gulp.src(['tmp-elm/Main.js','src/js/RendererInterface.js','src/js/disqus-include.js','src/js/ga-include.js','src/js/ImagePreloader.js'])
.pipe(concat('reader.js'))
.pipe(injectConfig())
.pipe(ifElse(env === "prod", stripDebug))
.pipe(uglifyJS({ mangle: false }))
.pipe(rename({
suffix: '.min'
}))
.pipe(gulp.dest('public/dist/js'));
gulp.src('src/js/Renderer.js')
.pipe(rename('renderer.js'))
.pipe(injectConfig())
.pipe(ifElse(env === "prod", stripDebug))
.pipe(uglifyJS({ mangle: false }).on('error', gutil.log))
.pipe(rename({
suffix: '.min'
}))
.pipe(gulp.dest('public/dist/js'));
});
gulp.task('build:reader-html', function() {
return gulp.src(['src/html/reader.html','src/html/renderer.html','src/html/mailchimp-signup.html'])
.pipe(injectConfig())
.pipe(gulp.dest('public'));
});
gulp.task('build:reader-elm', function() {
return gulp.src('src/elm/Reader/Main.elm')
.pipe(elm({ optimize: env === "prod" }))
.pipe(gulp.dest('tmp-elm'));
});
gulp.task('build:countdown-js', ['build:countdown-elm'], function() {
gulp.src(['tmp-elm/ReleaseCountdown.js','src/js/ga-include.js'])
.pipe(concat('countdown.js'))
.pipe(injectConfig())
.pipe(ifElse(env === "prod", stripDebug))
.pipe(uglifyJS({ mangle: false }))
.pipe(rename({
suffix: '.min'
}))
.pipe(gulp.dest('public/dist/js'));
});
gulp.task('build:countdown-html', function() {
return gulp.src(['src/html/coming_soon.html'])
.pipe(injectConfig())
.pipe(gulp.dest('public'));
});
gulp.task('build:countdown-css', function() {
buildCss("countdown");
});
gulp.task('build:countdown-elm', function() {
return gulp.src('src/elm/ReleaseCountdown.elm')
.pipe(elm({ optimize: env === "prod" }))
.pipe(gulp.dest('tmp-elm'));
});
gulp.task('build:reader', ['build:reader-html','build:reader-css','build:reader-js'], function() {
rimraf('./tmp-elm', function() {});
});
gulp.task('build:countdown', ['build:countdown-html','build:countdown-js','build:countdown-css'], function() {
rimraf('./tmp-elm', function() {});
});