This repository has been archived by the owner on Sep 29, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
117 lines (101 loc) · 3.37 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
console.time('\033[32mGulp init time\033[0m');
var config = require('./config'),
devMode = config.env === 'development',
path = require('path'),
// Gulp and plugins
gulp = require('gulp'),
gutil = require('gulp-util'),
rename = require('gulp-rename'),
gif = require('gulp-if-else'),
sass = require('gulp-sass'),
jshint = require('gulp-jshint'),
uglify = require('gulp-uglifyjs'),
clean = require('gulp-clean'),
concat = require('gulp-concat'),
nodemon = require('gulp-nodemon'),
notify = require('gulp-notify'),
bower = require('bower'),
mainBowerFiles = require('main-bower-files'),
// File and folder locations
files = {
'bower': './bower.json',
'sass': './server/scss/*.scss',
'js': './server/js/*.js'
},
dirs = {
'bower': './public/bower',
'css': './public/css',
'js': './public/js'
};
gulp.task('clean', function() {
gulp.src([dirs.bower, dirs.css, dirs.js])
.pipe(clean());
});
gulp.task('sass', function() {
gulp.src(files.sass)
.pipe(sass({
outputStyle: devMode ? 'nested' : 'compressed',
errLogToConsole: false,
onError: function(err) {
return notify().write(err);
}
}))
.pipe(gulp.dest(dirs.css));
});
gulp.task('jshint', function() {
gulp.src([files.js, './framework/*.js'])
.pipe(jshint())
.pipe(notify(function(file) {
if (file.jshint.success) {
return false;
}
var errors = file.jshint.results.map(function(data) {
if (data.error) {
return '(' + data.error.line + ':' + data.error.character + ') ' + data.error.reason;
}
}).join('\n');
return file.relative + ' (' + file.jshint.results.length + ' error' + (file.jshint.results.length !== 1 ? 's' : '') + ')\n' + errors;
}))
.pipe(jshint.reporter('jshint-stylish'));
});
gulp.task('js', ['jshint'], function() {
gulp.src(files.js)
.pipe(gif(!devMode, uglify))
.pipe(gulp.dest(dirs.js));
});
gulp.task('framework', ['jshint'], function () {
gulp.src('./framework/*.js')
.pipe(concat('framework.js'))
.pipe(gulp.dest(dirs.js));
});
gulp.task('bower', function() {
bower.commands.install().on('end', function(installed) {
var packages = Object.keys(installed).join(', ');
if (packages.length) {
gutil.log('Bower installed', gutil.colors.cyan(packages) + '.');
}
gulp.src(mainBowerFiles({
env: config.env
}))
.pipe(rename(function(pathName) {
pathName.basename = pathName.basename.replace(/\.min$/, '');
}))
.pipe(gulp.dest(dirs.bower));
});
});
gulp.task('watch', function() {
gulp.watch(files.bower, ['bower']);
gulp.watch(files.sass, ['sass']);
gulp.watch(files.js, ['js']);
gulp.watch('./framework/*.js', ['framework']);
nodemon({
'script': 'server.js',
'ext': 'html js json',
'ignore': ['server/*/', 'node_modules/', 'bower_components/']
});
});
gulp.task('build', ['bower', 'sass', 'js']);
gulp.task('default', ['build', 'watch'], function() {
console.timeEnd('\033[32mGulp init time\033[0m');
});
gulp.task('dev', ['framework', 'default']);