From: adam Date: Wed, 1 May 2013 16:13:05 +0000 (+0700) Subject: #61 X-Git-Tag: v1.2.12~311 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=0d2307321ecd5790a0bf2ae6183922f2c46aa1f8;p=platform%2Fupstream%2Fejdb.git #61 --- diff --git a/.gitignore b/.gitignore index 31a108e..594e0ec 100644 --- a/.gitignore +++ b/.gitignore @@ -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 diff --git a/.npmignore b/.npmignore index dc10101..9bca257 100644 --- a/.npmignore +++ b/.npmignore @@ -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 - diff --git a/node/platform.js b/node/platform.js index e69de29..8dbef3a 100644 --- a/node/platform.js +++ b/node/platform.js @@ -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 diff --git a/package.json b/package.json index 11624df..736c528 100644 --- a/package.json +++ b/package.json @@ -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", @@ -30,11 +33,12 @@ "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"