-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.ls
125 lines (105 loc) · 3.85 KB
/
gulpfile.ls
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
121
122
123
124
125
require! \browserify
require! \gulp
require! \gulp-connect
require! \gulp-if
require! \gulp-livescript
{instrument, hook-require, write-reports} = (require \gulp-livescript-istanbul)!
require! \gulp-mocha
require! \gulp-streamify
require! \gulp-stylus
require! \gulp-uglify
require! \gulp-util
require! \nib
{basename, dirname, extname} = require \path
require! \run-sequence
source = require \vinyl-source-stream
require! \watchify
{once} = require \underscore
config =
minify: process.env.MINIFY == \true
# build styles in components
gulp.task \build:components:styles, ->
gulp.src <[./public/components/App.styl]>
.pipe gulp-stylus {use: nib!, import: <[nib]>, compress: config.minify, "include css": true}
.pipe gulp.dest './public/components'
.pipe gulp-connect.reload!
# watch styles in components
gulp.task \watch:components:styles, ->
gulp.watch <[./public/components/*.styl]>, <[build:components:styles]>
# create a browserify Bundler
# create-bundler :: [String] -> Bundler
create-bundler = (entries) ->
bundler = browserify {} <<< watchify.args <<< debug: !config.minify
..add entries
..transform \liveify
# outputs a single javascript file (which is bundled and minified - depending on env)
# bundler :: Bundler -> {file :: String, directory :: String} -> IO()
bundle = (bundler, {file, directory}:output) ->
bundler.bundle!
.on \error, -> gulp-util.log arguments
.pipe source file
.pipe gulp-if config.minify, (gulp-streamify gulp-uglify!)
.pipe gulp.dest directory
.pipe gulp-connect.reload!
# build-and-watch :: Bundler -> {file :: String, directory :: String} -> (() -> Void) -> (() -> Void) -> (() -> Void)
build-and-watch = (bundler, {file}:output, done, on-update, on-build) ->
# must invoke done only once
once-done = once done
watchified-bundler = watchify bundler
# build once
bundle watchified-bundler, output
watchified-bundler
.on \update, ->
if !!on-update
on-update!
bundle watchified-bundler, output
.on \time, (time) ->
if !!on-build
on-build!
once-done!
gulp-util.log "#{file} built in #{time / 1000} seconds"
components-bundler = create-bundler [\./public/components/App.ls]
app-js = file: "App.js", directory: "./public/components/"
gulp.task \build:components:scripts, ->
bundle components-bundler, app-js
gulp.task \build-and-watch:components:scripts, (done) ->
build-and-watch components-bundler, app-js, done, null, null
gulp.task \build:src:styles, ->
gulp.src <[./src/*.styl]>
.pipe gulp-stylus {use: nib!, import: <[nib]>, compress: config.minify, "include css": true}
.pipe gulp.dest \./src
.pipe gulp-connect.reload!
gulp.task \watch:src:styles, ->
gulp.watch <[./src/*.styl]>, <[build:src:styles]>
gulp.task \build:src:scripts, ->
gulp.src <[./src/*.ls]>
.pipe gulp-livescript!
.pipe gulp.dest './src'
gulp.task \watch:src:scripts, ->
gulp.watch <[./src/*.ls]>, <[build:src:scripts]>
gulp.task \dev:server, ->
gulp-connect.server do
livereload: true
port: 8002
root: \./public/
gulp.task \coverage, ->
gulp.src <[./index.ls]> # files which we want coverage report
.pipe instrument!
.pipe hook-require!
.on \finish, ->
gulp.src <[./test/index.ls]>
.pipe gulp-mocha!
.pipe write-reports!
.on \finish, -> process.exit!
gulp.task \build:src, <[build:src:styles build:src:scripts]>
gulp.task \watch:src, <[watch:src:styles watch:src:scripts]>
gulp.task \build:components, <[build:components:styles build:components:scripts]>
gulp.task \default, -> run-sequence do
<[
build:src
watch:src
build:components:styles
watch:components:styles
build-and-watch:components:scripts
]>
\dev:server