Skip to content

Instantly share code, notes, and snippets.

@lilactown
Last active July 24, 2022 02:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lilactown/b0cb983158dcf453f2ac058d23fbe44f to your computer and use it in GitHub Desktop.
Save lilactown/b0cb983158dcf453f2ac058d23fbe44f to your computer and use it in GitHub Desktop.
Show a self-install nbb script by using a wrapper around nbb
#!/usr/bin/env bash
current_dir=$(pwd)
# make directory to hold node_modules
read -ra hash <<< "$(pwd | shasum)" # get hash of current path
modules_dir="$HOME/.nbb/_modules/${hash[0]}"
mkdir -p "$modules_dir"
# install node_modules
if [[ -z "${SKIP_INSTALL}" ]]; then
cd "$modules_dir" || exit
read -ra deps <<< "$1" # split deps into array
npm i "${deps[@]}"
cd "$current_dir" || exit
fi
shift # get rid of deps argument
NODE_PATH="$modules_dir/node_modules" npx nbb "$@"
#!./runner zx@7.0.7 source-map@0.7.4
(ns script
(:require
["zx" :refer [$]]))
($ #js ["echo hi"])
@lilactown
Copy link
Author

You can invoke ./script.cljs and it will automatically install any dependencies necessary to run it.

You can also specify the env var SKIP_INSTALL=true ./script.cljs to avoid running npm install

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment