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! 🚀
34 lines (33 loc) • 1.34 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
const fs_1 = require("fs");
const path_1 = require("path");
// Get the directory where package.json is located
const gitDir = process.env.INIT_CWD;
// Define hook files and their corresponding script files
const hooks = [
{ hookFile: 'pre-push', scriptFile: 'pre-push-script.sh' }
];
// Iterate over each hook file and process it
hooks.forEach(({ hookFile, scriptFile }) => {
const filePath = (0, path_1.join)(gitDir, '.git', 'hooks', hookFile);
const logicFile = (0, path_1.resolve)(__dirname, scriptFile);
try {
// Read content from the script file
const fileContent = (0, fs_1.readFileSync)(logicFile, 'utf8');
// Check if the hook file exists
if (!(0, fs_1.existsSync)(filePath)) {
// Create and write the file if it does not exist
(0, fs_1.appendFileSync)(filePath, fileContent, 'utf8');
console.log(`✅ File created: ${filePath}`);
}
else {
// Append content if the file already exists
(0, fs_1.appendFileSync)(filePath, '\n' + fileContent, 'utf8');
console.log(`🔄 Content appended to: ${filePath}`);
}
}
catch (error) {
console.error(`❌ Error processing ${scriptFile}:`, error);
}
});