-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.coffee
123 lines (104 loc) · 2.77 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
116
117
118
119
120
121
122
123
gulp = require 'gulp'
gutil = require 'gulp-util'
browserSync = require 'browser-sync'
browserify = require 'gulp-browserify'
sass = require 'gulp-sass'
rename = require 'gulp-rename'
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 -------------------------------------------------------------
gulp.task('browser-sync', ->
browserSync(
server:
baseDir: 'dist/'
)
)
# Compile and concatenate scripts
gulp.task('coffee', ->
gulp.src('app/scripts/main.coffee', read: false)
.pipe(browserify(
transform: ['coffeeify']
extensions: ['.coffee']
insertGlobals: true,
debug: !isProd
))
.pipe(rename('app.js'))
.pipe(gulp.dest(destinations.js))
.pipe(browserSync.reload(stream: true))
)
# 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))
.pipe(browserSync.reload(stream: true))
)
# 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', ->
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']
)
# 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', 'assets'])
)
gulp.task('default', [
'browser-sync'
'build'
'watch'
])