-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathgulpfile.js
69 lines (61 loc) · 1.66 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
const gulp = require('gulp')
const connect = require('gulp-connect')
const plumber = require('gulp-plumber')
const stylus = require('gulp-stylus')
const data = require('gulp-data')
const yaml = require('js-yaml')
const nib = require('nib')
const rupture = require('rupture')
const koutoSwiss = require('kouto-swiss')
const pug = require('gulp-pug')
const fs = require('fs')
let dataJson = {}
let files = []
const paths = {
html: './src/pug/**/*',
css: './src/stylus/**/*',
js: './docs/assets/js/**/*',
data: './src/data/'
}
gulp.task('read:data', () => {
fs.readdir(paths.data, (err, items) => {
for (var i = 0; i < items.length; i++) {
files.push(items[i].split('.')[0])
}
for (var i = 0; i < files.length; i++) {
dataJson[files[i]] = yaml.safeLoad(fs.readFileSync(`${paths.data}${files[i]}.yml`, 'utf-8'))
}
})
})
gulp.task('connect', () => {
connect.server({
root: './docs',
port: 2017,
livereload: true
})
})
gulp.task('stylus', () => {
gulp.src('./src/stylus/*.styl')
.pipe(plumber())
.pipe(stylus({
compress: false,
use: [nib(), rupture(), koutoSwiss()],
import: ['nib', 'kouto-swiss']
}))
.pipe(gulp.dest('./docs/assets/css'))
.pipe(connect.reload())
})
gulp.task('pug', () => {
gulp.src('./src/pug/*.pug')
.pipe(plumber())
.pipe(data(dataJson))
.pipe(pug())
.pipe(gulp.dest('./docs'))
.pipe(connect.reload())
})
gulp.task('watch', () => {
gulp.watch(paths.css, ['stylus'])
gulp.watch([paths.html, paths.js, `${paths.data}*.yml`], ['read:data', 'pug'])
})
gulp.task('build', ['read:data', 'stylus', 'pug'])
gulp.task('server', ['build', 'connect', 'watch'])