-
Notifications
You must be signed in to change notification settings - Fork 1
/
gulpfile.js
166 lines (145 loc) · 4.34 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
/* eslint strict: [2, "global"] */
'use strict';
let _ = require('lodash'),
st = require('st'),
argv = require('yargs').argv,
http = require('http'),
gulp = require('gulp'),
swig = require('gulp-swig'),
sass = require('gulp-sass'),
babel = require('gulp-babel'),
gulpif = require('gulp-if'),
eslint = require('gulp-eslint'),
uglify = require('gulp-uglify'),
rename = require('gulp-rename'),
concat = require('gulp-concat'),
notify = require('gulp-notify'),
cssnano = require('gulp-cssnano'),
plumber = require('gulp-plumber'),
imagemin = require('gulp-imagemin'),
pngquant = require('imagemin-pngquant'),
livereload = require('gulp-livereload'),
sourcemaps = require('gulp-sourcemaps'),
autoprefixer = require('gulp-autoprefixer'),
babelES2015 = require('babel-preset-es2015'),
babelStage2 = require('babel-preset-stage-2');
const vendor = {
scripts: [
'node_modules/odometer/odometer.js',
'node_modules/scrollmagic/scrollmagic/uncompressed/ScrollMagic.js',
'node_modules/scrollmagic/scrollmagic/uncompressed/plugins/jquery.ScrollMagic.js',
'node_modules/gumshoe/dist/js/gumshoe.js',
'node_modules/smooth-scroll/dist/js/smooth-scroll.js',
'node_modules/tether/dist/js/tether.js',
'node_modules/bootstrap/dist/js/bootstrap.js',
'node_modules/moment/moment.js',
'node_modules/moment/locale/pt-br.js',
],
styles: [
'node_modules/odometer/odometer-theme-minimal.css',
],
};
function isVendorScript(f) {
return _.some(vendor.scripts, (v) => {
return f.path.replace(/\\/g, '/').endsWith(v);
});
}
if (!argv.production) {
vendor.scripts.push('node_modules/scrollmagic/scrollmagic/uncompressed/plugins/debug.addIndicators.js');
}
// Server - listed on localhost:8080
gulp.task('webserver', () => {
http.createServer(
st({
path: __dirname + '/dist',
index: 'index.html',
cache: false,
})
).listen(8080);
});
gulp.task('styles', () => {
return gulp.src(vendor.styles.concat(['sass/styles.scss']))
.pipe(plumber())
.pipe(sourcemaps.init())
.pipe(sass({ outputStyle: 'expanded' }))
.pipe(autoprefixer())
.pipe(gulpif(argv.production, cssnano()))
.pipe(concat('crowdfunding.min.css'))
.pipe(sourcemaps.write('.'))
.pipe(gulp.dest('dist/css'))
.pipe(livereload())
.pipe(notify({ message: 'Styles task complete', onLast: true }));
});
// Lint JS
gulp.task('lint', () => {
return gulp.src(['js/**/*.js'])
.pipe(eslint())
.pipe(eslint.format())
.pipe(eslint.failAfterError());
});
// Concatenate & Minify JS
gulp.task('scripts', ['lint'], () => {
return gulp.src(vendor.scripts.concat(['js/**/*.js']))
.pipe(plumber())
.pipe(sourcemaps.init())
.pipe(gulpif(_.negate(isVendorScript), babel({
presets: [babelES2015, babelStage2],
compact: false,
})))
.pipe(gulpif(argv.production, uglify()))
.pipe(concat('crowdfunding.min.js'))
.pipe(sourcemaps.write('.'))
.pipe(livereload())
.pipe(gulp.dest('dist/js'))
.pipe(notify({ message: 'Scripts task complete', onLast: true }));
});
// Images
gulp.task('images', () => {
return gulp.src('img/**/*')
.pipe(plumber())
.pipe(gulpif(argv.production, imagemin({
progressive: true,
interlaced: true,
multipass: true,
use: [pngquant({speed: 1})],
})))
.pipe(gulp.dest('dist/img'))
.pipe(livereload())
.pipe(notify({ message: 'Images task complete', onLast: true }));
});
// Templates
gulp.task('templates', () => {
return gulp.src('swig/index.swig')
.pipe(plumber())
.pipe(swig({defaults: {cache: false}}))
.pipe(rename('index.html'))
.pipe(gulp.dest('dist'))
.pipe(livereload())
.pipe(notify({ message: 'Templates task complete', onLast: true }));
});
// Documents
gulp.task('documents', () => {
return gulp.src('doc/**/*')
.pipe(plumber())
.pipe(gulp.dest('dist/doc'))
.pipe(livereload())
.pipe(notify({ message: 'Documents task complete', onLast: true }));
});
// Watch
gulp.task('watch', () => {
// Watch .scss files
gulp.watch('sass/**/*.scss', ['styles']);
// Watch .js files
gulp.watch('js/**/*.js', ['scripts']);
// Watch image files
gulp.watch('img/**/*', ['images']);
// Watch template files
gulp.watch(['swig/**/*.swig'], ['templates']);
// Watch document files
gulp.watch(['doc/**/*'], ['documents']);
// Create LiveReload server
livereload.listen({ basePath: 'dist' });
});
// Build
gulp.task('build', ['styles', 'scripts', 'templates', 'images', 'documents']);
gulp.task('default', ['build', 'webserver', 'watch']);