-
Notifications
You must be signed in to change notification settings - Fork 70
/
gulpfile.coffee
98 lines (83 loc) · 3.88 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
path = require 'path'
_ = require 'underscore'
Queue = require 'queue-async'
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'
nuget = require 'nuget'
nugetGulp = -> es.map (file, callback) ->
nuget.pack file, (err, nupkg_file) ->
return callback(err) if err
nuget.push nupkg_file, (err) -> if err then gutil.log(err) else callback()
HEADER = module.exports = """
/*
<%= file.path.split('/').splice(-1)[0].replace('.min', '') %> <%= pkg.version %>
Copyright (c) 2011-#{(new Date()).getFullYear()} Kevin Malakoff.
License: MIT (http://www.opensource.org/licenses/mit-license.php)
Source: https://github.com/kmalakoff/knockback
Dependencies: Knockout.js, Backbone.js, and Underscore.js (or LoDash.js).
Optional dependencies: Backbone.ModelRef.js and BackboneORM.
*/\n
"""
LIBRARY_FILES = require('./config/files').libraries
gulp.task 'build', buildLibraries = (callback) ->
errors = []
gulp.src('config/builds/library/**/*.webpack.config.coffee')
.pipe(webpack())
.pipe(header(HEADER, {pkg: require('./package.json')}))
.pipe(gulp.dest('.'))
.on('end', callback)
return # promises workaround: https://github.com/gulpjs/gulp/issues/455
gulp.task 'watch', ['build'], ->
gulp.watch './src/**/*.coffee', -> buildLibraries(->)
return # promises workaround: https://github.com/gulpjs/gulp/issues/455
gulp.task 'minify', ['build'], (callback) ->
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))
.on('end', callback)
return # promises workaround: https://github.com/gulpjs/gulp/issues/455
testNode = (callback) ->
tags = ("@#{tag.replace(/^[-]+/, '')}" for tag in process.argv.slice(3)).join(' ')
mochaOptions = {reporter: 'dot', compilers: 'coffee:coffee-script/register'}
mochaOptions.grep = tags if tags
gutil.log "Running Node.js tests #{tags}"
gulp.src('test/spec/**/*.tests.coffee')
.pipe(mocha(mochaOptions))
.pipe es.writeArray callback
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 './config/karma/run')({tags}, callback)
return # promises workaround: https://github.com/gulpjs/gulp/issues/455
gulp.task 'test-node', ['build'], testNode
# gulp.task 'test-browsers', testBrowsers
gulp.task 'test-browsers', ['minify'], testBrowsers
gulp.task 'test', ['minify'], (callback) ->
Async.series [testNode, testBrowsers], (err) -> not err || console.log(err); process.exit(if err then 1 else 0)
return # promises workaround: https://github.com/gulpjs/gulp/issues/455
gulp.task 'publish', ['minify'], (callback) ->
copyLibraryFiles = (destination, others, callback) ->
gulp.src(LIBRARY_FILES.concat(['README.md', 'RELEASE_NOTES.md'].concat(others)))
.pipe(gulp.dest((file) -> path.join(destination, path.dirname(file.path).replace(__dirname, ''))))
.on('end', callback)
queue = new Queue(1)
queue.defer (callback) -> Async.series [testNode, testBrowsers], callback
queue.defer (callback) -> copyLibraryFiles('packages/npm', ['component.json', 'bower.json'], callback)
queue.defer (callback) -> copyLibraryFiles('packages/nuget/Content/Scripts', [], callback)
queue.defer (callback) ->
gulp.src('packages/nuget/*.nuspec')
.pipe(nugetGulp())
.on('end', callback)
queue.await (err) -> not err || console.log(err); process.exit(if err then 1 else 0)
return # promises workaround: https://github.com/gulpjs/gulp/issues/455
gulp.task 'default', ['test-node']