-
Notifications
You must be signed in to change notification settings - Fork 6
/
gulpfile.coffee
72 lines (59 loc) · 1.75 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
gulp = require 'gulp'
bump = require 'gulp-bump'
clean = require 'gulp-clean'
coffee = require 'gulp-coffee'
fs = require 'fs'
gutil = require 'gulp-util'
jade = require 'gulp-jade'
prettify = require 'gulp-prettify'
rename = require 'gulp-rename'
uglify = require 'gulp-uglify'
#
version = undefined
#
_markup = () ->
gulp.src("./stage/index.html", { read: false })
.pipe( clean({ force: true }),
gulp.src('./stage/index.jade')
.pipe( jade() )
.pipe( prettify() )
.pipe( gulp.dest('./stage') )
)
#
_scripts = () ->
_version ( ->
gulp.src("./dist/*.js", { read: false })
.pipe( clean({ force: true }),
gulp.src([ "./src/*.coffee" ])
.pipe( coffee({ bare: true }).on('error', gutil.log) ).on('error', gutil.beep)
# src (unminified and unversioned)
.pipe( gulp.dest('./src') )
# dist
.pipe( uglify() )
# minified unversioned
.pipe( rename({ suffix: ".min" }) )
.pipe( gulp.dest('./dist') )
# minified versioned
.pipe( rename({ suffix: ".#{version}.min" }) )
.pipe( gulp.dest('./dist') )
)
)
#
_bump = (type) ->
gulp.src('./package.json')
.pipe(bump({ type: type || 'patch' }))
.pipe(gulp.dest('./'))
#
_version = (cb) ->
fs.readFile './package.json', (err, data) ->
return console.log "Unable to read package.json :: #{err}" if err
version = JSON.parse(data).version
return cb()
#
_watch = () ->
gulp.watch "./stage/*.jade", -> _markup()
gulp.watch "./src/*.coffee", -> _scripts()
## tasks
gulp.task 'bump', () -> _bump(gulp.env.type)
gulp.task 'compile', () -> _markup(); _scripts()
gulp.task 'default', [ 'compile' ], -> _watch()