Commit a9c46aaf by Timmy Willison

Use a custom build task in grunt to build raphael in a way that creates a valid…

Use a custom build task in grunt to build raphael in a way that creates a valid anonymous module for AMD definition.

- Also pulls in the version from package.json to create the banner from copy.js (so the version can be set in one place)
- Conforms Gruntfile to most common tabs and spacing of other files
- grunt-cli should not be included in devDependencies (it is only ever installed globally)
parent 5a23713f
'use strict'; "use strict";
module.exports = function(grunt) { module.exports = function(grunt) {
// Project configuration. var pkg = grunt.file.readJSON("package.json");
grunt.initConfig({
// Metadata. // Project configuration.
pkg: grunt.file.readJSON('package.json'), grunt.initConfig({
banner: grunt.file.read('copy.js'), // Metadata.
// Task configuration. pkg: pkg,
concat: { banner: grunt.file.read("copy.js").replace(/@VERSION/, pkg.version),
options: { // Task configuration.
banner: '<%= banner %>', uglify: {
stripBanners: true options: {
}, banner: "<%= banner %>"
dist: { },
src: ['./eve/eve.js', 'raphael.core.js', 'raphael.svg.js', 'raphael.vml.js'], dist: {
dest: '<%= pkg.name %>.js' src: "<%= build.dist.dest %>",
}, dest: "<%= pkg.name %>-min.js"
}, }
uglify: { },
options: { build: {
banner: '<%= banner %>' options: {
}, banner: "<%= banner %>"
dist: { },
src: '<%= concat.dist.dest %>', dist: {
dest: '<%= pkg.name %>-min.js' dest: "raphael.js",
}, src: [
}, "./eve/eve.js",
}); "raphael.core.js",
"raphael.svg.js",
// These plugins provide necessary tasks. "raphael.vml.js"
grunt.loadNpmTasks('grunt-contrib-concat'); ]
grunt.loadNpmTasks('grunt-contrib-uglify'); }
}
});
// Default task.
grunt.registerTask('default', ['concat', 'uglify']);
// 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 = /(\n\s*\/\/\s*EXPOSE(?:\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"]);
}; };
...@@ -9,30 +9,18 @@ Visit the library website for more information: [http://raphaeljs.com](http://ra ...@@ -9,30 +9,18 @@ Visit the library website for more information: [http://raphaeljs.com](http://ra
(thank you [Wes Tood](https://github.com/wesleytodd)) (thank you [Wes Tood](https://github.com/wesleytodd))
## Dependencies ## Dependencies
* [grunt](https://github.com/gruntjs/grunt)
* [uglifyjs](https://github.com/mishoo/UglifyJS)
* [eve](https://github.com/adobe-webplatform/eve) * [eve](https://github.com/adobe-webplatform/eve)
* [grunt](https://github.com/gruntjs/grunt)
## Loading ## Loading
Raphael can be loaded in a script tag or with AMD: Raphael can be loaded in a script tag or with AMD:
```js ```js
define([ "raphael" ], function( Raphael ) { define([ "path/to/raphael" ], function( Raphael ) {
console.log( Raphael ); console.log( Raphael );
}); });
``` ```
To place raphael in a directory that is not your AMD's loader's base URL, adjust the path to raphael.
```js
// requirejs syntax
require.config({
paths: {
raphael: "libs/raphael"
}
});
```
## Development ## Development
At the moment we have 4 milestones: At the moment we have 4 milestones:
......
// ┌────────────────────────────────────────────────────────────────────┐ \\ // ┌────────────────────────────────────────────────────────────────────┐ \\
// │ Raphaël 2.1.0 - JavaScript Vector Library │ \\ // │ Raphaël @VERSION - JavaScript Vector Library │ \\
// ├────────────────────────────────────────────────────────────────────┤ \\ // ├────────────────────────────────────────────────────────────────────┤ \\
// │ Copyright © 2008-2012 Dmitry Baranovskiy (http://raphaeljs.com) │ \\ // │ Copyright © 2008-2012 Dmitry Baranovskiy (http://raphaeljs.com) │ \\
// │ Copyright © 2008-2012 Sencha Labs (http://sencha.com) │ \\ // │ Copyright © 2008-2012 Sencha Labs (http://sencha.com) │ \\
......
...@@ -15,9 +15,7 @@ ...@@ -15,9 +15,7 @@
"readmeFilename": "README.markdown", "readmeFilename": "README.markdown",
"gitHead": "52bff469f60988f1391e8b3d7cb5349163df8ba1", "gitHead": "52bff469f60988f1391e8b3d7cb5349163df8ba1",
"devDependencies": { "devDependencies": {
"grunt-cli": "~0.1.7",
"grunt": "~0.4.1", "grunt": "~0.4.1",
"grunt-contrib-uglify": "~0.2.0", "grunt-contrib-uglify": "~0.2.0"
"grunt-contrib-concat": "~0.3.0"
} }
} }
This source diff could not be displayed because it is too large. You can view the blob instead.
...@@ -8,16 +8,16 @@ ...@@ -8,16 +8,16 @@
(function (glob, factory) { (function (glob, factory) {
// AMD support // AMD support
if (typeof define === "function" && define.amd) { if (typeof define === "function" && define.amd) {
// Define as named module for the sake of raphael.svg.js and raphael.vml.js // Define as an anonymous module
// Adjust AMD paths if needed define(["eve"], function( eve ) {
// example: return factory(glob, eve);
// require.config({ paths: { raphael: "libs/raphael" } }); });
define("raphael", ["eve"], factory);
} else { } else {
// Browser globals (glob is window) // Browser globals (glob is window)
glob.Raphael = factory(glob.eve); // Raphael adds itself to window
factory(glob, glob.eve);
} }
}(this, function (eve) { }(this, function (window, eve) {
/*\ /*\
* Raphael * Raphael
[ method ] [ method ]
...@@ -5254,11 +5254,14 @@ ...@@ -5254,11 +5254,14 @@
isLoaded(); isLoaded();
})(document, "DOMContentLoaded"); })(document, "DOMContentLoaded");
oldRaphael.was ? (g.win.Raphael = R) : (Raphael = R);
eve.on("raphael.DOMload", function () { eve.on("raphael.DOMload", function () {
loaded = true; loaded = true;
}); });
// EXPOSE
// SVG and VML are appended just before the EXPOSE line
// Even with AMD, Raphael should be defined globally
oldRaphael.was ? (g.win.Raphael = R) : (Raphael = R);
return R; return R;
})); }));
...@@ -377,7 +377,6 @@ ...@@ -377,7 +377,6 @@
}; };
(typeof module != "undefined" && module.exports) ? (module.exports = eve) : (typeof define != "undefined" ? (define("eve", [], function() { return eve; })) : (glob.eve = eve)); (typeof module != "undefined" && module.exports) ? (module.exports = eve) : (typeof define != "undefined" ? (define("eve", [], function() { return eve; })) : (glob.eve = eve));
})(this); })(this);
// ┌─────────────────────────────────────────────────────────────────────┐ \\ // ┌─────────────────────────────────────────────────────────────────────┐ \\
// │ "Raphaël 2.1.0" - JavaScript Vector Library │ \\ // │ "Raphaël 2.1.0" - JavaScript Vector Library │ \\
// ├─────────────────────────────────────────────────────────────────────┤ \\ // ├─────────────────────────────────────────────────────────────────────┤ \\
...@@ -388,16 +387,16 @@ ...@@ -388,16 +387,16 @@
(function (glob, factory) { (function (glob, factory) {
// AMD support // AMD support
if (typeof define === "function" && define.amd) { if (typeof define === "function" && define.amd) {
// Define as named module for the sake of raphael.svg.js and raphael.vml.js // Define as an anonymous module
// Adjust AMD paths if needed define(["eve"], function( eve ) {
// example: return factory(glob, eve);
// require.config({ paths: { raphael: "libs/raphael" } }); });
define("raphael", ["eve"], factory);
} else { } else {
// Browser globals (glob is window) // Browser globals (glob is window)
glob.Raphael = factory(glob.eve); // Raphael adds itself to window
factory(glob, glob.eve);
} }
}(this, function (eve) { }(this, function (window, eve) {
/*\ /*\
* Raphael * Raphael
[ method ] [ method ]
...@@ -5634,15 +5633,10 @@ ...@@ -5634,15 +5633,10 @@
isLoaded(); isLoaded();
})(document, "DOMContentLoaded"); })(document, "DOMContentLoaded");
oldRaphael.was ? (g.win.Raphael = R) : (Raphael = R);
eve.on("raphael.DOMload", function () { eve.on("raphael.DOMload", function () {
loaded = true; loaded = true;
}); });
return R;
}));
// ┌─────────────────────────────────────────────────────────────────────┐ \\ // ┌─────────────────────────────────────────────────────────────────────┐ \\
// │ Raphaël - JavaScript Vector Library │ \\ // │ Raphaël - JavaScript Vector Library │ \\
// ├─────────────────────────────────────────────────────────────────────┤ \\ // ├─────────────────────────────────────────────────────────────────────┤ \\
...@@ -5652,16 +5646,8 @@ ...@@ -5652,16 +5646,8 @@
// │ Copyright (c) 2008-2011 Sencha Labs (http://sencha.com) │ \\ // │ Copyright (c) 2008-2011 Sencha Labs (http://sencha.com) │ \\
// │ Licensed under the MIT (http://raphaeljs.com/license.html) license. │ \\ // │ Licensed under the MIT (http://raphaeljs.com/license.html) license. │ \\
// └─────────────────────────────────────────────────────────────────────┘ \\ // └─────────────────────────────────────────────────────────────────────┘ \\
(function (glob, factory) {
// AMD support (function(){
if (typeof define === "function" && define.amd) {
// Require Raphael
require(["raphael"], factory);
} else if (glob.Raphael) {
// Browser globals (glob is window)
factory(glob.Raphael);
}
}(this, function (R) {
if (!R.svg) { if (!R.svg) {
return; return;
} }
...@@ -7014,7 +7000,7 @@ ...@@ -7014,7 +7000,7 @@
}; };
})(method); })(method);
} }
})); })();
// ┌─────────────────────────────────────────────────────────────────────┐ \\ // ┌─────────────────────────────────────────────────────────────────────┐ \\
// │ Raphaël - JavaScript Vector Library │ \\ // │ Raphaël - JavaScript Vector Library │ \\
...@@ -7025,16 +7011,8 @@ ...@@ -7025,16 +7011,8 @@
// │ Copyright (c) 2008-2011 Sencha Labs (http://sencha.com) │ \\ // │ Copyright (c) 2008-2011 Sencha Labs (http://sencha.com) │ \\
// │ Licensed under the MIT (http://raphaeljs.com/license.html) license. │ \\ // │ Licensed under the MIT (http://raphaeljs.com/license.html) license. │ \\
// └─────────────────────────────────────────────────────────────────────┘ \\ // └─────────────────────────────────────────────────────────────────────┘ \\
(function (glob, factory) {
// AMD support (function(){
if (typeof define === "function" && define.amd) {
// Require Raphael
require(["raphael"], factory);
} else if (glob.Raphael) {
// Browser globals (glob is window)
factory(glob.Raphael);
}
}(this, function (R) {
if (!R.vml) { if (!R.vml) {
return; return;
} }
...@@ -8000,4 +7978,12 @@ ...@@ -8000,4 +7978,12 @@
}; };
})(method); })(method);
} }
})();
// EXPOSE
// SVG and VML are appended just before the EXPOSE line
// Even with AMD, Raphael should be defined globally
oldRaphael.was ? (g.win.Raphael = R) : (Raphael = R);
return R;
})); }));
...@@ -7,19 +7,8 @@ ...@@ -7,19 +7,8 @@
// │ Copyright (c) 2008-2011 Sencha Labs (http://sencha.com) │ \\ // │ Copyright (c) 2008-2011 Sencha Labs (http://sencha.com) │ \\
// │ Licensed under the MIT (http://raphaeljs.com/license.html) license. │ \\ // │ Licensed under the MIT (http://raphaeljs.com/license.html) license. │ \\
// └─────────────────────────────────────────────────────────────────────┘ \\ // └─────────────────────────────────────────────────────────────────────┘ \\
(function (glob, factory) {
// AMD support window.Raphael && window.Raphael.svg && function(R) {
if (typeof define === "function" && define.amd) {
// Require Raphael
require(["raphael"], factory);
} else if (glob.Raphael) {
// Browser globals (glob is window)
factory(glob.Raphael);
}
}(this, function (R) {
if (!R.svg) {
return;
}
var has = "hasOwnProperty", var has = "hasOwnProperty",
Str = String, Str = String,
toFloat = parseFloat, toFloat = parseFloat,
...@@ -1369,4 +1358,4 @@ ...@@ -1369,4 +1358,4 @@
}; };
})(method); })(method);
} }
})); }(window.Raphael);
...@@ -7,19 +7,8 @@ ...@@ -7,19 +7,8 @@
// │ Copyright (c) 2008-2011 Sencha Labs (http://sencha.com) │ \\ // │ Copyright (c) 2008-2011 Sencha Labs (http://sencha.com) │ \\
// │ Licensed under the MIT (http://raphaeljs.com/license.html) license. │ \\ // │ Licensed under the MIT (http://raphaeljs.com/license.html) license. │ \\
// └─────────────────────────────────────────────────────────────────────┘ \\ // └─────────────────────────────────────────────────────────────────────┘ \\
(function (glob, factory) {
// AMD support window.Raphael && window.Raphael.vml && function(R) {
if (typeof define === "function" && define.amd) {
// Require Raphael
require(["raphael"], factory);
} else if (glob.Raphael) {
// Browser globals (glob is window)
factory(glob.Raphael);
}
}(this, function (R) {
if (!R.vml) {
return;
}
var has = "hasOwnProperty", var has = "hasOwnProperty",
Str = String, Str = String,
toFloat = parseFloat, toFloat = parseFloat,
...@@ -982,4 +971,4 @@ ...@@ -982,4 +971,4 @@
}; };
})(method); })(method);
} }
})); }(window.Raphael);
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment