Skip to content

Commit

Permalink
refactor: replace inherited log,exit utils in commands.(init|log(in|o…
Browse files Browse the repository at this point in the history
…ut)|switch|watch) (#3373)

Co-authored-by: ehmicky <ehmicky@users.noreply.github.com>
Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
  • Loading branch information
3 people authored Sep 21, 2021
1 parent 8d5538e commit 29fc966
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 22 deletions.
24 changes: 12 additions & 12 deletions src/commands/init.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const inquirer = require('inquirer')
const isEmpty = require('lodash/isEmpty')

const Command = require('../utils/command')
const { log } = require('../utils/command-helpers')
const { log, exit } = require('../utils/command-helpers')
const { getRepoData } = require('../utils/get-repo-data')
const ensureNetlifyIgnore = require('../utils/gitignore')
const { configureRepo } = require('../utils/init/config')
Expand All @@ -21,7 +21,7 @@ const persistState = ({ state, siteInfo }) => {

const getRepoUrl = ({ siteInfo }) => dotProp.get(siteInfo, 'build_settings.repo_url')

const logExistingAndExit = ({ exit, siteInfo }) => {
const logExistingAndExit = ({ siteInfo }) => {
log()
log(`This site has been initialized`)
log()
Expand All @@ -37,7 +37,7 @@ const logExistingAndExit = ({ exit, siteInfo }) => {
exit()
}

const createNewSiteAndExit = async ({ exit, state }) => {
const createNewSiteAndExit = async ({ state }) => {
const siteInfo = await SitesCreateCommand.run([])

log(`"${siteInfo.name}" site was created`)
Expand All @@ -49,7 +49,7 @@ const createNewSiteAndExit = async ({ exit, state }) => {
exit()
}

const logGitSetupInstructionsAndExit = ({ exit }) => {
const logGitSetupInstructionsAndExit = () => {
log()
log(`${chalk.bold('To initialize a new git repo follow the steps below.')}
Expand Down Expand Up @@ -82,7 +82,7 @@ const logGitSetupInstructionsAndExit = ({ exit }) => {
exit()
}

const handleNoGitRemoteAndExit = async ({ exit, error, state }) => {
const handleNoGitRemoteAndExit = async ({ error, state }) => {
log()
log(`${chalk.yellow('No git remote was found, would you like to set one up?')}`)
log(`
Expand Down Expand Up @@ -112,9 +112,9 @@ git remote add origin https://github.com/YourUserName/RepoName.git
])

if (noGitRemoteChoice === NEW_SITE_NO_GIT) {
await createNewSiteAndExit({ exit, state })
await createNewSiteAndExit({ state })
} else if (noGitRemoteChoice === NO_ABORT) {
logGitSetupInstructionsAndExit({ exit })
logGitSetupInstructionsAndExit()
}
}

Expand Down Expand Up @@ -147,7 +147,7 @@ const createOrLinkSiteToRepo = async () => {
}
}

const logExistingRepoSetupAndExit = ({ exit, siteName, repoUrl }) => {
const logExistingRepoSetupAndExit = ({ siteName, repoUrl }) => {
log()
log(chalk.underline.bold(`Success`))
log(`This site "${siteName}" is configured to automatically deploy via ${repoUrl}`)
Expand All @@ -161,7 +161,7 @@ class InitCommand extends Command {

this.setAnalyticsPayload({ manual: flags.manual, force: flags.force })

const { exit, netlify } = this
const { netlify } = this
const { repositoryRoot, state } = netlify
let { siteInfo } = this.netlify

Expand All @@ -173,13 +173,13 @@ class InitCommand extends Command {

const repoUrl = getRepoUrl({ siteInfo })
if (repoUrl && !flags.force) {
logExistingAndExit({ exit, siteInfo })
logExistingAndExit({ siteInfo })
}

// Look for local repo
const repoData = await getRepoData({ remoteName: flags.gitRemoteName })
if (repoData.error) {
await handleNoGitRemoteAndExit({ exit, error: repoData.error, state })
await handleNoGitRemoteAndExit({ error: repoData.error, state })
}

if (isEmpty(siteInfo)) {
Expand All @@ -189,7 +189,7 @@ class InitCommand extends Command {
// Check for existing CI setup
const remoteBuildRepo = getRepoUrl({ siteInfo })
if (remoteBuildRepo && !flags.force) {
logExistingRepoSetupAndExit({ exit, siteName: siteInfo.name, repoUrl: remoteBuildRepo })
logExistingRepoSetupAndExit({ siteName: siteInfo.name, repoUrl: remoteBuildRepo })
}

persistState({ state, siteInfo })
Expand Down
6 changes: 3 additions & 3 deletions src/commands/login.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ const { flags: flagsLib } = require('@oclif/command')
const chalk = require('chalk')

const Command = require('../utils/command')
const { log, getToken } = require('../utils/command-helpers')
const { log, exit, getToken } = require('../utils/command-helpers')

class LoginCommand extends Command {
async run() {
Expand All @@ -18,12 +18,12 @@ class LoginCommand extends Command {
log()
log(`To see all available commands run: ${chalk.cyanBright('netlify help')}`)
log()
return this.exit()
return exit()
}

await this.expensivelyAuthenticate()

return this.exit()
return exit()
}
}

Expand Down
6 changes: 3 additions & 3 deletions src/commands/logout.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const Command = require('../utils/command')
const { log, getToken } = require('../utils/command-helpers')
const { log, exit, getToken } = require('../utils/command-helpers')
const { track } = require('../utils/telemetry')

class LogoutCommand extends Command {
Expand All @@ -10,7 +10,7 @@ class LogoutCommand extends Command {
log(`Already logged out`)
log()
log('To login run "netlify login"')
this.exit()
exit()
}

await track('user_logout')
Expand All @@ -23,7 +23,7 @@ class LogoutCommand extends Command {
log()
log('To logout completely, unset the environment variable')
log()
this.exit()
exit()
}

log(`Logging you out of Netlify. Come back soon!`)
Expand Down
4 changes: 2 additions & 2 deletions src/commands/switch.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ const chalk = require('chalk')
const inquirer = require('inquirer')

const Command = require('../utils/command')
const { log } = require('../utils/command-helpers')
const { log, exit } = require('../utils/command-helpers')

const LoginCommand = require('./login')

Expand Down Expand Up @@ -35,7 +35,7 @@ class SwitchCommand extends Command {
log(`You're now using ${chalk.bold(selectedAccount[1])}.`)
}

return this.exit()
return exit()
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/commands/watch.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const pWaitFor = require('p-wait-for')
const prettyjson = require('prettyjson')

const Command = require('../utils/command')
const { log } = require('../utils/command-helpers')
const { log, exit } = require('../utils/command-helpers')

const InitCommand = require('./init')

Expand Down Expand Up @@ -70,7 +70,7 @@ class SitesWatchCommand extends Command {
throw new CLIError(error)
}

this.exit()
exit()
}
}

Expand Down

1 comment on commit 29fc966

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📊 Benchmark results

Package size: 353 MB

Please sign in to comment.