Skip to content

Commit

Permalink
feat: add Heroku CLI logout command
Browse files Browse the repository at this point in the history
  • Loading branch information
ivangabriele committed Jul 1, 2023
1 parent fb311db commit 254d251
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 33 deletions.
30 changes: 14 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
---

- [Features](#features)
- [Requirements](#requirements)
- [Commands](#commands)
- [Roadmap](#roadmap)
- [Issues \& Feature Requests](#issues--feature-requests)
- [Changelog](#changelog)
Expand All @@ -16,26 +16,24 @@

## Features

- **Check your project's Heroku deployment status.**
- **Log into Heroku CLI.**
- **Logout from Heroku CLI.**
- **Link your current project's workspace to your Heroku app via the Command Palette.**
- **Includes teams applications.**
- [x] Live Heroku application deployment status (Status Bar)
- [x] Heroku CLI Log In/Out (Command Palette)
- [x] Current workspace Heroku application linking (Command Palette)
- [x] Heroku Teams support

## Requirements
## Commands

- You need to have installed the [Heroku CLI](https://devcenter.heroku.com/articles/heroku-cli#install-the-heroku-cli).
- You need to be authenticated via Heroku CLI:<br />
**Command Palette** > `Heroku: Login`.
- Your workspace needs to be linked to an existing application hosted on Heroku:<br />
**Command Palette** > `Heroku: Link current workspace to an existing Heroku app`.
- `Heroku: Link current workspace to an existing Heroku app`
- `Heroku: Log In to Heroku CLI`
- `Heroku: Log Out of Heroku CLI`

## Roadmap

1. Open the current Heroku app Activity Dashboard when clicking on the Heroku Status.
2. Add a command in the Command Palette to open the Heroku-hosted app.
3. Create and deploy a new Heroku app via the Command Palette.
4. Handle pipelines.
- [ ] Heroku application Activity Dashboard opening (Status Bar Action)
- [ ] Heroku application creation (Command Palette)
- [ ] Heroku application deployment (Command Palette)
- [ ] Heroku application opening (Command Palette)
- [ ] Herokup Pipelines support

## Issues & Feature Requests

Expand Down
8 changes: 6 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,12 @@
"title": "Heroku: Link current workspace to an existing Heroku app"
},
{
"command": "extension.vscode-heroku.logIntoHeroku",
"title": "Heroku: Login"
"command": "extension.vscode-heroku.logInToHerokuCli",
"title": "Heroku: Log In to Heroku CLI"
},
{
"command": "extension.vscode-heroku.logOutOfHerokuCli",
"title": "Heroku: Log Out of Heroku CLI"
}
]
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { window } from 'vscode'

import { handleError } from '../helpers/handleError'

export async function logIntoHeroku() {
export async function logInToHerokuCli() {
try {
await new Promise(resolve => {
const child = spawn('heroku', ['login'])
Expand All @@ -17,7 +17,7 @@ export async function logIntoHeroku() {
child.stdin.end()
})

window.showInformationMessage('You are now logged into Heroku.')
window.showInformationMessage('You are now logged in to Heroku CLI.')
} catch (err) {
handleError(err)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import { $ } from 'execa'
import { window } from 'vscode'

import { exec } from '../helpers/exec'
import { handleError } from '../helpers/handleError'
import { showProgressNotification } from '../helpers/showProgressNotification'

export async function logOutHeroku() {
export async function logOutOfHerokuCli() {
try {
await showProgressNotification('Logging out from Heroku...', async () => {
await $`heroku logout`
await exec('heroku logout')
})

window.showInformationMessage('You are now logged out from Heroku.')
window.showInformationMessage('You are now logged out of Heroku CLI.')
} catch (err) {
handleError(err)
}
Expand Down
19 changes: 14 additions & 5 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ import isCommand from 'is-command'
import { commands, ExtensionContext, window, workspace } from 'vscode'

import { linkWorkspaceToHerokuApp } from './commands/linkWorkspaceToHerokuApp'
import { logIntoHeroku } from './commands/logIntoHeroku'
import { logInToHerokuCli } from './commands/logInToHerokuCli'
import { logOutOfHerokuCli } from './commands/logOutOfHerokuCli'
import { ACTION } from './constants'
import { handleError } from './helpers/handleError'
import { isHerokuCliAuthenticated } from './helpers/isHerokuCliAuthenticated'
Expand Down Expand Up @@ -38,12 +39,12 @@ export async function activate(context: ExtensionContext) {

if (!(await isHerokuCliAuthenticated())) {
const action = await window.showWarningMessage(
"Heroku CLI doesn't seem to be authenticated. Do you want to log in?",
'You are not logged in to Heroku CLI. Do you want to log in?',
ACTION.NO_HEROKU_AUTH.label,
)

if (action === ACTION.NO_HEROKU_AUTH.label) {
await logIntoHeroku()
await logInToHerokuCli()

if (!(await isHerokuCliAuthenticated())) {
return
Expand All @@ -67,10 +68,18 @@ export async function activate(context: ExtensionContext) {
'extension.vscode-heroku.linkWorkspaceToHerokuApp',
linkWorkspaceToHerokuApp,
)
const logIntoHerokuDisposable = commands.registerCommand('extension.vscode-heroku.logIntoHeroku', logIntoHeroku)
const logInToHerokuCliDisposable = commands.registerCommand(
'extension.vscode-heroku.logInToHerokuCli',
logInToHerokuCli,
)
const logOutOfHerokuCliDisposable = commands.registerCommand(
'extension.vscode-heroku.logOutOfHerokuCli',
logOutOfHerokuCli,
)

context.subscriptions.push(linkWorkspaceToHerokuAppDisposable)
context.subscriptions.push(logIntoHerokuDisposable)
context.subscriptions.push(logInToHerokuCliDisposable)
context.subscriptions.push(logOutOfHerokuCliDisposable)
} catch (err) {
handleError(err)
}
Expand Down
21 changes: 17 additions & 4 deletions src/helpers/exec.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
import { $, ExecaReturnValue, Options } from 'execa'
import { execa, ExecaReturnValue, Options } from 'execa'
import { workspace } from 'vscode'

import { InternalError } from '../libs/InternalError'

const DEFAULT_OPTIONS: Options = {
export interface ExecOptions extends Options {
shouldThrowOnStderr?: boolean
}

const DEFAULT_OPTIONS: ExecOptions = {
reject: false,
shouldThrowOnStderr: false,
}

export async function exec(statement: string, options: Options = {}): Promise<ExecaReturnValue<string>> {
export async function exec(statement: string, options: ExecOptions = {}): Promise<ExecaReturnValue<string>> {
if (!workspace.workspaceFolders) {
throw new InternalError('`workspace.workspaceFolders` is undefined.')
}
Expand All @@ -20,6 +25,14 @@ export async function exec(statement: string, options: Options = {}): Promise<Ex
cwd: workspace.workspaceFolders[0].uri.fsPath,
...options,
}
const { shouldThrowOnStderr, ...execaOptions } = controlledOptions

const [command, ...args] = statement.split(' ')
const execaChildProcess = await execa(command, args, execaOptions)

if (shouldThrowOnStderr && execaChildProcess.stderr.length > 0) {
throw new InternalError(`Command \`${statement}\` failed.`, execaChildProcess.stderr)
}

return $(controlledOptions)`${statement}`
return execaChildProcess
}

0 comments on commit 254d251

Please sign in to comment.