diff --git a/README.md b/README.md index 590cdec..4d568a4 100644 --- a/README.md +++ b/README.md @@ -34,7 +34,7 @@ npm uninstall -g yaba-release-cli Go to [Personal Access Tokens](https://github.com/settings/tokens) page on Github and generate new token to enable `yaba` CLI to access your repos. -* Give your desired name to your perosonal access token with `Note` section. +* Give your desired name to your personal access token with `Note` section. * Choosing `repo` scope is enough to use `yaba` CLI tool. Now, your personal access token is generated. Copy that token and define that one as an environment variable: @@ -93,7 +93,7 @@ By default, if you don't specify `-o`, `-t`, `-n` and `-b` the command will prep > **IMPORTANT NOTE:** If you don't explicitly define the release as draft with `-d`, `yaba` will directly create the release with given or pre-defined values. -## Local Setup +## Run Locally You have to clone the repository to your local machine diff --git a/bin/index.js b/bin/index.js index 12076da..ef1e9b6 100755 --- a/bin/index.js +++ b/bin/index.js @@ -1,16 +1,18 @@ #!/usr/bin/env node +// third party lib definitions const yargs = require("yargs"); const ora = require('ora'); const { Octokit } = require("octokit"); const helper = require('./utils/helper.js'); const pkg = require('../package.json'); const chalk = require("chalk"); -const log = console.log; -const error = chalk.bold.red; -const spinner = ora(); const isOnline = require('is-online'); +const supportsHyperlinks = require('supports-hyperlinks'); +const hyperlinker = require('hyperlinker'); +// local variables +const spinner = ora(); const octokit = new Octokit({ auth: process.env.GITHUB_ACCESS_TOKEN }); @@ -31,18 +33,26 @@ async function run() { .option("c", { alias: "changelog", describe: "Shows only changelog without creating the release.", type: "boolean" }) .argv; + + spinner.start('Checking required ENV variables...'); + if (helper.requiredEnvVariablesExist() == false) { + spinner.fail('The required env variables are not set in order to run the command.'); + return; + } + spinner.succeed('Required ENV variables in place.'); + if (options.repo == undefined && !helper.isGitRepo()) { error(`The directory '${helper.retrieveCurrentDirectory()}' is not a Git repo.`); return; } - spinner.start('Checking internet connection.'); + spinner.start('Checking internet connection...'); const isInternetUp = await isOnline(); if (!isInternetUp) { spinner.fail('There is no internet connection!'); return; } - spinner.succeed('Internet connection established'); + spinner.succeed('Internet connection established.'); const { data: user } = await octokit.request('GET /user'); const username = user.login; @@ -72,10 +82,14 @@ async function run() { base: latestTagName, head: headBranch }); - spinner.succeed('Changelog has been prepared...'); + if (changeLog.commits.length != 0) { + spinner.succeed('Changelog has been prepared...'); + } else { + spinner.succeed(chalk.yellow.underline('Nothing found to release.')); + } - if (options.changelog) { - log('\n\n' + chalk.green.underline(`${releaseRepo} changelog for upcoming release:`) + `\n\n${helper.prepareChangeLog(options.body, changeLog)}\n`); + if (changeLog.commits.length != 0 && options.changelog) { + console.log('\n\n' + chalk.green.underline(`${releaseRepo} changelog for upcoming release:`) + `\n\n${helper.prepareChangeLog(options.body, changeLog)}\n`); } if (!options.changelog) { @@ -90,8 +104,13 @@ async function run() { tag_name: helper.releaseTagName(options.tag) }); - spinner.succeed(`Release has been prepared on Github. ${newRelease.html_url}`); - // log(`${newRelease.tag_name} has been created from ${newRelease.target_commitish}. Click the link to check the release ${newRelease.html_url}`); + let releaseMessage; + if (supportsHyperlinks.stdout) { + releaseMessage = hyperlinker('Release has been prepared on Github.', `${newRelease.html_url}`); + } else { + releaseMessage = `Release has been prepared on Github. ${newRelease.html_url}`; + } + spinner.succeed(releaseMessage); } catch (error) { spinner.fail(`Something went wrong while preparing the release! => ${error.errors}`); @@ -99,7 +118,7 @@ async function run() { } } catch (error) { - log(error); + console.log(error); } } diff --git a/bin/utils/helper.js b/bin/utils/helper.js index 64d19d1..2cbb513 100755 --- a/bin/utils/helper.js +++ b/bin/utils/helper.js @@ -87,6 +87,13 @@ module.exports = { retrieveHeadBranch: function(branches) { let headBranch = branches.find(branch => branch.name === 'master' || branch.name === 'main'); return headBranch.name; + }, + + requiredEnvVariablesExist: function() { + if (process.env.GITHUB_ACCESS_TOKEN) { + return true; + } + return false; } } diff --git a/package.json b/package.json index 676b6ca..ef08319 100644 --- a/package.json +++ b/package.json @@ -13,9 +13,11 @@ }, "dependencies": { "chalk": "^4.1.1", + "hyperlinker": "^1.0.0", "is-online": "^9.0.0", "octokit": "^1.0.5", "ora": "^5.4.0", + "supports-hyperlinks": "^2.2.0", "yargs": "^17.0.1" }, "keywords": [