-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
311 lines (255 loc) · 8.43 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
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
// Requiring Gulp
var gulp = require('gulp');
// Requires the gulp-sass plugin
var sass = require('gulp-sass');
var autoprefixer = require('gulp-autoprefixer');
var sourcemaps = require('gulp-sourcemaps');
var browserSync = require('browser-sync');
var extender = require('gulp-html-extend');
var template = require('gulp-template');
var $ = require('gulp-load-plugins')();
var runSequence = require('run-sequence');
var del = require('del');
var reload = browserSync.reload;
var argv = require('yargs').argv;
var lazypipe = require('lazypipe');
var fc2json = require('gulp-file-contents-to-json');
var svgmin = require('gulp-svgmin');
var svgSymbols = require('gulp-svg-symbols');
//var rsp = require('remove-svg-properties').stream;
var rsp = require('remove-svg-properties');
var gutil = require('gulp-util');
var plugins = require("gulp-load-plugins")({
pattern: ['gulp-*', 'gulp.*'],
replaceString: /\bgulp[\-.]/
});
/* vars */
var appPath = './src';
var distPath = 'dist';
//var indexTmpl = appPath + '/index.html';
var partialsFolder = './src/partials/';
/* templates for nav and about */
var navTempl = partialsFolder + 'nav.html';
var aboutTempl = partialsFolder + 'about.html';
var pageBuildSrc = partialsFolder + 'index.html';
var partialsTemplateFolder = partialsFolder + '_master/templates/';
var generatedPartials = partialsFolder + '_master/globals/';
sassPath = appPath + '/sass/';
sassSpriteTmpl = partialsTemplateFolder + 'sprite-template.scss';
var dataFolder = appPath + '/data';
var navData = require( dataFolder + '/nav-data.json');
var aboutData = require( dataFolder + '/about-data.json');
var svgFolder = appPath + '/svg-original/';
var svgMinFolder = appPath + '/svg-min/';
var config = {
defaultPort: 3000,
supportedBrowsers: [
'ie >= 9',
'last 1 Firefox versions',
'last 1 Chrome versions',
'Safari >= 6',
'iOS >= 6',
'ChromeAndroid >= 4.2'
],
version: require('./package.json').version,
minify: argv.minify || true
};
gulp.task('svg-symbols', function () {
return gulp.src(svgMinFolder +'**/*.svg')
.pipe(svgSymbols())
.pipe(gulp.dest(dataFolder));
});
gulp.task('svgSprite', function () {
return gulp.src(appPath + '/icons/*.svg')
.pipe(svgmin())
.pipe(plugins.svgSprite({
"mode": {
"css": {
"dest": "./",
"sprite": "../images/sprite.svg",
"bust": false,
"render": {
"scss": {
"dest": "_sprite.scss",
"template": sassSpriteTmpl
}
}
}
}
}))
.pipe(gulp.dest(sassPath));
});
gulp.task('sprite', ['svgSprite']);
gulp.task('data', function() {
return gulp.src(appPath + '/data/*')
.pipe(gulp.dest(distPath + '/data/'));
});
// Clean site directory
gulp.task('clean', del.bind(null, ['dist'], {dot: true}));
gulp.task('minify-svgs', function () {
return gulp.src(svgFolder + '**/*')
.pipe(svgmin())
.pipe(gulp.dest('./src/svg-min/'));
});
gulp.task('styles', function() {
gulp.src('src/sass/**/*.scss')
//.pipe(sourcemaps.init()) // Initialize sourcemap plugin
.pipe(sass({outputStyle: 'compressed'}).on('error', sass.logError))
.pipe(autoprefixer()) // Passes it through gulp-autoprefixer
//.pipe(sourcemaps.write()) // Writing sourcemaps
.pipe(gulp.dest('dist/css')) // Outputs it in the css folder
// Reloading the stream
.pipe(browserSync.reload({
stream: true
}));
});
//https://www.npmjs.com/package/gulp-template
gulp.task('build:about', function () {
return gulp.src(aboutTempl)
.pipe(template( {data: aboutData}))
.pipe(gulp.dest(generatedPartials))
// Reloading the stream
.pipe(browserSync.reload({
stream: true
}));
});
//https://www.npmjs.com/package/gulp-template
gulp.task('build:nav', function () {
return gulp.src(navTempl)
.pipe(template( {data: navData}))
.pipe(gulp.dest(generatedPartials))
// Reloading the stream
.pipe(browserSync.reload({
stream: true
}));
});
/*
Builds out and compiles all the template pages
*/
gulp.task('build:pages', ['build:nav', 'build:about'], function () {
return gulp.src( pageBuildSrc )
.pipe(extender({annotations:false,verbose:false}))
.pipe(gulp.dest( distPath ))
.pipe(browserSync.reload({
stream: true
}));
});
gulp.task('trickortreat', function () {
return gulp.src( appPath + '/trickortreat/index.html' )
.pipe(gulp.dest( distPath + '/trickortreat/' ))
.pipe(browserSync.reload({
stream: true
}));
});
gulp.task('pages', function () {
return gulp.src( appPath + '/*.html' )
.pipe(gulp.dest( distPath ))
.pipe(browserSync.reload({
stream: true
}));
});
/*
Builds beast data from minified svgs
*/
gulp.task('create-json-beast', function() {
gulp.src(svgMinFolder + 'beast/**/*')
.pipe(fc2json('beast-data.json', {
extname : false, // default is true
}))
.pipe(gulp.dest(dataFolder));
});
/*
Builds nav data from minified svgs
*/
gulp.task('create-json-nav', function() {
gulp.src(svgMinFolder + 'nav/**/*')
.pipe(fc2json('nav-data.json', {
extname : false, // default is true
}))
.pipe(gulp.dest(dataFolder));
});
gulp.task('libs', function() {
return gulp.src(['src/js/libs/*.js'])
.pipe(gulp.dest(distPath + '/js/'));
});
var scriptsFinish = lazypipe()
.pipe(gulp.dest, 'dist/js/')
.pipe(function () {
return $.if(config.minify, $.uglify());
})
.pipe(function () {
return $.if(config.minify, $.rename({suffix: '.min'}));
})
.pipe(function () {
return $.if(config.minify, gulp.dest('dist/js'));
});
// Lint and build scripts
gulp.task('scripts', ['libs'], function() {
return gulp.src(['src/js/shared/*.js', 'src/js/create-beast/*.js'])
.pipe($.plumber({errorHandler: $.notify.onError('Error: <%= error.message %>')}))
.pipe($.if(config.isWatching, $.jshint()))
.pipe($.if(config.isWatching, $.jshint.reporter('jshint-stylish')))
.pipe($.if(!browserSync.active, $.jshint.reporter('fail')))
.pipe($.concat('scripts.js'))
.pipe(scriptsFinish());
});
// Lint and build scripts
gulp.task('trickortreat-scripts', function() {
return gulp.src(['src/js/shared/*.js', 'src/js/*.js'])
.pipe($.plumber({errorHandler: $.notify.onError('Error: <%= error.message %>')}))
.pipe($.if(config.isWatching, $.jshint()))
.pipe($.if(config.isWatching, $.jshint.reporter('jshint-stylish')))
.pipe($.if(!browserSync.active, $.jshint.reporter('fail')))
.pipe($.concat('trickortreat.js'))
.pipe(scriptsFinish());
});
// Optimize images and copy that version to dist
// if the script is run with the --minify flag
gulp.task('images', function () {
return gulp.src(['src/images/**/**'])
.pipe($.plumber({errorHandler: $.notify.onError('Error: <%= error.message %>')}))
.pipe($.if(config.isWatching, $.cached('images')))
/* .pipe($.if(config.minify, $.cache($.imagemin({
progressive: true,
interlaced: true
}))))*/
.pipe(gulp.dest('dist/images'));
});
gulp.task('setWatch', function() {
config.isWatching = true;
});
// Development task
gulp.task('dev', ['default', 'setWatch'], function() {
browserSync({
port: argv.port || config.defaultPort, //default: 3000
server: { baseDir: './dist/'},
ui: {
port: argv.port + 5000 || config.defaultPort + 5000, //default: 8000
weinre: { port: argv.port + 6092 || config.defaultPort + 6092 } //default: 9092
},
notify: false,
logLevel: 'silent' //other oprions: info, debug
});
gulp.watch(['src/sass/**/*.scss'], ['styles', reload]);
gulp.watch(['src/partials/*.html'], ['build:pages', reload]);
gulp.watch(['src/*.html'], ['pages', reload]);
gulp.watch(['src/trickortreat/index.html'], ['trickortreat', reload]);
gulp.watch(['src/data/*'], ['build:pages', reload]);
gulp.watch(['src/img/**/*'], ['images', reload]);
gulp.watch(['src/js/**/*.js'], ['trickortreat-scripts', 'scripts', reload]);
});
// Build production files, the default task
gulp.task('default', ['clean'], function (cb) {
runSequence([
'build:nav',
'build:about',
'build:pages',
'pages',
'styles',
'scripts',
'trickortreat',
'trickortreat-scripts',
'images',
'data'
], cb);
});