forked from SunBentBoulders/Dream-Dash-WebVersion
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
177 lines (154 loc) · 4.48 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
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
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
'use strict';
var gulp = require('gulp');
var gutil = require('gulp-util');
var stripDebug = require('gulp-strip-debug');
var stripComments = require('gulp-strip-comments');
var uncss = require('gulp-uncss');
var rename = require('gulp-rename');
var concat = require('gulp-concat');
var uglify = require('gulp-uglify');
var imagemin = require('gulp-imagemin');
var cssmin = require('gulp-minify-css');
var htmlmin = require('gulp-htmlmin');
var htmlbuild = require('gulp-htmlbuild');
var clean = require('gulp-clean'); //will delete non-min files for deployment
var git = require('gulp-git');
var paths = {
scripts: [
'public_html/app.js',
'public_html/factories/**/*.js',
'public_html/aboutGame/**/*.js',
'public_html/info/**/*.js',
'public_html/game/**/*.js',
'public_html/vendor/**/*.js',
'public_html/lib/**/*.js',
'public_html/src/**/*.js'
],
images: [
'public_html/img/**/*',
'public_html/assets/images/**/*',
'public_html/icons/**/*'
],
css: [
'public_html/css/**/*.css',
'public_html/assets/style/**/*.css'
],
html: [
'public_html/**/*.html',
'public_html/game/**/*.html',
'public_html/aboutGame/**/*.html',
'public_html/info/**/*.html'
]
};
gulp.task('watch', function() {
gulp.watch(paths.scripts, ['scripts']);
/*
gulp.watch(paths.images, ['images']);
*/
gulp.watch(paths.css, ['mincss']);
});
//TASK to Remove Console.log and Debugger statements
gulp.task('devstrip', function(){
return gulp.src('paths.scripts')
.pipe(stripDebug())
.pipe(stripComments())
});
//TASK to Remove NonMin & Add Min Script Tags to Index.html
gulp.task('injecthtml', function(){
gulp.src(['public_html/index.html'])
.pipe(htmlbuild({
js: htmlbuild.preprocess.js(function(block){
block.write('minified/allfiles.min.js');
block.end();
}),
css: htmlbuild.preprocess.css(function(block){
block.write('minified/stylesheet.min.css');
block.end();
})
// .pipe(gulp.dest('public_html/index.html'))
}))
//.pipe(gulp.dest('./')); Needed?
});
gulp.task('minhtml', function(){
gulp.src(paths.html)
.pipe(htmlmin({collapseWhitespace: true}))
.pipe(rename({
extname: '.min.html'
}))
.pipe(gulp.dest('public_html/minified'))
});
gulp.task('scripts', function() {
//output and put script in build folder
return gulp.src(paths.scripts)
//concat and uglify scripts
.pipe(concat('allfiles.js'))
.pipe(uglify().on('error', gutil.log))
//rename minified file, then place in public folder
.pipe(rename({
extname: '.min.js'
}))
.pipe(gulp.dest('public_html/minified'));
});
//TASK to Minify All Images - Currently only reduces size by 1.5MB, using API instead
/*gulp.task('minimgs', function(){
return gulp.src(paths.images)
.pipe(imagemin({optimizationLevel: 6}))
.pipe(gulp.dest('minified'));
});*/
//TASK to Remove Unused CSS
/*gulp.task('delcss', function(){
return gulp.src(paths.css)
.pipe(uncss(paths.html))
// .pipe(gulp.dest('./css'))
});*/
//TASK to Minify All CSS
gulp.task('mincss', function() {
return gulp.src(paths.css)
.pipe(cssmin({
compatibility: 'ie8'
}))
.pipe(rename({
extname: '.min.css'
}))
.pipe(gulp.dest('public_html/minified'));
});
//TASK to delete non-minified files, to-be-used after minification ONLY
gulp.task('cleanup', function(){
return gulp.src([paths.scripts, paths.html, paths.css], {read: false})
.pipe(clean())
});
//Start of Git TASKS
gulp.task('clone', function(){
git.clone('https://github.com/sunbentboulders/Dream-Dash-WebVersion.git', function (err) {
if (err) throw err;
});
});
gulp.task('checkout', function(){
git.checkout('branchName', function (err) {
if (err) throw err;
});
});
gulp.task('pull', function(){
git.pull('upstream', ' ', {args: '--rebase'}, function (err) {
if (err) throw err;
});
});
gulp.task('push', function(){
git.push('origin', 'master', {args: " -f"}, function (err) {
if (err) throw err;
});
});
gulp.task('default', [
'watch',
'mincss'
]);
gulp.task('deploy', [
'watch',
'devstrip',
// 'cleanup',
'scripts',
// 'delcss',
'mincss',
'injecthtml',
'minhtml'
]);