Skip to content

Commit e3d127c

Browse files
committed
Custom gatsby bin to clean and retry on certain errors
1 parent 8b3b27d commit e3d127c

File tree

2 files changed

+33
-3
lines changed

2 files changed

+33
-3
lines changed

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@
77
},
88
"private": true,
99
"scripts": {
10-
"develop": "gatsby develop",
11-
"develop:ssr": "DEV_SSR=true gatsby develop",
12-
"build": "gatsby build --verbose --log-pages",
10+
"develop": "./scripts/gatsby.sh develop",
11+
"develop:ssr": "DEV_SSR=true ./scripts/gatsby.sh develop",
12+
"build": "./scripts/gatsby.sh build --verbose --log-pages",
1313
"clean": "gatsby clean",
1414
"serve": "gatsby serve",
1515
"lint": "eslint \"**/*.js\"",

scripts/gatsby.sh

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
2+
#!/bin/bash
3+
4+
ARGS=$@
5+
LOG_FILE=".gatsby-stderr.log"
6+
7+
trap "rm -f $LOG_FILE" EXIT
8+
9+
function run_with_args {
10+
gatsby $ARGS
11+
}
12+
13+
function clean_and_run {
14+
rm -f $LOG_FILE
15+
gatsby clean
16+
run_with_args
17+
}
18+
19+
run_with_args 2> $LOG_FILE
20+
CODE=$?
21+
22+
if [ $CODE -ne 0 ]; then
23+
echo "Command failed with code $CODE and error logs:"
24+
cat $LOG_FILE
25+
26+
if grep -iqE 'segmentation fault|mutex' $LOG_FILE; then
27+
echo "Cleaning caches and running again..."
28+
clean_and_run
29+
fi
30+
fi

0 commit comments

Comments
 (0)