Skip to content

Commit aceabb1

Browse files
committed
Use local node_modules cache
1 parent 1371dd9 commit aceabb1

File tree

5 files changed

+125
-29
lines changed

5 files changed

+125
-29
lines changed

get_geth.sh

+3-4
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
#!/bin/bash
22
# WARNING: the following script has a high concentration of YOLOs
33

4-
ETHNODE_HOME=${HOME}/.ethnode
5-
mkdir -p ${ETHNODE_HOME}
4+
# Note: $HOMEDIR is defined in main.js, check it out
65

76
PLATFORM=$(uname | tr '[:upper:]' '[:lower:]')
87
ARCH=$(uname -m)
@@ -11,5 +10,5 @@ VERSION=$(curl -s https://api.github.com/repos/ethereum/go-ethereum/releases/lat
1110
COMMIT=$(curl -s https://api.github.com/repos/ethereum/go-ethereum/commits/${VERSION} | python -c "import sys, json; print(json.load(sys.stdin)['sha'])")
1211
NAME="geth-${PLATFORM}-amd64-${VERSION:1}-${COMMIT:0:8}"
1312
DOWNLOAD_URL="https://gethstore.blob.core.windows.net/builds/${NAME}.tar.gz"
14-
curl ${DOWNLOAD_URL} | tar -Oxzf - ${NAME}/geth > ${ETHNODE_HOME}/geth
15-
chmod +x ${ETHNODE_HOME}/geth
13+
curl ${DOWNLOAD_URL} | tar -Oxzf - ${NAME}/geth > ${HOMEDIR}/geth
14+
chmod +x ${HOMEDIR}/geth

get_parity.sh

+4-3
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
# This is a modified version of https://get.parity.io/, Copyright 2015-2018
33
# Parity Technologies (UK) Ltd.
44

5-
ETHNODE_HOME=${HOME}/.ethnode
5+
# Note: $HOMEDIR is defined in main.js, check it out
6+
67
ORIGINAL_SOURCE=$(curl -s https://get.parity.io/)
78
VERSION_STABLE=$(echo "${ORIGINAL_SOURCE}" | grep 'VERSION_STABLE=' | grep -oE '[0-9.]+')
89
VERSION_BETA=$(echo "${ORIGINAL_SOURCE}" | grep 'VERSION_BETA=' | grep -oE '[0-9.]+')
@@ -45,8 +46,8 @@ install() {
4546
TMPDIR=$(mktemp -d) && cd $TMPDIR
4647
curl -S -O $DOWNLOAD_FILE
4748
check_sha256
48-
mkdir -p ${ETHNODE_HOME}
49-
cp $TMPDIR/parity ${ETHNODE_HOME} && chmod +x ${ETHNODE_HOME}/parity
49+
mkdir -p ${HOMEDIR}
50+
cp $TMPDIR/parity ${HOMEDIR} && chmod +x ${HOMEDIR}/parity
5051
}
5152

5253
check_sha256() {

main.js

+10-8
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,15 @@
11
const fs = require("fs");
22
const path = require("path");
33
const { spawnSync } = require("child_process");
4+
const findCacheDir = require("find-cache-dir");
45
const { getKeypairs } = require("./crypto");
56

6-
const HOMEDIR = path.join(require("os").homedir(), ".ethnode");
77
const KEYS_SOURCE = path.join(__dirname, "keys");
8+
const HOMEDIR = findCacheDir({
9+
name: "ethnode",
10+
cwd: __dirname,
11+
create: true
12+
});
813

914
function randomId() {
1015
return 1e9 + Math.round(Math.random() * 1e9);
@@ -54,15 +59,12 @@ function generateBalances(keypairs, balance) {
5459

5560
function setup(client, workdir) {
5661
const paths = getPaths(client, workdir);
57-
try {
58-
fs.mkdirSync(HOMEDIR);
59-
} catch (err) {
60-
if (err.code !== "EEXIST") throw err;
61-
}
62-
6362
if (!fs.existsSync(paths.binary)) {
6463
console.log(`Download latest ${client} version, please wait.`);
65-
spawnSync(path.join(__dirname, `get_${client}.sh`), { stdio: "inherit" });
64+
spawnSync(path.join(__dirname, `get_${client}.sh`), {
65+
env: { HOMEDIR },
66+
stdio: "inherit"
67+
});
6668
}
6769
}
6870

package-lock.json

+106-13
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "ethnode",
3-
"version": "0.0.9",
3+
"version": "0.0.10",
44
"description": "Run an Ethereum node for development.",
55
"homepage": "https://github.com/vrde/ethnode",
66
"main": "main.js",
@@ -12,6 +12,7 @@
1212
"license": "MPL-2.0",
1313
"dependencies": {
1414
"commander": "^2.19.0",
15+
"find-cache-dir": "^3.0.0",
1516
"js-sha3": "^0.8.0",
1617
"keythereum": "^1.0.4",
1718
"request": "^2.88.0",

0 commit comments

Comments
 (0)