-
Notifications
You must be signed in to change notification settings - Fork 288
/
gulpfile.coffee
88 lines (74 loc) · 2.59 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
gulp = require 'gulp'
vinyl = require 'vinyl-source-stream'
browserify = require 'browserify'
watchify = require 'watchify'
gutil = require 'gulp-util'
prettyHrtime = require 'pretty-hrtime'
notify = require 'gulp-notify'
mocha = require 'gulp-mocha'
mochaPhantomJS = require 'gulp-mocha-phantomjs'
template = require 'gulp-lodash-template'
coffee = require 'gulp-coffee'
del = require 'del'
startTime = null
logger =
start: ->
startTime = process.hrtime()
gutil.log 'Running', gutil.colors.green("'bundle'") + '...'
end: ->
taskTime = process.hrtime startTime
prettyTime = prettyHrtime taskTime
gutil.log 'Finished', gutil.colors.green("'bundle'"), 'in', gutil.colors.magenta(prettyTime)
handleErrors = ->
notify.onError
title: 'Compile error'
message: '<%= error.message %>'
.apply this, arguments
@emit 'end'
build = (test) ->
[output, entry, options] = if test
['tests.js', './test/index', debug: true]
else
['html-docx.js', './src/api', standalone: 'html-docx']
bundleMethod = if global.isWatching then watchify else browserify
bundler = bundleMethod
entries: [entry]
extensions: ['.coffee', '.tpl']
bundle = ->
logger.start()
bundler
.transform 'jstify', engine: 'lodash-micro', minifierOpts: false
.bundle options
.on 'error', handleErrors
.pipe vinyl(output)
.pipe gulp.dest('./build')
.on 'end', logger.end
if global.isWatching
bundler.on 'update', bundle
bundle()
testsBundle = './test/index.coffee'
clean = (cb) -> del 'build', cb
gulp.task 'clean', clean
gulp.task 'setWatch', -> global.isWatching = true
gulp.task 'build', -> build()
gulp.task 'watch', ['setWatch', 'build']
buildNode = (compileCoffee = true) ->
logger.start()
gulp.src('src/**/*', base: 'src').pipe(gulp.dest('build'))
gulp.src('src/templates/*.tpl').pipe(template commonjs: true).pipe(gulp.dest('build/templates'))
if compileCoffee
gulp.src('src/**/*.coffee').pipe(coffee bare: true)
.on('error', handleErrors).on('end', logger.end).pipe(gulp.dest('build'))
else
logger.end()
gulp.task 'build-node', buildNode
gulp.task 'test-node', (growl = false) ->
buildNode(false)
gulp.src(testsBundle, read: false).pipe mocha {reporter: 'spec', growl}
gulp.task 'test-node-watch', ->
sources = ['src/**', 'test/**']
gulp.watch sources, ['test-node']
gulp.task 'build-test-browserify', -> build(true)
gulp.task 'run-phantomjs', -> gulp.src('test/testbed.html').pipe(mochaPhantomJS reporter: 'spec')
gulp.task 'test-phantomjs', ['build-test-browserify', 'run-phantomjs']
gulp.task 'default', ['test-node', 'test-node-watch']