-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
113 lines (100 loc) · 2.74 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
var gulp = require('gulp');
var gutil = require('gulp-util');
var markdownToJSON = require('gulp-markdown-to-json');
var marked = require('marked');
var connect = require('gulp-connect');
var del = require('del');
var data = require('gulp-data');
var uglify = require('gulp-uglify');
var less = require('gulp-less');
var path = require('path');
var cleanCSS = require('gulp-clean-css');
var htmlmin = require('gulp-htmlmin');
var nunjucks = require('gulp-nunjucks');
var autoprefixer = require('gulp-autoprefixer');
var fs = require('fs');
var gcmq = require('gulp-group-css-media-queries');
var paths = {
templates: './pages/**/*'
};
marked.setOptions({
smartypants: true
});
gulp.task('connect', function() {
connect.server({
root: 'docs'
});
});
gulp.task('clean:html', function (done) {
gulp.on('end', function () { done(); });
return del([
'docs/*.html'
]);
});
gulp.task('clean:js', function () {
return del([
'docs/*.js'
]);
});
gulp.task('clean:css', function () {
return del([
'docs/*.css'
]);
});
gulp.task('clean:assets', function () {
return del([
'docs/**/*',
'!docs/**/*.js',
'!docs/**/*.css',
'!docs/**/*.html',
]);
});
gulp.task('copy',['copy:html','copy:assets']);
gulp.task('copy:html', ['clean:html','data'], function() {
//var pageData = require('./data/pages.json');
gulp.src(['./pages/**/*.html'])
.pipe(data(function(file){
return {pages: JSON.parse(fs.readFileSync('./data/data.json'))};
}))
.pipe(nunjucks.compile())
.pipe(htmlmin({collapseWhitespace: true, minifyJS: true, removeComments: true}))
.pipe(gulp.dest('./docs/'));
});
gulp.task('copy:assets', ['clean:assets'], function() {
gulp.src(['./assets/**/*'])
.pipe(gulp.dest('./docs/'))
});
gulp.task('watch', function () {
gulp.watch(['./pages/**/*','./data/**/*'],['copy']);
gulp.watch(['./modules/**/*.js'],['js']);
gulp.watch(['./less/**/*.less'],['less']);
});
gulp.task('js', ['clean:js'],function() {
return gulp.src(['./modules/fn.js'])
.pipe(uglify())
.pipe(gulp.dest('docs/'));
});
gulp.task('less', ['clean:css'],function() {
return gulp.src(['./less/b.less','./less/fonts.less'])
.pipe(less({
plugins: [],
paths: [path.join(__dirname, 'less', 'includes')]
}))
.pipe(autoprefixer({
browsers: ['last 2 versions'],
cascade: false
}))
.pipe(gcmq())
.pipe(cleanCSS())
.pipe(gulp.dest('docs/'));
});
//build a new data file from the pages markdown files.
gulp.task('data', function(done) {
gulp.src('./data/**/*.md')
.pipe(gutil.buffer())
.pipe(markdownToJSON(marked, 'data.json'))
.pipe(gulp.dest('./data'))
.on('end', function () { done(); });
});
gulp.task('default', ['connect', 'copy', 'js', 'less', 'watch']);
gulp.task('build',['copy','js','less'])