-
Notifications
You must be signed in to change notification settings - Fork 1
/
gulpfile.js
137 lines (100 loc) · 3.26 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
var gulp = require('gulp');
var browserSync = require('browser-sync').create();
var sass = require('gulp-sass');
var concat = require('gulp-concat');
var uglify = require('gulp-uglify');
var uglifyCss = require('gulp-uglifycss');
var plumber = require('gulp-plumber');
var gulpif = require('gulp-if');
var notify = require("gulp-notify");
var gutil = require('gulp-util');
var argv = require('minimist');
var autoprefixer = require('gulp-autoprefixer');
var nodemon = require('gulp-nodemon');
gulp.task('watch', ['sass', 'concat-min-js', 'nodemon', 'browserSync'], function(){
gulp.watch('src/scss/**/*.scss', ['sass']);
gulp.watch('src/js/**/*.js', ['concat-min-js']);
gulp.watch('src/js/working/**/*.js',['concat-min-js']);
gulp.watch('docs/assets/js/*.js', browserSync.reload);
gulp.watch('docs/index.html', browserSync.reload);
})
gulp.task('browserSync', function(){
browserSync.init(null, {
proxy: "http://localhost:8080",
files: ["docs/*.*"],
browser: "google chrome",
port: 7000,
});
});
gulp.task('nodemon', function (cb) {
var started = false;
return nodemon({
script: 'app.js'
}).on('start', function () {
// to avoid nodemon being started multiple times
// thanks @matthisk
if (!started) {
cb();
started = true;
}
});
});
gulp.task('sass', function(){
return gulp.src('./src/scss/apiDocs.scss')
.pipe(plumber())
.pipe(sass({includePaths: ['./src/scss/*']}, {errLogToConsole: true}))
.on('error', reportError)
.pipe(autoprefixer({
browsers: ['last 4 versions'],
cascade: false
}))
.pipe(gulp.dest('./docs/assets/css/'))
.pipe(concat('apiDocs.css'))
.pipe(browserSync.reload({stream: true}));
});
gulp.task('concat-min-js', function(){
return gulp.src([
'src/js/libs/*.js',
'src/js/apiDocs.js',
])
.pipe(plumber())
.pipe(concat('apiDocs.min.js'))
.pipe(uglify({errLogToConsole: true}))
.on('error', reportError)
.pipe(gulp.dest('docs/assets/js/'))
.pipe(browserSync.reload({stream: true}));
});
/// error handeling
var reportError = function (error) {
// [log]
//console.log(error);
// Format and ouput the whole error object
//console.log(error.toString());
// ----------------------------------------------
// Pretty error reporting
var report = '\n';
var chalk = gutil.colors.white.bgRed;
if (error.plugin) {
report += chalk('PLUGIN:') + ' [' + error.plugin + ']\n';
}
if (error.message) {
report += chalk('ERROR:\040') + ' ' + error.message + '\n';
}
console.error(report);
// ----------------------------------------------
// Notification
if (error.line && error.column) {
var notifyMessage = 'LINE ' + error.line + ':' + error.column + ' -- ';
} else {
var notifyMessage = '';
}
notify({
title: 'FAIL: ' + error.plugin,
message: notifyMessage + 'See console.',
sound: 'Sosumi' // See: https://github.com/mikaelbr/node-notifier#all-notification-options-with-their-defaults
}).write(error);
gutil.beep(); // System beep (backup)
// ----------------------------------------------
// Prevent the 'watch' task from stopping
this.emit('end');
}