forked from DmitryBaranovskiy/raphael
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGruntfile.js
91 lines (79 loc) · 2.8 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
"use strict";
module.exports = function(grunt) {
var pkg = grunt.file.readJSON("package.json");
// Project configuration.
grunt.initConfig({
// Metadata.
pkg: pkg,
banner: grunt.file.read("copy.js").replace(/@VERSION/, pkg.version),
// Task configuration.
uglify: {
options: {
banner: "<%= banner %>"
},
dist: {
src: "<%= build.dist.dest %>",
dest: "<%= pkg.name %>-min.js"
}
},
build: {
options: {
banner: "<%= banner %>"
},
dist: {
dest: "raphael.js",
src: [
"./eve/eve.js",
"raphael.core.js",
"raphael.svg.js",
"raphael.vml.js"
]
}
}
});
// These plugins provide necessary tasks.
grunt.loadNpmTasks("grunt-contrib-uglify");
// Special concat/build task to handle Raphael's build requirements
grunt.registerMultiTask(
"build",
"Concatenate source, remove individual closures, embed version",
function() {
var data = this.data,
name = data.dest,
src = data.src,
options = this.options({
banner: ""
}),
// Start with banner
compiled = options.banner,
svgorvmlRegex = /\.(svg|vml)\.js/,
closureRegex = /window\.Raphael.*\(R\)\s*\{/,
closureEndRegex = /\}\(window\.Raphael\);\s*$/,
exposeRegex = /(\r?\n\s*\/\/\s*EXPOSE(?:\r|\n|.)*\}\)\);)/;
// Concatenate src
src.forEach(function(path) {
var source = grunt.file.read(path);
var match = svgorvmlRegex.exec(path);
// If either SVG or VML,
// remove the closure and add an early return if not required
if (match) {
source = "\n\n" +
source.replace(closureRegex,
"(function(){\n" +
" if (!R." + match[1] + ") {\n" +
" return;\n" +
" }"
)
.replace( closureEndRegex, "})();" );
// Add source before EXPOSE line
compiled = compiled.replace(exposeRegex, source + "$1");
} else {
compiled += source;
}
});
grunt.file.write( name, compiled );
grunt.log.ok("Built file " + name);
});
// Default task.
grunt.registerTask("default", ["build", "uglify"]);
};