forked from loadingio/loading-bar
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.ls
140 lines (118 loc) · 3.49 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
argv = require 'yargs' .argv
only-compile = false
require! <[ watchify gulp browserify glob path fs globby touch ]>
require! 'prelude-ls': {union, join, keys, map, unique}
require! 'vinyl-source-stream': source
require! 'vinyl-buffer': buffer
require! 'gulp-watch': watch
require! 'gulp-pug': pug
require! 'gulp-stylus': stylus
require! 'node-notifier': notifier
require! 'gulp-concat': cat
require! 'gulp-uglify': uglify
require! 'gulp-flatten': flatten
require! 'gulp-tap': tap
require! 'gulp-cached': cache
require! 'gulp-sourcemaps': sourcemaps
require! 'browserify-livescript'
require! 'run-sequence'
require! 'through2':through
require! 'optimize-js'
require! 'gulp-if-else': if-else
require! 'gulp-rename': rename
require! 'gulp-zip': zip
# Build Settings
notification-enabled = yes
# Project Folder Structure
src-path = "#{__dirname}/src"
build-path = "#{__dirname}/build"
out-dir = argv.out-dir or build-path
on-error = (source, msg) ->
msg = try
msg.to-string!
catch
"unknown message: #{e}"
console-msg = "GULP ERROR: #{source} : #{msg}"
console.log console-msg
log-info = (source, msg) ->
msg = try
msg.to-string!
catch
"unknown message: #{e}"
console-msg = "GULP INFO: #{source} : #{msg}"
console.log console-msg
ls-entry-file = "#{src-path}/loading-bar.ls"
for-browserify =
"#{src-path}/*.ls"
...
# Organize Tasks
gulp.task \default, ->
do function run-all
gulp.start do
\browserify
\css
\zip
\compressjs
...
watch for-browserify, ->
gulp.start \browserify
watch ["#{src-path}/*.styl"], ->
gulp.start \css
watch ["#{out-dir}/*.js", "#{out-dir}/*.css"], ->
gulp.start \zip
watch ["#{out-dir}/loading-bar.js"], ->
gulp.start \compressjs
browserify-cache = {}
bundler = browserify do
entries: ls-entry-file
debug: true
paths:
src-path
...
extensions: <[ .ls ]>
cache: browserify-cache
package-cache: {}
plugin:
watchify unless only-compile
...
bundler.transform browserify-livescript
first-browserify-done = no
function bundle
bundler
.bundle!
.on \error, (err) ->
msg = try
err.message
catch
err
on-error \browserify, msg
@emit \end
.pipe source "loading-bar.js"
.pipe buffer!
#.pipe sourcemaps.init {+load-maps, +large-files}
.pipe if-else only-compile, uglify
#.pipe rename basename: 'app'
#.pipe sourcemaps.write '.'
.pipe gulp.dest out-dir
.pipe tap (file) ->
log-info \browserify, "Browserify finished #{if out-dir isnt build-path then "out-dir: #{out-dir}"}"
console.log "------------------------------------------"
first-browserify-done := yes
gulp.task \browserify, ->
bundle!
gulp.task \css, ->
gulp.src \src/loading-bar.styl
.pipe stylus({compress: true})
.pipe gulp.dest out-dir
.pipe tap (file) ->
log-info \css, "Stylus -> CSS finished #{if out-dir isnt build-path then "out-dir: #{out-dir}"}"
console.log "------------------------------------------"
gulp.task \zip, ->
gulp.src ["#out-dir/*.js","#out-dir/*.css"]
.pipe zip("loading-bar.zip")
.pipe gulp.dest out-dir
gulp.task \compressjs, ->
gulp.src ["#out-dir/*.js"]
.pipe uglify!
.pipe rename suffix: \.min
.pipe gulp.dest out-dir