-
Notifications
You must be signed in to change notification settings - Fork 4
/
build.js
executable file
·90 lines (79 loc) · 2 KB
/
build.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
const gulp = require('gulp')
const connect = require('gulp-connect')
const plumber = require('gulp-plumber')
const stylus = require('gulp-stylus')
const rename = require('gulp-rename')
const data = require('gulp-data')
const yaml = require('js-yaml')
const del = require('del')
const nib = require('nib')
const rupture = require('rupture')
const koutoSwiss = require('kouto-swiss')
const pug = require('gulp-pug')
const fs = require('fs')
const sequence = require('run-sequence')
const BUILD_FOLDER = 'build'
const paths = {
html: './src/pug/**/*',
css: './src/stylus/**/*',
js: `./${BUILD_FOLDER}/assets/js/**/*`,
}
gulp.task('connect', () => {
connect.server({
host: '0.0.0.0',
root: `./${BUILD_FOLDER}`,
port: 3000,
livereload: true,
})
})
gulp.task('stylus', () => {
gulp.src('./src/stylus/*.styl')
.pipe(plumber())
.pipe(stylus({
compress: false,
use: [nib(), rupture(), koutoSwiss()],
import: ['nib', 'kouto-swiss'],
'include css': true,
}))
.pipe(gulp.dest(`./${BUILD_FOLDER}/assets/css`))
.pipe(connect.reload())
})
gulp.task('pug', () => {
const data_config = yaml.safeLoad(fs.readFileSync('./_config.yml', 'utf-8'))
const data_events = yaml.safeLoad(fs.readFileSync('./_events.yml', 'utf-8'))
gulp.src('./src/pug/*.pug')
.pipe(plumber())
.pipe(data({
config: data_config,
events: data_events,
}))
.pipe(pug())
.pipe(gulp.dest(`./${BUILD_FOLDER}`))
.pipe(connect.reload())
})
gulp.task('copy:static', () => {
return gulp.src('./src/static/**/*')
.pipe(gulp.dest(`./${BUILD_FOLDER}/assets/static`))
})
gulp.task('clean:static', () => {
return del(`./${BUILD_FOLDER}/assets/static`)
})
gulp.task('watch', () => {
gulp.watch(paths.css, ['stylus'])
gulp.watch([paths.html, paths.js, './*.yml'], ['pug'])
})
gulp.task('build', () => {
sequence(
'clean:static',
'copy:static',
'stylus',
'pug',
)
})
gulp.task('server', () => {
sequence(
'build',
'connect',
'watch',
)
})