-
Notifications
You must be signed in to change notification settings - Fork 33
/
Gruntfile.js
128 lines (114 loc) · 4.71 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
"use strict";
module.exports = function(grunt) {
var pkg = grunt.file.readJSON('package.json');
// Project configuration.
grunt.initConfig({
// Metadata.
pkg: pkg,
banner: grunt.file.read("source/copy.js").replace(/@VERSION/, pkg.version).replace(/@RVERSION/, pkg.rversion),
// Task configuration.
uglify: {
options: {
banner: "<%= banner %>"
},
dist: {
src: "<%= build.dist.dest %>",
dest: "package/<%= pkg.filename %>-min.js"
}
},
build: {
options: {
banner: "<%= banner %>"
},
dist: {
dest: "package/raphael.js",
fusioncharts: "package/raphael-fusioncharts.js",
fusionchartsWrapper: "source/fusioncharts-wrapper-template.js",
src: [
"source/eve/eve.js",
"source/raphael.core.js",
"source/raphael.svg.js",
"source/raphael.vml.js",
"source/raphael.canvas.js"
]
}
},
jasmine: {
pivotal: {
src: 'package/raphael.js',
options: {
specs: 'tests/unit/*-spec.js',
helpers: 'tests/unit/*-helper.js'
}
}
}
});
// These plugins provide necessary tasks.
grunt.loadNpmTasks("grunt-contrib-uglify");
grunt.loadNpmTasks("grunt-contrib-jasmine");
// Special concat/build task to handle RedRaphael's build requirements
grunt.registerMultiTask(
"build",
"Concatenate source, remove individual closures, embed version",
function() {
var data = this.data,
name = data.dest,
fcName = data.fusioncharts,
fcSrcName = data.fusionchartsWrapper,
src = data.src,
options = this.options({
banner: ""
}),
// Start with banner
compiled = options.banner,
compiledFc = options.banner,
svgorvmlRegex = /\.(svg|vml|canvas)\.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.replace(exposeRegex, function () {
// Using this method instead of the raphael way as it makes it difficult to
// to have the string '$1' in the target file like raphael.svg.js.
var text = arguments[3],
index = arguments[2];
compiled = (text.slice(0, index) + source + text.slice(index));
});
// Excluding canvas.js in raphael-fusioncharts.js
if (!/canvas\.js/.test(path)) {
// Add source before EXPOSE line
compiledFc.replace(exposeRegex, function () {
// Using this method instead of the raphael way as it makes it difficult to
// to have the string '$1' in the target file like raphael.svg.js.
var text = arguments[3],
index = arguments[2];
compiledFc = (text.slice(0, index) + source + text.slice(index));
});
}
} else {
compiled += source;
compiledFc += source;
}
});
grunt.file.write( name, compiled );
grunt.file.write(fcName, grunt.file.read(fcSrcName).replace(/@REDRAPHAEL_CODE/, compiledFc));
}
);
// Default task.
grunt.registerTask("default", ["build", "uglify", "jasmine"]);
};