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

Method getBuildFilePaths

src/deploy.ts:452–528  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

450
451 // Get the list of build files, doing a build if necessary.
452 private async getBuildFilePaths(): Promise<string[]> {
453 let doBuild = this.deployOptions.force === "build";
454 let buildFilePaths: string[] | null = null;
455
456 // Check if the build is missing. If it is present, then continue; otherwise
457 // if --no-build was specified, then error; otherwise if in a tty, ask the
458 // user if they want to build; otherwise build automatically.
459 try {
460 buildFilePaths = await this.findBuildFiles();
461 } catch (error) {
462 if (CliError.match(error, {message: /No build files found/})) {
463 if (this.deployOptions.force === "deploy") {
464 throw new CliError("No build files found.");
465 } else if (!this.deployOptions.force) {
466 if (this.effects.isTty) {
467 const choice = await this.effects.clack.confirm({
468 message: "No build files found. Do you want to build the app now?",
469 active: "Yes, build and then deploy",
470 inactive: "No, cancel deploy"
471 });
472 if (this.effects.clack.isCancel(choice) || !choice) {
473 throw new CliError("User canceled deploy", {print: false, exitCode: 0});
474 }
475 }
476 doBuild = true;
477 }
478 } else {
479 throw error;
480 }
481 }
482
483 // If we haven’t decided yet whether or not we’re building, check how old the
484 // build is, and whether it is stale (i.e., whether the source files are newer
485 // than the build). If in a tty, ask the user if they want to build; otherwise
486 // deploy as is.
487 if (!doBuild && !this.deployOptions.force && this.effects.isTty) {
488 const leastRecentBuildMtimeMs = await this.findLeastRecentBuildMtimeMs();
489 const mostRecentSourceMtimeMs = await this.findMostRecentSourceMtimeMs();
490 const buildAge = Date.now() - leastRecentBuildMtimeMs;
491 let initialValue = buildAge > BUILD_AGE_WARNING_MS;
492 if (mostRecentSourceMtimeMs > leastRecentBuildMtimeMs) {
493 this.effects.clack.log.warn(
494 wrapAnsi(`Your source files have changed since you built ${formatAge(buildAge)}.`, this.effects.outputColumns)
495 );
496 initialValue = true;
497 } else {
498 this.effects.clack.log.info(wrapAnsi(`You built this app ${formatAge(buildAge)}.`, this.effects.outputColumns));
499 }
500 const choice = await this.effects.clack.confirm({
501 message: "Would you like to build again before deploying?",
502 initialValue,
503 active: "Yes, build and then deploy",
504 inactive: "No, deploy as is"
505 });
506 if (this.effects.clack.isCancel(choice)) throw new CliError("User canceled deploy", {print: false, exitCode: 0});
507 doBuild = !!choice;
508 }
509

Callers 2

startNewDeployMethod · 0.95

Calls 11

findBuildFilesMethod · 0.95
formatAgeFunction · 0.85
matchMethod · 0.80
confirmMethod · 0.80
isCancelMethod · 0.80
infoMethod · 0.80
stepMethod · 0.80
buildMethod · 0.80
warnMethod · 0.45

Tested by

no test coverage detected