-
Notifications
You must be signed in to change notification settings - Fork 163
/
Copy pathgulpfile.js
104 lines (94 loc) · 2.65 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
var gulp = require('gulp'),
zip = require('gulp-zip'),
watch = require('gulp-watch'),
clean = require('gulp-clean'),
jshint = require('gulp-jshint'),
concat = require('gulp-concat'),
uglify = require('gulp-uglify'),
cssmin = require('gulp-cssmin'),
rename = require('gulp-rename'),
htmlmin = require('gulp-htmlmin'),
replace = require('gulp-replace-path');
var APP_NAME = 'save_the_forest';
var bases = {
app: 'src/',
dist: 'dist/',
};
var paths = {
scripts: [
'src/utils.js',
'src/jsfxr.js',
'src/sound.js',
'src/flame.js',
'src/menu.js',
'src/weather.js',
'src/particles.js',
'src/background.js',
'src/player.js',
'src/tree.js',
'src/game.js',
'src/main.js'
],
html: [ 'src/index.html' ],
css: [ 'src/css/*.css' ],
images: [ 'src/images/*.*' ]
};
// Delete the dist directory
gulp.task('clean', function() {
return gulp.src(bases.dist, {read: false})
.pipe(clean());
});
// Process scripts and concatenate them into one output file
gulp.task('scripts', ['clean'], function() {
return gulp.src(paths.scripts)
// .pipe(jshint())
// .pipe(jshint.reporter('default'))
.pipe(concat('game.js'))
.pipe(gulp.dest(bases.dist)) // for dev mode
.pipe(uglify())
.pipe(rename({suffix: '.min'}))
.pipe(gulp.dest(bases.dist)) // for prod
});
// Copy all other files to dist directly
gulp.task('copy', ['clean'], function() {
// Copy images, maintaining the original directory structure
return gulp.src(paths.images, {cwd: bases.app})
.pipe(gulp.dest(bases.dist));
});
gulp.task('uglify-html', ['clean'], function() {
return gulp.src('src/*.html')
.pipe(htmlmin({collapseWhitespace: true}))
.pipe(replace(/..\/dist\//g, ''))
.pipe(replace(/game.css/g, 'game.min.css'))
.pipe(replace(/game.js/g, 'game.min.js'))
.pipe(gulp.dest(bases.dist));
});
gulp.task('uglify-css', ['clean'], function () {
return gulp.src('css/*.css', {cwd: bases.app})
.pipe(gulp.dest(bases.dist)) // for dev mode
.pipe(cssmin())
.pipe(rename({suffix: '.min'}))
.pipe(gulp.dest(bases.dist)); // for prod
});
// Delete the dist directory
gulp.task('zip', ['default'], function() {
return gulp.src([ 'dist/**/*.min.*', 'dist/index.html' ])
.pipe(zip(APP_NAME + '.zip'))
.pipe(gulp.dest('.'));
});
gulp.task('watch' , function () {
return gulp.watch([
paths.scripts,
paths.html,
paths.images,
paths.css
], ['default']);
});
// Define the default task as a sequence of the above tasks
gulp.task('default', [
'clean',
'copy',
'scripts',
'uglify-html',
'uglify-css'
]);