@farm.js/cli 0.1.0-beta.6 → 0.1.0-beta.60

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 CHANGED
@@ -16,20 +16,58 @@ const { program } = require("commander");
16
16
  const { version } = require("../package.json");
17
17
 
18
18
  const banner = `
19
- _______
20
- | ___ |__ _ _ __ _ __ ___
21
- | |_ /| / _\` | '__| '_ \` _ \\
22
- | _ \\| | (_| | | | | | | | |
23
- |_| \\_\\_|\\__,_|_| |_| |_| |_|
19
+ ░██████████ ░███ ░█████████ ░███ ░███ ░█████ ░██████
20
+ ░██ ░██░██ ░██ ░██ ░████ ░████ ░██ ░██ ░██
21
+ ░██ ░██ ░██ ░██ ░██ ░██░██ ░██░██ ░██ ░██
22
+ ░█████████ ░█████████ ░█████████ ░██ ░████ ░██ ░██ ░████████
23
+ ░██ ░██ ░██ ░██ ░██ ░██ ░██ ░██ ░██ ░██ ░██
24
+ ░██ ░██ ░██ ░██ ░██ ░██ ░██ ░██ ░██ ░██ ░██
25
+ ░██ ░██ ░██ ░██ ░██ ░██ ░██ ░██ ░██████ ░██████
24
26
  `;
25
27
 
26
- program.name("farm").description("Farm.js CLI - A modern React meta-framework").version(version);
28
+ program
29
+ .name("farm")
30
+ .description("Farm.js CLI - A framework for product-integrated apps")
31
+ .version(version);
27
32
  program.addHelpText("beforeAll", `${banner}\n`);
28
33
 
29
34
  function collectOption(value, previous) {
30
35
  return [...(previous || []), value];
31
36
  }
32
37
 
38
+ function telemetryCommandPath(command) {
39
+ const segments = [];
40
+ let current = command;
41
+ while (current && current !== program) {
42
+ segments.unshift(current.name());
43
+ current = current.parent;
44
+ }
45
+ return segments.join(":");
46
+ }
47
+
48
+ function telemetryDeployTarget(commandPath, options) {
49
+ if (commandPath !== "deploy") return undefined;
50
+ if (options.vercel) return "vercel";
51
+ if (options.cloudflare) return "cloudflare";
52
+ if (options.netlify) return "netlify";
53
+ if (options.custom) return "custom";
54
+ return undefined;
55
+ }
56
+
57
+ program.hook("preAction", (_command, actionCommand) => {
58
+ const commandPath = telemetryCommandPath(actionCommand);
59
+ if (commandPath.startsWith("telemetry")) return;
60
+ const { resolveFarmTelemetryCommand, trackFarmCommand } = require("../dist/telemetry.js");
61
+ const command = resolveFarmTelemetryCommand(commandPath);
62
+ if (!command) return;
63
+ const options = actionCommand.opts();
64
+ void trackFarmCommand({
65
+ command,
66
+ packageVersion: version,
67
+ deployTarget: telemetryDeployTarget(commandPath, options),
68
+ });
69
+ });
70
+
33
71
  program
34
72
  .command("dev")
35
73
  .description("Start development server")
@@ -80,6 +118,24 @@ program
80
118
  }
81
119
  });
82
120
 
121
+ program
122
+ .command("start")
123
+ .description("Run the Node server produced by farm build")
124
+ .option("-r, --root <root>", "Root directory", process.cwd())
125
+ .option("-p, --port <port>", "Port for the server to listen on")
126
+ .option("-H, --host <host>", "Host for the server to bind to")
127
+ .action(async (options) => {
128
+ try {
129
+ const { startFarm } = require("../dist/index.js");
130
+ await startFarm(options);
131
+ } catch (error) {
132
+ const code = error?.name === "FarmStartError" ? ` [${error.code}]` : "";
133
+ const message = error instanceof Error ? error.message : String(error);
134
+ console.error(`Failed to start${code}: ${message}`);
135
+ process.exitCode = 1;
136
+ }
137
+ });
138
+
83
139
  const authCommand = program.command("auth").description("Manage Farm-native authentication");
84
140
 
85
141
  authCommand
@@ -144,6 +200,7 @@ program
144
200
  )
145
201
  .option("--dialect <dialect>", "SQL dialect for Drizzle generation (postgres, mysql, sqlite)")
146
202
  .option("-o, --output <output>", "Custom output path")
203
+ .option("--check", "Fail when committed generated framework types are stale")
147
204
  .action(async (options) => {
148
205
  try {
149
206
  const { generateFarmArtifacts } = require("../dist/index.js");
@@ -153,6 +210,7 @@ program
153
210
  orm: options.orm,
154
211
  dialect: options.dialect,
155
212
  output: options.output,
213
+ check: options.check,
156
214
  });
157
215
  } catch (error) {
158
216
  console.error("Failed to generate Farm artifacts:", error);
@@ -169,6 +227,7 @@ program
169
227
  .option("--host <host>", "Host of a running local app")
170
228
  .option("--url <url>", "Base URL of a running Farm app")
171
229
  .option("--offline", "Inspect project files without probing a running app")
230
+ .option("--fix", "Apply safe additive corrections without overwriting application files")
172
231
  .option("--timeout <ms>", "Live runtime probe timeout in milliseconds", "1200")
173
232
  .option("--json", "Print machine-readable JSON")
174
233
  .action(async (options) => {
@@ -185,6 +244,7 @@ program
185
244
  host: options.host,
186
245
  url: options.url,
187
246
  offline: options.offline,
247
+ fix: options.fix,
188
248
  timeoutMs,
189
249
  });
190
250
  console.log(options.json ? JSON.stringify(report, null, 2) : formatFarmDoctorReport(report));
@@ -195,6 +255,30 @@ program
195
255
  }
196
256
  });
197
257
 
258
+ program
259
+ .command("explain <path>")
260
+ .description("Explain how a URL maps to a Farm route and deployment runtime")
261
+ .option("-r, --root <root>", "Root directory", process.cwd())
262
+ .option("-c, --config <config>", "Path to farm config file")
263
+ .option("--json", "Print machine-readable JSON")
264
+ .action(async (pathname, options) => {
265
+ try {
266
+ const { explainFarmRoute, formatFarmRouteExplanation } = require("../dist/index.js");
267
+ const explanation = await explainFarmRoute(pathname, {
268
+ root: options.root,
269
+ configPath: options.config,
270
+ });
271
+ console.log(
272
+ options.json
273
+ ? JSON.stringify(explanation, null, 2)
274
+ : formatFarmRouteExplanation(explanation),
275
+ );
276
+ } catch (error) {
277
+ console.error("Failed to explain Farm route:", error);
278
+ process.exit(1);
279
+ }
280
+ });
281
+
198
282
  program
199
283
  .command("preview")
200
284
  .description("Create a public URL for a running local Farm app")
@@ -433,15 +517,63 @@ program
433
517
  .option("--cloudflare", "Deploy to Cloudflare")
434
518
  .option("--netlify", "Deploy to Netlify")
435
519
  .option("--prod", "Deploy to production (Vercel: uses prebuilt output)")
520
+ .option("--plan", "Print the resolved deployment plan without building or deploying")
436
521
  .option("--custom", "Use your own credentials (not Farm.js managed)")
437
522
  .action(async (options) => {
438
523
  try {
439
524
  const { deployFarm } = require("../dist/index.js");
440
525
  await deployFarm(options);
441
526
  } catch (error) {
442
- console.error("Failed to deploy:", error);
443
- process.exit(1);
527
+ const code = error?.name === "FarmDeployError" ? ` [${error.code}]` : "";
528
+ const message = error instanceof Error ? error.message : String(error);
529
+ console.error(`Failed to deploy${code}: ${message}`);
530
+ process.exitCode = 1;
531
+ }
532
+ });
533
+
534
+ const telemetryCommand = program
535
+ .command("telemetry")
536
+ .description("Control anonymous Farm.js product telemetry");
537
+
538
+ telemetryCommand
539
+ .command("status")
540
+ .description("Show the current telemetry setting")
541
+ .action(async () => {
542
+ const { getFarmTelemetryStatus } = require("../dist/telemetry.js");
543
+ const status = await getFarmTelemetryStatus();
544
+ console.log(`Anonymous telemetry: ${status.enabled ? "enabled" : "disabled"}`);
545
+ console.log(`Active for this command: ${status.active ? "yes" : "no"}`);
546
+ console.log(`Setting source: ${status.source}`);
547
+ if (status.reason) console.log(`Reason: ${status.reason}`);
548
+ console.log(`Local anonymous ID: ${status.anonymousId ? "created" : "not created"}`);
549
+ console.log(`Configuration: ${status.configFile}`);
550
+ console.log("Privacy details: https://farmjs.dev/docs/telemetry");
551
+ });
552
+
553
+ telemetryCommand
554
+ .command("enable")
555
+ .description("Enable anonymous Farm.js product telemetry")
556
+ .action(async () => {
557
+ const { setFarmTelemetryEnabled } = require("../dist/telemetry.js");
558
+ const status = await setFarmTelemetryEnabled(true);
559
+ console.log("Anonymous Farm.js telemetry is enabled.");
560
+ if (!status.active && status.reason)
561
+ console.log(`It is inactive here because ${status.reason}.`);
562
+ });
563
+
564
+ telemetryCommand
565
+ .command("disable")
566
+ .description("Opt out and delete the local anonymous installation ID")
567
+ .action(async () => {
568
+ const { setFarmTelemetryEnabled } = require("../dist/telemetry.js");
569
+ const status = await setFarmTelemetryEnabled(false);
570
+ console.log("Anonymous Farm.js telemetry is disabled and its local ID was deleted.");
571
+ if (status.enabled) {
572
+ console.log("An environment variable currently overrides the saved setting.");
444
573
  }
445
574
  });
446
575
 
447
- program.parse();
576
+ program.parseAsync().catch((error) => {
577
+ console.error("Farm CLI failed:", error);
578
+ process.exitCode = 1;
579
+ });