forked from 5calls/5calls-old
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgulpfile.js
More file actions
151 lines (129 loc) · 3.71 KB
/
Copy pathgulpfile.js
File metadata and controls
151 lines (129 loc) · 3.71 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
'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')
, spawn = require('child_process').spawn
;
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));
});
function runKarmaTests (singleRun) {
return new Promise((resolve, reject) => {
const karmaArguments = ['start'];
if (singleRun) {
karmaArguments.push('--single-run');
}
// Karma has a nice public API, but has issues where it can hang when
// trying to shut down after completing tests, so run it as a separate
// process instead. See:
// https://github.com/karma-runner/karma/issues/1693
// https://github.com/karma-runner/karma/issues/1035
const karma = spawn('./node_modules/.bin/karma', karmaArguments, {
cwd: __dirname,
stdio: 'inherit'
});
karma.on('close', code => {
if (code) {
reject(new util.PluginError('Karma', `JS unit tests failed (code ${code})`));
return;
}
resolve();
});
});
}
gulp.task('test', function() {
return runKarmaTests(true);
});
gulp.task('test:watch', function() {
return runKarmaTests(false);
});
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']);