#61
authoradam <adamansky@gmail.com>
Wed, 1 May 2013 16:13:05 +0000 (23:13 +0700)
committeradam <adamansky@gmail.com>
Wed, 1 May 2013 16:13:05 +0000 (23:13 +0700)
.gitignore
.npmignore
node/platform.js
package.json

index 31a108e..594e0ec 100644 (file)
@@ -21,6 +21,8 @@
 *.tag.gz
 *.tgz
 .dep.inc
+/ejdbdll
+/node_modules
 
 addressbook*
 autom4te.cache/
@@ -108,6 +110,7 @@ tcejdb/debian/*.debhelper
 /pyejdb/pyejdb.egg-info/
 
 
+__pycache__
 /pyejdb/debian/files
 /pyejdb/debian/python3-ejdb.debhelper.log
 /pyejdb/debian/python3-ejdb.postinst.debhelper
index dc10101..9bca257 100644 (file)
@@ -26,6 +26,8 @@
 *.changes
 .dep.inc
 */nbproject/private/*
+/ejdbdll
+/node_modules
 
 addressbook*
 /.idea/workspace.xml
@@ -91,4 +93,3 @@ addressbook*
 /node/nodejs
 nbproject
 .idea
-
index e69de29..8dbef3a 100644 (file)
@@ -0,0 +1,133 @@
+var cmd = process.argv[2];
+var exec = require("child_process").exec;
+var spawn = require("child_process").spawn;
+var fs = require("fs");
+var path = require("path");
+var http = require("http");
+var util = require("util");
+var AdmZip = require("adm-zip");
+
+if (process.platform === "win32") {
+    win();
+} else {
+    win();
+}
+
+function exithandler(cmd, cb) {
+    return function(code) {
+        if (code !== 0) {
+            console.log("" + cmd + " process exited with code " + code);
+            process.exit(code);
+        }
+        if (cb) {
+            cb();
+        }
+    }
+}
+
+function nix() {
+
+    switch (cmd) {
+
+        case "preinstall":
+        {
+            console.log("Building EJDB...");
+            var m = spawn("make", ["all"], {"stdio" : "inherit"});
+            m.on("close", exithandler("make all", function() {
+                var ng = spawn("node-gyp", ["rebuild"], {stdio : "inherit"});
+                ng.on("close", exithandler("node-gyp"));
+            }));
+            break;
+        }
+        case "test":
+        {
+            console.log("Tesing Node EJDB...");
+            var m = spawn("make", ["-f", "tests.mk", "check-all"], {stdio : "inherit"});
+            m.on("close", exithandler("make"));
+        }
+    }
+}
+
+
+function win() {
+
+    switch (cmd) {
+
+        case "preinstall":
+        {
+            var dlurl = process.env["npm_package_config_windownloadurl"] || "http://dl.dropboxusercontent.com/u/4709222/ejdb/tcejdb-1.1.3-mingw32-i686.zip";
+            if (dlurl == null) {
+                console.log("Invalid package configuration, missing windows binaries download url");
+                process.exit(1);
+            }
+            var sdir = "ejdbdll";
+            try {
+                fs.statSync(sdir);
+            } catch (e) {
+                if ("ENOENT" !== e.code) {
+                    throw e;
+                }
+                fs.mkdirSync(sdir);
+            }
+
+            var zfileExist = false;
+            var zfile = path.join(sdir, path.basename(dlurl));
+            try {
+                fs.statSync(zfile);
+                zfileExist = true;
+            } catch (e) {
+                if ("ENOENT" !== e.code) {
+                    throw e;
+                }
+            }
+
+            if (!zfileExist) {
+                console.log("Downloading windows binaries from: %s ...", dlurl);
+                console.log("File: %s", zfile);
+                var req = http.get(dlurl, function(res) {
+                    if (res.statusCode !== 200) {
+                        console.log("Invalid response code %d", res.statusCode);
+                        process.exit(1);
+                    }
+                    var len = 0;
+                    var cnt = 0;
+                    var wf = fs.createWriteStream(zfile);
+                    var eh = function(ev) {
+                        console.log("Error receiving data from %s Error: %s", dlurl, ev);
+                        process.exit(1);
+                    };
+                    wf.on("error", eh);
+                    res.on("error", eh);
+                    res.on("data", function(chunk) {
+                        if (++cnt % 80 == 0) {
+                            process.stdout.write("\n");
+                        }
+                        len += chunk.length;
+                        process.stdout.write(".");
+                    });
+                    res.on("end", function() {
+                        console.log("\n%d bytes downloaded", len);
+                        processArchive();
+                    });
+                    res.pipe(wf);
+                });
+                req.end();
+            } else {
+                processArchive();
+            }
+
+            function processArchive() {
+                console.log("Unzip archive '%s'", zfile);
+                var azip = new AdmZip(zfile);
+                azip.extractAllTo(sdir, true);
+                sdir = path.resolve(sdir);
+                var args = ["rebuild", util.format("-DEJDB_HOME=%s", sdir)];
+                console.log("node-gyp %j", args);
+                var ng = spawn("node-gyp", args, {stdio : "inherit"});
+                ng.on("close", exithandler("node-gyp"));
+            }
+        }
+    }
+
+
+}
\ No newline at end of file
index 11624df..736c528 100644 (file)
@@ -1,6 +1,9 @@
 {
     "name" : "ejdb",
     "version" : "1.1.3-0",
+    "config" : {
+        "windownloadurl" : "http://dl.dropboxusercontent.com/u/4709222/ejdb/tcejdb-1.1.3-mingw32-i686.zip"
+    },
     "main" : "node/ejdb.js",
     "homepage" : "http://ejdb.org",
     "description" : "EJDB - Embedded JSON Database engine",
         "node" : "0.8.x || 0.10.x"
     },
     "dependencies" : {
-        "nodeunit" : ">=0.7.0"
+        "nodeunit" : ">=0.7.0",
+        "adm-zip" : "*"
     },
     "scripts" : {
-        "preinstall" : "make all && node-gyp rebuild",
-        "test" : "make -f tests.mk check-all"
+        "preinstall" : "node node/platform.js preinstall",
+        "test" : "node node/platform.js test"
     },
     "bin" : {
         "ejdb" : "node/bin/cli.js"