-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
172 lines (144 loc) · 6.03 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
'use strict';
const gulp = require('gulp');
const gls = require('gulp-live-server');
const rename = require('gulp-rename');
const stylus = require('gulp-stylus');
const cleanCSS = require('gulp-clean-css');
const uglify = require('gulp-uglify');
const download = require('gulp-download');
const replace = require('gulp-replace');
const paths = {
styles: {
stylus: 'app/public/stylesheets/src/main.styl',
css: 'app/public/stylesheets/src/main.css',
},
app: [
'app/app.js',
'app/sockets.js',
'app/bin/www',
'app/routes/**/*.js',
'app/lib/**/*.js',
'app/config/**/*.js',
],
uglify: [
'app/public/javascripts/src/main-vanilla.js',
'app/public/javascripts/src/ajax-vanilla.js',
'app/public/javascripts/src/main-jquery.js',
'app/public/javascripts/src/slick.js',
],
vendor: [
'https://raw.githubusercontent.com/jquery/jquery-dist/master/dist/jquery.min.js',
'https://raw.githubusercontent.com/kenwheeler/slick/master/slick/slick.js',
],
files: [
'app/views/*.hbs',
'app/views/**/*.hbs',
'app/database/data.json',
'app/locales/*.json',
],
};
////////////////////////////////////////////////////////////////////////////////////////////////////
// SERVER
////////////////////////////////////////////////////////////////////////////////////////////////////
const server = gls.new([
//'--trace-deprecation', '--trace-sync-io', '--ignition', 'index',
'--trace-deprecation', '--ignition', 'app/index',
//{ env: { NODE_ENV: 'production' } }
]);
//you can access cwd args in `bin/www` via `process.argv`
gulp.task('start', () => server.start());
////////////////////////////////////////////////////////////////////////////////////////////////////
// CSS
////////////////////////////////////////////////////////////////////////////////////////////////////
// Stylus
gulp.task('stylus', () =>
gulp.src(paths.styles.stylus)
.pipe(stylus({ 'include css': true, compress: false }))
.pipe(rename({ extname: '.css' }))
.pipe(gulp.dest('app/public/stylesheets/src'))
);
// MINIFY CSS
// http://goalsmashers.github.io/css-minification-benchmark/
gulp.task('minify-css', () =>
gulp.src(paths.styles.css)
.pipe(cleanCSS({ compatibility: '*', debug: true }, details =>
console.log('%s: The file was reduced from %s bytes to %s bytes. This means %s% reduction in size!',
details.name,
details.stats.originalSize,
details.stats.minifiedSize,
Math.round(details.stats.efficiency * 100)
)
))
.pipe(rename({ basename: 'style', extname: '.min.css' }))
.pipe(gulp.dest('app/public/stylesheets'))
);
gulp.task('css', gulp.series('stylus', 'minify-css'));
////////////////////////////////////////////////////////////////////////////////////////////////////
// CLIENT LIBRARIES
////////////////////////////////////////////////////////////////////////////////////////////////////
gulp.task('vendor', () =>
download(paths.vendor)
.pipe(gulp.dest('app/public/vendor'))
);
gulp.task('slick', () =>
gulp.src(['app/public/vendor/slick.js'])
.pipe(replace(
/animProps\[_\.animType\] = 'translate3d\(' \+ targetLeft \+ 'px, 0px, 0px\)';/igm,
'animProps[_.animType] = \'translate(\' + targetLeft + \'px, 0px)\'; // FIX BY LANTI'
))
.pipe(replace(
/animProps\[_\.animType\] = 'translate3d\(0px,' \+ targetLeft \+ 'px, 0px\)';/igm,
'animProps[_.animType] = \'translate(0px,\' + targetLeft + \'px)\'; // FIX BY LANTI'
))
.pipe(replace(
/positionProps\[_\.animType\] = 'translate3d\(' \+ x \+ ', ' \+ y \+ ', 0px\)';/igm,
'positionProps[_.animType] = \'translate(\' + x + \', \' + y + \')\'; // FIX BY LANTI'
))
.pipe(replace(/mozHidden/igm, 'hidden'))
.pipe(replace(/mozVisibilityState/igm, 'visibilityState'))
.pipe(uglify({ output: { quote_style: 1 } }))
.pipe(rename({ extname: '.min.js' }))
.pipe(gulp.dest('app/public/vendor'))
);
gulp.task('vendors', gulp.series('vendor', 'slick'));
////////////////////////////////////////////////////////////////////////////////////////////////////
// UGLIFY JS
////////////////////////////////////////////////////////////////////////////////////////////////////
gulp.task('uglify', () =>
gulp.src(paths.uglify)
.pipe(uglify({ output: { quote_style: 1 } }))
.pipe(rename({ extname: '.min.js' }))
.pipe(gulp.dest('app/public/javascripts'))
);
////////////////////////////////////////////////////////////////////////////////////////////////////
// FILES
////////////////////////////////////////////////////////////////////////////////////////////////////
gulp.task('files', () => gulp.src(paths.files));
////////////////////////////////////////////////////////////////////////////////////////////////////
// INIT: APP
////////////////////////////////////////////////////////////////////////////////////////////////////
gulp.task('app', gulp.parallel('start', 'css', 'uglify', 'files'));
////////////////////////////////////////////////////////////////////////////////////////////////////
// WATCH: Rerun the task when a file changes
////////////////////////////////////////////////////////////////////////////////////////////////////
gulp.task('watch:start', () =>
// server.start OR server.notify
gulp.watch(paths.app, gulp.series('start'), file => server.notify.apply(server, [file]))
);
gulp.task('watch:stylus', () =>
gulp.watch(paths.styles.stylus, gulp.series('stylus'), server.notify)
);
gulp.task('watch:css', () =>
gulp.watch(paths.styles.css, gulp.series('minify-css'), server.notify)
);
gulp.task('watch:uglify', () =>
gulp.watch(paths.uglify, gulp.series('uglify'), server.notify)
);
gulp.task('watch:files', () =>
gulp.watch(paths.files, gulp.series('files'), server.notify)
);
gulp.task('watch', gulp.parallel('watch:start', 'watch:stylus', 'watch:css', 'watch:uglify', 'watch:files'));
////////////////////////////////////////////////////////////////////////////////////////////////////
// EXECUTE GULP
////////////////////////////////////////////////////////////////////////////////////////////////////
gulp.task('default', gulp.parallel('app', 'watch'));