Skip to content

Commit bfb57a4

Browse files
committed
Version 0.3
Fixed CPU architecture mismatch, added local npm cache.
1 parent 7027e5f commit bfb57a4

1 file changed

Lines changed: 8 additions & 6 deletions

File tree

node.php

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
<?php
22

33
/**
4-
* Node.php v0.2
5-
* (c) 2014 Jerzy Głowacki
4+
* Node.php v0.3
5+
* (c) 2016 Jerzy Głowacki
66
* MIT License
77
*/
88

@@ -14,7 +14,9 @@
1414

1515
define("NODE_VER", "v5.1.0");
1616

17-
define("NODE_FILE", "node-" . NODE_VER . "-linux-x86.tar.gz");
17+
define("NODE_ARCH", "x" . substr(php_uname("m"), -2)); //x86 or x64
18+
19+
define("NODE_FILE", "node-" . NODE_VER . "-linux-" . NODE_ARCH . ".tar.gz");
1820

1921
define("NODE_URL", "http://nodejs.org/dist/" . NODE_VER . "/" . NODE_FILE);
2022

@@ -41,7 +43,7 @@ function node_install() {
4143
echo $resp === true ? "Done.\n" : "Failed. Error: curl_error($curl)\n";
4244
}
4345
echo "Installing Node.js:\n";
44-
passthru("tar -xzf " . NODE_FILE . " 2>&1 && mv node-" . NODE_VER . "-linux-x86 " . NODE_DIR . " && touch nodepid && rm -f " . NODE_FILE, $ret);
46+
passthru("tar -xzf " . NODE_FILE . " 2>&1 && mv node-" . NODE_VER . "-linux-" . NODE_ARCH . " " . NODE_DIR . " && touch nodepid && rm -f " . NODE_FILE, $ret);
4547
echo $ret === 0 ? "Done.\n" : "Failed. Error: $ret\nTry putting node folder via (S)FTP, so that " . __DIR__ . "/node/bin/node exists.";
4648
}
4749

@@ -96,11 +98,11 @@ function node_npm($cmd) {
9698
echo "Node.js is not yet installed. <a href='?install'>Install it</a>.\n";
9799
return;
98100
}
99-
$cmd = escapeshellcmd(NODE_DIR . "/bin/npm $cmd");
101+
$cmd = escapeshellcmd(NODE_DIR . "/bin/npm --cache ./.npm -- $cmd");
100102
echo "Running: $cmd\n";
101103
$ret = -1;
102104
passthru($cmd, $ret);
103-
echo $ret === 0 ? "Done.\n" : "Failed. Error: $ret\n";
105+
echo $ret === 0 ? "Done.\n" : "Failed. Error: $ret. See <a href=\"npm-debug.log\">npm-debug.log</a>\n";
104106
}
105107

106108
function node_serve($path = "") {

0 commit comments

Comments
 (0)