Browse Source

Fuck UMDs, none work with requirejs. Use babel simple-amd.

Herbert Vojčík 1 year ago
parent
commit
2ee3e82330
5 changed files with 84 additions and 75 deletions
  1. 5 0
      .babelrc
  2. 72 0
      amd/brikz.js
  3. 4 2
      brikz.js
  4. 3 2
      package.json
  5. 0 71
      umd/brikz.js

+ 5 - 0
.babelrc

@@ -0,0 +1,5 @@
+{
+  "plugins": [
+    "transform-es2015-modules-simple-amd"
+  ]
+}

+ 72 - 0
amd/brikz.js

@@ -0,0 +1,72 @@
+define([], function () {
+    return function Brikz(api, apiKey, initKey) {
+        var brikz = this,
+            backup = {};
+        apiKey = apiKey || 'exports';
+        initKey = initKey || '__init__';
+
+        function mixin(src, target, what) {
+            for (var keys = Object.keys(what || src), l = keys.length, i = 0; i < l; ++i) {
+                if (src == null) {
+                    target[keys[i]] = undefined;
+                } else {
+                    var value = src[keys[i]];
+                    if (typeof value !== "undefined") {
+                        target[keys[i]] = value;
+                    }
+                }
+            }
+            return target;
+        }
+
+        Object.defineProperties(this, {
+            rebuild: { value: null, enumerable: false, configurable: true, writable: true }
+        });
+        var exclude = mixin(this, {});
+
+        this.rebuild = function () {
+            Object.keys(backup).forEach(function (key) {
+                mixin(null, api, (backup[key] || 0)[apiKey] || {});
+            });
+            var oapi = mixin(api, {}),
+                order = [],
+                chk = {};
+
+            function ensure(key) {
+                if (key in exclude) {
+                    return null;
+                }
+                var b = brikz[key],
+                    bak = backup[key];
+                mixin(null, api, api);
+                while (typeof b === "function") {
+                    (b.deps || []).forEach(ensure);
+                    b = new b(brikz, api, bak);
+                }
+                brikz[key] = b;
+                if (b && !chk[key]) {
+                    chk[key] = true;
+                    order.push(b);
+                }
+                if (b && !b[apiKey]) {
+                    b[apiKey] = mixin(api, {});
+                }
+            }
+
+            Object.keys(brikz).forEach(ensure);
+            mixin(oapi, mixin(null, api, api));
+            order.forEach(function (brik) {
+                mixin(brik[apiKey] || {}, api);
+            });
+            order.forEach(function (brik) {
+                if (brik[initKey]) {
+                    brik[initKey]();
+                    if (brik[initKey].once) {
+                        delete brik[initKey];
+                    }
+                }
+            });
+            backup = mixin(brikz, {});
+        };
+    };
+});

+ 4 - 2
brikz.js

@@ -1,4 +1,6 @@
-function Brikz(api, apiKey, initKey) {
+export default (
+
+function Brikz (api, apiKey, initKey) {
     var brikz = this, backup = {};
     apiKey = apiKey || 'exports';
     initKey = initKey || '__init__';
@@ -65,4 +67,4 @@ function Brikz(api, apiKey, initKey) {
     };
 }
 
-return Brikz;
+);

+ 3 - 2
package.json

@@ -4,7 +4,7 @@
   "description": "Reconfigurable micro composition of object APIs",
   "main": "brikz.js",
   "scripts": {
-    "build": "umd brikz < brikz.js > umd/brikz.js",
+    "build": "babel --out-dir amd brikz.js",
     "test": "echo \"Error: no test specified\" && exit 1"
   },
   "repository": {
@@ -14,6 +14,7 @@
   "author": "Herby Vojčík <herby@mailbox.sk>",
   "license": "MIT",
   "devDependencies": {
-    "umd": "^3.0.1"
+    "babel-cli": "^6.14.0",
+    "babel-plugin-transform-es2015-modules-simple-amd": "^0.3.0"
   }
 }

+ 0 - 71
umd/brikz.js

@@ -1,71 +0,0 @@
-(function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.brikz = f()}})(function(){var define,module,exports;
-function Brikz(api, apiKey, initKey) {
-    var brikz = this, backup = {};
-    apiKey = apiKey || 'exports';
-    initKey = initKey || '__init__';
-
-    function mixin(src, target, what) {
-        for (var keys = Object.keys(what || src), l = keys.length, i = 0; i < l; ++i) {
-            if (src == null) {
-                target[keys[i]] = undefined;
-            } else {
-                var value = src[keys[i]];
-                if (typeof value !== "undefined") {
-                    target[keys[i]] = value;
-                }
-            }
-        }
-        return target;
-    }
-
-    Object.defineProperties(this, {
-        rebuild: {value: null, enumerable: false, configurable: true, writable: true}
-    });
-    var exclude = mixin(this, {});
-
-    this.rebuild = function () {
-        Object.keys(backup).forEach(function (key) {
-            mixin(null, api, (backup[key] || 0)[apiKey] || {});
-        });
-        var oapi = mixin(api, {}), order = [], chk = {};
-
-        function ensure(key) {
-            if (key in exclude) {
-                return null;
-            }
-            var b = brikz[key], bak = backup[key];
-            mixin(null, api, api);
-            while (typeof b === "function") {
-                (b.deps || []).forEach(ensure);
-                b = new b(brikz, api, bak);
-            }
-            brikz[key] = b;
-            if (b && !chk[key]) {
-                chk[key] = true;
-                order.push(b);
-            }
-            if (b && !b[apiKey]) {
-                b[apiKey] = mixin(api, {});
-            }
-        }
-
-        Object.keys(brikz).forEach(ensure);
-        mixin(oapi, mixin(null, api, api));
-        order.forEach(function (brik) {
-            mixin(brik[apiKey] || {}, api);
-        });
-        order.forEach(function (brik) {
-            if (brik[initKey]) {
-                brik[initKey]();
-                if (brik[initKey].once) {
-                    delete brik[initKey];
-                }
-            }
-        });
-        backup = mixin(brikz, {});
-    };
-}
-
-return Brikz;
-
-});