MCPcopy Create free account
hub / github.com/observablehq/framework / getDeployTarget

Method getDeployTarget

src/deploy.ts:282–404  ·  view source on GitHub ↗
(deployConfig: DeployConfig)

Source from the content-addressed store, hash-verified

280
281 // Get the deploy target, prompting the user as needed.
282 private async getDeployTarget(deployConfig: DeployConfig): Promise<DeployTargetInfo> {
283 let deployTarget: DeployTargetInfo;
284 if (deployConfig.workspaceLogin && deployConfig.projectSlug) {
285 try {
286 const project = await this.apiClient.getProject({
287 workspaceLogin: deployConfig.workspaceLogin,
288 projectSlug: deployConfig.projectSlug
289 });
290 deployTarget = {create: false, workspace: project.owner, project};
291 } catch (error) {
292 if (!isHttpError(error) || error.statusCode !== 404) {
293 throw error;
294 }
295 }
296 }
297
298 deployTarget ??= await promptDeployTarget(
299 this.effects,
300 this.deployOptions.config,
301 this.apiClient,
302 this.currentUser
303 );
304
305 if (!deployTarget.create) {
306 // Check last deployed state. If it's not the same project, ask the user if
307 // they want to continue anyways. In non-interactive mode just cancel.
308 const targetDescription = `${deployTarget.project.title} (${deployTarget.project.slug}) in the @${deployTarget.workspace.login} workspace`;
309 if (deployConfig.projectId && deployConfig.projectId !== deployTarget.project.id) {
310 this.effects.clack.log.warn(
311 wrapAnsi(
312 `The \`projectId\` in your deploy.json does not match. Continuing will overwrite ${bold(
313 targetDescription
314 )}.`,
315 this.effects.outputColumns
316 )
317 );
318 if (this.effects.isTty) {
319 const choice = await this.effects.clack.confirm({
320 message: "Do you want to continue deploying?",
321 active: "Yes, overwrite",
322 inactive: "No, cancel"
323 });
324 if (!choice) {
325 this.effects.clack.outro(yellow("Deploy canceled."));
326 }
327 if (this.effects.clack.isCancel(choice) || !choice) {
328 throw new CliError("User canceled deploy", {print: false, exitCode: 0});
329 }
330 } else {
331 throw new CliError("Cancelling deploy due to misconfiguration.");
332 }
333 } else if (deployConfig.projectId) {
334 this.effects.clack.log.info(wrapAnsi(`Deploying to ${bold(targetDescription)}.`, this.effects.outputColumns));
335 } else {
336 this.effects.clack.log.warn(
337 wrapAnsi(
338 `The \`projectId\` in your deploy.json is missing. Continuing will overwrite ${bold(targetDescription)}.`,
339 this.effects.outputColumns

Callers 1

startNewDeployMethod · 0.95

Calls 13

isHttpErrorFunction · 0.85
promptDeployTargetFunction · 0.85
isApiErrorFunction · 0.85
linkFunction · 0.85
getProjectMethod · 0.80
confirmMethod · 0.80
outroMethod · 0.80
isCancelMethod · 0.80
infoMethod · 0.80
postProjectMethod · 0.80
setDeployConfigMethod · 0.80
warnMethod · 0.45

Tested by

no test coverage detected