forked from sundaysenergy/client-dev-demo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.coffee
162 lines (136 loc) · 4.08 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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
path = require 'path'
fs = require 'fs-extra'
gulp = require 'gulp'
r = require 'request'
yaml = require 'js-yaml'
browserSync = require 'browser-sync'
browserify = require 'browserify'
watchify = require 'watchify'
coffeeify = require 'coffeeify'
bd = require 'browserify-data'
source = require('vinyl-source-stream')
jade = require 'gulp-jade'
less = require 'gulp-less'
clean = require 'gulp-clean'
zopfli = require 'gulp-zopfli'
rename = require 'gulp-rename'
runSequence = require 'run-sequence'
data = yaml.safeLoad fs.readFileSync('data.yaml', 'utf8')
gulp.task "browser-sync", ->
browserSync.init ["public/*.css", "public/*.js", "public/*.html"],
server:
baseDir: "public" # Change this to your web root dir
injectChanges: false
logConnections: true
# ghostMode:
# clicks: true
# scroll: true
# location: true
return
gulp.task "templates", ->
gulp.src("templates/*.jade")
.pipe jade(locals: data)
.pipe gulp.dest("./public/")
return
gulp.task 'copy', ->
gulp.src('./images/**')
.pipe gulp.dest('./public/images/')
gulp.task 'styles', ->
gulp.src(["styles/app.less", 'styles/print.less', 'styles/iefix.less'])
.pipe less(paths: [path.join(__dirname, "less", "includes")])
.pipe gulp.dest("./public")
gulp.task 'compile', ->
opts = watchify.args
opts.extensions = ['.coffee', '.json']
w = watchify(browserify('./app/index.coffee', opts))
w.transform coffeeify
w.transform bd
bundle = () ->
w.bundle()
.pipe(source('app.js'))
.pipe(gulp.dest('./public/'))
w.on('update', bundle)
bundle()
return
gulp.task "default", ['compile', 'styles', 'templates', 'browser-sync', 'copy'], ->
gulp.watch "templates/*.jade", ["templates"]
gulp.watch "styles/*.less", ["styles"]
gulp.watch 'images/**', ['copy']
return
# - - - - prod - - - -
gulp.task 'set_sha', (cb) ->
r_ops =
uri: 'https://api.github.com/repos/webmasterkai/sailboat_data/branches/master'
json: true
headers:
'user-agent': 'request.js'
r r_ops, (err, response, body) ->
if err then throw err
global.sha = body.commit.sha
cb()
return
# Remove contents from prod directory.
gulp.task 'prod_clean', ->
gulp.src(['./prod/*.js', './prod/*.css', './prod/*.html', './prod/*.html.gz'], read: false)
.pipe(clean())
gulp.task 'prod_compile', (cb) ->
# Javascript bundle
opts =
debug: true
extensions: ['.coffee', '.json']
bundler = browserify opts
bundler.transform coffeeify
bundler.transform bd
bundler.add('./app/index.coffee')
bundler.plugin 'minifyify',
map: 'script.map.json'
output: './prod/script.map.json'
bundler.bundle debug: true
.pipe(source(global.sha+'.js'))
.pipe(gulp.dest('./prod/'))
.on('end', cb)
return
gulp.task 'prod_template', ->
# Templates
data.sha = global.sha
gulp.src("templates/*.jade")
.pipe jade(locals: data)
.pipe gulp.dest("./prod/")
gulp.task 'copy_css', ['styles'], ->
gulp.src('./public/app.css')
.pipe(rename(global.sha+'.css'))
.pipe(gulp.dest('./prod'))
gulp.src('./public/print.css', './public/iefix.css')
.pipe(gulp.dest('./prod'))
gulp.src('./images/**')
.pipe gulp.dest('./prod/images/')
gulp.task 'copy_api', ->
gulp.src('./api/**')
.pipe gulp.dest('./prod/api/')
gulp.task 'compress', ->
gulp.src(["./prod/*.js", './prod/*.css', './prod/*.html'])
.pipe(zopfli())
.pipe(gulp.dest("./prod"))
gulp.task 'prod', (cb) ->
runSequence ['prod_clean', 'set_sha'],
['prod_template', 'copy_css', 'prod_compile'],
'compress',
cb
return
gulp.task 'boats', ['data', 'hooper'], ->
boats = require './app/models/names.json'
boats.map (boat) ->
r('http://localhost:8000/boat/'+boat.id)
.pipe source(boat.id+'.json')
.pipe gulp.dest('./api/boat')
gulp.task 'hooper', ->
r('http://localhost:8000/hooper')
.pipe source('hooper.json')
.pipe gulp.dest('./api')
gulp.task 'data', ->
r('http://localhost:8000/boat')
.pipe source('names.json')
.pipe gulp.dest('./app/models/')
# r('http://localhost:8000/phrf')
# .pipe source('phrf.json')
# .pipe gulp.dest('./api/')