-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
181 lines (165 loc) · 5.23 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
179
180
181
//var bourbon = require('node-bourbon');
var gulp = require('gulp');
var plugins = require('gulp-load-plugins')({
pattern: ['gulp-*', 'gulp.*', 'del', 'streamqueue', 'autoprefixer']
});
var paths = {
src: {
base: 'src/',
allMd: 'markup/**/*.md',
templates: 'markup/templates/**/*.hbs',
img: 'images/**/*',
sass: 'sass/base.scss',
js: 'js/**/*.js',
projects: 'markup/projects/**/*.md',
blog: 'markup/blog/**/*.md',
design: 'markup/design/**/*.md',
layout: 'markup/layout/**/*'
},
vendor: {
css: 'src/vendor/**/*.css',
js: 'src/vendor/**/*.js'
},
icon: 'src/vendor/icons/**/*',
target: {
base: 'dist/',
css: 'css/',
js: 'js/',
img: 'images/',
blog: 'content/blog/',
projects: 'content/projects/',
deisgn: 'content/design/'
}
};
gulp.task('icons', function(){
return gulp.src([paths.icon])
.pipe(gulp.dest(paths.target.base+paths.target.css));
});
//style
gulp.task('style', function () {
return plugins.streamqueue({objectMode: true},
gulp.src([paths.vendor.css, '!'+paths.icon]),
gulp.src(paths.src.base+paths.src.sass)
.pipe(plugins.sass({
includePaths: require('node-bourbon').includePaths
})))
.pipe(plugins.concat('main.css'))
.pipe(plugins.postcss([plugins.autoprefixer()]))
.pipe(plugins.minifyCss())
.pipe(gulp.dest(paths.target.base+paths.target.css))
.pipe(plugins.connect.reload());
});
//script
gulp.task('script', function(){
return plugins.streamqueue({objectMode: true},
//vendor files first
gulp.src(paths.vendor.js),
//project specific js files
gulp.src([paths.src.base+paths.src.js])
.pipe(plugins.jshint())
.pipe(plugins.jshint.reporter('default')),
//templates
gulp.src([paths.src.base+paths.src.templates])
.pipe(plugins.handlebars())
.pipe(plugins.wrap('Handlebars.template(<%= contents %>)'))
.pipe(plugins.declare({
namespace: 'pApp.templates',
noRedeclare: true, // Avoid duplicate declarations
}))
.pipe(plugins.concat('templates.js'))
)
.pipe(plugins.sourcemaps.init())
.pipe(plugins.concat('main.js'))
.pipe(plugins.uglify())
.pipe(plugins.sourcemaps.write())
.pipe(gulp.dest(paths.target.base+paths.target.js))
.pipe(plugins.connect.reload());
});
//markup this is possibly
gulp.task('markup:base', function(){
return gulp.src([paths.src.base+'*.html'])
.pipe(gulp.dest(paths.target.base))
.pipe(plugins.connect.reload());
});
/*
* function to generate json
***********************************/
function dumpJson(directory){
return gulp.src(paths.src.base+paths.src[directory], {base: paths.src.base + 'markup'})
.pipe(plugins.frontMatter({property: 'meta'}))
.pipe(plugins.data(function(file){
file.meta.path = file.relative;
if(!file.meta.createDate)
file.meta.createDate = file.stat.birthtime;
}))
.pipe(plugins.pluck('meta', directory+'.json'))
.pipe(plugins.data(function(file){
file.contents = new Buffer(JSON.stringify(file.meta))
}))
//.pipe(gulp.dest(paths.target.base+paths.target[directory]));
.pipe(gulp.dest(paths.target.base+'content/'));
}
gulp.task('contentJson', function(){
return dumpJson('allMd')
.pipe(plugins.connect.reload());
});
/**********************************************/
gulp.task('markup:blog', function(){
return gulp.src([paths.src.base+paths.src.blog])
.pipe(plugins.grayMatter())
.pipe(plugins.markdown())
.pipe(plugins.layout(function(file){
if(!file.data.createDate) {
file.data.createDate = file.stat.birthtime;
}
return file.data;
}))
.pipe(gulp.dest(paths.target.base+paths.target.blog))
.pipe(plugins.connect.reload());
});
gulp.task('markup:projects', function(){
return gulp.src([paths.src.base+paths.src.projects])
.pipe(plugins.grayMatter())
.pipe(plugins.markdown())
.pipe(plugins.layout(function(file){
if(!file.data.createDate) {
file.data.createDate = file.stat.birthtime;
}
return file.data;
}))
.pipe(gulp.dest(paths.target.base+paths.target.projects))
.pipe(plugins.connect.reload());
});
//Images
gulp.task('images', function() {
//plugins.cache.clearAll();
return gulp.src(paths.src.base+paths.src.img)
.pipe(plugins.cache(plugins.imagemin({ optimizationLevel: 3, progressive: true, interlaced: true })))
.pipe(gulp.dest(paths.target.base+paths.target.img))
.pipe(plugins.connect.reload());
});
// Clean
gulp.task('clean', function(cb) {
return plugins.del([paths.target.base], cb);
});
gulp.task('connect', function(){
plugins.connect.server({
root: [paths.target.base],
port: 8888,
livereload: true
});
});
gulp.task('default',['clean'], function(){
gulp.start('style', 'script', 'icons', 'contentJson',
'markup:base', 'markup:blog', 'markup:projects',
'images', 'connect', 'watch');
});
gulp.task('watch', function(){
gulp.watch(paths.src.base+'sass/**/*.scss', ['style']);
gulp.watch([paths.src.base+paths.src.js, paths.src.base+paths.src.templates], ['script']);
gulp.watch(paths.src.base+'*.html', ['markup:base']);
gulp.watch(paths.src.base+paths.src.blog, ['markup:blog', 'contentJson']);
gulp.watch(paths.src.base+paths.src.projects, ['markup:projects', 'contentJson']);
gulp.watch(paths.src.base+paths.src.layout, ['markup:blog','markup:projects']);
gulp.watch(paths.src.base+paths.src.img, ['images']);
});