Skip to content

Commit

Permalink
feat: run build:json when any model changes
Browse files Browse the repository at this point in the history
  • Loading branch information
buuhuu committed Jul 19, 2024
1 parent dc170f1 commit 62f8e31
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
node .husky/pre-commit.mjs
git update-index --again
20 changes: 20 additions & 0 deletions .husky/pre-commit.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { exec } from "node:child_process";

const run = (cmd) => new Promise((resolve, reject) => exec(
cmd,
(error, stdout, stderr) => {
if (error) reject();
if (stderr) reject(stderr);
resolve(stdout);
}
));

const changeset = await run('git diff --cached --name-only --diff-filter=ACMR');
const modifiedFiles = changeset.split('\n').filter(Boolean);

// check if there are any model files staged
const modifledPartials = modifiedFiles.filter((file) => file.match(/(^|\/)_.*.json/));
if (modifledPartials.length > 0) {
const output = await run('npm run build:json --silent');
console.log(output);
}

0 comments on commit 62f8e31

Please sign in to comment.