Permalink
Browse files

Brought back the make file with a fake implementation of AMD to make …

…it work.
  • Loading branch information...
1 parent 1894679 commit 9a6125bb518bc6c76e45430cd6b46186ec9cd2d4 Patrick McElhaney committed Mar 21, 2012
Showing with 78 additions and 19 deletions.
  1. +22 −0 fakedefine.js
  2. +0 −18 how-to-build.txt
  3. +56 −1 make
View
@@ -0,0 +1,22 @@
+/* This is a fake, local version of AMD's define function. It makes files
+built with the make script work without requiring a full AMD loader. If
+you're using an AMD loader in your project, don't require the built files
+(raphel.js and raphel.min.js). Use raphael.amd.js instead. */
+
+/*global Raphael*/
+
+var glob = (function () { return this; }());
+
+var define = function (name, deps, factory) {
+ if (name === 'eve') {
+ glob.eve = factory();
+ return glob.eve;
+ }
+
+ if (name === 'raphael.core') {
+ return factory(glob.eve);
+ }
+
+ return factory(Raphael);
+
+};
View
@@ -1,18 +0,0 @@
-Make has been replaced with r.js. To build the project, you'll need:
-
-- r.js (npm install requirejs)
-- almond.js (copy it from https://github.com/jrburke/almond to the root directory)
-- eve.js (copy it from https://github.com/DmitryBaranovskiy/eve to the root directory)
-
-Then run:
-
- r.js -o r.build.js
-
-This will compile everything to raphael.js, and it should work the same as before. There's
-no need to use RequireJS or another AMD loader to load Raphael.
-
-However, if you want to use AMD:
-
-1. Use the module defined in raphael.amd.js instead of raphael.js.
-2. You'll need to have eve.js in the root of your project (or somewhere else, with a path mapping for 'eve').
-
View
57 make 100644 → 100755
@@ -1,2 +1,57 @@
-Make has been replaced with r.js. See how-to-build.txt.
+#!/usr/bin/env node
+/*
+To use this script, must have:
+- uglify.js (npm install uglify)
+- eve/eve.js (get it from https://github.com/DmitryBaranovskiy/eve)
+*/
+
+
+var setup = {
+ input: {
+ core: "raphael.core.js",
+ svg: "raphael.svg.js",
+ vml: "raphael.vml.js",
+ eve: "eve/eve.js",
+ copy: "copy.js",
+ fakeDefine: "fakedefine.js"
+ },
+ output: {
+ "raphael-min.js": function () {
+ return this.copy + "\n" + minify(this.fakeDefine + "\n\n" + this.eve + this.core + this.svg + this.vml);
+ },
+ "raphael.js": function () {
+ return this.copy + "\n" + this.fakeDefine + "\n\n" + this.eve + "\n\n" + this.core + "\n\n" + this.svg + "\n\n" + this.vml;
+ },
+ "raphael.pro-min.js": function () {
+ return this.copy + "\n" + minify(this.fakeDefine + "\n\n" + this.eve + this.core + this.svg);
+ },
+ "raphael.pro.js": function () {
+ return this.copy + "\n" + this.fakeDefine + "\n\n" + this.eve + "\n\n" + this.core + "\n\n" + this.svg ;
+ }
+ }
+ },
+ ujs = require("uglify-js"),
+ jsp = ujs.parser,
+ pro = ujs.uglify,
+ fs = require("fs"),
+ rxdr = /\/\*\\[\s\S]+?\\\*\//g;
+
+function minify(code) {
+ return pro.gen_code(pro.ast_squeeze(pro.ast_mangle(jsp.parse(code))));
+}
+
+var files = {};
+for (var file in setup.input) {
+
+ files[file] = String(fs.readFileSync(setup.input[file], "utf8")).replace(rxdr, "").replace(/^define\(/m, "define('" + setup.input[file].replace('.js', '') + "', ");
+}
+for (file in setup.output) {
+ var before = "(function () {\n\n";
+ var after = "\n\n}());";
+ (function (file) {
+ fs.writeFile(file, before + setup.output[file].call(files) + after, function () {
+ console.log("Saved to \033[32m" + file + "\033[0m\n");
+ });
+ })(file);
+}

0 comments on commit 9a6125b

Please sign in to comment.