From 9c57d891b8a031046e8f739cc26260a5bcac2c17 Mon Sep 17 00:00:00 2001 From: Carlos Date: Tue, 13 Aug 2024 21:36:50 -0400 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20fix:=20fixing=20loop=20on=20publ?= =?UTF-8?q?ish?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- release.js | 33 +++++++++++++++++++++++---------- 1 file changed, 23 insertions(+), 10 deletions(-) diff --git a/release.js b/release.js index b0eac9c..224f40f 100644 --- a/release.js +++ b/release.js @@ -6,12 +6,22 @@ const chalk = require('chalk'); async function run() { try { + // Prevent the script from running during npm lifecycle hooks + if (process.env.npm_lifecycle_event) { + console.log( + chalk.yellow( + '⚠️ Script is running in an npm lifecycle hook, exiting...' + ) + ); + return; + } + // 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.' + '❌ Error: Your working directory is not clean. Please commit or stash your changes first.' ) ); process.exit(1); @@ -19,38 +29,41 @@ async function run() { // Pull the latest changes console.log( - chalk.blue('Pulling the latest changes from the remote repository...') + chalk.blue('🔄 Pulling the latest changes from the remote repository...') ); - execSync('git pull origin master', { stdio: 'inherit' }); + 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:', + message: '🔢 Select the type of version bump:', choices: ['patch', 'minor', 'major'], }, ]); // Bump the version - console.log(chalk.blue(`Bumping the ${versionType} 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 master --follow-tags', { stdio: 'inherit' }); + 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...')); + console.log(chalk.blue('📤 Publishing the package to npm...')); execSync('npm publish', { stdio: 'inherit' }); console.log( - chalk.green(`🚀 Successfully released a new ${versionType} version!`) + chalk.green(`✅ 🚀 Successfully released a new ${versionType} version!`) ); + + // Exit the process to avoid any potential loops + process.exit(0); } catch (error) { console.error( - chalk.red('An error occurred during the release process:'), + chalk.red('❌ An error occurred during the release process:'), error.message ); process.exit(1);