-
Notifications
You must be signed in to change notification settings - Fork 37
/
Copy pathgulpfile.js
166 lines (151 loc) · 3.94 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
// Include gulp
const gulp = require('gulp')
// Plugins
const sass = require('gulp-sass')
const autoprefixer = require('gulp-autoprefixer')
const cleanCSS = require('gulp-clean-css')
const jshint = require('gulp-jshint')
const uglify = require('gulp-uglify')
const imagemin = require('gulp-imagemin')
const svgmin = require('gulp-svgmin')
const header = require('gulp-header')
const rename = require('gulp-rename')
const concat = require('gulp-concat')
const cache = require('gulp-cache')
const runsequence = require('run-sequence')
const del = require('del')
const pkg = require('./package.json')
const banner = [
'/**',
' * <%= pkg.name %> - <%= pkg.description %>',
' * @version v<%= pkg.version %>',
' * @homepage <%= pkg.homepage %>',
' * @copyright ' + new Date().getFullYear() + ' <%= pkg.author.name %> ',
' * @license <%= pkg.license %>',
' */',
'\n'
].join('\n')
const files = {
lint: [ 'gulpfile.js', 'package.json', 'assets/js/bastard.js' ],
sass: [ 'assets/sass/**/*.scss' ],
css: [
'node_modules/highlightjs/styles/railscasts.css',
'assets/css/compiled_sass.css'
],
js: [
'node_modules/bootstrap/dist/js/bootstrap.js',
'node_modules/highlightjs/highlight.pack.js',
'assets/vendor/js/jquery.fitvids.js',
'assets/vendor/js/jquery.parallax-1.1.3.js',
'assets/vendor/js/jquery.easing.1.3.js',
'assets/js/bastard.js'
],
images: [ 'image_sources/{,*/}*.jpg', 'image_sources/{,*/}*.png' ],
svgs: [ 'image_sources/{,*/}*.svg' ],
clean: [
'assets/css/compiled_sass.css',
'assets/css/bastard.css',
'assets/css/bastard.min.css',
'assets/js/scripts.js',
'assets/js/scripts.min.js',
'assets/js/concat_scripts.js'
]
}
// Lint Task
gulp.task('lint', function () {
return gulp.src(files.lint).pipe(jshint()).pipe(jshint.reporter('default'))
})
// Compile Our Sass
gulp.task('compileSass', function () {
return gulp
.src(files.sass)
.pipe(
sass({ style: 'expanded', quiet: true, cacheLocation: '.sass-cache' })
)
.pipe(sass())
.pipe(autoprefixer('last 1 version'))
.pipe(rename('compiled_sass.css'))
.pipe(gulp.dest('assets/css'))
})
// Concatenate & minify css files
gulp.task('concatMinifyCss', function () {
return gulp
.src(files.css)
.pipe(concat('bastard.css'))
.pipe(gulp.dest('assets/css'))
.pipe(cleanCSS({ specialComments: 0 }))
.pipe(
rename({
suffix: '.min'
})
)
.pipe(header(banner, { pkg: pkg }))
.pipe(gulp.dest('assets/css'))
})
gulp.task('css', function () {
runsequence('compileSass', 'concatMinifyCss')
})
// Concatenate & Minify JS
gulp.task('js', function () {
return gulp
.src(files.js)
.pipe(concat('scripts.js'))
.pipe(uglify())
.pipe(
rename({
suffix: '.min'
})
)
.pipe(header(banner, { pkg: pkg }))
.pipe(gulp.dest('assets/js'))
})
gulp.task('concatJs', function () {
return gulp
.src(files.js)
.pipe(concat('concat_scripts.js'))
.pipe(gulp.dest('assets/js'))
.pipe(header(banner, { pkg: pkg }))
.pipe(gulp.dest('assets/js'))
})
// Images
gulp.task('imgmin', function () {
return gulp
.src(files.images)
.pipe(
cache(
imagemin({
optimizationLevel: 3,
progressive: true,
interlaced: true
})
)
)
.pipe(gulp.dest('assets/images'))
})
// Images
gulp.task('svgmin', function () {
return gulp
.src(files.svgs)
.pipe(cache(svgmin()))
.pipe(gulp.dest('assets/images'))
})
// Build
gulp.task('build', function () {
gulp.start([ 'compileSass', 'concatJs' ])
})
// Watch Files For Changes
gulp.task('watch', [ 'default' ], function () {
gulp.watch(files.lint, [ 'js' ])
gulp.watch(files.sass, [ 'css' ])
})
// Clean
gulp.task('clean', function () {
files.clean.map(function (x) {
console.log('Deleting ' + x)
})
return del(files.clean)
})
// Default Task
gulp.task('default', function () {
gulp.start('lint', 'css', 'js', 'imgmin', 'svgmin')
})