From b8025b207f66356979ba6ed3c0362abc81e08ee0 Mon Sep 17 00:00:00 2001 From: devel-pa Date: Fri, 30 Sep 2016 21:19:18 +0200 Subject: [PATCH 1/2] Unbuilding structure. --- gun.js | 28 ++++++++++++++-------------- lib/unbuild.js | 12 +++++++----- 2 files changed, 21 insertions(+), 19 deletions(-) diff --git a/gun.js b/gun.js index ef5924bd..e1932efc 100644 --- a/gun.js +++ b/gun.js @@ -162,7 +162,7 @@ var list_is = Type.list.is; var obj = Type.obj, obj_is = obj.is, obj_has = obj.has, obj_map = obj.map; module.exports = Type; - })(require, './src/type'); + })(require, './type'); ;require(function(module){ // On event emitter generic javascript utility. @@ -291,7 +291,7 @@ } function noop(){}; module.exports = Scope(); - })(require, './src/on'); + })(require, './on'); ;require(function(module){ var On = require('./on'); @@ -418,7 +418,7 @@ } */ module.exports = Chain; - })(require, './src/onify'); + })(require, './onify'); ;require(function(module){ // Generic javascript scheduler utility. @@ -458,7 +458,7 @@ s.set(ctx.soonest); } module.exports = s; - })(require, './src/schedule'); + })(require, './schedule'); ;require(function(module){ /* Based on the Hypothetical Amnesia Machine thought experiment */ @@ -519,7 +519,7 @@ } var undefined; module.exports = HAM; - })(require, './src/HAM'); + })(require, './HAM'); ;require(function(module){ var Type = require('./type'); @@ -564,7 +564,7 @@ var text_is = Type.text.is; var obj = Type.obj, obj_is = obj.is, obj_put = obj.put, obj_map = obj.map; module.exports = Val; - })(require, './src/val'); + })(require, './val'); ;require(function(module){ var Type = require('./type'); @@ -622,7 +622,7 @@ var _soul = Val.rel._; var u; module.exports = Node; - })(require, './src/node'); + })(require, './node'); ;require(function(module){ var Type = require('./type'); @@ -680,7 +680,7 @@ var fn = Type.fn, fn_is = fn.is; var N_ = Node._, u; module.exports = State; - })(require, './src/state'); + })(require, './state'); ;require(function(module){ var Type = require('./type'); @@ -831,7 +831,7 @@ var obj = Type.obj, obj_is = obj.is, obj_del = obj.del, obj_has = obj.has, obj_empty = obj.empty, obj_put = obj.put, obj_map = obj.map, obj_copy = obj.copy; var u; module.exports = Graph; - })(require, './src/graph'); + })(require, './graph'); ;require(function(module){ @@ -994,7 +994,7 @@ if(typeof window !== "undefined"){ window.Gun = Gun } if(typeof common !== "undefined"){ common.exports = Gun } module.exports = Gun; - })(require, './src/gun'); + })(require, './gun'); ;require(function(module){ @@ -1075,7 +1075,7 @@ var u; }()); - })(require, './src/index'); + })(require, './index'); ;require(function(module){ var Gun = require('./index'); @@ -2020,7 +2020,7 @@ }); } }()); - })(require, './src/api'); + })(require, './api'); }()); @@ -2065,7 +2065,7 @@ } Gun.on('put', put); Gun.on('get', get); - })(require, './src/localStorage'); + })(require, './adapters/localStorage'); ;require(function(module){ Gun.on('get', function(at){ @@ -2108,7 +2108,7 @@ }); Tab.peers(peers).send(msg, {headers: {'gun-sid': Tab.server.sid}}); }); - })(require, './src/WebSocket'); + })(require, './adapters/WebSocket'); }()); /* Gun.on('put', function(at){ diff --git a/lib/unbuild.js b/lib/unbuild.js index 674405f9..67f1f2a9 100644 --- a/lib/unbuild.js +++ b/lib/unbuild.js @@ -1,17 +1,18 @@ var fs = require('fs'); +var nodePath = require('path'); var dir = __dirname + '/../'; var read = function(path){ - return fs.readFileSync(dir + path).toString(); + return fs.readFileSync(nodePath.join(dir, path)).toString(); } var write = function(path, data){ - return fs.writeFileSync(dir + path, data); + return fs.writeFileSync(nodePath.join(dir, path), data); } var rm = function(path, full) { - path = full || dir + path; + path = full || nodePath.join(dir, path); if(!fs.existsSync(path)){ return } fs.readdirSync(path).forEach(function(file,index){ var curPath = path + "/" + file; @@ -25,7 +26,7 @@ var rm = function(path, full) { }; var mk = function(path){ - path = dir + path; + path = nodePath.join(dir, path); if(fs.existsSync(path)){ return } fs.mkdirSync(path); } @@ -61,7 +62,7 @@ var path = function(){ if('.js' !== path.slice(-3)){ path += '.js'; } - return path; + return nodePath.join('./src', path); } var undent = function(code, n){ @@ -76,6 +77,7 @@ var undent = function(code, n){ rm('./src'); mk('./src'); + mk('./src/adapters'); var gun = read('gun.js'); var code = next(gun); From 9098380a903d8b88ddd4b2391da0c3b243ecd178 Mon Sep 17 00:00:00 2001 From: devel-pa Date: Fri, 30 Sep 2016 21:24:01 +0200 Subject: [PATCH 2/2] Put out of the way require polyfill. --- lib/unbuild.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/unbuild.js b/lib/unbuild.js index 67f1f2a9..d81c3389 100644 --- a/lib/unbuild.js +++ b/lib/unbuild.js @@ -77,6 +77,7 @@ var undent = function(code, n){ rm('./src'); mk('./src'); + mk('./src/polyfill'); mk('./src/adapters'); var gun = read('gun.js'); @@ -84,7 +85,7 @@ var undent = function(code, n){ code = next("/* UNBUILD */"); - write('src/unbuild.js', undent(code, 1)); + write('src/polyfill/unbuild.js', undent(code, 1)); (function recurse(c){ code = next(";require(function(module){", "})(require");