forked from cloudinary/cloudinary_js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGruntfile.coffee
321 lines (296 loc) · 11.1 KB
/
Gruntfile.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
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
module.exports = (grunt)->
repos = [
'cloudinary-core',
'cloudinary-core-shrinkwrap',
'cloudinary-jquery',
'cloudinary-jquery-file-upload'
]
# grunt.initConfig
gruntOptions =
pkg: grunt.file.readJSON('package.json')
coffee:
options:
bare: true
sourceMap: true
sources:
cwd: 'src'
expand: true
src: ['**/*.coffee']
dest: 'src'
ext: '.js'
test:
expand: true
cwd: 'test/spec'
src: ['*.coffee']
dest: 'test/spec'
ext: '.js'
build:
expand: true
bare: false
sourceMap: true
cwd: 'build'
src: ['*.coffee']
dest: 'build'
ext: '.js'
uglify:
build:
options:
sourceMap: true
mangle: false
files: for repo in repos
src: ["build/#{repo}.js"]
dest: "build/#{repo}.min.js"
ext: '.min.js'
karmaCommon: [
"build/<%= grunt.task.current.target %>.js"
'test/spec/spec-helper.js'
'test/spec/cloudinary-spec.js'
'test/spec/transformation-spec.js'
'test/spec/tagspec.js'
'test/spec/videourlspec.js'
'test/spec/chaining-spec.js'
'test/spec/conditional-transformation-spec.js'
]
karma:
options:
reporters: ['dots']
configFile: 'karma.coffee'
browserDisconnectTolerance: 3
files: [
{ pattern: 'test/docRoot/*', watched: false, included: false, served: true, nocache: false}
{ pattern: 'test/docRoot/css/*', watched: false, included: false, served: true, nocache: false}
{ pattern: 'bower_components/bootstrap/dist/css/*', watched: false, included: false, served: true, nocache: false}
{ pattern: 'bower_components/bootstrap/dist/js/*', watched: false, included: false, served: true, nocache: false}
{ pattern: 'bower_components/blueimp-file-upload/js/*', watched: false, included: false, served: true, nocache: false}
{ pattern: 'bower_components/jquery.ui/ui/*', watched: false, included: false, served: true, nocache: false}
]
'cloudinary-core':
files:
src:
[
"bower_components/lodash/lodash.js"
"<%= karmaCommon %>"
"test/spec/responsive-core-spec.js"
]
'cloudinary-core-shrinkwrap':
files:
src: [
"<%= karmaCommon %>"
"test/spec/responsive-shrinkwrap-spec.js"
]
'cloudinary-jquery':
files:
src: [
"bower_components/jquery/dist/jquery.js"
"<%= karmaCommon %>"
"test/spec/responsive-jquery-spec.js"
]
'cloudinary-jquery-file-upload':
files:
src: [
"bower_components/jquery/dist/jquery.js"
"bower_components/jquery.ui/ui/widget.js"
"bower_components/blueimp-file-upload/js/jquery.fileupload.js"
"bower_components/blueimp-file-upload/js/jquery.fileupload-process.js"
"bower_components/blueimp-file-upload/js/jquery.iframe-transport.js"
"bower_components/blueimp-file-upload/js/jquery.fileupload-image.js"
"<%= karmaCommon %>"
"test/spec/cloudinary-jquery-upload-spec.js"
]
jsdoc:
options:
template: 'template'
configure: "jsdoc-conf.json"
'cloudinary-core':
options:
destination: "doc/pkg-<%=grunt.task.current.target%>"
src: ["build/<%=grunt.task.current.target%>.js", './README.md']
'cloudinary-jquery':
options:
destination: "doc/pkg-<%=grunt.task.current.target%>"
src: ["build/<%=grunt.task.current.target%>.js", './README.md']
'cloudinary-jquery-file-upload':
options:
destination: "doc/pkg-<%=grunt.task.current.target%>"
src: ["build/<%=grunt.task.current.target%>.js", './README.md']
clean:
build: ["build/*", "!build/lodash*"]
doc: ["doc"]
js: ["js"]
copy:
'backward-compatible':
# For backward compatibility, copy jquery.cloudianry.js and vendor files to the js folder
options:
process: (content, srcpath) ->
if /build.cloudinary-jquery-file-upload\.js/.test(srcpath)
content.replace( /\/\/# sourceMappingURL=cloudinary-jquery-file-upload.js.map/g, "")
else
content
files: [
{
expand: true
flatten: true
src: [
"bower_components/blueimp-canvas-to-blob/js/canvas-to-blob.min.js"
"bower_components/blueimp-load-image/js/load-image.all.min.js" # formerly load-image.min.js
"bower_components/blueimp-file-upload/js/jquery.fileupload-image.js"
"bower_components/blueimp-file-upload/js/jquery.fileupload-process.js"
"bower_components/blueimp-file-upload/js/jquery.fileupload-validate.js"
"bower_components/blueimp-file-upload/js/jquery.fileupload.js"
"bower_components/blueimp-file-upload/js/jquery.iframe-transport.js"
"bower_components/blueimp-file-upload/js/vendor/jquery.ui.widget.js"
]
dest: "js/"
}
{
src: 'build/cloudinary-jquery-file-upload.js'
dest: 'js/jquery.cloudinary.js'
}
]
dist:
files: for repo in repos
dest = if /shrinkwrap/.test(repo) then "cloudinary-core" else repo
{'cwd': 'build','src': ["#{repo}.js", "#{repo}.min.js", "#{repo}.min.js.map"], 'dest': "../pkg/pkg-#{dest}/", 'expand': true}
# doc:
# files: for repo in repos when !/shrinkwrap/.test(repo)
# expand: true
# cwd: "doc/pkg-#{repo}/"
# src: ["**"]
# dest: "../pkg/pkg-#{repo}/"
version:
options:
release: 'patch'
package:
src: ['bower.json', 'package.json']
source:
options:
prefix: 'VERSION\\s+=\\s+[\'"]'
src: ['src/cloudinary.coffee']
dist:
files: for repo in repos when !/shrinkwrap/.test(repo)
src: ["../pkg/pkg-#{repo}/bower.json", "../pkg/pkg-#{repo}/package.json"]
dest: "../pkg/pkg-#{repo}/"
srcList: [
'src/utf8_encode.coffee',
'src/crc32.coffee',
'src/parameters.coffee',
'src/condition.coffee',
'src/transformation.coffee',
'src/configuration.coffee',
'src/tags/htmltag.coffee',
'src/tags/imagetag.coffee',
'src/tags/videotag.coffee',
'src/layer/layer.coffee',
'src/layer/Textlayer.coffee',
'src/layer/Subtitleslayer.coffee',
'src/cloudinary.coffee'
],
concat:
options:
dest: "build/<%= grunt.task.current.target %>.coffee"
banner:
"""
###*
* Cloudinary's JavaScript library - Version <%= pkg.version %>
* Copyright Cloudinary
* see https://github.com/cloudinary/cloudinary_js
*
###
((root, factory) ->
if (typeof define == 'function') && define.amd
define <%= /jquery/.test(grunt.task.current.target) ? "['jquery']," : (/shrink/.test(grunt.task.current.target) ? "" : "['lodash']," )%> factory
else if typeof exports == 'object'
module.exports = factory(<%= /jquery/.test(grunt.task.current.target) ? "require('jquery')" : (/shrink/.test(grunt.task.current.target) ? "" : "require('lodash')")%>)
else
root.cloudinary ||= {}
for name, value of factory(<%=/jquery/.test(grunt.task.current.target) ? "jQuery" : (/shrink/.test(grunt.task.current.target) ? "" : "_")%>)
root.cloudinary[name] = value
)(this, (<%=/jquery/.test(grunt.task.current.target) ? "jQuery" : (/shrink/.test(grunt.task.current.target) ? "" : "_")%>)->
"""
footer:
"""
cloudinary =
utf8_encode: utf8_encode
crc32: crc32
Util: Util
Condition: Condition
Transformation: Transformation
Configuration: Configuration
HtmlTag: HtmlTag
ImageTag: ImageTag
VideoTag: VideoTag
Layer: Layer
TextLayer: TextLayer
SubtitlesLayer: SubtitlesLayer
Cloudinary: Cloudinary
VERSION: "<%= pkg.version %>"
<%= /jquery/.test(grunt.task.current.target) ? "CloudinaryJQuery: CloudinaryJQuery" : ""%>
cloudinary
)
"""
process: (src, path)->
# add indentation to each source file
" " + src.replace( /\n/g, "\n ")
'cloudinary-core':
src: [
"src/util/lodash.coffee"
"<%= srcList%>"
]
dest: "build/cloudinary-core.coffee"
'cloudinary-core-shrinkwrap':
src: [
"build/lodash-shrinkwrap.coffee"
"src/util/lodash.coffee"
"<%= srcList%>"
]
dest: "build/cloudinary-core-shrinkwrap.coffee"
'cloudinary-jquery':
src: [
"src/util/jquery.coffee"
"<%= srcList%>"
"src/cloudinaryjquery.coffee"
]
dest: "build/cloudinary-jquery.coffee"
'cloudinary-jquery-file-upload':
src: [
"src/util/jquery.coffee"
"<%= srcList%>"
"src/cloudinaryjquery.coffee"
"src/jquery-file-upload.coffee"
]
dest: "build/cloudinary-jquery-file-upload.coffee"
grunt.initConfig(gruntOptions)
grunt.loadNpmTasks('grunt-contrib-concat')
grunt.loadNpmTasks('grunt-contrib-coffee')
grunt.loadNpmTasks('grunt-contrib-uglify')
grunt.loadNpmTasks('grunt-contrib-requirejs')
grunt.loadNpmTasks('grunt-contrib-copy')
grunt.loadNpmTasks('grunt-contrib-clean')
grunt.loadNpmTasks('grunt-jsdoc')
grunt.loadNpmTasks('grunt-karma')
grunt.loadNpmTasks('grunt-version')
grunt.registerTask('default', ['concat', 'coffee'])
grunt.registerTask('compile', ['clean:build', 'clean:js', 'concat', 'coffee', 'copy:backward-compatible'])
grunt.registerTask('build', ['clean', 'concat', 'coffee', 'copy:backward-compatible', 'jsdoc'])
grunt.registerTask('lodash', (name, target)->
lodashCalls = grunt.file.read('src/util/lodash.coffee').match(/_\.\w+/g)
include = []
# gather unique function names
include.push(func[2..]) for func in lodashCalls when include.indexOf(func[2..]) < 0
require('lodash-cli')([
"include=#{include.join(',')}",
"exports=none",
"iife=var lodash = _ = (function() {%output%; \nreturn lodash;\n}.call(this));",
"--output", "build/lodash-shrinkwrap.js",
"--development"]
, (data)->
outputPath = data.outputPath
sourceMap = data.sourceMap
if outputPath
grunt.file.write outputPath, data.source
grunt.file.write "#{outputPath[0..-4]}.coffee", "\n`#{data.source.replace(/`/g, "'")}`"
# .replace(/\n/g, "\n ")
if sourceMap
grunt.file.write path.join(path.dirname(outputPath), path.basename(outputPath, '.js') + '.map'), sourceMap
)
)