Skip to content

Commit

Permalink
feat: check for deno vs code ext and download when prompted (#4698)
Browse files Browse the repository at this point in the history
* fix: check for deno vs code ext and download when prompted

* fix: change execSync to use execa

* fix: change execSync to use execa

* fix: catch error during extension install to fix tests or if vscode not installed

* fix: add error catching

* fix: bypass prompt when error checking for deno

* fix: move error handling to single block

* fix: add stderr piping to execa command

* fix: add stderr piping to execa commands

* fix: dot diff in test

* Update src/recipes/vscode/index.js

Co-authored-by: Eduardo Bouças <[email protected]>

* chore: revert snapshot change

Co-authored-by: Eduardo Bouças <[email protected]>
  • Loading branch information
JWhist and eduardoboucas authored Jun 21, 2022
1 parent a67ec05 commit b09b86e
Showing 1 changed file with 33 additions and 4 deletions.
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' })
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

1 comment on commit b09b86e

@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: 226 MB

Please sign in to comment.