Skip to content

Commit

Permalink
If Firmata installed serialport successfully, just steal it so we bot…
Browse files Browse the repository at this point in the history
…h can use it.
  • Loading branch information
rwaldron committed Oct 19, 2015
1 parent bfb3204 commit 33e1c8d
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 10 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,8 @@
"nanotimer": "0.3.10",
"temporal": "latest",
"array-includes": "latest",
"semver": "^5.0.3"
"semver": "^5.0.3",
"mv": "2.1.1"
},
"optionalDependencies": {
"firmata": "git://github.com/jgautier/firmata.git"
Expand All @@ -140,7 +141,6 @@
},
"scripts": {
"test": "grunt",
"preinstall": "node scripts/preinstall",
"postinstall": "node scripts/postinstall"
},
"browser": {
Expand Down
39 changes: 31 additions & 8 deletions scripts/postinstall.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
require("es6-shim");

var path = require("path");
var fs = require("fs");
var mv = require("mv");
var semver = require("semver");
var spawn = require("child_process").spawn;
var cp = require("child_process");
var exec = cp.exec;
var spawn = cp.spawn;

var sp = {
version: "1.7.4",
get atVersion() {
Expand All @@ -13,15 +19,32 @@ if (semver.gte(process.version, "3.0.0")) {
sp.version = "latest";
}

var npm = spawn("npm", ["install", sp.atVersion]);
var sPath = path.join(process.cwd(), "node_modules", "firmata", "node_modules", "serialport");
var dPath = path.join(process.cwd(), "node_modules", "serialport");

npm.stdout.on("data", function(data) {
console.log(data.toString("utf8"));
});
fs.exists(sPath, function(exists) {
if (exists) {
mv(sPath, dPath, {mkdirp: true}, function(error) {
if (error) {
console.log("mv failed: ", error);
}
});
} else {
var npm = spawn("npm", ["install", sp.atVersion]);

npm.stdout.on("data", function(data) {
console.log(data.toString("utf8"));
});

npm.on("close", function(code) {
if (code !== 0) {
console.log("serialport installation failed. Error Code:", code);
}

npm.on("close", function(code) {
if (code !== 0) {
console.log("serialport installation failed. Error Code:", code);
exec("npm uninstall mv semver", function(error, result) {
console.log(result);
});
});
}
});

Expand Down

0 comments on commit 33e1c8d

Please sign in to comment.