-
Notifications
You must be signed in to change notification settings - Fork 7
/
gulpfile.coffee
115 lines (95 loc) · 2.86 KB
/
gulpfile.coffee
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
fs = require('fs')
path = require('path')
gulp = require('gulp')
pkg = require('./package.json')
clean = require('gulp-clean')
header = require('gulp-header')
footer = require('gulp-footer')
rename = require('gulp-rename')
source = require('vinyl-source-stream')
# js
browserify = require('browserify')
shim = require('browserify-shim')
to5 = require('6to5-browserify')
# css
sass = require('gulp-sass')
autoprefixer = require('gulp-autoprefixer')
minifycss = require('gulp-minify-css')
### preview ###
browserSync = require('browser-sync')
# Source and build paths.
paths=
sass: 'sass/**/*.scss'
js: 'lib/**/*.js'
vendorjs: 'vendor/**/*.js'
html: 'html/**/*.html'
build: 'dist'
paths.dest=
css: path.join(paths.build, 'css')
vendorjs: path.join(paths.build, 'js', 'vendor')
js: path.join(paths.build, 'js')
# Banner
banner = """/*!
* <%= pkg.name %>
* <%= pkg.url %>
* Copyright #{new Date().getFullYear()} <%= pkg.author %>.
*/
"""
# HTML5 Boilerplate header and footer
htmlHeader = fs.readFileSync('h5bp-header.html').toString('utf8')
htmlFooter = fs.readFileSync('h5bp-footer.html').toString('utf8')
# Site header and footer
siteHeader = fs.readFileSync('site-header.html').toString('utf8')
siteFooter = fs.readFileSync('site-footer.html').toString('utf8')
gulp.task 'clean', ->
gulp.src(paths.build, {read: false})
.pipe clean()
# Wrap each html file with HTML5 Boilerplate.
gulp.task 'html', ->
gulp.src(paths.html)
.pipe header(siteHeader, {pkg: pkg})
.pipe footer(siteFooter, {pkg: pkg})
.pipe header(htmlHeader, {pkg: pkg, now: new Date()})
.pipe footer(htmlFooter, {pkg: pkg})
.pipe gulp.dest(paths.build)
.pipe browserSync.reload({stream: true})
gulp.task 'sass', ->
gulp.src(paths.sass)
.pipe sass(errLogToConsole: true)
.pipe autoprefixer(['> 1%', 'last 2 versions', 'IE 8'])
.pipe gulp.dest(paths.dest.css)
.pipe browserSync.reload({stream: true})
.pipe minifycss()
.pipe rename({ suffix: '.min' })
.pipe header(banner, {pkg: pkg})
.pipe gulp.dest(paths.dest.css)
.pipe browserSync.reload({stream: true})
gulp.task 'js', (cb)->
gulp.src(paths.vendorjs)
.pipe gulp.dest(paths.dest.vendorjs)
.pipe browserSync.reload({stream: true, once: true})
browserify(debug: true, standalone: 'geom')
.external(['d3'])
.add('.')
.bundle()
.on('error', (err)->
console.error("Error", err)
cb()
this.emit('end')
)
.pipe(source('geometry.js'))
.pipe gulp.dest(paths.dest.js)
.pipe browserSync.reload({stream: true, once: true})
gulp.task 'bs-init', ->
browserSync.init
server:
baseDir: paths.build
gulp.task('buildall', ['sass', 'js', 'html'], ->)
gulp.task('build', ['clean'], ->
gulp.start 'buildall'
)
gulp.task('default', ['sass', 'js', 'html', 'bs-init'], ->
gulp.watch(paths.sass, ['sass'])
gulp.watch([paths.js, './index.js'], ['js'])
gulp.watch(paths.html, ['html'])
)