Skip to content

Commit 893e5f9

Browse files
biilmannclaude
andauthored
fix(deploy): make --create-site flag always work without interaction (#7570)
* fix(deploy): make --create-site flag always work without interaction 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]> * fix(deploy): fix "Create & configure" option in interactive mode The interactive deploy prompt was incorrectly checking for a '+' prefix that didn't exist in the choice text, causing "Create & configure a new project" to always fall through to the link flow instead of creating a new site. Fixed by using proper constants and exact equality check, consistent with the init command pattern. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]> * fix(deploy): remove non-null assertion and improve error handling Replace non-null assertion operator with proper error handling to fix ESLint violation. Also apply Prettier formatting fixes. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]> * refactor(deploy): use inquirer choice objects for robust option handling Replace brittle string matching with inquirer's choice objects pattern, separating display text from programmatic values. This prevents future breakage when display text changes and follows established codebase patterns. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]> * fix(deploy): add proper error handling for --create-site name conflicts Handle 422 status code when site name is already taken, providing clear error messages instead of generic "JSONHTTPError: Unprocessable Entity". This improves the user experience for non-interactive site creation. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]> --------- Co-authored-by: Claude <[email protected]>
1 parent cc34a97 commit 893e5f9

File tree

1 file changed

+38
-10
lines changed

1 file changed

+38
-10
lines changed

src/commands/deploy/deploy.ts

Lines changed: 38 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -926,15 +926,34 @@ const createSiteWithFlags = async (options: DeployOptionValues, command: BaseCom
926926
log(message)
927927
}
928928

929-
const siteData = await sitesCreate(
930-
{
931-
name: siteName,
929+
// Create site directly via API to bypass interactive prompts
930+
const { api } = command.netlify
931+
const body: { name?: string } = {}
932+
if (siteName) {
933+
body.name = siteName.trim()
934+
}
935+
936+
if (!options.team) {
937+
throw new Error('Team must be specified to create a site')
938+
}
939+
940+
try {
941+
const siteData = await api.createSiteInTeam({
932942
accountSlug: options.team,
933-
},
934-
command,
935-
)
936-
site.id = siteData.id
937-
return siteData
943+
body,
944+
})
945+
site.id = siteData.id
946+
return siteData as SiteInfo
947+
} catch (error_) {
948+
if ((error_ as APIError).status === 422) {
949+
return logAndThrowError(
950+
siteName
951+
? `Site name "${siteName}" is already taken. Please try a different name.`
952+
: 'Unable to create site with a random name. Please try again or specify a different name.',
953+
)
954+
}
955+
return logAndThrowError(`Failed to create site: ${(error_ as APIError).status}: ${(error_ as APIError).message}`)
956+
}
938957
}
939958

940959
const promptForSiteAction = async (options: DeployOptionValues, command: BaseCommand, site: $TSFixMe) => {
@@ -954,11 +973,20 @@ const promptForSiteAction = async (options: DeployOptionValues, command: BaseCom
954973
type: 'list',
955974
name: 'initChoice',
956975
message: 'What would you like to do?',
957-
choices: ['Link this directory to an existing project', 'Create & configure a new project'],
976+
choices: [
977+
{
978+
name: '⇄ Link this directory to an existing project',
979+
value: 'link',
980+
},
981+
{
982+
name: '+ Create & configure a new project',
983+
value: 'create',
984+
},
985+
],
958986
},
959987
])
960988

961-
const siteData = initChoice.startsWith('+') ? await sitesCreate({}, command) : await link({}, command)
989+
const siteData = initChoice === 'create' ? await sitesCreate({}, command) : await link({}, command)
962990

963991
site.id = siteData.id
964992
return siteData

0 commit comments

Comments
 (0)