Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[tooling]: post-checkout git hook #2063

Open
castastrophe opened this issue Jul 22, 2022 · 3 comments
Open

[tooling]: post-checkout git hook #2063

castastrophe opened this issue Jul 22, 2022 · 3 comments

Comments

@castastrophe
Copy link
Contributor

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

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

@bennypowers
Copy link
Member

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

@castastrophe
Copy link
Contributor Author

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
Copy link
Contributor Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants