diff --git a/.env.example b/.env.example deleted file mode 100644 index 1a0e50111..000000000 --- a/.env.example +++ /dev/null @@ -1,7 +0,0 @@ -# Nx 18 enables using plugins to infer targets by default -# This is disabled for existing workspaces to maintain compatibility -# For more info, see: https://nx.dev/concepts/inferred-tasks -NX_ADD_PLUGINS=false - -# Set to true to enable development mode features in Vite -VITE_DEV="true" diff --git a/README.md b/README.md index 8590658a5..4020ad129 100644 --- a/README.md +++ b/README.md @@ -8,15 +8,7 @@ on designers and developers alike throughout the development process. ## Development environment -Create .env file from .env.example - -```bash -if [ ! -f .env ]; then cp ./.env.example ./.env; fi -``` - -### Playground setup - -Run the `pg-setup` file. +Run the `pg-setup` script. ```bash npm run pg:setup @@ -28,31 +20,12 @@ You can then test the playground apps at `localhost:4200` by running: # build the web components npm run dev:watch -# add one of the following +# and one of the following npm run serve:angular npm run serve:react npm run serve:web ``` -### Multiple playgrounds - -Since the playground is not included in the CVS it is common to have playground -comment/uncomment code the `npm run pg:switch` script can automate this by switching -code that is out of sync with library code. To prevent having to continually -between playgrounds that are specific to the branch. - -To switch to a branch that doesn't yet exist, run the following - -```bash -npm run pg:switch new [branch-name] -``` - -To switch to an existing branch run the following - -```bash -npm run pg:switch [branch-name] -``` - --- ## Contribution Guidelines diff --git a/scripts/pg-setup b/scripts/pg-setup index c601f022d..ad1574f3e 100755 --- a/scripts/pg-setup +++ b/scripts/pg-setup @@ -1,9 +1,28 @@ -#!/usr/bin/bash +#!/bin/bash -if [ -d playground ]; then - echo "Playground folder already exists!" - exit 1 +if [ ! -f .env ]; then + echo "VITE_DEV="true"" >.env fi -mkdir ./playground -cp -r ./_templates/* ./playground +if [ ! -d playground ]; then + mkdir ./playground + cp -r ./.templates/* ./playground +fi + +while true; do + read -p "Do you want to automate playground swapping? (yes/no) " yn + case $yn in + [Yy]*) break ;; + [Nn]*) + echo "Done!" + exit + ;; + *) echo "Invalid input. Please answer yes or no." ;; + esac +done + +if [ ! -e ".git/hooks/post-checkout" ]; then + cp "./scripts/post-checkout" ".git/hooks" + chmod +x ".git/hooks/post-checkout" + echo "[post-checkout] file has been added to .git/hooks" +fi diff --git a/scripts/pg-switch b/scripts/pg-switch deleted file mode 100755 index 7fde9b75d..000000000 --- a/scripts/pg-switch +++ /dev/null @@ -1,61 +0,0 @@ -#!/bin/bash - -if [ "$1" = "new" ]; then - target=$2 - option=$1 -else - target=$1 - option="" -fi - -# Ensure local repo is in sync with remote () -git fetch upstream - -if [ ! -n "$target" ]; then - echo "pg-switch [target] => Target repository is required" - exit 1 -fi - -if [ -n "$(git status -s -uno)" ]; then - echo "Uncommitted changes exist, commit or stash changes before proceeding" - exit 1 -fi - -# Create new branch if specified -if [ "$option" = "new" ]; then - git branch "$target" -elif [ -z "$(git branch | grep "$target")" ]; then - echo "[$target] is an invalid target branch name" - exit 1 -fi - -# Get the current git branch name -branch=$(git branch --show-current) - -# Check if branch equals target -if [ "$branch" = "$target" ]; then - echo "Already on target branch: $target" - exit 0 -fi - -# Check if .playgrounds directory exists, create it if it doesn't -if [ ! -d ".playgrounds/$branch" ]; then - mkdir -p .playgrounds/"$branch" -fi - -# Move the existing playground to the .playgrounds dir -if [ -d "playground" ]; then - mv playground/* .playgrounds/"$branch" -fi - -# Move the target playground to the `playground` dir to allow it to tested -targetdir=".playgrounds/$target" -if [ -n "$target" ] && [ -d "$targetdir" ]; then - cp -r "$targetdir"/* playground - rm -rf "$targetdir" -else - cp -r .templates/* playground -fi - -# Checkout the defined target repo -git checkout "$target" diff --git a/scripts/post-checkout b/scripts/post-checkout new file mode 100644 index 000000000..d454d7484 --- /dev/null +++ b/scripts/post-checkout @@ -0,0 +1,34 @@ +#!/bin/bash + +prev_branch=$(git rev-parse --symbolic-full-name --abbrev-ref=loose @{-1}) +current_branch=$(git branch --show-current) + +if [ ! -n "$prev_branch" ]; then + echo "No previous branch exists to swap" + exit 0 +fi + +# Move the existing playground to the .playgrounds dir +if [ -d "./playground" ]; then + rm -rf .playgrounds/"$prev_branch" + mv playground .playgrounds/"$prev_branch" +fi + +src_dir=".playgrounds/$current_branch" + +# Init a playground if it is a new branch +if [ ! -d "$src_dir" ]; then + mkdir -p "$src_dir" + cp -r .templates/* "$src_dir" +fi + +# ensure the playground dir exists +if [ ! -d "./playground" ]; then + mkdir "./playground" +fi + +# move by copying the new test playground +# mv is used as it is less destructive in the event something happens +cp -r "$src_dir"/* playground + +echo "Switched playgrounds => ["$current_branch"]"