forked from jsplumb/jsplumb
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Gruntfile.js
378 lines (340 loc) · 14.1 KB
/
Gruntfile.js
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
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
/**
By default, jsPlumb's build incudes all of the connector types, endpoint types and render modes. But
you can specify which of these you want via command line flags, eg:
grunt --connectors=flowchart,bezier --renderers=svg,vml
Connectors
----------
flowchart
statemachine
bezier
straight
Endpoints
---------
dot
rectangle
image
Renderers
---------
canvas
svg
vml
*/
// http://flippinawesome.org/2013/07/01/building-a-javascript-library-with-grunt-js/?utm_source=javascriptweekly&utm_medium=email
// also to checkout:
// https://github.com/ModelN/grunt-blanket-qunit
var JS_BEZIER = "0.6", // current js bezier version
JS_PLUMB_GEOM = "0.1",
getJsBezier = function() { return "lib/jsBezier-" + JS_BEZIER + ".js"; },
getJsPlumbGeom = function() { return "lib/jsplumb-geom-" + JS_PLUMB_GEOM + ".js"; },
libraries = [ "jquery", "mootools", "yui" ],
runtimeLibraries = {
jquery:"<script type='text/javascript' src='http://ajax.googleapis.com/ajax/libs/jquery/1.9.0/jquery.min.js'></script><script type='text/javascript' src='http://ajax.googleapis.com/ajax/libs/jqueryui/1.9.2/jquery-ui.min.js'></script><script type='text/javascript' src='../../lib/jquery.ui.touch-punch.min.js'></script>",
mootools:"<script type='text/javascript' src='http://ajax.googleapis.com/ajax/libs/mootools/1.3.2/mootools-yui-compressed.js'></script>",
yui:""
},
version = "1.5.0",
objects = {
connectors : [
"flowchart", "statemachine", "bezier", "straight"
],
renderers : [
"canvas", "svg", "vml"
],
common:[
'util.js', 'dom-adapter.js', 'jsPlumb.js', 'endpoint.js', 'connection.js', 'anchors.js', 'defaults.js'
]
},
optionList = function(grunt, type) {
return grunt.option(type) && grunt.option(type).split(",") || [];
},
getOutputFilename = function(grunt, lib, suffix) {
var suffix2 = grunt.option('outputSuffix') ? ('-' + grunt.option("outputSuffix")) : '';
return 'dist/js/' + lib + '.jsPlumb' + suffix2 + '-<%= pkg.version%>' + suffix + '.js';
},
filter = function(l, v, t, o) {
if (l.length === 0 || l.indexOf(v) != -1)
o.push("src/" + t + "-" + v + ".js");
},
getList = function(grunt, type) {
var ol = optionList(grunt, type), l = objects[type], out = [];
for (var i = 0; i < l.length; i++)
filter(ol, l[i], type, out);
return out;
},
getSources = function(grunt, lib) {
var sources = [ getJsBezier(), getJsPlumbGeom() ];
sources.push.apply(sources, objects.common.map(function(v) { return "src/" + v; }));
sources.push.apply(sources, getList(grunt, "connectors"));
sources.push.apply(sources, getList(grunt, "renderers"));
sources.push("src/" + lib + ".jsPlumb.js");
return sources;
},
help = "\nBuilding jsPlumb\n" +
"-----------------\n" +
"To build jsPlumb, execute the 'build' task:\n\n" +
"--> grunt build\n\n" +
"this will, by default, build a version of jsPlumb with all the available connectors and renderers (SVG, Canvas and VML).\n\n" +
"You can build a custom version of jsPlumb by specifying a list of connectors and/or renderers on the command line, for example:\n\n" +
"--> grunt build --connectors=flowchart,statemachine --renderers=svg,vml\n\n";
module.exports = function(grunt) {
grunt.registerTask('help', 'Help with the jsPlumb build', function(arg1, arg2) {
grunt.log.write(help);
});
grunt.registerTask('info', 'dumps info about what will be built', function(arg1, arg2) {
grunt.log.write('Build jsPlumb');
});
grunt.registerTask('prepare', function() {
grunt.file.delete("dist");
});
var fileLists = function(suffix) {
suffix = suffix || "";
var o = {};
libraries.forEach(function(l) {
o[l] = {
src:getSources(grunt, l),
dest:getOutputFilename(grunt, l, suffix)
};
});
return o;
};
var makeReplacements = function() {
var o = {};
// expand out lists of individual imports into concatenated versions for dist.
// also replace link to docs
libraries.forEach(function(l) {
o[l] = {
src: ['dist/demo/*/' + l + '.html', 'dist/tests/*.html', 'dist/demo/demo-all*.html' ],
actions: [
{
name:"dep",
search:"(<!-- DEP.*>.*\n)(.*\n)*(.*/DEP -->)",
replace: runtimeLibraries[l],
flags: 'gm'
},
{
name:"js",
search:"(<!-- JS.*>.*\n)(.*\n)*(.*/JS -->)",
replace:"<script type='text/javascript' src='../js/" + l + ".jsPlumb-<%= pkg.version%>-min.js'></script>",
flags:'gm'
},
{
search:"<a href=\"http://localhost:4567\">",
replace:"<a href=\"../../doc/\">",
flags:"gm"
}
]
};
});
// change media wiki style links into standard markdown links
// [[Changes since version 1.4.0|changelog]] -> [Changes since version 1.4.0](changelog)
o["doc"] = {
src:['jsPlumb.wiki/*.md'],
actions:[
{
name:"links",
search:"\\[\\[(.*)\\|(.*)\\]\\]",
replace:"[$1]($2)",
flags:"gm"
}
]
};
return o;
};
//
// this is a helper for the copy task, because the copy task is strange about the way it copies
// things. basically the only way to get a file from some folder into another is to use a 'rename'
// function! wtf. anyway this is a helper for that.
var moveFolder = function(toDir) {
return function() {
var idx = arguments[1].lastIndexOf("/"), _idx = idx < 0 ? 0 : idx;
return toDir + "/" + arguments[1].substring(_idx);
};
};
// Project configuration.
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
concat: fileLists(),
uglify: fileLists("-min"),
qunit:{
target: {
src: ['tests/qunit-svg-jquery*.html'/*, 'tests/qunit-canvas-jquery*.html'*/ ]
}
},
copy:{
demos:{
files:[
{ expand:true, src:"demo/**/*", dest:"dist" },
{ expand:true, cwd:"dist/js/", src:"*.js", dest:"dist/demo/js/"},
{
expand:true,
cwd:"dist/js/",
src:"jquery.jsPlumb-<%=pkg.version%>.js",
//dest:"dist/demo/requirejs/scripts/",
rename:function() {
return "dist/demo/requirejs/scripts/jsplumb.js";
}
},
{
expand:true,
cwd:"lib",
src:["mootools-1.3.2.1-more.js", "jquery-1.9.0.js", "jquery-ui-1.9.2-min.js", "jquery.ui.touch-punch.min.js"],
dest:"dist/lib/"
}
]
},
tests:{
files:[
{
expand:true,
src:[ "tests/jsPlumb-tests.js", "tests/qunit-*.*", "tests/all-tests.html", "tests/loadTestHarness.js", "tests/loadTestHarness.html" ],
dest:"dist/"
}
]
},
doc:{
files:[
{
expand:true,
src:[ "doc/gollum-template.css", "demo/demo-all.css", "demo/*.ttf", "demo/*.woff", "demo/logo_bw_44h.jpg" ],
rename:moveFolder("dist/doc")
}
]
},
// copy markdown to temp dir for pre-processing
temp:{
files:[
{
expand:true,
src:"../jsPlumb.wiki/*.md",
dest:"TEMPOUT/"
}
]
},
logo:{
files:[
{
expand:false,
src:"./logo-bw.png",
dest:"dist/logo-bw.png"
}
]
}
},
"regex-replace": makeReplacements(),
markdown: {
all: {
files: [{
expand: true,
flatten:true,
src: 'jsPlumb.wiki/*.md',
dest: 'dist/doc/',
ext: '.html'
}],
options:{
template:'./doc/doc-template.html'
}
}
},
clean:{
temp:"jsPlumb.wiki"
},
//http://www.kajabity.com/2012/02/how-i-introduced-jsdoc-into-a-javascript-project-and-found-my-eclipse-outline/
jsdoc : {
dist : {
src:['doc/api/README.md', 'doc/api/util-api.js', 'doc/api/jsplumb-api.js', 'doc/api/uicomponent.js', 'doc/api/overlaycomponent.js', 'doc/api/endpoint-api.js', 'doc/api/connection-api.js', 'doc/api/connectors.js', 'doc/api/overlays-api.js'],
options: {
destination: 'dist/apidocs/',
configure:'jsdoc.json',
"private":false
}
}
},
jshint: {
options: {
eqnull: true,
loopfunc:true,
'-W099': true,
'-W018':true,
'-W038':true
},
files:{
src: ['src/anchors.js', 'src/util.js', 'src/connection.js', 'src/connectors-bezier.js', 'src/connectors-flowchart.js', 'src/connectors-statemachine.js', 'src/defaults.js', 'src/dom-adapter.js', 'src/endpoint.js', 'src/jquery.jsPlumb.js', 'src/mootools.jsPlumb.js', 'src/renderers-canvas.js', 'src/renderers-svg.js', 'src/renderers-vml.js', 'src/yui.jsPlumb.js', 'src/jsPlumb.js']
}
},
watch: {
scripts: {
files: ['src/*.js'],
tasks: ['build-src']
}
}
});
// Load the plugin that provides the "docular" tasks.
grunt.loadNpmTasks('grunt-contrib-concat');
grunt.loadNpmTasks('grunt-contrib-uglify');
grunt.loadNpmTasks('grunt-contrib-qunit');
grunt.loadNpmTasks('grunt-contrib-copy');
grunt.loadNpmTasks('grunt-regex-replace');
grunt.loadNpmTasks('grunt-markdown');
grunt.loadNpmTasks('grunt-contrib-clean');
grunt.loadNpmTasks('grunt-jsdoc');
grunt.loadNpmTasks('grunt-contrib-jshint');
grunt.loadNpmTasks('grunt-contrib-watch');
grunt.registerTask('writeIndex', function() {
// write an index file to the root of the dist dir (redirects to main jquery demo)
grunt.file.write("dist/index.html", "<!doctype html><html><head><meta http-equiv='refresh' content='0;url=demo/home/jquery.html'/></head></html>");
// write an index file to the root of the docs dir (redirects to 'home')
grunt.file.write("dist/doc/index.html", "<!doctype html><html><head><meta http-equiv='refresh' content='0;url=home'/></head></html>");
});
var _replace = function(cwd, pattern, oldV, newV, exclusions) {
exclusions = exclusions || [];
var _one = function(f) {
if (exclusions.indexOf(f) == -1) {
if (!grunt.file.isDir(cwd + "/" + f)) {
var c = grunt.file.read(cwd + "/" + f);
grunt.file.write(cwd + "/" + f, c.replace(oldV, newV));
}
}
};
var sources = grunt.file.expand({ cwd:cwd }, pattern);
for (var i = 0; i < sources.length; i++)
_one(sources[i]);
};
grunt.registerTask('update', function() {
var newV = grunt.option("newver");
if (newV ===null) {
grunt.log.error("You must provide the new version: grunt update --newver=X.X.X");
}
else {
var oldV = new RegExp(grunt.config("pkg").version, "g");
// now update version number in all demos and src files
_replace("src", "*.js", oldV, newV);
_replace("demo", "**/*.html", oldV, newV);
_replace(".", "bower.json", oldV, newV);
_replace(".", "package.json", oldV, newV);
_replace(".", "README.md", oldV, newV);
}
});
// reads the contents of home.html (the docs index), and writes it into all of the other files.
grunt.registerTask("docIndex", function() {
var f = grunt.file.read("dist/doc/contents.html"),
re = /(<!-- BODY.*>.*\n)(.*\n)*(.*\/BODY -->)/,
idx = f.match(re);
_replace("dist/doc", "*.html", /<\!-- NAV -->/, idx[0], ["contents.html"]);
});
/*
<target name="upgrade-jsbezier" depends="old,new">
<!-- replace refs to old version in demo html to new version -->
<replace dir="demo/jquery" token="jsBezier-${old}.js" value="jsBezier-${new}.js"/>
<replace dir="demo/yui3" token="jsBezier-${old}.js" value="jsBezier-${new}.js"/>
<replace dir="demo/mootools" token="jsBezier-${old}.js" value="jsBezier-${new}.js"/>
</target>
// also add one for jsplumb-geom
*/
grunt.registerTask('build-src', ['prepare', 'concat', 'uglify' ]);
grunt.registerTask('build', [/*'qunit', */'build-src', 'copy:temp', 'copy:demos', 'copy:tests', 'copy:doc', 'copy:logo', 'regex-replace', 'markdown', 'docIndex', 'jsdoc', 'info', 'clean', 'writeIndex']);
grunt.registerTask('default', ['help']);
grunt.registerTask('build-all', ['qunit', 'build']);
/* grunt.registerTask("build-all", function() {
grunt.task.run("build")
})*/
};