-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgulpfile.coffee
More file actions
128 lines (105 loc) · 3.02 KB
/
Copy pathgulpfile.coffee
File metadata and controls
128 lines (105 loc) · 3.02 KB
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
gulp = require 'gulp'
gutil = require 'gulp-util'
sass = require 'gulp-sass'
rename = require 'gulp-rename'
browserify = require 'gulp-browserify'
ngAnnotate = require 'gulp-ng-annotate'
coffeelint = require 'gulp-coffeelint'
coffee = require 'gulp-coffee'
autoprefixer = require 'gulp-autoprefixer'
concat = require 'gulp-concat'
uglify = require 'gulp-uglify'
rimraf = require 'gulp-rimraf'
runSequence = require 'run-sequence'
# CONFIG ---------------------------------------------------------
isProd = gutil.env.type is 'prod'
sources =
html: 'app/**/*.html'
sass: 'app/styles/styles.scss'
coffee: 'app/scripts/*.coffee'
assets: 'app/assets/**/*'
libjs: 'app/scripts/lib/*.js'
libcss: 'app/styles/lib/*.css'
data: 'app/data/**/*'
destinations =
css: 'dist/'
html: 'dist/'
js: 'dist/'
assets: 'dist/assets'
libjs: 'dist/lib/'
libcss: 'dist/lib'
data: 'dist/data/'
# TASKS -------------------------------------------------------------
express = require('express')
refresh = require('gulp-livereload')
livereload = require('connect-livereload')
LIVERELOADPORT = 35729
SERVERPORT = 8000
server = express()
server.use(livereload(port: LIVERELOADPORT))
server.use(express.static('./dist'))
server.all('/*', (req, res) -> res.sendFile('index.html', root: 'dist' ))
# Compile and concatenate scripts
gulp.task('coffee', ->
gulp.src(sources.coffee)
.pipe(coffee({bare: true})
.on('error', gutil.log))
.pipe(concat('app.js'))
.pipe(if isProd then uglify() else gutil.noop())
.pipe(gulp.dest(destinations.js))
)
# Compile stylesheets
gulp.task('sass', ->
gulp.src(sources.sass)
.pipe(sass(onError: (e) -> console.log(e)))
.pipe(autoprefixer('last 2 versions', '> 1%', 'ie 8'))
.pipe(gulp.dest(destinations.css))
)
# Lint coffeescript
# TODO Fix this
gulp.task('lint', ->
gulp.src(sources.coffee)
.pipe(coffeelint())
.pipe(coffeelint.reporter())
)
gulp.task('data', ->
gulp.src(sources.data).pipe(gulp.dest(destinations.data))
)
gulp.task('html', ->
gulp.src(sources.html).pipe(gulp.dest(destinations.html))
)
gulp.task('assets', ->
gulp.src(sources.assets).pipe(gulp.dest(destinations.assets))
)
gulp.task('libjs', ->
gulp.src(sources.libjs).pipe(gulp.dest(destinations.libjs))
)
gulp.task('libcss', ->
gulp.src(sources.libcss).pipe(gulp.dest(destinations.libcss))
)
# Watched tasks
gulp.task('watch', ->
server.listen(SERVERPORT)
refresh.listen(LIVERELOADPORT)
gulp.watch sources.data, ['data']
gulp.watch 'app/styles/*.scss', ['sass']
gulp.watch sources.assets, ['assets']
gulp.watch sources.html, ['html']
gulp.watch sources.coffee, ['coffee', 'lint']
gulp.watch sources.libjs, ['libjs']
gulp.watch sources.libcss, ['libcss']
gulp.watch('./dist/**').on('change', refresh.changed);
)
# Remove /dist directory
gulp.task('clean', ->
gulp.src(['dist/'], read: false)
.pipe(rimraf(force: true))
)
# Build sequence
gulp.task('build', ->
runSequence('clean', ['coffee', 'sass', 'data', 'html', 'libjs', 'libcss', 'assets'])
)
gulp.task('default', [
'build'
'watch'
])