Merge pull request #724 from timmywil/grunt_modules
Build Raphael as a compatible anonymous module for AMD using Grunt
This commit is contained in:
commit
490ea360b9
|
|
@ -0,0 +1,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 = /(\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,29 +9,18 @@ Visit the library website for more information: [http://raphaeljs.com](http://ra
|
|||
(thank you [Wes Tood](https://github.com/wesleytodd))
|
||||
|
||||
## Dependencies
|
||||
* [uglifyjs](https://github.com/mishoo/UglifyJS)
|
||||
* [eve](https://github.com/adobe-webplatform/eve)
|
||||
* [grunt](https://github.com/gruntjs/grunt)
|
||||
|
||||
## Loading
|
||||
Raphael can be loaded in a script tag or with AMD:
|
||||
|
||||
```js
|
||||
define([ "raphael" ], function( Raphael ) {
|
||||
define([ "path/to/raphael" ], function( 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
|
||||
|
||||
At the moment we have 4 milestones:
|
||||
|
|
@ -52,7 +41,7 @@ We are organizing the current issues between this milestones, setting the ground
|
|||
|
||||
All changes in code must go to `raphael.core`, `raphael.svg` or `raphael.vml`. `raphael.js` is a generated file.
|
||||
|
||||
After adding your changes, execute `./make`, the minified version will be created, commit and you are ready to make a pull request!
|
||||
After adding your changes, execute `grunt`, the minified version will be created, commit and you are ready to make a pull request!
|
||||
|
||||
## Found an issue?
|
||||
|
||||
|
|
|
|||
4
copy.js
4
copy.js
|
|
@ -1,8 +1,8 @@
|
|||
// ┌────────────────────────────────────────────────────────────────────┐ \\
|
||||
// │ 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 Sencha Labs (http://sencha.com) │ \\
|
||||
// ├────────────────────────────────────────────────────────────────────┤ \\
|
||||
// │ Licensed under the MIT (http://raphaeljs.com/license.html) license.│ \\
|
||||
// └────────────────────────────────────────────────────────────────────┘ \\
|
||||
// └────────────────────────────────────────────────────────────────────┘ \\
|
||||
|
|
|
|||
44
make
44
make
|
|
@ -1,44 +0,0 @@
|
|||
#!/usr/bin/env node
|
||||
var ujs = require('uglify-js'),
|
||||
fs = require('fs'),
|
||||
input = {
|
||||
core : 'raphael.core.js',
|
||||
svg : 'raphael.svg.js',
|
||||
vml : 'raphael.vml.js',
|
||||
eve : './eve/eve.js',
|
||||
copy : 'copy.js'
|
||||
},
|
||||
output = {
|
||||
'raphael-min.js' : ['eve', 'core', 'svg', 'vml'],
|
||||
'raphael.js' : ['eve', 'core', 'svg', 'vml']
|
||||
};
|
||||
|
||||
for (var file in input) {
|
||||
input[file] = fs.readFileSync(input[file], 'utf8');
|
||||
}
|
||||
for (file in output) {
|
||||
var out = '';
|
||||
if (file.indexOf('min') !== -1) {
|
||||
console.log('Compressing ' + file);
|
||||
for (var i = 0, l = output[file].length; i < l; i++) {
|
||||
var o = ujs.minify(input[output[file][i]], {
|
||||
fromString : true
|
||||
});
|
||||
out += o.code;
|
||||
}
|
||||
} else {
|
||||
console.log('Concatinating ' + file);
|
||||
for (i = 0, l = output[file].length; i < l; i++) {
|
||||
out += input[output[file][i]] + '\n';
|
||||
}
|
||||
}
|
||||
(function(f, code){
|
||||
fs.writeFile(f, input.copy + '\n' + code, function(err) {
|
||||
if (err) {
|
||||
console.log(err);
|
||||
} else {
|
||||
console.log('Saved to \033[32m' + f + '\033[0m\n');
|
||||
}
|
||||
});
|
||||
})(file, out);
|
||||
}
|
||||
|
|
@ -15,6 +15,7 @@
|
|||
"readmeFilename": "README.markdown",
|
||||
"gitHead": "52bff469f60988f1391e8b3d7cb5349163df8ba1",
|
||||
"devDependencies": {
|
||||
"uglify-js": "~2.2.3"
|
||||
"grunt": "~0.4.1",
|
||||
"grunt-contrib-uglify": "~0.2.0"
|
||||
}
|
||||
}
|
||||
|
|
|
|||
File diff suppressed because one or more lines are too long
|
|
@ -8,16 +8,16 @@
|
|||
(function (glob, factory) {
|
||||
// AMD support
|
||||
if (typeof define === "function" && define.amd) {
|
||||
// Define as named module for the sake of raphael.svg.js and raphael.vml.js
|
||||
// Adjust AMD paths if needed
|
||||
// example:
|
||||
// require.config({ paths: { raphael: "libs/raphael" } });
|
||||
define("raphael", ["eve"], factory);
|
||||
// Define as an anonymous module
|
||||
define(["eve"], function( eve ) {
|
||||
return factory(glob, eve);
|
||||
});
|
||||
} else {
|
||||
// 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
|
||||
[ method ]
|
||||
|
|
@ -5254,11 +5254,14 @@
|
|||
isLoaded();
|
||||
})(document, "DOMContentLoaded");
|
||||
|
||||
oldRaphael.was ? (g.win.Raphael = R) : (Raphael = R);
|
||||
|
||||
eve.on("raphael.DOMload", function () {
|
||||
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;
|
||||
}));
|
||||
|
|
|
|||
54
raphael.js
54
raphael.js
|
|
@ -377,7 +377,6 @@
|
|||
};
|
||||
(typeof module != "undefined" && module.exports) ? (module.exports = eve) : (typeof define != "undefined" ? (define("eve", [], function() { return eve; })) : (glob.eve = eve));
|
||||
})(this);
|
||||
|
||||
// ┌─────────────────────────────────────────────────────────────────────┐ \\
|
||||
// │ "Raphaël 2.1.0" - JavaScript Vector Library │ \\
|
||||
// ├─────────────────────────────────────────────────────────────────────┤ \\
|
||||
|
|
@ -388,16 +387,16 @@
|
|||
(function (glob, factory) {
|
||||
// AMD support
|
||||
if (typeof define === "function" && define.amd) {
|
||||
// Define as named module for the sake of raphael.svg.js and raphael.vml.js
|
||||
// Adjust AMD paths if needed
|
||||
// example:
|
||||
// require.config({ paths: { raphael: "libs/raphael" } });
|
||||
define("raphael", ["eve"], factory);
|
||||
// Define as an anonymous module
|
||||
define(["eve"], function( eve ) {
|
||||
return factory(glob, eve);
|
||||
});
|
||||
} else {
|
||||
// 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
|
||||
[ method ]
|
||||
|
|
@ -5634,15 +5633,10 @@
|
|||
isLoaded();
|
||||
})(document, "DOMContentLoaded");
|
||||
|
||||
oldRaphael.was ? (g.win.Raphael = R) : (Raphael = R);
|
||||
|
||||
eve.on("raphael.DOMload", function () {
|
||||
loaded = true;
|
||||
});
|
||||
|
||||
return R;
|
||||
}));
|
||||
|
||||
// ┌─────────────────────────────────────────────────────────────────────┐ \\
|
||||
// │ Raphaël - JavaScript Vector Library │ \\
|
||||
// ├─────────────────────────────────────────────────────────────────────┤ \\
|
||||
|
|
@ -5652,16 +5646,8 @@
|
|||
// │ Copyright (c) 2008-2011 Sencha Labs (http://sencha.com) │ \\
|
||||
// │ Licensed under the MIT (http://raphaeljs.com/license.html) license. │ \\
|
||||
// └─────────────────────────────────────────────────────────────────────┘ \\
|
||||
(function (glob, factory) {
|
||||
// AMD support
|
||||
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) {
|
||||
|
||||
(function(){
|
||||
if (!R.svg) {
|
||||
return;
|
||||
}
|
||||
|
|
@ -7014,7 +7000,7 @@
|
|||
};
|
||||
})(method);
|
||||
}
|
||||
}));
|
||||
})();
|
||||
|
||||
// ┌─────────────────────────────────────────────────────────────────────┐ \\
|
||||
// │ Raphaël - JavaScript Vector Library │ \\
|
||||
|
|
@ -7025,16 +7011,8 @@
|
|||
// │ Copyright (c) 2008-2011 Sencha Labs (http://sencha.com) │ \\
|
||||
// │ Licensed under the MIT (http://raphaeljs.com/license.html) license. │ \\
|
||||
// └─────────────────────────────────────────────────────────────────────┘ \\
|
||||
(function (glob, factory) {
|
||||
// AMD support
|
||||
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) {
|
||||
|
||||
(function(){
|
||||
if (!R.vml) {
|
||||
return;
|
||||
}
|
||||
|
|
@ -8000,4 +7978,12 @@
|
|||
};
|
||||
})(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 @@
|
|||
// │ Copyright (c) 2008-2011 Sencha Labs (http://sencha.com) │ \\
|
||||
// │ Licensed under the MIT (http://raphaeljs.com/license.html) license. │ \\
|
||||
// └─────────────────────────────────────────────────────────────────────┘ \\
|
||||
(function (glob, factory) {
|
||||
// AMD support
|
||||
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;
|
||||
}
|
||||
|
||||
window.Raphael && window.Raphael.svg && function(R) {
|
||||
var has = "hasOwnProperty",
|
||||
Str = String,
|
||||
toFloat = parseFloat,
|
||||
|
|
@ -1369,4 +1358,4 @@
|
|||
};
|
||||
})(method);
|
||||
}
|
||||
}));
|
||||
}(window.Raphael);
|
||||
|
|
|
|||
|
|
@ -7,19 +7,8 @@
|
|||
// │ Copyright (c) 2008-2011 Sencha Labs (http://sencha.com) │ \\
|
||||
// │ Licensed under the MIT (http://raphaeljs.com/license.html) license. │ \\
|
||||
// └─────────────────────────────────────────────────────────────────────┘ \\
|
||||
(function (glob, factory) {
|
||||
// AMD support
|
||||
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;
|
||||
}
|
||||
|
||||
window.Raphael && window.Raphael.vml && function(R) {
|
||||
var has = "hasOwnProperty",
|
||||
Str = String,
|
||||
toFloat = parseFloat,
|
||||
|
|
@ -982,4 +971,4 @@
|
|||
};
|
||||
})(method);
|
||||
}
|
||||
}));
|
||||
}(window.Raphael);
|
||||
|
|
|
|||
Loading…
Reference in New Issue