Skip to content
This repository was archived by the owner on Nov 6, 2025. It is now read-only.

Commit e0240c8

Browse files
committed
chore: 🔧 added commit hook verify startingTemplate changes
1 parent 3f2d9c9 commit e0240c8

File tree

2 files changed

+36
-1
lines changed

2 files changed

+36
-1
lines changed
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import shell from 'shelljs';
2+
import fs from 'fs';
3+
4+
interface Options {}
5+
6+
/*
7+
* Check if the changed files are also updated if they are in the startingTemplate
8+
*/
9+
export function verifyStartingTemplateChanges(opts: Options = {}) {
10+
const gitDiff = shell.exec(`git diff --staged --name-only`, { silent: true });
11+
const changedFiles = gitDiff.stdout.split('\n');
12+
for (const file of changedFiles) {
13+
if (file.startsWith(pathInTemplate(''))) {
14+
continue;
15+
}
16+
if (fileIsInStartingTemplate(file)) {
17+
const fileNotChangedInStartingTemplate =
18+
changedFiles.find(f => f === pathInTemplate(file)) === undefined;
19+
if (fileNotChangedInStartingTemplate) {
20+
console.error(`File: ${file} must be updated in the startingTemplate`);
21+
process.exit(1);
22+
}
23+
}
24+
}
25+
}
26+
27+
function fileIsInStartingTemplate(file: string) {
28+
const path = pathInTemplate(file);
29+
return fs.existsSync(path) && !fs.statSync(path).isDirectory();
30+
}
31+
32+
const pathInTemplate = (file: string) => `internals/startingTemplate/${file}`;
33+
34+
verifyStartingTemplateChanges();

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
"cleanAndSetup": "ts-node --project=./internals/ts-node.tsconfig.json ./internals/scripts/clean.ts",
4848
"prettify": "prettier --write",
4949
"// ---TESTING TEMPLATE---": "",
50+
"verify-startingTemplate-changes": "ts-node --project=./internals/ts-node.tsconfig.json ./internals/scripts/verify-startingTemplate-changes.ts",
5051
"test:all": "npm run test -- --watchAll=false",
5152
"test:coverage": "npm run test:all -- --coverage",
5253
"test:cra": "npm run create:cra-app && cd generated-cra-app && npm run test:generators && npm run lint && npm run checkTs && npm run cleanAndSetup && npm run lint && npm run checkTs",
@@ -69,7 +70,7 @@
6970
},
7071
"husky": {
7172
"hooks": {
72-
"pre-commit": "npm run checkTs && lint-staged",
73+
"pre-commit": "npm run verify-startingTemplate-changes && npm run checkTs && lint-staged",
7374
"prepare-commit-msg": "devmoji -e",
7475
"commit-msg": "if git-branch-is dev; then commitlint -E HUSKY_GIT_PARAMS; fi"
7576
}

0 commit comments

Comments
 (0)