forked from catrielmuller/shaman
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
103 lines (88 loc) · 2.95 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
var gulp = require('gulp'),
spawn = require('child_process').spawn,
htmlreplace = require('gulp-html-replace'),
node,
watch = require('gulp-watch'),
uglify = require('gulp-uglifyjs'),
rimraf = require('gulp-rimraf'),
sass = require('gulp-sass');
runSequence = require('run-sequence'),
concat = require('gulp-concat');
livereload = require('gulp-livereload');
gulp.task('server', function() {
if (node) node.kill();
node = spawn('node', ['index.js'], {stdio: 'inherit'})
node.on('close', function (code) {
if (code === 8) {
gulp.log('Error detected, waiting for changes...');
}
});
});
gulp.task('server:watch', function(){
livereload.listen();
gulp.run('server');
gulp.watch(['index.js', 'server/*'], function(){
gulp.run('server');
livereload();
});
});
gulp.task('sass', function () {
gulp.src('./public/assets/sass/*.scss')
.pipe(sass().on('error', sass.logError))
.pipe(gulp.dest('./dist/assets'))
.pipe(livereload());
});
gulp.task('sass:watch', function () {
gulp.watch('./public/assets/sass/*.scss', ['sass']);
});
gulp.task('copyDev', function () {
gulp.run('copy');
gulp.watch( ['./public/**/*','./public/**/**/*'], ['copy']);
});
gulp.task('uglify:vendor', function() {
return gulp.src(['./public/app/pixi.js','./public/app/tween.js','./public/app/socketio.js','./public/app/lodash.js'])
.pipe(concat('vendor.js'))
.pipe(uglify())
.pipe(gulp.dest('./dist/app'))
});
gulp.task('uglify:app', function() {
return gulp.src(['!./public/app/pixi.js','!./public/app/socketio.js','!./public/app/lodash.js','!./public/app/tween.js','./public/app/*.js'])
.pipe(concat('app.js'))
.pipe(uglify())
.pipe(gulp.dest('./dist/app'))
});
gulp.task('htmlCompile', function() {
return gulp.src('./public/index.html')
.pipe(htmlreplace({
'css': 'assets/styles.min.css',
'vendor': 'app/vendor.js',
'js': 'app/app.js'
}))
.pipe(gulp.dest('./dist/'));
});
gulp.task('copy', function(){
gulp.src('./public/**')
.pipe(gulp.dest('./dist'))
.pipe(livereload());
});
gulp.task('copy:json', function(){
gulp.src('./public/assets/*.json')
.pipe(gulp.dest('./dist/assets'))
.pipe(livereload());
});
gulp.task('copyImages', function(){
gulp.src(['./public/assets/*.png', './public/assets/*.jpg', './public/assets/*.gif', './public/assets/*.mp3'])
.pipe(gulp.dest('./dist/assets'));
});
gulp.task('clean', function(){
return gulp.src('./dist/**/*', {read: false})
.pipe(rimraf());
});
gulp.task('dev', ['sass:watch', 'copyDev', 'server:watch'] );
gulp.task('compile',function() {
runSequence('clean', 'sass', 'copyImages', 'uglify:vendor','uglify:app', 'htmlCompile','copy:json');
});
// clean up if an error goes unhandled.
process.on('exit', function() {
if (node) node.kill();
});