Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: check for deno vs code ext and download when prompted #4698

Merged
merged 18 commits into from
Jun 21, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 33 additions & 4 deletions src/recipes/vscode/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const { join } = require('path')

const execa = require('execa')
const inquirer = require('inquirer')

const { NETLIFYDEVLOG, NETLIFYDEVWARN, chalk, error, log } = require('../../utils/command-helpers')
Expand Down Expand Up @@ -27,6 +28,26 @@ const getEdgeFunctionsPath = ({ config, repositoryRoot }) =>

const getSettingsPath = (repositoryRoot) => join(repositoryRoot, '.vscode', 'settings.json')

const hasDenoVSCodeExt = async () => {
const { stdout: extensions } = await execa('code', ['--list-extensions'], { stderr: 'inherit' })
Copy link
Member

Choose a reason for hiding this comment

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

I'm curious why you've used inherit here and on L37?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I want to save the data from the extensions if the stdout is ok, but log the error to the screen if it is going to stderr.

return extensions.split('\n').includes('denoland.vscode-deno')
}

const getDenoVSCodeExt = async () => {
await execa('code', ['--install-extension', 'denoland.vscode-deno'], { stdio: 'inherit' })
}

const getDenoExtPrompt = () => {
const message = 'The Deno VS Code extension is recommended. Would you like to install it now?'

return inquirer.prompt({
type: 'confirm',
name: 'confirm',
message,
default: true,
})
}

const run = async ({ config, repositoryRoot }) => {
const { DenoBridge } = await import('@netlify/edge-bundler')
const deno = new DenoBridge({
Expand All @@ -45,14 +66,22 @@ const run = async ({ config, repositoryRoot }) => {
}

try {
await writeSettings({ settings, settingsPath })

log(`${NETLIFYDEVLOG} VS Code settings file ${fileExists ? 'updated' : 'created'}.`)
if (!(await hasDenoVSCodeExt())) {
const { confirm: denoExtConfirm } = await getDenoExtPrompt()
if (denoExtConfirm) getDenoVSCodeExt()
}
} catch {
log(
`${NETLIFYDEVWARN} If you don't have the Deno VS Code extension, install it by visiting ${chalk.blue(
`${NETLIFYDEVWARN} Unable to install Deno VS Code extension. To install it manually, visit ${chalk.blue(
'https://ntl.fyi/deno-vscode',
)}.`,
)
}

try {
await writeSettings({ settings, settingsPath })

log(`${NETLIFYDEVLOG} VS Code settings file ${fileExists ? 'updated' : 'created'}.`)
} catch {
error('Could not write VS Code settings file.')
}
Expand Down