-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.coffee
191 lines (166 loc) · 4.68 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
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
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
gulp = require("gulp")
$ = require("gulp-load-plugins")({lazy: true})
del = require("del")
addStream = require("add-stream");
args = require("yargs").argv
run = require("run-sequence")
fs = require("fs")
constructConfig = ->
root = "./"
src = root + "tiny-gallery-js/"
utils = "utils/"
pkg =
npm: root + "package.json"
bower: root + "bower.json"
packageNpm = require(pkg.npm)
config =
root: root
src: src
allScripts: [src + "**/*.coffee", src + "**/*.js"]
allLess: [src + "**/*.less"]
allHtml: [src + "**/*.html"]
build: root + "build/"
utils: utils
importerJs: utils + "importer.coffee"
compiledJsFile: "tgjs.js"
compiledCssFile: "tgjs.css"
templateCache:
file: "templates.js"
options:
module: "TinyGalleryApp"
standalone: false
root: "./tiny-gallery-js/"
dev: false
dist: root + "dist/"
pkg: pkg
packages: [pkg.npm, pkg.bower]
version: packageNpm.version
packageNpm: packageNpm
config = constructConfig()
banner = [
'/**'
' * <%= pkg.name %> - <%= pkg.description %>'
' * @author <%= pkg.author %>'
' * @version v<%= pkg.version %>'
' * @link <%= pkg.homepage %>'
' * @license <%= pkg.license %>'
' */'
''
].join('\n')
gulp.task "help", $.taskListing.withFilters(-> false)
gulp.task "default", ["help"]
busySleep = (time) ->
stop = new Date().getTime();
noop = ->
noop() while (new Date().getTime() < stop + time)
prepareTemplates = ->
gulp.src config.allHtml
.pipe $.plumber()
.pipe $.minifyHtml({empty: true})
.pipe $.angularTemplatecache(config.templateCache.file, config.templateCache.options)
gulp.task "scripts", ->
log("Processing scripts")
gulp.src config.allScripts
.pipe $.print()
.pipe $.plumber()
.pipe $.if(/[.]coffee$/, $.coffee())
.pipe addStream.obj(prepareTemplates())
.pipe $.concat(config.compiledJsFile)
.pipe $.if(!config.dev, $.ngAnnotate())
.pipe $.if(!config.dev, $.uglify())
.pipe $.header(banner, {pkg: config.packageNpm})
.pipe gulp.dest(config.build)
gulp.task "styles", ->
log "Processing styles"
gulp.src config.allLess
.pipe $.print()
.pipe $.plumber()
.pipe $.less()
.pipe $.autoprefixer({browsers: ["last 2 versions", "> 5%"]})
.pipe $.concat(config.compiledCssFile)
.pipe $.if(!config.dev, $.minifyCss())
.pipe gulp.dest(config.build)
gulp.task "build", (cb) ->
log "Building"
run ["styles", "scripts"], -> cb()
gulp.task "rebuild", (cb) ->
log "Rebuilding"
run "clean", "build", -> cb()
gulp.task "build-dev", (cb) ->
config.dev = true
run "build", -> cb()
gulp.task "rebuild-dev", ["clean"], (cb) ->
config.dev = true
run "clean", "build", -> cb()
gulp.task "clean", (cb) ->
log "Cleaning build and dist directory"
files = [config.build + "**/*", config.dist + "**/*"]
clean files, cb
gulp.task "watch", ->
log "Watching"
config.dev = true
gulp.watch config.allLess, ["styles"]
gulp.watch config.allScripts, ["scripts"]
gulp.task "server", ->
log("Running server")
serverOptions =
livereload:
enable: true
filter: (path) -> path.match(/(build)|(testing-app)/)
directoryListing: true
open: "testing-app/test.html"
gulp.src config.root
.pipe $.webserver(serverOptions)
gulp.task "serve", ["server", "watch"], ->
log "Serving"
gulp.task "importer", ->
log "Building importer"
gulp.src config.importerJs
.pipe $.plumber()
.pipe $.coffee()
.pipe gulp.dest(config.utils)
gulp.task "watch-importer", ->
gulp.watch [config.importerJs], ["importer"]
gulp.task "pack", ->
fileName = "tgjs_#{config.version}.zip"
log "Packing built files to #{fileName}"
files = fs.readdirSync(config.build)
if (files.length != 2) then log "Missing files for packaging. " + JSON.stringify(files)
gulp.src config.build + "**/*.*"
.pipe $.print()
.pipe $.plumber()
.pipe $.zip(fileName)
.pipe gulp.dest(config.dist)
gulp.task "dist", (cb) ->
log "Building and packing for distribution"
run "rebuild", "pack", -> cb()
# Bumps the version
# --type=[pre,patch,minor,major] bumps specified value
# --version=1.2.3 bumps to a specific value
gulp.task "bump", ->
msg = "Bumping versions"
type = args.type
version = args.version
options = {}
if version
options.version = version
msg += ' to ' + version
else
options.type = type
msg += ' for a ' + type
log msg
gulp.src config.packages
.pipe $.print()
.pipe $.bump(options)
.pipe gulp.dest(config.root)
#---
clean = (path, done) ->
log "Cleaning: " + $.util.colors.blue(path)
del path, done
log = (msg) ->
if typeof msg == "object"
for item of msg
if msg.hasOwnProperty item
$.util.log $.util.colors.blue(msg[item])
else
$.util.log $.util.colors.blue(msg)