forked from vidigami/backbone-http
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.coffee
74 lines (62 loc) · 3.01 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
path = require 'path'
_ = require 'underscore'
Async = require 'async'
es = require 'event-stream'
gulp = require 'gulp'
gutil = require 'gulp-util'
webpack = require 'gulp-webpack-config'
rename = require 'gulp-rename'
uglify = require 'gulp-uglify'
header = require 'gulp-header'
mocha = require 'gulp-mocha'
HEADER = """
/*
<%= file.path.split('/').splice(-1)[0].replace('.min', '') %> <%= pkg.version %>
Copyright (c) 2013-#{(new Date()).getFullYear()} Vidigami
License: MIT (http://www.opensource.org/licenses/mit-license.php)
Source: https://github.com/vidigami/backbone-http
Dependencies: Backbone.js, Underscore.js, and BackboneORM.
*/\n
"""
gulp.task 'build', buildLibraries = ->
return gulp.src('config/builds/library/**/*.webpack.config.coffee', {read: false, buffer: false})
.pipe(webpack())
.pipe(header(HEADER, {pkg: require './package.json'}))
.pipe(gulp.dest('.'))
gulp.task 'watch', ['build'], ->
return gulp.watch './src/**/*.coffee', -> buildLibraries()
gulp.task 'minify', ['build'], ->
return gulp.src(['*.js', '!*.min.js', '!_temp/**/*.js', '!node_modules/'])
.pipe(uglify())
.pipe(rename({suffix: '.min'}))
.pipe(header(HEADER, {pkg: require './package.json'}))
.pipe(gulp.dest((file) -> file.base))
gulp.task 'start-test-server', (callback) ->
console.log 'Starting server'
(require './test/lib/test_server').start (callback)
return # promises workaround: https://github.com/gulpjs/gulp/issues/455
testNode = (callback) ->
tags = ("@#{tag.replace(/^[-]+/, '')}" for tag in process.argv.slice(3)).join(' ')
gutil.log "Running Node.js tests #{tags}"
(require './test/lib/test_server').retain()
require './test/lib/node_jquery_xhr' # ensure that globals for the target backend are loaded
global.test_parameters = require './test/parameters'
gulp.src("{node_modules/backbone-#{if tags.indexOf('@quick') >= 0 then 'orm' else '{orm,rest}'}/,}test/{issues,spec/sync}/**/*.tests.coffee")
.pipe(mocha({reporter: 'dot', grep: tags}))
.pipe es.writeArray (err, array) ->
delete global.test_parameters
(require './test/lib/test_server').release(err); callback(err)
return # promises workaround: https://github.com/gulpjs/gulp/issues/455
testBrowsers = (callback) ->
tags = ("@#{tag.replace(/^[-]+/, '')}" for tag in process.argv.slice(3)).join(' ')
gutil.log "Running Browser tests #{tags}"
(require './test/lib/test_server').retain()
(require './config/karma/run') {tags: tags}, (err) ->
(require './test/lib/test_server').release(err); callback(err)
return # promises workaround: https://github.com/gulpjs/gulp/issues/455
gulp.task 'test-node', ['build', 'start-test-server'], testNode
gulp.task 'test-browsers', ['build', 'start-test-server'], testBrowsers
gulp.task 'test', ['minify', 'start-test-server'], (callback) ->
(require './test/lib/test_server').retain()
Async.series [testNode, testBrowsers], (err) -> (require './test/lib/test_server').release(err); callback(err)
return # promises workaround: https://github.com/gulpjs/gulp/issues/455