-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgulpfile.js
More file actions
114 lines (106 loc) · 3.06 KB
/
gulpfile.js
File metadata and controls
114 lines (106 loc) · 3.06 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
109
110
111
112
113
114
var gulp = require('gulp');
var args = require('yargs').argv;
var browserSync = require('browser-sync');
var config = require('./gulp.config')();
var $ = require('gulp-load-plugins')({
lazy: true
});
/************* Gulp Tasks START **************/
gulp.task('jslint', function() {
log('Starting JS Lint Task in Gulp');
return gulp
.src(config.paths.js)
.pipe($.if(args.verbose, $.print()))
.pipe($.jscs())
.pipe($.jshint())
.pipe($.jshint.reporter('jshint-stylish', {
verbose: true
}))
.pipe($.jshint.reporter('fail'));
});
gulp.task('build-scripts', function() {
return gulp
.src(config.paths.js)
.pipe($.concat('all.js'))
.pipe(gulp.dest('dist'))
.pipe($.rename('all.min.js'))
.pipe($.uglify())
.pipe(gulp.dest('dist/js'));
});
gulp.task('beautify', function() {
var lineFeed = osCheck();
return gulp.src(config.paths.beautify, {
base: './'
})
.pipe($.jsbeautifier({
config: './beautify-settings.json',
eol: lineFeed
}))
.pipe($.jsbeautifier.reporter())
.pipe(gulp.dest('./'));
});
gulp.task('serve', function() {
var isDev = true;
var nodeOptions = {
script: config.nodeServer,
delayTime: 1,
env: {
'PORT': config.defaultPort,
'NODE_ENV': isDev ? 'dev' : 'build'
},
watch: [config.serverWatchFiles]
};
return $.nodemon(nodeOptions)
.on('start', function() {
log('Node server started')
setTimeout(() => {
startBrowserSync();
}, config.browserReloadDelay);
})
.on('restart', function(event) {
log('Node server restarted');
log('Files changed : ' + event);
setTimeout(() => {
browserSync.notify('Reloaded BrowserSync');
browserSync.reload({
stream: false
});
}, config.browserReloadDelay);
})
.on('exit', function() {
log('Node server exited');
});
});
/************* Gulp Tasks END **************/
/************* Custom Functions START **************/
function log(message) {
if (typeof(message) === 'object') {
for (var item in message) {
if (message.hasOwnProperty(item)) {
$.util.log($.util.colors.blue(message[item]));
}
}
} else {
$.util.log($.util.colors.blue(message));
}
}
function osCheck() {
var lineFeed;
if (process.platform === 'win32') {
lineFeed = '\r\n';
} else if (process.platform === 'darwin' || process.platform === 'linux') {
lineFeed = '\n';
} else {
var error = 'Unfamiliar operating system.';
log(error);
throw error;
}
return lineFeed;
}
function startBrowserSync() {
if (args.nosync || browserSync.active) {
return;
}
browserSync(config.browserSyncOptions);
}
/************* Custom Functions END **************/