Skip to content

Instantly share code, notes, and snippets.

@rsperl
Last active July 25, 2022 12:26
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 rsperl/288b563bf90b834da8b0cb8e15e91679 to your computer and use it in GitHub Desktop.
Save rsperl/288b563bf90b834da8b0cb8e15e91679 to your computer and use it in GitHub Desktop.
create typescript playground in nx workspace
tsplay () {
local app="$1"
local workspace="${2:-default}"
local default_root="$HOME/tsplay"
local work_root="${TSPLAY_ROOT:-$default_root}"
local workspace_dir="$work_root/$workspace"
local lsws="$(ls -1 "$work_root"|sort|sed 's/^/ /')"
local usage="Usage: tsplay -a <app> [-w <workspace>]\n"
usage+="Existing workspaces:\n"
usage+="$lsws"
if [[ -z ${app-} ]]
then
echo "$usage"
echo "an app is required"
return 1
fi
mkdir -p "$work_root"
cd "$work_root"
if [[ -d $workspace_dir ]]
then
echo "Workspace already exists: $workspace"
else
echo "Creating new workspace: $workspace"
npx create-nx-workspace@latest --preset=ts --nxCloud=no --name="$workspace"
fi
cd "$workspace_dir"
if [[ -d "$workspace_dir/packages/$app" ]]
then
echo "App already exists: $app"
else
echo "Creating app in $workspace workspace: $app"
npm install --save @nrwl/node
npx nx generate @nrwl/node:application "$app" --tags=type:app
fi
echo "Workspace directory: $workspace_dir"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment