Skip to content

Commit a46634e

Browse files
committedFeb 6, 2016
updated gulpfile, added 'dist' task for generating umd build
1 parent ed52cb0 commit a46634e

File tree

4 files changed

+88
-34
lines changed

4 files changed

+88
-34
lines changed
 

‎.gitignore

+2-1
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,5 @@ npm-debug.log
77
*.css
88
*.rdb
99
coverage/
10-
node_modules/
10+
dist/
11+
node_modules/

‎gulpfile.ls

+77-33
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
require! \browserify
2-
# require! \./config
2+
require! \browserify-shim
33
require! \fs
44
require! \gulp
55
require! \gulp-connect
@@ -10,69 +10,107 @@ require! \gulp-stylus
1010
require! \gulp-uglify
1111
require! \gulp-util
1212
require! \nib
13-
{basename, dirname, extname} = require \path
13+
require! \run-sequence
14+
{once} = require \underscore
1415
source = require \vinyl-source-stream
1516
require! \watchify
1617

1718
config =
1819
minify: process.env.MINIFY == \true
1920

20-
create-bundler = (entries) ->
21-
bundler = browserify {} <<< watchify.args <<< {debug: config.minify, paths: <[./src ./public/components]>}
21+
# build public/components/App.styl which requires other styl files
22+
gulp.task \build:examples:styles, ->
23+
gulp.src <[./public/components/App.styl]>
24+
.pipe gulp-stylus {use: nib!, import: <[nib]>, compress: config.minify, "include css": true}
25+
.pipe gulp.dest './public/components'
26+
.pipe gulp-connect.reload!
27+
28+
# watch all the style files both in public/components directory & themes directory
29+
gulp.task \watch:examples:styles, ->
30+
gulp.watch <[./public/components/*.styl ./themes/*.styl]>, <[build:examples:styles]>
31+
32+
# create a browserify Bundler
33+
# create-bundler :: [String] -> object -> Bundler
34+
create-bundler = (entries, extras) ->
35+
bundler = browserify {} <<< watchify.args <<< extras <<< {paths: <[./src ./public/components]>}
2236
..add entries
2337
..transform \liveify
2438
..transform \brfs
25-
watchify bundler
2639

27-
bundle = (bundler, {file, directory}:output) ->
40+
# outputs a single javascript file (which is bundled and minified - depending on env)
41+
# bundler :: Bundler -> {file :: String, directory :: String} -> IO()
42+
bundle = (minify, bundler, {file, directory}:output) ->
2843
bundler.bundle!
29-
.on \error, -> console.log arguments
44+
.on \error, -> gulp-util.log arguments
3045
.pipe source file
31-
.pipe gulp-if config.minify, (gulp-streamify gulp-uglify!)
46+
.pipe gulp-if minify, (gulp-streamify gulp-uglify!)
3247
.pipe gulp.dest directory
33-
.pipe gulp-connect.reload!
3448

35-
##
36-
# Examples
37-
##
38-
gulp.task \build:examples:styles, ->
39-
gulp.src <[./public/components/App.styl]>
40-
.pipe gulp-stylus {use: nib!, import: <[nib]>, compress: config.minify, "include css": true}
41-
.pipe gulp.dest './public/components'
42-
.pipe gulp-connect.reload!
49+
# build-and-watch :: Bundler -> {file :: String, directory :: String} -> Boolean -> (() -> ()) -> ()
50+
build-and-watch = (minify, bundler, {file}:output, done) !->
51+
# must invoke done only once
52+
once-done = once done
4353

44-
gulp.task \watch:examples:styles, ->
45-
gulp.watch <[./public/components/*.styl ./themes/*.styl]>, <[build:examples:styles]>
54+
watchified-bundler = watchify bundler
55+
56+
# build once
57+
bundle minify, watchified-bundler, output
58+
59+
watchified-bundler
60+
.on \update, ->
61+
bundle minify, watchified-bundler, output
62+
.pipe gulp-connect.reload!
4663

47-
examples-bundler = create-bundler \./public/components/App.ls
48-
bundle-examples = -> bundle examples-bundler, {file: "App.js", directory: "./public/components/"}
64+
.on \time, (time) ->
65+
once-done!
66+
gulp-util.log "#{file} built in #{time / 1000} seconds"
4967

50-
gulp.task \build:examples:scripts, ->
51-
bundle-examples!
68+
examples-bundler = create-bundler [\./public/components/App.ls], debug: !config.minify
69+
app-js = file: \App.js, directory: \./public/components/
5270

53-
gulp.task \watch:examples:scripts, ->
54-
examples-bundler.on \update, -> bundle-examples!
55-
examples-bundler.on \time, (time) -> gulp-util.log "App.js built in #{time} ms"
71+
# first, builds public/components/App.ls once, then builds it everytime there is a change
72+
gulp.task \build-and-watch:examples:scripts, (done) ->
73+
build-and-watch config.minify, examples-bundler, app-js, done
5674

57-
##
58-
# Source
59-
##
6075
gulp.task \build:themes, ->
6176
gulp.src <[./themes/*.styl]>
62-
.pipe gulp-stylus use: nib!, import: <[nib]>, compress: config.minify
63-
.pipe gulp.dest './themes'
77+
.pipe gulp-stylus {use: nib!, import: <[nib]>, compress: config.minify, "include css": true}
78+
.pipe gulp.dest \./themes
79+
.pipe gulp-connect.reload!
6480

6581
gulp.task \watch:themes, ->
6682
gulp.watch <[./themes/*.styl]>, <[build:themes]>
6783

6884
gulp.task \build:src:scripts, ->
6985
gulp.src <[./src/*.ls]>
7086
.pipe gulp-livescript!
71-
.pipe gulp.dest './src'
87+
.pipe gulp.dest \./src
7288

7389
gulp.task \watch:src:scripts, ->
7490
gulp.watch <[./src/*.ls]>, <[build:src:scripts]>
7591

92+
# create-standalone-build :: Boolean -> {file :: String, directory :: String} -> Stream
93+
create-standalone-build = (minify, {file, directory}) ->
94+
browserify standalone: \react-selectize, debug: false
95+
.add <[./src/index.js]>
96+
.exclude \prelude-ls
97+
.exclude \prelude-extension
98+
.exclude \react
99+
.exclude \react-dom
100+
.exclude \react-addons-css-transition-group
101+
.exclude \react-addons-shallow-compare
102+
.exclude \tether
103+
.transform browserify-shim
104+
.bundle!
105+
.on \error, -> gulp-util.log arguments
106+
.pipe source file
107+
.pipe gulp-if minify, (gulp-streamify gulp-uglify!)
108+
.pipe gulp.dest directory
109+
110+
gulp.task \dist, <[build:src:scripts]>, ->
111+
create-standalone-build false, {file: \index.js, directory: \./dist} .on \finish, ->
112+
create-standalone-build true, {file: \index.min.js, directory: \./dist}
113+
76114
gulp.task \dev:server, ->
77115
gulp-connect.server do
78116
livereload: true
@@ -83,4 +121,10 @@ gulp.task \build:src, <[build:themes build:src:scripts]>
83121
gulp.task \watch:src, <[watch:themes watch:src:scripts]>
84122
gulp.task \build:examples, <[build:examples:styles build:examples:scripts]>
85123
gulp.task \watch:examples, <[watch:examples:styles watch:examples:scripts]>
86-
gulp.task \default, <[dev:server build:src watch:src build:examples watch:examples]>
124+
gulp.task \default, -> run-sequence do
125+
\build:src
126+
\watch:src
127+
\build:examples:styles
128+
\watch:examples:styles
129+
\build-and-watch:examples:scripts
130+
\dev:server

‎package.json

+9
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,14 @@
2020
"react-addons-shallow-compare": "^0.14.6",
2121
"react-dom": "^0.14.0"
2222
},
23+
"browserify-shim": {
24+
"prelude-extension": "global:preludeExtension",
25+
"react": "global:React",
26+
"react-addons-css-transition-group": "global:React.addons.CSSTransitionGroup",
27+
"react-addons-shallow-compare": "global:React.addons.shallowCompare",
28+
"react-dom": "global:ReactDOM",
29+
"tether": "global:Tether"
30+
},
2331
"devDependencies": {
2432
"async-ls": "0.0.3",
2533
"brace": "git+https://github.com/furqanZafar/brace.git",
@@ -51,6 +59,7 @@
5159
"react-dom": "^0.14.0",
5260
"react-router": "^1.0.0-rc1",
5361
"react-tools": "^0.13.3",
62+
"run-sequence": "^1.1.5",
5463
"should": "^7.1.0",
5564
"underscore": "^1.8.3",
5665
"vinyl-source-stream": "^1.0.0",
File renamed without changes.

0 commit comments

Comments
 (0)