-
Notifications
You must be signed in to change notification settings - Fork 393
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: 🔧 added commit hook verify startingTemplate changes
- Loading branch information
Showing
2 changed files
with
36 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import shell from 'shelljs'; | ||
import fs from 'fs'; | ||
|
||
interface Options {} | ||
|
||
/* | ||
* Check if the changed files are also updated if they are in the startingTemplate | ||
*/ | ||
export function verifyStartingTemplateChanges(opts: Options = {}) { | ||
const gitDiff = shell.exec(`git diff --staged --name-only`, { silent: true }); | ||
const changedFiles = gitDiff.stdout.split('\n'); | ||
for (const file of changedFiles) { | ||
if (file.startsWith(pathInTemplate(''))) { | ||
continue; | ||
} | ||
if (fileIsInStartingTemplate(file)) { | ||
const fileNotChangedInStartingTemplate = | ||
changedFiles.find(f => f === pathInTemplate(file)) === undefined; | ||
if (fileNotChangedInStartingTemplate) { | ||
console.error(`File: ${file} must be updated in the startingTemplate`); | ||
process.exit(1); | ||
} | ||
} | ||
} | ||
} | ||
|
||
function fileIsInStartingTemplate(file: string) { | ||
const path = pathInTemplate(file); | ||
return fs.existsSync(path) && !fs.statSync(path).isDirectory(); | ||
} | ||
|
||
const pathInTemplate = (file: string) => `internals/startingTemplate/${file}`; | ||
|
||
verifyStartingTemplateChanges(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters