@farm.js/cli 0.1.0-beta.53 → 0.1.0-beta.55

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.mjs CHANGED
@@ -6,11 +6,12 @@ import { createServer, startDevServer } from "@farm.js/core/server";
6
6
  import { existsSync, mkdirSync, readFileSync, readdirSync, realpathSync, writeFileSync } from "node:fs";
7
7
  import { mkdir, readFile, readdir, stat, writeFile } from "node:fs/promises";
8
8
  import path from "node:path";
9
- import { execFileSync } from "child_process";
9
+ import { execFileSync, spawn } from "child_process";
10
10
  import { existsSync as existsSync$1, readFileSync as readFileSync$1 } from "fs";
11
11
  import path$1 from "path";
12
12
  import { farmRouteRuleMatches, generateFarmTypeArtifacts, getDeployTargetForPreset, getFarmDocsRouteTypeEntries, getFarmPresetRuntime, getFarmSourceRoots, getIntegrationSchemas, getPresetForDeployTarget, loadConfig, logger, mergeFarmRouteRuntimeConfigs, normalizeDeployTarget, resolveConfig, resolveDeployConfig, resolveDeployOutputPath, resolveFarmRouteRuleRuntimeConfig, resolveFarmRouteRuntimeConfig, resolveRouteRenderingConfig, scanProgrammaticPagePaths } from "@farm.js/core";
13
- import { spawn, spawnSync } from "node:child_process";
13
+ import { constants } from "os";
14
+ import { spawn as spawn$1, spawnSync } from "node:child_process";
14
15
  import { setTimeout as setTimeout$1 } from "node:timers/promises";
15
16
  import pc from "picocolors";
16
17
  import { Cron } from "croner";
@@ -436,6 +437,77 @@ function getErrorMessage(error) {
436
437
  return error instanceof Error ? error.message : String(error);
437
438
  }
438
439
  //#endregion
440
+ //#region src/start.ts
441
+ var FarmStartError = class extends Error {
442
+ constructor(code, message) {
443
+ super(message);
444
+ this.name = "FarmStartError";
445
+ this.code = code;
446
+ }
447
+ };
448
+ const PLATFORM_HINTS = {
449
+ vercel: "Deploy it with `farm deploy --vercel`",
450
+ cloudflare: "Deploy it with `farm deploy --cloudflare`",
451
+ netlify: "Deploy it with `farm deploy --netlify`"
452
+ };
453
+ async function createFarmStartPlan(options = {}) {
454
+ const root = path$1.resolve(options.root || process.cwd());
455
+ const userConfig = await loadConfig(root, void 0, "production");
456
+ const deployConfig = resolveDeployConfig(userConfig || {});
457
+ const target = deployConfig.target;
458
+ const preset = deployConfig.preset || "node-server";
459
+ const outputDir = resolveDeployOutputPath(root, deployConfig.outputDir);
460
+ if (target && target !== "node") throw new FarmStartError("PLATFORM_TARGET", `The "${target}" target builds platform output with no local server to start. ${PLATFORM_HINTS[target]}, or set deploy.target: "node" in farm.config.ts to self-host.`);
461
+ if (!target) throw new FarmStartError("UNSUPPORTED_PRESET", `Preset "${preset}" has no known local server entry. Set deploy.target: "node" in farm.config.ts to self-host.`);
462
+ const serverEntry = path$1.join(outputDir, "server", "index.mjs");
463
+ if (!existsSync$1(serverEntry)) throw new FarmStartError("MISSING_OUTPUT", `No build output found at ${serverEntry}. Run \`farm build\` first.`);
464
+ const env = {};
465
+ if (options.port !== void 0 && options.port !== "") env.NITRO_PORT = String(options.port);
466
+ if (options.host) env.NITRO_HOST = options.host;
467
+ return {
468
+ root,
469
+ target: "node",
470
+ preset,
471
+ outputDir,
472
+ serverEntry,
473
+ command: {
474
+ command: process.execPath,
475
+ args: [serverEntry]
476
+ },
477
+ env
478
+ };
479
+ }
480
+ async function startFarm(options = {}) {
481
+ const plan = await createFarmStartPlan(options);
482
+ logger.info(`Starting Node server: node ${path$1.relative(plan.root, plan.serverEntry)}`);
483
+ const child = spawn(plan.command.command, plan.command.args, {
484
+ cwd: plan.root,
485
+ stdio: "inherit",
486
+ env: {
487
+ ...process.env,
488
+ ...plan.env
489
+ }
490
+ });
491
+ const forward = (signal) => {
492
+ const handler = () => child.kill(signal);
493
+ process.on(signal, handler);
494
+ return () => process.off(signal, handler);
495
+ };
496
+ const cleanups = [forward("SIGINT"), forward("SIGTERM")];
497
+ try {
498
+ await new Promise((resolve, reject) => {
499
+ child.on("error", reject);
500
+ child.on("exit", (code, signal) => {
501
+ if (signal) process.exitCode = 128 + (constants.signals[signal] ?? 1);
502
+ else if (code !== null) process.exitCode = code;
503
+ resolve();
504
+ });
505
+ });
506
+ } finally {
507
+ for (const cleanup of cleanups) cleanup();
508
+ }
509
+ }
510
+ //#endregion
439
511
  //#region src/preview-gateway.ts
440
512
  const DEFAULT_GATEWAY_URL = "https://preview.farming-labs.dev";
441
513
  const DEFAULT_PREVIEW_DOMAIN = "preview.farming-labs.dev";
@@ -865,7 +937,7 @@ function parsePreviewPublicUrl(output, preferredHostname) {
865
937
  }) || urls[0];
866
938
  }
867
939
  async function runPreviewTunnel(plan, timeoutMs) {
868
- const child = spawn(plan.command, plan.args, {
940
+ const child = spawn$1(plan.command, plan.args, {
869
941
  env: {
870
942
  ...process.env,
871
943
  FARM_PREVIEW_LOCAL_URL: plan.target.localUrl,
@@ -2679,7 +2751,7 @@ function resolveMigrationCommand(root, entry, index) {
2679
2751
  }
2680
2752
  function runMigrationCommand(command) {
2681
2753
  return new Promise((resolve, reject) => {
2682
- const child = spawn(command.command, {
2754
+ const child = spawn$1(command.command, {
2683
2755
  cwd: command.cwd,
2684
2756
  env: {
2685
2757
  ...process.env,
@@ -3249,7 +3321,7 @@ function getDependencySectionFlags(packageManager, section) {
3249
3321
  function runFarmUpgradeCommand(command) {
3250
3322
  return new Promise((resolve, reject) => {
3251
3323
  const executable = process.platform === "win32" ? `${command.command}.cmd` : command.command;
3252
- const child = spawn(executable, command.args, {
3324
+ const child = spawn$1(executable, command.args, {
3253
3325
  cwd: command.cwd,
3254
3326
  env: process.env,
3255
3327
  stdio: "inherit"
@@ -3278,6 +3350,6 @@ function formatError(error) {
3278
3350
  return error instanceof Error ? error.message : String(error);
3279
3351
  }
3280
3352
  //#endregion
3281
- export { FarmDeployError, FarmGeneratedArtifactsStaleError, addFarmIntegration, buildFarm, createFarmDeployPlan, createFarmUpgradePlan, createFrameworkMigrationPlan, createGatewaySession, createPreviewGatewayPlan, createPreviewTunnelPlan, createServer, deployFarm, detectFarmPackageManager, explainFarmRoute, formatFarmCronJobs, formatFarmDeployPlan, formatFarmDoctorReport, formatFarmRouteExplanation, formatFarmUpgradePlan, forwardGatewayRequest, generateFarmArtifacts, getFarmTelemetryConfigFile, getFarmTelemetryStatus, inspectFrameworkMigrations, listFarmCronJobs, listFarmIntegrationProviders, loadFarmCronConfig, migrateFarm, migrateFarmAuth, parsePreviewPublicUrl, previewFarm, resolveCloudflareAgentDeployPlan, resolveFarmCreateAppTelemetryCommand, resolveFarmTelemetryCommand, resolvePreviewTarget, runFarmCronJob, runFarmDoctor, runNativePreviewTunnel, runPreviewGateway, setFarmTelemetryEnabled, showFarmTelemetryNotice, startDevServer, startFarmCronScheduler, trackFarmCommand, trackFarmCreateAppCommand, trackFarmProjectCreated, upgradeFarm };
3353
+ export { FarmDeployError, FarmGeneratedArtifactsStaleError, FarmStartError, addFarmIntegration, buildFarm, createFarmDeployPlan, createFarmStartPlan, createFarmUpgradePlan, createFrameworkMigrationPlan, createGatewaySession, createPreviewGatewayPlan, createPreviewTunnelPlan, createServer, deployFarm, detectFarmPackageManager, explainFarmRoute, formatFarmCronJobs, formatFarmDeployPlan, formatFarmDoctorReport, formatFarmRouteExplanation, formatFarmUpgradePlan, forwardGatewayRequest, generateFarmArtifacts, getFarmTelemetryConfigFile, getFarmTelemetryStatus, inspectFrameworkMigrations, listFarmCronJobs, listFarmIntegrationProviders, loadFarmCronConfig, migrateFarm, migrateFarmAuth, parsePreviewPublicUrl, previewFarm, resolveCloudflareAgentDeployPlan, resolveFarmCreateAppTelemetryCommand, resolveFarmTelemetryCommand, resolvePreviewTarget, runFarmCronJob, runFarmDoctor, runNativePreviewTunnel, runPreviewGateway, setFarmTelemetryEnabled, showFarmTelemetryNotice, startDevServer, startFarm, startFarmCronScheduler, trackFarmCommand, trackFarmCreateAppCommand, trackFarmProjectCreated, upgradeFarm };
3282
3354
 
3283
3355
  //# sourceMappingURL=index.mjs.map