-
Notifications
You must be signed in to change notification settings - Fork 12
/
gulpfile.js
145 lines (133 loc) · 3.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
var concat = require('gulp-concat');
var connect = require('gulp-connect');
var footer = require('gulp-footer');
var fs = require('fs');
var gulp = require('gulp');
var header = require('gulp-header');
var marked = require('gulp-markdown');
var rename = require('gulp-rename');
var sort = require('sort-stream');
var pygmetize = require('pygmentize-bundled');
var paths = {
'blog': 'blog/*.md',
'componentsDir': './bower_components/',
'docs': 'docs/*.md',
'docsDir': './docs/',
'pages': './*.md',
'site': ['header.html', 'footer.html']
};
gulp.task('copydocs', function() {
var readmes = [];
var files = fs.readdirSync(paths.componentsDir);
for (var i = 0; i < files.length; i++) {
if (files[i][0] !== '.' && files[i].substring(0,6) === 'brick-') {
var path = paths.componentsDir + files[i];
var stat = fs.statSync(path);
if (stat.isDirectory) {
if (fs.existsSync(path + '/readme.md')) {
readmes.push(path + '/readme.md');
}
}
}
}
return gulp.src(readmes, {'base': paths.componentsDir})
.pipe(rename(function (path){
var name = path.dirname;
path.dirname = '.';
path.basename = name;
}))
.pipe(gulp.dest(paths.docsDir));
});
gulp.task('build', ['docs', 'pages', 'blog']);
gulp.task('docs', ['copydocs'], function () {
var content = {
footer: fs.readFileSync('footer.html'),
header: fs.readFileSync('header.html')
};
gulp.src(paths.docs)
.pipe(marked({
highlight: function (code, lang, callback) {
pygmetize({ lang: lang, format: 'html' }, code, function (err, result) {
callback(err, result.toString());
});
}
}))
.pipe(rename(function (path) {
path.extname = '.html';
}))
.pipe(header(content.header))
.pipe(footer(content.footer))
.pipe(gulp.dest('docs'));
});
gulp.task('pages', function () {
var content = {
footer: fs.readFileSync('footer.html'),
header: fs.readFileSync('header.html')
};
gulp.src(paths.pages)
.pipe(marked({
highlight: function (code, lang, callback) {
pygmetize({ lang: lang, format: 'html' }, code, function (err, result) {
callback(err, result.toString());
});
}
}))
.pipe(rename(function (path) {
path.extname = '.html';
}))
.pipe(header(content.header))
.pipe(footer(content.footer))
.pipe(gulp.dest('.'));
});
gulp.task('blog', function () {
var content = {
footer: fs.readFileSync('footer.html'),
header: fs.readFileSync('header.html')
};
gulp.src(paths.blog)
.pipe(sort(function (a, b) {
return a.path < b.path;
}))
.pipe(marked({
highlight: function (code, lang, callback) {
pygmetize({ lang: lang, format: 'html' }, code, function (err, result) {
callback(err, result.toString());
});
}
}))
.pipe(rename(function (path) {
path.extname = '.html';
}))
.pipe(header('<section>'))
.pipe(footer('</section>'))
.pipe(concat('index.html'))
.pipe(header(content.header))
.pipe(footer(content.footer))
.pipe(gulp.dest('blog'));
gulp.src(paths.blog)
.pipe(marked({
highlight: function (code, lang, callback) {
pygmetize({ lang: lang, format: 'html' }, code, function (err, result) {
callback(err, result.toString());
});
}
}))
.pipe(rename(function (path) {
path.extname = '.html';
}))
.pipe(header('<section>'))
.pipe(footer('</section>'))
.pipe(header(content.header))
.pipe(footer(content.footer))
.pipe(gulp.dest('blog'));
});
gulp.task('connect', function() {
connect.server({
port: process.env.PORT || 3001
});
});
gulp.task('watch', function() {
gulp.watch([paths.docs, paths.blog, paths.site], ['build']);
});
gulp.task('server', ['build', 'connect', 'watch']);
gulp.task('default', ['server']);