@bakery-framework/cli 2.0.0-alpha.12 → 2.0.0-alpha.14

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.
Files changed (2) hide show
  1. package/package.json +3 -3
  2. package/src/index.ts +48 -0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bakery-framework/cli",
3
- "version": "2.0.0-alpha.12",
3
+ "version": "2.0.0-alpha.14",
4
4
  "description": "Bakery entry point and process supervision: mode dispatch, dev watcher, cluster.",
5
5
  "keywords": [
6
6
  "bakery",
@@ -39,10 +39,10 @@
39
39
  "bun": ">=1.4.0"
40
40
  },
41
41
  "dependencies": {
42
- "@bakery-framework/core": "^2.0.0-alpha.12"
42
+ "@bakery-framework/core": "^2.0.0-alpha.14"
43
43
  },
44
44
  "peerDependencies": {
45
- "@bakery-framework/orm": "^2.0.0-alpha.12"
45
+ "@bakery-framework/orm": "^2.0.0-alpha.14"
46
46
  },
47
47
  "peerDependenciesMeta": {
48
48
  "@bakery-framework/orm": {
package/src/index.ts CHANGED
@@ -14,6 +14,44 @@ const isThreadWorker = import.meta.env.THREAD_WORKER
14
14
 
15
15
  const threadsOption = parseThreadsOption(process.argv.slice(2))
16
16
 
17
+ /**
18
+ * `--help` before anything else, because everything else starts a server.
19
+ *
20
+ * There was no help branch at all: `bakery --help` fell through to `./prod`,
21
+ * booted a production server, bound the configured port and sat there. On a
22
+ * machine where that port is already taken it fails with a bind error, and on
23
+ * one where it is free it silently *takes* it — either way the user asked what
24
+ * the flags were and got a running service.
25
+ *
26
+ * Printed with `console.log` and not the structured logger, for the reason
27
+ * CLAUDE.md records as one of the two standing exceptions: usage text is
28
+ * program output, not a log line, and it goes to stdout so it can be piped.
29
+ */
30
+ if (process.argv.includes('--help') || process.argv.includes('-h')) {
31
+ console.log(`
32
+ Usage: bakery [--dev] [--sync] [--threads N] [--port N]
33
+
34
+ Runs the application in the current directory — the one whose
35
+ \`server.config.ts\` sits beside it.
36
+
37
+ Flags:
38
+ --dev Development: a supervisor that watches files, compiles on
39
+ demand and reloads the browser. Without it, production.
40
+ --sync, -s Run the schema sync before starting. Requires
41
+ @bakery-framework/orm; it is an error rather than a skip
42
+ when that is missing, because asking for a sync and
43
+ silently not doing one looks like it worked.
44
+ --threads N, -t N Fork a cluster of N workers. Production only — ignored
45
+ under --dev. THREAD_ID 0 owns the startup banner.
46
+ --port N, -p N Listening port. Overrides \`port\` in server.config.ts and
47
+ the PORT environment variable.
48
+ --help, -h This.
49
+
50
+ Schema commands have their own help: \`bun run db:sync --help\`.
51
+ `)
52
+ process.exit(0)
53
+ }
54
+
17
55
  // Before any mode takes over, and before the config is read: `applyPortFlag`
18
56
  // writes `process.env.PORT`, which is what the worker, the startup banner and
19
57
  // the dev master's advertised URL all resolve from — and what the spawned dev
@@ -23,6 +61,16 @@ applyPortFlag()
23
61
 
24
62
  if (
25
63
  (process.argv.includes('--sync') || process.argv.includes('-s')) &&
64
+ // **Not in development, where `dev.ts` owns the decision.** Under `--dev`
65
+ // this file is the watcher master, which then spawns a `--dev-worker` that
66
+ // reaches `dev.ts` — and that path reads `--sync` as `force`, hashes the
67
+ // schema sources, decides skip-or-run against the recorded hash and writes
68
+ // the new one. Running here as well meant `--dev --sync` synced twice per
69
+ // boot: once blindly in the master and once properly in the worker, against
70
+ // the same database, with the master's pass doing work the worker was about
71
+ // to redo. Production keeps this branch, because `prod.ts` does not sync at
72
+ // all and this is the only thing that answers `--sync` there.
73
+ !isDev &&
26
74
  !isDevWorker &&
27
75
  !isThreadWorker
28
76
  ) {