Custom gatsby bin to clean and retry on certain errors
Luke Karrys committed
Oct 20, 2023 at 15:54 UTC
e3d127cfd93315f1f7654c3d5b9316d24bb39859
2 files changed
+33
-3
package.json
+3
-3
@@ -7,9 +7,9 @@
7
},
8
"private": true,
9
"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",
13
"clean": "gatsby clean",
14
"serve": "gatsby serve",
15
"lint": "eslint \"**/*.js\"",
scripts/gatsby.sh
new
+30
@@ -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