This repository has been archived by the owner on May 10, 2019. It is now read-only.
forked from 5calls/5calls
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
123 lines (105 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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
'use strict';
var gulp = require('gulp')
, sass = require('gulp-sass')
, autoprefixer = require('gulp-autoprefixer')
, imagemin = require('gulp-imagemin')
, util = require('gulp-util')
, browserify = require('browserify')
, es2040 = require('es2040')
, buffer = require('vinyl-buffer')
, source = require('vinyl-source-stream')
, uglify = require('gulp-uglify')
, http_server = require('http-server')
, connect_logger = require('connect-logger')
, mocha = require('gulp-mocha');
;
var SRC = {
html: './static/html',
scss: './static/scss',
img: './static/img',
js: './static/js',
extra: './static/rootExtra'
};
var DEST = {
html:'./app/static',
css: './app/static/css',
img: './app/static/img',
js: './app/static/js'
};
gulp.task('html', function() {
gulp.src(SRC.html + '/*.html')
.pipe(gulp.dest(DEST.html));
});
gulp.task('html:watch', function() {
gulp.watch(`${SRC.html}/*.html`, ['html']);
});
gulp.task('html:serve', function (cb) {
var server = new http_server.HttpServer({
root: 'app/static',
before: [connect_logger()]
});
server.listen(8000, function () {
util.log('HTTP server started on port 8000');
cb();
});
});
// Compile Sass into CSS
gulp.task('sass', function() {
gulp.src(`${SRC.scss}/*.scss`)
.pipe(sass({
outputStyle: 'compressed'
}).on('error', sass.logError))
.pipe(autoprefixer('last 2 version'))
.pipe(gulp.dest(DEST.css));
});
gulp.task('sass:watch', function() {
gulp.watch(`${SRC.scss}/**/*.scss`, ['sass']);
});
// Copy/minify image assets
gulp.task('copy-images', function() {
gulp.src(SRC.img + '/**/*.+(png|jpg|jpeg|gif|svg)')
.pipe(imagemin())
.pipe(gulp.dest(DEST.img));
});
gulp.task('copy-images:watch', function() {
gulp.watch(SRC.img + '/**/*.+(png|jpg|jpeg|gif|svg)');
});
// Bundle and transpile javascript
gulp.task('scripts', function() {
var b = browserify({
entries: `${SRC.js}/main.js`,
debug: true,
transform: [es2040]
});
return b.bundle()
.pipe(source('app.js'))
.pipe(buffer())
.pipe(gulp.dest(DEST.js));
});
gulp.task('build-scripts', function() {
var b = browserify({
entries: `${SRC.js}/main.js`,
debug: false,
transform: [es2040]
});
return b.bundle()
.pipe(source('app.js'))
.pipe(buffer())
.pipe(uglify())
.pipe(gulp.dest(DEST.js));
});
gulp.task('scripts:watch', function() {
gulp.watch(`${SRC.js}/**/*.js`, ['scripts']);
});
gulp.task('extra', function() {
gulp.src(SRC.extra + '/*.+(ico|xml|json)')
.pipe(gulp.dest(DEST.html));
});
gulp.task('test', function() {
return gulp.src(['**/*_test.js', '!./node_modules/**'], { read: false })
.pipe(mocha({
reporter: 'spec',
}));
});
gulp.task('default', ['html', 'html:watch', 'html:serve', 'sass', 'sass:watch', 'copy-images', 'copy-images:watch', 'scripts', 'scripts:watch', 'extra']);
gulp.task('deploy', ['html', 'sass', 'build-scripts', 'extra', 'copy-images']);