branchname-validator
Version:
Enforces Git branch naming conventions. It ensures branches follow the required format (e.g., feature/branch-name, bugfix/issue-123) and prevents invalid names before creation. Ideal for teams maintaining consistent workflows! 🚀
28 lines (24 loc) • 878 B
text/typescript
import { writeFile, existsSync } from 'fs';
import { join, resolve } from 'path';
import * as fs from 'fs';
// Get the directory where package.json is located
const gitDir: any = process.env.INIT_CWD;
const fileName = 'pre-push-mine';
const filePath = join(gitDir, '.git', 'hooks', fileName);
// Check if the file already exists
if (!existsSync(filePath)) {
// The content of the generated JavaScript file
console.log('__dirname - ', __dirname);
let logicFile = resolve(__dirname, 'validator-script.sh');
const fileContent = fs.readFileSync(logicFile, 'utf8');
// Write the file to the directory
writeFile(filePath, fileContent, (err) => {
if (err) {
console.error('Error creating file:', err);
} else {
console.log('File created:', filePath);
}
});
} else {
console.log('File already exists:', filePath);
}