Skip to content
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
51 changes: 16 additions & 35 deletions src/utils/link/link-by-prompt.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ const { track } = require('../telemetry')
module.exports = async function linkPrompts(context) {
const { api, state } = context.netlify

const SITE_NAME_PROMPT = 'Site Name'
const SITE_ID_PROMPT = 'Site ID'
const SITE_NAME_PROMPT = 'Choose from a list of your sites'
const SITE_ID_PROMPT = `Use a site ID`

let GIT_REMOTE_PROMPT = `Use current git remote URL`
let GIT_REMOTE_PROMPT = `Use a current git remote URL`
let site
// Get git remote data if exists
const repoInfo = await getRepoData()
Expand Down Expand Up @@ -110,47 +110,28 @@ Run ${chalk.cyanBright('`git remote -v`')} to see a list of your git remotes.`)
}
case SITE_NAME_PROMPT: {
kind = 'byName'
const { siteName } = await inquirer.prompt([
{
type: 'input',
name: 'siteName',
message: 'What is the name of the site?'
}
])

let sites
try {
sites = await api.listSites({
name: siteName,
filter: 'all'
})
sites = await api.listSites()
} catch (e) {
if (e.status === 404) {
context.error(`${siteName} not found`)
} else {
context.error(e)
}
context.error(e)
}

if (sites.length === 0) {
context.error(`No sites found named ${siteName}`)
context.error(`You don't have any sites. Use netlify 'sites:create' to create a site.`)
Copy link
Member

Choose a reason for hiding this comment

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

At some point we could even consider letting the user pick a prompt to create a new site directly here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That's a great idea.

}

if (sites.length > 1) {
const { selectedSite } = await inquirer.prompt([
{
type: 'list',
name: 'selectedSite',
paginated: true,
choices: sites.map(site => ({ name: site.name, value: site }))
}
])
if (!selectedSite) {
context.error('No site selected')
const siteSelection = await inquirer.prompt([
{
type: 'list',
name: 'siteName',
message: 'What is the name of the site?',
paginated: true,
choices: sites.map(site => ({ name: site.name, value: site }))
}
site = selectedSite
} else {
site = sites[0]
}
])
site = siteSelection.siteName
break
}
case SITE_ID_PROMPT: {
Expand Down