Skip to content

Instantly share code, notes, and snippets.

@kaanra
Last active October 2, 2024 22:45
Show Gist options
  • Save kaanra/8234c71bf746d5842a24cfb80d23bdc1 to your computer and use it in GitHub Desktop.
Save kaanra/8234c71bf746d5842a24cfb80d23bdc1 to your computer and use it in GitHub Desktop.
[Husky "yarn build" pre-commit hook with Sage WordPress] #husky #git #wordpress #sage

1: Install

Install Husky from https://typicode.github.io/husky/get-started.html

yarn add --dev husky
# Add pinst ONLY if your package is not private
yarn add --dev pinst

2: Create pre-commit file

In the wp-content/themes/your-theme/.husky folder add a file called pre-commit. Inside pre-commit type:

# .husky/pre-commit
cd wp-content/themes/canadian-centre-recovery-excellence
yarn build
git add public

# To test a hook, add exit 1 to the hook script to abort the Git command
# exit 1

3: Update package json

In the package.json add the line under "scripts":

"postinstall": "cd ../../../ && husky wp-content/themes/your-theme/.husky"

4: Run yarn postinstall

5: Done

Now when you commit, yarn build should run.

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