@farm.js/cli 0.1.0-beta.54 → 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/bin/farm.js +18 -0
- package/dist/index.js +75 -0
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +78 -6
- package/dist/index.mjs.map +1 -1
- package/dist/telemetry.js +1 -0
- package/dist/telemetry.js.map +1 -1
- package/dist/telemetry.mjs +1 -0
- package/dist/telemetry.mjs.map +1 -1
- package/package.json +2 -2
package/bin/farm.js
CHANGED
|
@@ -123,6 +123,24 @@ program
|
|
|
123
123
|
}
|
|
124
124
|
});
|
|
125
125
|
|
|
126
|
+
program
|
|
127
|
+
.command("start")
|
|
128
|
+
.description("Run the Node server produced by farm build")
|
|
129
|
+
.option("-r, --root <root>", "Root directory", process.cwd())
|
|
130
|
+
.option("-p, --port <port>", "Port for the server to listen on")
|
|
131
|
+
.option("-H, --host <host>", "Host for the server to bind to")
|
|
132
|
+
.action(async (options) => {
|
|
133
|
+
try {
|
|
134
|
+
const { startFarm } = require("../dist/index.js");
|
|
135
|
+
await startFarm(options);
|
|
136
|
+
} catch (error) {
|
|
137
|
+
const code = error?.name === "FarmStartError" ? ` [${error.code}]` : "";
|
|
138
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
139
|
+
console.error(`Failed to start${code}: ${message}`);
|
|
140
|
+
process.exitCode = 1;
|
|
141
|
+
}
|
|
142
|
+
});
|
|
143
|
+
|
|
126
144
|
const authCommand = program.command("auth").description("Manage Farm-native authentication");
|
|
127
145
|
|
|
128
146
|
authCommand
|
package/dist/index.js
CHANGED
|
@@ -13,6 +13,7 @@ let fs = require("fs");
|
|
|
13
13
|
let path = require("path");
|
|
14
14
|
path = require_rolldown_runtime.__toESM(path);
|
|
15
15
|
let _farm_js_core = require("@farm.js/core");
|
|
16
|
+
let os = require("os");
|
|
16
17
|
let node_child_process = require("node:child_process");
|
|
17
18
|
let node_timers_promises = require("node:timers/promises");
|
|
18
19
|
let picocolors = require("picocolors");
|
|
@@ -438,6 +439,77 @@ function getErrorMessage(error) {
|
|
|
438
439
|
return error instanceof Error ? error.message : String(error);
|
|
439
440
|
}
|
|
440
441
|
//#endregion
|
|
442
|
+
//#region src/start.ts
|
|
443
|
+
var FarmStartError = class extends Error {
|
|
444
|
+
constructor(code, message) {
|
|
445
|
+
super(message);
|
|
446
|
+
this.name = "FarmStartError";
|
|
447
|
+
this.code = code;
|
|
448
|
+
}
|
|
449
|
+
};
|
|
450
|
+
const PLATFORM_HINTS = {
|
|
451
|
+
vercel: "Deploy it with `farm deploy --vercel`",
|
|
452
|
+
cloudflare: "Deploy it with `farm deploy --cloudflare`",
|
|
453
|
+
netlify: "Deploy it with `farm deploy --netlify`"
|
|
454
|
+
};
|
|
455
|
+
async function createFarmStartPlan(options = {}) {
|
|
456
|
+
const root = path.default.resolve(options.root || process.cwd());
|
|
457
|
+
const userConfig = await (0, _farm_js_core.loadConfig)(root, void 0, "production");
|
|
458
|
+
const deployConfig = (0, _farm_js_core.resolveDeployConfig)(userConfig || {});
|
|
459
|
+
const target = deployConfig.target;
|
|
460
|
+
const preset = deployConfig.preset || "node-server";
|
|
461
|
+
const outputDir = (0, _farm_js_core.resolveDeployOutputPath)(root, deployConfig.outputDir);
|
|
462
|
+
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.`);
|
|
463
|
+
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.`);
|
|
464
|
+
const serverEntry = path.default.join(outputDir, "server", "index.mjs");
|
|
465
|
+
if (!(0, fs.existsSync)(serverEntry)) throw new FarmStartError("MISSING_OUTPUT", `No build output found at ${serverEntry}. Run \`farm build\` first.`);
|
|
466
|
+
const env = {};
|
|
467
|
+
if (options.port !== void 0 && options.port !== "") env.NITRO_PORT = String(options.port);
|
|
468
|
+
if (options.host) env.NITRO_HOST = options.host;
|
|
469
|
+
return {
|
|
470
|
+
root,
|
|
471
|
+
target: "node",
|
|
472
|
+
preset,
|
|
473
|
+
outputDir,
|
|
474
|
+
serverEntry,
|
|
475
|
+
command: {
|
|
476
|
+
command: process.execPath,
|
|
477
|
+
args: [serverEntry]
|
|
478
|
+
},
|
|
479
|
+
env
|
|
480
|
+
};
|
|
481
|
+
}
|
|
482
|
+
async function startFarm(options = {}) {
|
|
483
|
+
const plan = await createFarmStartPlan(options);
|
|
484
|
+
_farm_js_core.logger.info(`Starting Node server: node ${path.default.relative(plan.root, plan.serverEntry)}`);
|
|
485
|
+
const child = (0, child_process.spawn)(plan.command.command, plan.command.args, {
|
|
486
|
+
cwd: plan.root,
|
|
487
|
+
stdio: "inherit",
|
|
488
|
+
env: {
|
|
489
|
+
...process.env,
|
|
490
|
+
...plan.env
|
|
491
|
+
}
|
|
492
|
+
});
|
|
493
|
+
const forward = (signal) => {
|
|
494
|
+
const handler = () => child.kill(signal);
|
|
495
|
+
process.on(signal, handler);
|
|
496
|
+
return () => process.off(signal, handler);
|
|
497
|
+
};
|
|
498
|
+
const cleanups = [forward("SIGINT"), forward("SIGTERM")];
|
|
499
|
+
try {
|
|
500
|
+
await new Promise((resolve, reject) => {
|
|
501
|
+
child.on("error", reject);
|
|
502
|
+
child.on("exit", (code, signal) => {
|
|
503
|
+
if (signal) process.exitCode = 128 + (os.constants.signals[signal] ?? 1);
|
|
504
|
+
else if (code !== null) process.exitCode = code;
|
|
505
|
+
resolve();
|
|
506
|
+
});
|
|
507
|
+
});
|
|
508
|
+
} finally {
|
|
509
|
+
for (const cleanup of cleanups) cleanup();
|
|
510
|
+
}
|
|
511
|
+
}
|
|
512
|
+
//#endregion
|
|
441
513
|
//#region src/preview-gateway.ts
|
|
442
514
|
const DEFAULT_GATEWAY_URL = "https://preview.farming-labs.dev";
|
|
443
515
|
const DEFAULT_PREVIEW_DOMAIN = "preview.farming-labs.dev";
|
|
@@ -3282,9 +3354,11 @@ function formatError(error) {
|
|
|
3282
3354
|
//#endregion
|
|
3283
3355
|
exports.FarmDeployError = FarmDeployError;
|
|
3284
3356
|
exports.FarmGeneratedArtifactsStaleError = FarmGeneratedArtifactsStaleError;
|
|
3357
|
+
exports.FarmStartError = FarmStartError;
|
|
3285
3358
|
exports.addFarmIntegration = require_add_integration.addFarmIntegration;
|
|
3286
3359
|
exports.buildFarm = require_build.buildFarm;
|
|
3287
3360
|
exports.createFarmDeployPlan = createFarmDeployPlan;
|
|
3361
|
+
exports.createFarmStartPlan = createFarmStartPlan;
|
|
3288
3362
|
exports.createFarmUpgradePlan = createFarmUpgradePlan;
|
|
3289
3363
|
exports.createFrameworkMigrationPlan = createFrameworkMigrationPlan;
|
|
3290
3364
|
exports.createGatewaySession = createGatewaySession;
|
|
@@ -3332,6 +3406,7 @@ Object.defineProperty(exports, "startDevServer", {
|
|
|
3332
3406
|
return _farm_js_core_server.startDevServer;
|
|
3333
3407
|
}
|
|
3334
3408
|
});
|
|
3409
|
+
exports.startFarm = startFarm;
|
|
3335
3410
|
exports.startFarmCronScheduler = startFarmCronScheduler;
|
|
3336
3411
|
exports.trackFarmCommand = require_telemetry.trackFarmCommand;
|
|
3337
3412
|
exports.trackFarmCreateAppCommand = require_telemetry.trackFarmCreateAppCommand;
|