From 420774d872830f63ea1c1742c4047644993cc599 Mon Sep 17 00:00:00 2001 From: David Winter Date: Fri, 3 Sep 2021 09:51:09 +0100 Subject: [PATCH] fix: ensure update-notifier notifies of new version --- cli.js | 134 +++++++++++++++++++++++++++++---------------------------- 1 file changed, 69 insertions(+), 65 deletions(-) diff --git a/cli.js b/cli.js index 8c65937..a654272 100755 --- a/cli.js +++ b/cli.js @@ -12,95 +12,99 @@ import createClient from './client.js'; import * as readysteady from './index.js'; readJson('./package.json', (error, data) => { - updateNotifier({pkg: data}); + updateNotifier({pkg: data, updateCheckInterval: 0}).notify({isGlobal: true}); + + app(); }); -const cli = meow({ - importMeta: import.meta, - flags: { - owner: { - type: 'string', - isRequired: true, - }, - repo: { - type: 'string', - isRequired: true, - }, - tag: { - type: 'string', - isRequired: true, - }, - force: { - type: 'boolean', - default: false, +function app() { + const cli = meow({ + importMeta: import.meta, + flags: { + owner: { + type: 'string', + isRequired: true, + }, + repo: { + type: 'string', + isRequired: true, + }, + tag: { + type: 'string', + isRequired: true, + }, + force: { + type: 'boolean', + default: false, + }, + files: { + type: 'string', + isMultiple: true, + default: [], + }, }, - files: { - type: 'string', - isMultiple: true, - default: [], - }, - }, -}); + }); -const {owner, repo, tag, force, files} = cli.flags; + const {owner, repo, tag, force, files} = cli.flags; -(async () => { - let spinner = null; - spinner = createSpinner('Checking for GitHub authentication token'); + (async () => { + let spinner = null; + spinner = createSpinner('Checking for GitHub authentication token'); - try { - const client = createClient(); + try { + const client = createClient(); - spinner.succeed('GitHub authentication token detected'); + spinner.succeed('GitHub authentication token detected'); - spinner = createSpinner(`Checking that tag is available: ${tag}`); + spinner = createSpinner(`Checking that tag is available: ${tag}`); - if (!await readysteady.isTagAvailable({client, owner, repo, tag})) { - throw new Error(`Tag is not available and has already been used: ${tag}`); - } + if (!await readysteady.isTagAvailable({client, owner, repo, tag})) { + throw new Error(`Tag is not available and has already been used: ${tag}`); + } - spinner.succeed(`Tag is available for a draft release: ${tag}`); + spinner.succeed(`Tag is available for a draft release: ${tag}`); - const releaseName = tag.slice(1); + const releaseName = tag.slice(1); - spinner = createSpinner(`Checking if draft release is available: ${releaseName}`); + spinner = createSpinner(`Checking if draft release is available: ${releaseName}`); - const existingDraftRelease = await readysteady.getExistingDraftRelease({client, owner, repo, releaseName}); + const existingDraftRelease = await readysteady.getExistingDraftRelease({client, owner, repo, releaseName}); - if (existingDraftRelease) { - spinner.info(`A draft release already exists: ${releaseName}`); + if (existingDraftRelease) { + spinner.info(`A draft release already exists: ${releaseName}`); - if (force) { - spinner.info('--force flag detected, deleting the existing draft release'); - await readysteady.deleteDraftRelease({client, owner, repo, release: existingDraftRelease}); - spinner.succeed('Existing draft release deleted'); - } else { - throw new Error('An existing draft release was found. Use --force to delete and replace with a new draft release'); + if (force) { + spinner.info('--force flag detected, deleting the existing draft release'); + await readysteady.deleteDraftRelease({client, owner, repo, release: existingDraftRelease}); + spinner.succeed('Existing draft release deleted'); + } else { + throw new Error('An existing draft release was found. Use --force to delete and replace with a new draft release'); + } } - } - spinner = createSpinner(`Creating a new draft release: ${releaseName}`); + spinner = createSpinner(`Creating a new draft release: ${releaseName}`); - const newDraftRelease = await readysteady.createDraftRelease({client, owner, repo, tag, releaseName}); + const newDraftRelease = await readysteady.createDraftRelease({client, owner, repo, tag, releaseName}); - spinner.succeed(`A new draft release was created: ${releaseName}`); + spinner.succeed(`A new draft release was created: ${releaseName}`); - if (files.length > 0) { - spinner = createSpinner('Uploading files to the draft release'); + if (files.length > 0) { + spinner = createSpinner('Uploading files to the draft release'); - await readysteady.uploadFilesToDraftRelease({client, fs, owner, repo, release: newDraftRelease, files}); + await readysteady.uploadFilesToDraftRelease({client, fs, owner, repo, release: newDraftRelease, files}); - spinner.succeed('Files uploaded to draft release'); - } + spinner.succeed('Files uploaded to draft release'); + } - console.log('\nDraft release successfully created 🎉'); + console.log('\nDraft release successfully created 🎉'); - console.log(`You can edit the release here: ${newDraftRelease.data.html_url.replace('/tag/', '/edit/')}\n`); - } catch (error) { - spinner.fail(error.message); - process.exit(1); - } -})(); + console.log(`You can edit the release here: ${newDraftRelease.data.html_url.replace('/tag/', '/edit/')}\n`); + } catch (error) { + spinner.fail(error.message); + process.exit(1); + } + })(); +} function createSpinner(text) { return (new Ora(text)).start();