-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
196 lines (171 loc) · 5.32 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
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
var gulp = require('gulp');
var $ = require('gulp-load-plugins')();
var argv = require('yargs').argv;
var browser = require('browser-sync');
var compatibility = ['last 2 versions', 'ie >= 9'];
var mainBowerFiles = require('main-bower-files');
var merge = require('merge-stream');
var panini = require('panini');
var rimraf = require('rimraf');
var sequence = require('run-sequence');
var sherpa = require('style-sherpa');
var gutil = require('gulp-util');
var isGziped = !!(argv.gzip);
var isProduction = !!(argv.production);
var port = 8000;
var PATHS = {
dist: 'dist',
bootstrap_fonts: [
'bower_components/bootstrap-sass/assets/fonts/bootstrap/**/*'
],
assets: [
'src/assets/**/*',
"!src/assets/{img,js,sass,img/**/,js/**/*,sass/**/*}"
],
css: [],
sass: [
'bower_components/foundation-sites/scss',
'bower_components/bootstrap-sass/assets/stylesheets',
'bower_components/motion-ui/src/'
],
javascript: [
'src/assets/js/**/*.js'
],
javascriptVendors: [
'bower_components/jquery2/dist/jquery.js',
'bower_components/clipboard/dist/clipboard.js',
'bower_components/bootstrap-sass/assets/javascripts/bootstrap.js',
'node_modules/chart.js/dist/Chart.js'
]
};
// Delete the "dist" folder every time a build starts
gulp.task('clean', function(done) {
rimraf(PATHS.dist, done);
});
// Copy files out of the assets folder
gulp.task('copy', function() {
gulp
.src(PATHS.assets)
.pipe(gulp.dest(PATHS.dist + '/assets'));
});
// Copy Bootstrap fonts
gulp.task('bootstrapFonts', function() {
gulp
.src(PATHS.bootstrap_fonts)
.pipe(gulp.dest(PATHS.dist + '/assets/fonts/bootstrap'));
});
// Compiles the sass files and appends the css files from vendors in one app.css file
gulp.task('stylesheets', function() {
var minifycss = $.if(isProduction, $.minifyCss());
var cssStream =
gulp
.src(PATHS.css)
.pipe($.concat('css-styles.css'));
var scssStream =
gulp
.src('src/assets/sass/app.sass')
.pipe($.sourcemaps.init())
.pipe($.sass({
includePaths: PATHS.sass
})
.on('error', $.sass.logError))
.pipe($.autoprefixer({
browsers: compatibility
}))
.pipe(minifycss)
.pipe($.if(!isProduction, $.sourcemaps.write()))
.pipe($.concat('scss-styles.css'));
var mergedStream =
merge(cssStream, scssStream)
.pipe($.concat('app.css'))
.pipe($.if(isProduction && isGziped, $.gzip({})))
.pipe(gulp.dest(PATHS.dist + '/assets/css'));
return mergedStream;
});
// Combine JavaScript
gulp.task('javascript', function() {
var uglify = $.if(isProduction, $.uglify()
.on('error', function(e) {
console.log(e);
}));
return gulp
.src(PATHS.javascript)
.pipe($.sourcemaps.init())
.pipe($.concat('app.js'))
.pipe(uglify)
.pipe($.if(!isProduction, $.sourcemaps.write()))
.pipe(gulp.dest(PATHS.dist + '/assets/js'));
});
// Combine the vendors JavaScript
gulp.task('javascriptVendors', function() {
var uglify = $.if(isProduction, $.uglify()
.on('error', function(e) {
console.log(e);
}));
return gulp
.src(PATHS.javascriptVendors)
.pipe($.concat('vendor.js'))
.pipe(uglify)
.pipe(gulp.dest(PATHS.dist + '/assets/js'));
});
// Copy images to the "dist" folder
gulp.task('images', function() {
var imagemin = $.if(isProduction, $.imagemin({
progressive: true
}));
return gulp
.src('src/assets/img/**/*')
.pipe(imagemin)
.pipe(gulp.dest(PATHS.dist + '/assets/img'));
});
// Use this only when prototyping
// Copy page templates into finished HTML files
gulp.task('pages', function() {
gulp
.src('src/pages/**/*.{html,hbs,handlebars,jade}')
.pipe(panini({
root: 'src/pages/',
layouts: 'src/layouts/',
partials: 'src/partials/',
data: 'src/data/',
helpers: 'src/helpers/'
}))
.pipe(gulp.dest(PATHS.dist));
});
gulp.task('messages', ['server'], function() {
if (!isProduction && !isGziped) {
gutil.log(gutil.colors.yellow("DEVELOPMENT build was finished!"));
} else if (isProduction && !isGziped) {
gutil.log(gutil.colors.green("PRODUCTION build without GZIP was finished!"));
} else if (isProduction && isGziped) {
gutil.log(gutil.colors.green("PRODUCTION with GZIP build was finished!"));
}
});
gulp.task('pages:reset', function(cb) {
panini.refresh();
gulp.run('pages');
cb();
});
// Build the "dist" folder
gulp.task('build', function(done) {
sequence('clean', ['pages', 'stylesheets', 'javascript', 'javascriptVendors', 'images', 'copy', 'bootstrapFonts'], done);
});
// Start a server with LiveReload
gulp.task('server', ['build'], function() {
browser.init({
server: PATHS.dist,
files: [PATHS.dist + '/assets/css/**/*'],
middleware: require("connect-gzip-static")(PATHS.dist),
port: port
});
});
// Build the "dist" folder by running all of the below tasks
gulp.task('default', ['build', 'server', 'messages'], function() {
gulp.watch(PATHS.assets, ['copy', browser.reload]);
gulp.watch(['src/assets/sass/**/*.sass'], ['stylesheets', browser.reload]);
gulp.watch(['src/assets/js/**/*.js'], ['javascript', browser.reload]);
gulp.watch(['src/assets/img/**/*'], ['images', browser.reload]);
// Use only for prototyping
gulp.watch(['src/pages/**/*.html'], ['pages', browser.reload]);
gulp.watch(['src/{layouts,partials}/**/*.html'], ['pages:reset', browser.reload]);
});