This repository was archived by the owner on May 10, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathGulpfile.coffee
More file actions
120 lines (101 loc) · 3.97 KB
/
Gulpfile.coffee
File metadata and controls
120 lines (101 loc) · 3.97 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
# ------------------------------------------------------------------------------
# Load in modules
# ------------------------------------------------------------------------------
gulp = require 'gulp'
$ = require('gulp-load-plugins')()
runSequence = require 'run-sequence'
path = require 'path'
fs = require 'fs'
_ = require 'underscore'
{config} = require 'rygr-util'
config.initialize 'config/*.json'
# ------------------------------------------------------------------------------
# Custom vars and methods
# ------------------------------------------------------------------------------
alertError = $.notify.onError (error) ->
message = error?.message or error?.toString() or 'Something went wrong'
"Error: #{ message }"
# ------------------------------------------------------------------------------
# Directory management
# ------------------------------------------------------------------------------
gulp.task 'clean', (cb) ->
dirs = [config.dirs.test]
glob = []
for dir in dirs
fs.mkdirSync dir unless fs.existsSync dir
glob.push "#{ dir }/**", "!#{ dir }"
require('del') glob, cb
# ------------------------------------------------------------------------------
# Compile assets
# ------------------------------------------------------------------------------
gulp.task 'compile', ->
pjson = JSON.parse fs.readFileSync('./package.json')
context =
ENV: process.env.NODE_ENV or 'development'
VERSION: pjson.version
YEAR: new Date().getFullYear()
AUTHOR: pjson.author
LICENSE: pjson.license
REPO: pjson.repository.url
gulp.src("#{ config.dirs.src }/**/*.coffee")
.pipe($.plumber errorHandler: alertError)
.pipe($.preprocess context: context)
.pipe($.coffeelint optFile: './.coffeelintrc')
.pipe($.coffeelint.reporter())
.pipe($.coffee bare: false, sourceMap: false)
.pipe(gulp.dest config.dirs.dest)
.pipe(gulp.dest config.dirs.dest)
gulp.task 'minify', ->
gulp.src("#{config.dirs.dest}/backbone.statemanager.js")
.pipe($.uglify preserveComments: 'all')
.pipe($.rename (path) ->
path.basename += '.min'
undefined
)
.pipe(gulp.dest config.dirs.dest)
# ------------------------------------------------------------------------------
# Build
# ------------------------------------------------------------------------------
gulp.task 'build', (cb) ->
runSequence 'clean', 'compile', 'minify', cb
# ------------------------------------------------------------------------------
# Test
# ------------------------------------------------------------------------------
gulp.task 'test', (cb) ->
gulp.src("#{ config.dirs.test }/*.spec.js")
.pipe($.jasmine())
# ------------------------------------------------------------------------------
# Release
# ------------------------------------------------------------------------------
(->
bump = (type) ->
(cb) ->
gulp.src(['./package.json', './bower.json'])
.pipe($.bump type: type)
.pipe(gulp.dest './')
.on 'end', -> runSequence 'build', cb
undefined
publish = (type) ->
(cb) ->
sequence = [if type then "bump:#{ type }" else 'build']
sequence.push 'test'
sequence.push ->
spawn = require('child_process').spawn
spawn('npm', ['publish'], stdio: 'inherit').on 'close', cb
runSequence sequence...
for type, index in ['prerelease', 'patch', 'minor', 'major']
gulp.task "bump:#{ type }", bump type
gulp.task "publish:#{ type }", publish type
gulp.task 'bump', bump 'patch'
gulp.task 'publish', publish()
)()
# ------------------------------------------------------------------------------
# Watch
# ------------------------------------------------------------------------------
gulp.task 'watch', ->
gulp.watch "#{ config.dirs.src }/**/*.coffee", ['compile']
# ------------------------------------------------------------------------------
# Default
# ------------------------------------------------------------------------------
gulp.task 'default', ->
runSequence 'build', 'watch'