From 32f2a15bfb61ba90c1f1011084319000e62965cd Mon Sep 17 00:00:00 2001 From: Carlos Date: Tue, 13 Aug 2024 21:31:21 -0400 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20feat:=20adding=20versioning=20scrip?= =?UTF-8?q?t?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- release.js | 60 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 release.js diff --git a/release.js b/release.js new file mode 100644 index 0000000..98e92ce --- /dev/null +++ b/release.js @@ -0,0 +1,60 @@ +#!/usr/bin/env node + +const { execSync } = require('child_process'); +const inquirer = require('inquirer'); +const chalk = require('chalk'); + +async function run() { + try { + // Check if working directory is clean + const status = execSync('git status --porcelain').toString().trim(); + if (status) { + console.error( + chalk.red( + 'Error: Your working directory is not clean. Please commit or stash your changes first.' + ) + ); + process.exit(1); + } + + // Pull the latest changes + console.log( + chalk.blue('Pulling the latest changes from the remote repository...') + ); + execSync('git pull origin main', { stdio: 'inherit' }); + + // Ask the user to choose the version bump type + const { versionType } = await inquirer.prompt([ + { + type: 'list', + name: 'versionType', + message: 'Select the type of version bump:', + choices: ['patch', 'minor', 'major'], + }, + ]); + + // Bump the version + console.log(chalk.blue(`Bumping the ${versionType} version...`)); + execSync(`npm version ${versionType}`, { stdio: 'inherit' }); + + // Commit and push changes + console.log(chalk.blue('Pushing changes to the remote repository...')); + execSync('git push origin main --follow-tags', { stdio: 'inherit' }); + + // Publish the package + //console.log(chalk.blue('Publishing the package to npm...')); + //execSync('npm publish', { stdio: 'inherit' }); + + console.log( + chalk.green(`🚀 Successfully released a new ${versionType} version!`) + ); + } catch (error) { + console.error( + chalk.red('An error occurred during the release process:'), + error.message + ); + process.exit(1); + } +} + +run();