var path = require("path");
var http = require("http");
var util = require("util");
-var AdmZip = require("adm-zip");
if (process.platform === "win32") {
win();
function exithandler(cmd, cb) {
return function(code) {
- if (code !== 0) {
+ if (code != null && code !== 0) {
console.log("" + cmd + " process exited with code " + code);
process.exit(code);
}
process.stdout.write(".");
});
res.on("end", function() {
- console.log("\n%d bytes downloaded", len);
- processArchive();
+ console.log("\n%d bytes received", len);
+ setTimeout(processArchive, 2000);
});
res.pipe(wf);
});
}
function processArchive() {
+ var AdmZip = require("adm-zip");
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)];
+
+ var config = {};
+ config["variables"] = {
+ "EJDB_HOME" : sdir
+ };
+ fs.writeFileSync("configure.gypi", JSON.stringify(config));
+
+ var args = ["configure", "rebuild"];
console.log("node-gyp %j", args);
- var ng = spawn("node-gyp", args, {stdio : "inherit"});
- ng.on("close", exithandler("node-gyp"));
+ var ng = spawn("node-gyp.cmd", args, {stdio : "inherit"});
+ ng.on("error", function(ev) {
+ console.log("Spawn error: " + ev);
+ process.exit(1);
+ });
+ ng.on("close", exithandler("node-gyp", function() {
+ copyFile(path.join(sdir, "lib/tcejdbdll.dll"),
+ "build/Release/tcejdbdll.dll",
+ exithandler("copy tcejdbdll.dll"));
+ }));
}
}
}
+}
+function copyFile(source, target, cb) {
+ var cbCalled = false;
+ var rd = fs.createReadStream(source);
+ rd.on("error", function(err) {
+ done(err);
+ });
+ var wr = fs.createWriteStream(target);
+ wr.on("error", function(err) {
+ done(err);
+ });
+ wr.on("close", function(ex) {
+ done();
+ });
+ rd.pipe(wr);
+ function done(err) {
+ if (!cbCalled) {
+ cb(err);
+ cbCalled = true;
+ }
+ }
}
\ No newline at end of file