-
Notifications
You must be signed in to change notification settings - Fork 9
/
gulpfile.coffee
91 lines (75 loc) · 2.18 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
require 'coffee-script/register'
gulp = require 'gulp'
browserify = require 'browserify'
coffee = require 'coffee-script'
spawn = require('child_process').spawn
vinyl =
buffer: require 'vinyl-buffer'
source: require 'vinyl-source-stream'
through = require 'through'
# Loads all gulp plugins located in package.json
# > Call plugins using `gp.<camelizedPluginName>
gp = do require 'gulp-load-plugins'
# Load configurations for gulp files
Tasks = require './Tasks'
paths = Tasks.paths
options = Tasks.options
gulp.task 'css:build', ->
gulp.src paths.scss.src
.pipe gp.sourcemaps.init()
.pipe gp.rename 'build.scss'
.pipe(
gp.sass options.scss
.on 'error', gp.sass.logError
)
.pipe gp.sourcemaps.write('./sass-maps')
.pipe gulp.dest paths.build
gulp.task 'js:build', ->
b = browserify(
entries: [
paths.coffee.src
]
debug: true
paths: paths.npm
)
b.transform (fileName) ->
data = ''
fileExtensionRe = /\.[0-9a-z]+$/i
write = (buf) ->
data += buf
end = () ->
# console.log fileName
fileExt = fileExtensionRe.exec fileName
if fileExt and fileExt[0] is '.coffee'
this.queue coffee.compile data
else
this.queue data
this.queue null
through write, end
b.bundle()
.on 'error', (err) ->
console.log 'browserify error:'
console.log err
@emit 'end'
.pipe vinyl.source 'build.js'
.pipe vinyl.buffer()
.pipe gp.sourcemaps.init(loadMaps : true)
.pipe gp.uglify options.uglify
.pipe gp.sourcemaps.write('.maps')
.pipe gulp.dest paths.build
gulp.task 'server', ->
gp.liveServer.static '.', 8890, false
.start()
gulp.task 'watch', ->
gulp.watch paths.scss.watch, options.gulpNoRead, ['css:build']
gulp.watch [paths.coffee.watch], options.gulpNoRead, ['js:build']
gulp.task 'build', [
'js:build'
'css:build'
]
gulp.task 'dev', [
'build'
'watch'
'server'
]
gulp.task 'default', ['dev']