Repository navigation
Expand file tree
/
Copy pathgulpfile.js
More file actions
108 lines (93 loc) · 3.44 KB
/
Copy pathgulpfile.js
File metadata and controls
108 lines (93 loc) · 3.44 KB
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
var
gulp = require('gulp'),
browserSync = require('browser-sync').create(),
sass = require('gulp-sass'),
sourcemaps = require('gulp-sourcemaps'),
autoprefixer = require('gulp-autoprefixer');
header = require('gulp-header');
uglify = require('gulp-uglify');
concat = require('gulp-concat');
notify = require('gulp-notify');
gutil = require('gulp-util');
rename = require('gulp-rename');
pkg = require('./package.json');
;
var reportError = function (error) {
var lineNumber = (error.lineNumber) ? 'LINE ' + error.lineNumber + ' -- ' : '';
notify({
title: 'Task Failed [' + error.plugin + ']',
message: lineNumber + 'See console.',
sound: 'Sosumi' // See: https://github.com/mikaelbr/node-notifier#all-notification-options-with-their-defaults
}).write(error);
gutil.beep(); // Beep 'sosumi' again
// Inspect the error object
//console.log(error);
// Easy error reporting
//console.log(error.toString());
// Pretty error reporting
var report = '';
var chalk = gutil.colors.white.bgRed;
report += chalk('TASK:') + ' [' + error.plugin + ']\n';
report += chalk('PROB:') + ' ' + error.message + '\n';
if (error.lineNumber) { report += chalk('LINE:') + ' ' + error.lineNumber + '\n'; }
if (error.fileName) { report += chalk('FILE:') + ' ' + error.fileName + '\n'; }
console.error(report);
// Prevent the 'watch' task from stopping
this.emit('end');
}
var banner = [
'/* <%= pkg.name %> - v<%= pkg.version %> */',
''
].join('\n');
// Static Server + watching scss/html files
gulp.task('dev', ['sass', 'dist'], function() {
browserSync.init({
server: {
baseDir: "examples",
routes: {
"/dist": "dist"
},
directory: true
}
});
gulp.watch("src/flipclock/scss/**/*.scss", ['sass']);
gulp.watch("src/flipclock/js/**/*.js", ['dist']).on('change', browserSync.reload);
gulp.watch("examples/*.html").on('change', browserSync.reload);
});
// Minify js files
gulp.task('dist', function () {
return gulp.src([
'src/flipclock/js/vendor/*.js',
'src/flipclock/js/libs/Base.js',
'src/flipclock/js/libs/Plugins.js',
'src/flipclock/js/libs/List.js',
'src/flipclock/js/libs/ListItem.js',
'src/flipclock/js/libs/EnglishAlphaList.js',
'src/flipclock/js/libs/*.js',
'src/flipclock/js/faces/TwentyFourHourClockFace.js',
'src/flipclock/js/faces/*.js',
'src/flipclock/js/lang/*.js'
]) //select all javascript files
.pipe(concat('flipclock.js')) //the name of the resulting file
.pipe(gulp.dest('dist')) //the destination folder
.pipe(rename('flipclock.min.js')) //minify the compiled js
.pipe(uglify())
.pipe(header(banner, {pkg: pkg})) //add a small version banner to the minified js
.pipe(gulp.dest('dist'))
.pipe(notify({ message: 'Finished minifying JavaScript'}));
});
// Compile sass into CSS & auto-inject into browsers
gulp.task('sass', function() {
return gulp.src("src/flipclock/scss/**/*.scss")
.pipe(sourcemaps.init())
.pipe(sass({outputStyle: 'compressed'}).on('error', reportError))
.pipe(autoprefixer({
browsers: ['last 2 versions'],
cascade: false
}))
.pipe(sourcemaps.write("./"))
.pipe(gulp.dest("dist"))
.pipe(browserSync.stream())
.pipe(notify({ message: 'Styles recompiled'}));
});
gulp.task('default', ['dev']);