-
Notifications
You must be signed in to change notification settings - Fork 1
/
gulpfile.js
121 lines (91 loc) · 2.44 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
'use strict';
var gulp = require('gulp');
var gutil = require('gulp-util');
var browserify = require('browserify');
var watchify = require('watchify');
var source = require('vinyl-source-stream');
var browserSync = require('browser-sync').create();
var del = require('del');
var merge = require('merge-stream');
// IMPORTANT
// edit gulp.config.json and customize there your deployment settings
var rsync = require('gulp-rsync');
var config = {};
try {
config = require('./gulp.config.json');
}
catch (e) {
console.warn('Edit or create gulp.config.json to customize your deployment' +
' settings.');
}
//
// browserify and js
//
var bundler = browserify([
'./src/js/main.js'
]);
var bundle = function () {
return bundler
.bundle()
.on('error', gutil.log)
.pipe(source('bundle.js'))
.pipe(gulp.dest('.tmp/js/'))
.pipe(browserSync.stream({once: true}));
};
gulp.task('browserify', bundle);
// 3rd party libs that don't play nice with browserify
gulp.task('libs', function () {
var dir = './node_modules/phaser/build/';
return gulp.src(['phaser.min.js', 'phaser.map'], { cwd: dir, base: dir})
.pipe(gulp.dest('./.tmp/js/lib/'));
});
gulp.task('js', ['browserify', 'libs']);
//
// build and deploy
//
gulp.task('build', ['js']);
gulp.task('dist', ['build'], function () {
var rawFiles = gulp.src([
'index.html', 'raw.html',
'styles.css',
'images/**/*', 'fonts/**/*', 'audio/**/*'
], { cwd: './src', base: './src' })
.pipe(gulp.dest('./dist/'));
var builtFiles = gulp.src(['js/**/*'], { cwd: '.tmp', base: '.tmp' })
.pipe(gulp.dest('./dist/'));
return merge(rawFiles, builtFiles);
});
gulp.task('clean', function () {
return del(['.tmp', 'dist', '.publish']);
});
gulp.task('deploy:rsync', ['dist'], function () {
return gulp.src('dist')
.pipe(rsync({
root: 'dist',
username: config.deploy.user,
hostname: config.deploy.host,
destination: config.deploy.destination,
recursive: true,
clean: true,
progress: true,
incremental: true
}));
});
gulp.task('deploy', ['deploy:rsync'])
//
// dev tasks
//
gulp.task('watch', function () {
bundler = watchify(bundler, watchify.args);
bundler.on('update', bundle);
});
gulp.task('run', ['watch', 'build'], function () {
browserSync.init({
server: ['src', '.tmp']
});
gulp.watch('src/**/*.{html,css}').on('change', browserSync.reload);
});
//
// default task
//
gulp.task('default', ['dist']);