hypershield
Version:
Middleware suite for high-performance and resilient APIs
53 lines • 2.03 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const fs_1 = __importDefault(require("fs"));
const child_process_1 = require("child_process");
function updateVersion(type) {
const pkg = JSON.parse(fs_1.default.readFileSync('package.json', 'utf-8'));
const [major, minor, patch] = pkg.version.split('.').map(Number);
switch (type) {
case 'major':
pkg.version = `${major + 1}.0.0`;
break;
case 'minor':
pkg.version = `${major}.${minor + 1}.0`;
break;
case 'patch':
pkg.version = `${major}.${minor}.${patch + 1}`;
break;
}
fs_1.default.writeFileSync('package.json', JSON.stringify(pkg, null, 2));
return pkg.version;
}
function createGitTag(version) {
try {
(0, child_process_1.execSync)(`git tag v${version}`);
(0, child_process_1.execSync)('git push --tags');
console.log(`Created and pushed tag v${version}`);
}
catch (error) {
console.error('Failed to create git tag:', error);
}
}
function updateChangelog(version) {
const changelog = fs_1.default.readFileSync('CHANGELOG.md', 'utf-8');
const date = new Date().toISOString().split('T')[0];
const newEntry = `\n## [${version}] - ${date}\n\n### Added\n- \n\n### Changed\n- \n\n### Fixed\n- \n`;
fs_1.default.writeFileSync('CHANGELOG.md', changelog.replace(/# Changelog/, `# Changelog${newEntry}`));
}
function main() {
const type = process.argv[2];
if (!['major', 'minor', 'patch'].includes(type)) {
console.error('Please specify version type: major, minor, or patch');
process.exit(1);
}
const newVersion = updateVersion(type);
updateChangelog(newVersion);
createGitTag(newVersion);
console.log(`Version bumped to ${newVersion}`);
}
main();
//# sourceMappingURL=version-bump.js.map