patternfly-elements icon indicating copy to clipboard operation
patternfly-elements copied to clipboard

[tooling]: post-checkout git hook

Open castastrophe opened this issue 3 years ago • 3 comments

I just snagged the leftover component script for Spectrum and applied it to the post-checkout git hook via husky: https://github.com/adobe/spectrum-web-components/pull/2439

Thought you might be interested in adding the same! I can open a PR if you want.

castastrophe avatar Jul 22 '22 15:07 castastrophe

neat idea. Do you think running the clean script on each checkout would be helpful, too?

bennypowers avatar Jul 24 '22 11:07 bennypowers

Interesting - probably not is my guess. I'm imagining working on some code and creating a new branch to put it in but perhaps don't want it blown away. The hanging folders feels safe because it's just a lonely node_modules with no package.json.

castastrophe avatar Jul 25 '22 14:07 castastrophe

Copying the code here in case the history gets deleted:

.husky/post-checkout

#!/bin/sh
. "$(dirname "$0")/_/husky.sh"

# If this is a file checkout (== 0) exit.
if [ "$3" == "0" ]; then exit; fi

# If this is a branch checkout (== 1) continue...

# For each element, check for a node_modules dir without a corresponding
# package.json.  That indicates the element does not exist in this branch.
for e in {packages,projects,tools}/*; do
  if [[ -d $e/node_modules && !( -f $e/package.json ) ]]; then
    # Safe to delete this folder
    rm -rf $e
  fi
done

exit 0

castastrophe avatar Jun 03 '23 15:06 castastrophe