Skip to content

Instantly share code, notes, and snippets.

@paul-vd
Last active March 18, 2022 21:44
Show Gist options
  • Save paul-vd/dbcc56a181a52d6b794cf9e2c7928fb2 to your computer and use it in GitHub Desktop.
Save paul-vd/dbcc56a181a52d6b794cf9e2c7928fb2 to your computer and use it in GitHub Desktop.
git-diff
const ABORT_BUILD_CODE = 0;
const CONTINUE_BUILD_CODE = 1;
const continueBuild = () => {
console.log("🟢 - building");
process.exit(CONTINUE_BUILD_CODE);
};
const abortBuild = (reason) => {
console.log("⚪️ - build canceled :", reason);
process.exit(ABORT_BUILD_CODE);
};
const currentApp = process.cwd().split("/").pop();
/**
* This checks if there are any changes in the folder for the targeted application
*/
const checkGitDiff = () => {
if (!currentApp || !fs.existsSync(fromRootPath(`./apps/${currentApp}`))) {
abortBuild("app not found");
}
const diffInApp = Number(
childProcess
.execSync(`git diff --name-only HEAD^ HEAD ${appPath} | wc -l`)
.toString()
.replace("\n", "")
);
return diffInApp ? true : abortBuild("no changes in app");
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment