-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
178 lines (164 loc) · 5.83 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
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
172
173
174
175
176
177
178
/*------------------------------------------------------------------------------
Gulpfile.js
------------------------------------------------------------------------------*/
// Name your theme - this is outputted only when packaging your project.
var theme = 'oneil';
// Set the paths you will be working with
var phpFiles = ['./**/*.php', './*.php'],
htmlFiles = ['./**/*.html', './*.html'],
cssFiles = ['./assets/css/*.css', '!./assets/css/*.min.css'],
sassFiles = ['./assets/scss/**/*.scss'],
styleFiles = [cssFiles, sassFiles],
jsFiles = ['./assets/js/theme.js'],
imageFiles = ['./assets/img/*.{jpg,png,gif,svg}'],
concatFiles = [
'./assets/js/*.js',
'./bower_components/nifty-nav/src/js/nifty-nav.js',
'./bower_components/slick-carousel/slick/slick.js',
'./bower_components/waypoints/lib/noframework.waypoints.js',
'./bower_components/share-button/share-button.js',
'./bower_components/moment/moment.js',
'./bower_components/macy/dist/macy.js',
'./bower_components/bowser/src/bowser.js',
'!./assets/js/theme.min.js',
'!./assets/js/all.js'
],
url = 'http://oneil.d.mt.com:8080/'; // See https://browsersync.io/docs/options/#option-proxy
// Include gulp
var gulp = require('gulp');
// Include plugins
var jshint = require('gulp-jshint'),
sass = require('gulp-sass'),
concat = require('gulp-concat'),
uglify = require('gulp-uglify'),
rename = require('gulp-rename'),
imagemin = require('gulp-imagemin'),
nano = require('gulp-cssnano'),
sourcemaps = require('gulp-sourcemaps'),
autoprefixer = require('gulp-autoprefixer'),
browserSync = require('browser-sync'),
plumber = require('gulp-plumber'),
stylish = require('jshint-stylish'),
notify = require('gulp-notify'),
exec = require('gulp-exec'),
zip = require('gulp-zip');
/*------------------------------------------------------------------------------
Development Tasks
------------------------------------------------------------------------------*/
// Launch a development server
gulp.task('serve', function () {
browserSync.init({
proxy: url
// port: 3000
});
});
// Compile Sass
gulp.task('sass', function () {
return gulp.src(sassFiles)
.pipe(sourcemaps.init())
.pipe(plumber())
.pipe(sass({
includePaths: [
'./node_modules/normalize-scss/sass/',
'./node_modules/ginger-grid/',
'./bower_components/sugar/',
'./bower_components/nifty-nav/',
'./bower_components/slick-carousel/',
'./bower_components/font-awesome/scss/'
]
})
.on('error', sass.logError))
.on('error', notify.onError("Error compiling SASS!")
)
.pipe(autoprefixer({
browsers: ['last 3 versions', 'Safari > 7'],
cascade: false
}))
.pipe(sourcemaps.write())
.pipe(gulp.dest('./assets/css'))
.pipe(browserSync.reload({
stream: true
}));
});
// Lint JavaScript
gulp.task('lint', function () {
return gulp.src(jsFiles)
.pipe(sourcemaps.init())
.pipe(plumber())
.pipe(jshint())
.pipe(jshint.reporter(stylish))
.pipe(jshint.reporter('fail'))
.on('error', notify.onError({message: 'Error compiling JavaScript!'}))
.pipe(sourcemaps.write())
.pipe(browserSync.reload({
stream: true
}));
});
/*------------------------------------------------------------------------------
Production Tasks
------------------------------------------------------------------------------*/
// Minimize CSS
gulp.task('minify-css', ['sass'], function () {
return gulp.src(cssFiles)
.pipe(rename({
suffix: '.min'
}))
.pipe(nano({
discardComments: {removeAll: true},
autoprefixer: false,
discardUnused: false,
mergeIdents: false,
reduceIdents: false,
calc: {mediaQueries: true},
zindex: false
}))
.pipe(gulp.dest('./assets/css'))
//.pipe(exec('styledown assets/scss/**/*.scss config.md > styleguide.html')) - styleguide generation, removed post launch
.pipe(browserSync.reload({
stream: true
}));
});
// Concatenate & Minify JavaScript
gulp.task('scripts', ['lint'], function () {
return gulp.src(concatFiles)
.pipe(concat('all.js'))
.pipe(gulp.dest('./assets/js/'))
.pipe(rename('theme.min.js'))
.pipe(uglify())
.pipe(gulp.dest('./assets/js/'));
});
// Compress Images
gulp.task('images', function () {
return gulp.src(imageFiles)
.pipe(plumber())
.pipe(imagemin())
.pipe(gulp.dest('./assets/img/'));
});
// Package a zip for theme upload
gulp.task('package', function () {
return gulp.src([
'./**/*',
'!bower_components',
'!node_modules',
'!bower_components/**',
'!node_modules/**'
])
.pipe(zip(theme + '.zip'))
.pipe(gulp.dest('./'));
});
// Build task to run all tasks and and package for distribution
gulp.task('build', ['sass', 'scripts', 'images', 'package']);
// Styles Task - minify-css is the only task we call, because it is dependent upon sass running first.
gulp.task('styles', ['minify-css']);
/*------------------------------------------------------------------------------
Default Tasks
------------------------------------------------------------------------------*/
// Default Task
gulp.task('default', ['sass', 'scripts', 'serve', 'watch']);
// Watch Files For Changes
gulp.task('watch', function () {
gulp.watch(sassFiles, ['styles']);
gulp.watch(jsFiles, ['scripts']);
gulp.watch(phpFiles, browserSync.reload);
gulp.watch(htmlFiles, browserSync.reload);
});