Skip to content

Commit

Permalink
Add a one-terminal REPL script
Browse files Browse the repository at this point in the history
  • Loading branch information
arichiardi committed Dec 3, 2018
1 parent ee0a974 commit 455cb93
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 1 deletion.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
},
"scripts": {
"print-version": "echo $npm_package_version",
"repl": "yarn shadow-cljs watch lib",
"repl": "./scripts/repl",
"watch": "yarn shadow-cljs watch lib",
"build": "yarn shadow-cljs release lib",
"test": "yarn shadow-cljs release test && node dist/test.js",
Expand Down
52 changes: 52 additions & 0 deletions scripts/repl
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
#!/usr/bin/env bash
#
# Call yarn shadow-cljs watch and then launch node fonda.js.
#
# Note: the $@ parameters are forwarded to yarn shadow-cljs not to the node
# command.
#
set -euo pipefail

output_dir=dist
output_file=$output_dir/fonda.js

shadow_dir=.shadow-cljs
shadow_pid_file=$shadow_dir/server.pid

shadow_build="lib"
shadow_bin="yarn shadow-cljs"
shadow_subcmd="watch"

node_bin=$(which node)
node_opts="--inspect $output_file"

function cleanup {
pkill $(cat "$shadow_pid_file");
}

set +e
rm -v "$output_file"
set -e

shadow_cmd="$shadow_bin $shadow_subcmd $shadow_build $@"
echo "Executing \"$shadow_cmd\"..."
$shadow_cmd &

# active loop waiting for the js file to appear
i=1
spinner="/-\|"
echo -n ' '
while [ ! -f "$output_file" ]; do
for c in / - \\ \|; do
printf '\b%s' "$c";
sleep .1
done
done

node_cmd="$node_bin $node_opts"
echo "The shadow-cljs REPL is up."
echo "Executing \"$node_cmd\"..."

$node_cmd

trap "set +e; do_cleanup" ERR SIGTERM SIGINT EXIT

0 comments on commit 455cb93

Please sign in to comment.