This repository has been archived by the owner on Jun 24, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 99
/
Gulpfile.js
107 lines (91 loc) · 2.94 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
var gulp = require('gulp');
var sass = require('gulp-sass');
var minifyCSS = require('gulp-minify-css');
var es6ify = require('es6ify');
var rename = require('gulp-rename');
var browserify = require('browserify');
var uglify = require('gulp-uglify');
var streamify = require('gulp-streamify')
var source = require('vinyl-source-stream');
var exec = require('child_process').exec;
var args = require('yargs').argv;
var express = require('express');
var util = require('gulp-util');
var livereload = require('gulp-livereload');
var s3 = require('s3');
var fs = require('fs');
var files = {
css: 'public/*.css',
scss: 'public/*.scss',
html: 'public/*.html'
};
gulp.task('pre-build', ['sass', 'copy-html', 'copy-css'], function(done) {
exec('node bin/hook.js', done);
});
gulp.task('build', ['pre-build'], function(b) {
var isProd = ['prod', 'production'].indexOf(args.env) !== -1 ? true : false;
var stream = browserify()
.transform(es6ify.configure(/^(?!.*node_modules)+.+\.js$/))
.add(es6ify.runtime)
.add('./index.js', {entry: true})
.external('base_object')
.external('playback')
.external('browser')
.external('zepto')
.external('underscore')
.external('hls')
.bundle()
.pipe(source('main.js'))
.pipe(rename('p2phls' + (isProd ? '.min.js' : '.js')));
if(isProd) {
stream.pipe(streamify(uglify()));
}
stream.pipe(gulp.dest('./dist'))
});
gulp.task('sass', function () {
return gulp.src(files.scss)
.pipe(sass())
.pipe(minifyCSS())
.pipe(gulp.dest("build"));
});
gulp.task("copy-css", function() {
return gulp.src(files.css)
.pipe(minifyCSS())
.pipe(gulp.dest('build'));
});
gulp.task("copy-html", function() {
return gulp.src(files.html)
.pipe(gulp.dest('build'));
});
gulp.task('serve', ['watch'], function() {
express()
.use(express.static('.'))
.use(express.static('./dist'))
.listen(3000, "0.0.0.0");
util.log(util.colors.bgGreen('Listening on port 3000'));
});
gulp.task('watch', function() {
var reloadServer = livereload();
var js = gulp.watch('./*.js');
js.on('change', function(event) {
gulp.start('build', function() {
reloadServer.changed(event.path);
});
});
var assets = gulp.watch('./public/*.{html,scss,css}');
assets.on('change', function(event) {
gulp.start(['sass', 'copy-html', 'copy-css'], function() {
reloadServer.changed(event.path);
});
});
util.log(util.colors.bgGreen('Watching for changes...'));
});
gulp.task('upload', function(b) {
var awsOptions = JSON.parse(fs.readFileSync('./aws.json'));
var client = s3.createClient({s3Options: awsOptions});
var params = {localDir: "./dist/", deleteRemoved: true, s3Params: {Bucket: "cdn.clappr.io", Prefix: "bemtv/latest/"}};
var uploader = client.uploadDir(params);
uploader.on('error', function(err) { console.error("unable to sync:", err.stack); });
uploader.on('end', function() { console.log("done uploading"); });
return;
});