-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
124 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
118
119
120
121
122
123
124
var gulp = require('gulp')
, cache = require('gulp-cache')
, concat = require('gulp-concat')
, jshint = require('gulp-jshint')
, stylish = require('jshint-stylish')
, uglify = require('gulp-uglify')
, rename = require('gulp-rename')
, sass = require('gulp-ruby-sass')
, scsslint = require('gulp-scss-lint')
, imagemin = require('gulp-imagemin')
, frontMatter = require('gulp-front-matter')
, marked = require('gulp-marked')
, applyTemplate = require('gulp-apply-template')
, gulpFilter = require('gulp-filter')
, connect = require('gulp-connect')
, livereload = require('gulp-livereload')
, gulpIgnore = require('gulp-ignore')
, debug = require('gulp-debug')
var packageJSON = require('./package')
, jshintConfig = packageJSON.jshintConfig
var paths = {
src: 'src/'
, layout: 'layouts/'
, dest: 'dest/'
}
gulp.task('common-scripts', function() {
var scripts = gulp.src(paths.src + 'assets/js/*.js')
// validate scripts (lint)
scripts.pipe(jshint(jshintConfig))
.pipe(jshint.reporter(stylish))
.pipe(jshint.reporter('fail'))
// combine and minify scripts
return scripts.pipe(concat('main.js'))
.pipe(rename({suffix: '.min'}))
.pipe(uglify())
.pipe(gulp.dest(paths.dest + 'assets/js'))
})
gulp.task('specific-scripts', function() {
var scripts = gulp.src(paths.src + 'assets/js/specific/*.js')
// validate scripts (lint)
scripts.pipe(jshint(jshintConfig))
.pipe(jshint.reporter(stylish))
.pipe(jshint.reporter('fail'))
// combine and minify scripts
return scripts.pipe(rename({suffix: '.min'}))
.pipe(uglify())
.pipe(gulp.dest(paths.dest + 'assets/js'))
})
// compile sass
gulp.task('sass', function() {
return sass(paths.src + 'scss/', {style: 'compressed'})
.on('error', function (err) {
console.error('Error!', err.message)
})
.pipe(rename({suffix: '.min'}))
.pipe(gulp.dest(paths.dest + 'css'))
})
gulp.task('scss-lint', function() {
return gulp.src(paths.src + 'scss/*.scss')
.pipe(scsslint())
.pipe(scsslint.failReporter())
})
gulp.task('images', function() {
return gulp.src(paths.src + 'assets/img/**/*')
.pipe(cache(imagemin({ optimizationLevel: 5, progressive: true, interlaced: true })))
.pipe(gulp.dest(paths.dest + 'assets/img'))
})
gulp.task('assets', ['common-scripts', 'specific-scripts', 'scss-lint', 'sass', 'images'])
gulp.task('pages', function() {
var mdFilter = gulpFilter('*.md')
var pages= gulp.src(paths.src + 'pages/**/*.*')
.pipe(frontMatter({
property: 'data',
remove: true
}))
pages.pipe(gulpIgnore.include(function(file) { return Object.keys(file.data).length === 0 }))
.pipe(debug({title: 'Invalid page: missing front matter'}))
return pages.pipe(gulpIgnore.include(function(file) { return Object.keys(file.data).length !== 0 }))
.pipe(applyTemplate({
engine: 'ejs'
, template: function (context) {
return paths.src + paths.layout + context.data.template + '.ejs'
}
}))
.pipe(mdFilter)
.pipe(marked())
.pipe(mdFilter.restore())
.pipe(gulp.dest(function(file) {
return paths.dest + (file.data.lang || 'en')
}))
})
gulp.task('index', function() {
})
gulp.task('watch', function() {
gulp.watch(paths.src + 'assets/js/*.js', ['scripts'])
gulp.watch(paths.src + 'assets/scss/*.scss', ['sass'])
gulp.watch(paths.src + 'assets/img/*', ['images'])
gulp.watch(paths.src + 'pages/*', ['pages'])
})
// Default Task
gulp.task('default', ['assets', 'pages'])