forked from furqanZafar/react-selectize
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.ls
151 lines (127 loc) · 4.92 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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
require! \browserify
require! \browserify-shim
require! \fs
require! \gulp
require! \gulp-connect
require! \gulp-if
require! \gulp-livescript
require! \gulp-rename
require! \gulp-streamify
require! \gulp-stylus
require! \gulp-uglify
require! \gulp-util
require! \nib
require! \run-sequence
{once} = require \underscore
source = require \vinyl-source-stream
require! \watchify
config =
minify: process.env.MINIFY == \true
# stylus-config :: Boolean -> object
stylus-config = (minify) ->
use: nib!
import: <[nib]>
compress: minify
"include css": true
# build public/components/App.styl which requires other styl files
gulp.task \build:examples:styles, ->
gulp.src <[./public/components/App.styl]>
.pipe gulp-stylus (stylus-config config.minify)
.pipe gulp.dest './public/components'
.pipe gulp-connect.reload!
# watch all the style files both in public/components directory & themes directory
gulp.task \watch:examples:styles, ->
gulp.watch <[./public/components/*.styl ./themes/*.styl]>, <[build:examples:styles]>
# create a browserify Bundler
# create-bundler :: [String] -> object -> Bundler
create-bundler = (entries, extras) ->
bundler = browserify {} <<< watchify.args <<< extras <<< {paths: <[./src ./public/components]>}
..add entries
..transform \liveify
..transform \brfs
# outputs a single javascript file (which is bundled and minified - depending on env)
# bundler :: Bundler -> {file :: String, directory :: String} -> IO()
bundle = (minify, bundler, {file, directory}:output) ->
bundler.bundle!
.on \error, -> gulp-util.log arguments
.pipe source file
.pipe gulp-if minify, (gulp-streamify gulp-uglify!)
.pipe gulp.dest directory
# build-and-watch :: Bundler -> {file :: String, directory :: String} -> Boolean -> (() -> ()) -> ()
build-and-watch = (minify, bundler, {file}:output, done) !->
# must invoke done only once
once-done = once done
watchified-bundler = watchify bundler
# build once
bundle minify, watchified-bundler, output
watchified-bundler
.on \update, ->
bundle minify, watchified-bundler, output
.pipe gulp-connect.reload!
.on \time, (time) ->
once-done!
gulp-util.log "#{file} built in #{time / 1000} seconds"
examples-bundler = create-bundler [\./public/components/App.ls], debug: !config.minify
app-js = file: \App.js, directory: \./public/components/
# first, builds public/components/App.ls once, then builds it everytime there is a change
gulp.task \build-and-watch:examples:scripts, (done) ->
build-and-watch config.minify, examples-bundler, app-js, done
gulp.task \build:themes, ->
gulp.src <[./themes/*.styl]>
.pipe gulp-stylus (stylus-config config.minify)
.pipe gulp.dest \./themes
gulp.task \watch:themes, ->
gulp.watch <[./themes/*.styl]>, <[build:themes]>
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]>
# create-standalone-build :: Boolean -> {file :: String, directory :: String} -> Stream
create-standalone-build = (minify, {file, directory}) ->
browserify standalone: \react-selectize, debug: false
.add <[./src/index.js]>
.exclude \prelude-ls
.exclude \prelude-extension
.exclude \react
.exclude \react-dom
.exclude \react-addons-css-transition-group
.exclude \react-addons-shallow-compare
.exclude \tether
.transform browserify-shim
.bundle!
.on \error, -> gulp-util.log arguments
.pipe source file
.pipe gulp-if minify, (gulp-streamify gulp-uglify!)
.pipe gulp.dest directory
gulp.task \dist, <[build:src:scripts]>, ->
# create dist/index.js
<- create-standalone-build false, {file: \index.js, directory: \./dist} .on \finish
# create dist/index.min.js
<- create-standalone-build true, {file: \index.min.js, directory: \./dist} .on \finish
# create dist/index.css
gulp.src <[./themes/index.styl]>
.pipe gulp-stylus (stylus-config false)
.pipe gulp.dest \./dist
# create dist/index.min.css
gulp.src <[./themes/index.styl]>
.pipe gulp-stylus (stylus-config true)
.pipe gulp-rename (path) -> path.extname = \.min.css
.pipe gulp.dest \./dist
gulp.task \dev:server, ->
gulp-connect.server do
livereload: true
port: 8000
root: \./public/
gulp.task \build:src, <[build:themes build:src:scripts]>
gulp.task \watch:src, <[watch:themes watch:src:scripts]>
gulp.task \build:examples, <[build:examples:styles build:examples:scripts]>
gulp.task \watch:examples, <[watch:examples:styles watch:examples:scripts]>
gulp.task \default, -> run-sequence do
\build:src
\watch:src
\build:examples:styles
\watch:examples:styles
\build-and-watch:examples:scripts
\dev:server