-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathgulpfile.js
More file actions
171 lines (156 loc) · 4.23 KB
/
gulpfile.js
File metadata and controls
171 lines (156 loc) · 4.23 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
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
'use strict';
var gulp = require('gulp');
var sass = require('gulp-sass');
var gutil = require('gulp-util');
var jshint = require('gulp-jshint');
var sourcemaps = require('gulp-sourcemaps');
var uglify = require('gulp-uglify');
var stylish = require('jshint-stylish');
var plumber = require('gulp-plumber');
var notify = require('gulp-notify');
var fileinclude = require('gulp-file-include');
var autoprefixer = require('gulp-autoprefixer');
var runSequence = require('run-sequence');
var zip = require('gulp-zip');
var bs = require('browser-sync').create();
var rimraf = require('rimraf');
var gm = require('gulp-gm');
var path = {
src: {
// source
html : 'src/*.html',
others : 'src/*.+(php|ico|png)',
htminc : 'src/partials/**/*.htm',
incdir : 'src/partials/',
plugins : 'src/plugins/**/*.*',
js : 'src/js/*.js',
scss : 'src/scss/**/*.scss',
images : 'src/images/**/*.+(png|jpg|gif|svg)',
blur : 'src/images/**/*.jpg'
},
build: {
// build
dir : 'dist/development/'
}
};
var template = {
version: {
free: 'free',
premium: 'premium'
}
};
/* =====================================================
Development Builds
===================================================== */
// HTML
gulp.task('html:build', function () {
return gulp.src(path.src.html)
.pipe(customPlumber('Error Running html-include'))
.pipe(fileinclude({
basepath: path.src.incdir, context: {
version: template.version.premium
}
}))
.pipe(gulp.dest(path.build.dir))
.pipe(bs.reload({
stream: true
}));
});
// SCSS
gulp.task('scss:build', function () {
var ignoreNotification = false;
return gulp.src(path.src.scss)
.pipe(customPlumber('Error Running Sass'))
.pipe(sourcemaps.init())
.pipe(sass({ outputStyle: 'expanded' }).on('error', sass.logError))
.pipe(autoprefixer())
.pipe(sourcemaps.write('/maps'))
.pipe(gulp.dest(path.build.dir + 'css/'))
.pipe(bs.reload({
stream: true
}));
});
// Javascript
gulp.task('js:build', function () {
return gulp.src(path.src.js)
.pipe(customPlumber('Error Running JS'))
.pipe(jshint('./.jshintrc'))
.pipe(notify(function (file) {
if (!file.jshint.success) {
return file.relative + " (" + file.jshint.results.length + " errors)\n";
}
}))
.pipe(jshint.reporter('jshint-stylish'))
.on('error', gutil.log)
.pipe(gulp.dest(path.build.dir + 'js/'))
.pipe(bs.reload({
stream: true
}));
});
// Images
gulp.task('images:build', function () {
return gulp.src(path.src.images)
.pipe(gulp.dest(path.build.dir + 'images/'))
.pipe(bs.reload({
stream: true
}));
});
// Plugins
gulp.task('plugins:build', function () {
return gulp.src(path.src.plugins)
.pipe(gulp.dest(path.build.dir + 'plugins/'))
.pipe(bs.reload({
stream: true
}));
});
// Other files like favicon, php, apple-icon on root directory
gulp.task('others:build', function () {
return gulp.src(path.src.others)
.pipe(gulp.dest(path.build.dir))
});
// Error Message Show
function customPlumber(errTitle) {
return plumber({
errorHandler: notify.onError({
// Customizing error title
title: errTitle || "Error running Gulp",
message: "Error: <%= error.message %>",
sound: "Glass"
})
});
}
// Clean Build Folder
gulp.task('clean', function (cb) {
rimraf('./dist', cb);
});
// Watch Task
gulp.task('watch:build', function () {
gulp.watch(path.src.html, ['html:build']);
gulp.watch(path.src.htminc, ['html:build']);
gulp.watch(path.src.scss, ['scss:build']);
gulp.watch(path.src.js, ['js:build']);
gulp.watch(path.src.images, ['images:build']);
gulp.watch(path.src.plugins, ['plugins:build']);
});
// Build Task
gulp.task('build', function () {
runSequence(
'clean',
'html:build',
'js:build',
'scss:build',
'images:build',
'plugins:build',
'others:build',
'watch:build',
function () {
bs.init({
server: {
baseDir: path.build.dir,
},
port: 3050
});
}
);
});
gulp.task("default", ["build"]);