@bakery-framework/cli 2.0.0 → 2.0.2

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bakery-framework/cli",
3
- "version": "2.0.0",
3
+ "version": "2.0.2",
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"
42
+ "@bakery-framework/core": "^2.0.2"
43
43
  },
44
44
  "peerDependencies": {
45
- "@bakery-framework/orm": "^2.0.0"
45
+ "@bakery-framework/orm": "^2.0.2"
46
46
  },
47
47
  "peerDependenciesMeta": {
48
48
  "@bakery-framework/orm": {
package/src/index.ts CHANGED
@@ -30,6 +30,7 @@ const threadsOption = parseThreadsOption(process.argv.slice(2))
30
30
  if (process.argv.includes('--help') || process.argv.includes('-h')) {
31
31
  console.log(`
32
32
  Usage: bakery [--dev] [--sync] [--threads N] [--port N]
33
+ bakery --types
33
34
 
34
35
  Runs the application in the current directory: the one whose
35
36
  \`server.config.ts\` sits beside it.
@@ -37,6 +38,10 @@ Runs the application in the current directory: the one whose
37
38
  Flags:
38
39
  --dev Development: a supervisor that watches files, compiles on
39
40
  demand and reloads the browser. Without it, production.
41
+ --types Write the TypeScript projects (.cache/tsconfig/ and
42
+ tsconfig.bakery.json) and exit, without starting a server.
43
+ Every dev boot does the same; a fresh clone or a CI job
44
+ needs it before tsc can find them.
40
45
  --sync, -s Run the schema sync before starting. Requires
41
46
  @bakery-framework/orm; it is an error rather than a skip
42
47
  when that is missing, because asking for a sync and
@@ -52,6 +57,13 @@ Schema commands have their own help: \`bun run db:sync --help\`.
52
57
  process.exit(0)
53
58
  }
54
59
 
60
+ // Before any mode takes over, for the same reason as `--help`: it is a
61
+ // command, not a server, and every branch below starts one.
62
+ if (process.argv.includes('--types')) {
63
+ const { writeTypes } = await import('./write-types')
64
+ process.exit(await writeTypes())
65
+ }
66
+
55
67
  // Before any mode takes over, and before the config is read: `applyPortFlag`
56
68
  // writes `process.env.PORT`, which is what the worker, the startup banner and
57
69
  // the dev master's advertised URL all resolve from, and what the spawned dev
@@ -0,0 +1,56 @@
1
+ import { errorMsg, serveLog } from '@bakery-framework/core/logger'
2
+
3
+ /**
4
+ * `bakery --types`: the TypeScript projects a dev boot writes, without the boot.
5
+ *
6
+ * The app's `tsconfig.json` reaches its scope projects through
7
+ * `tsconfig.bakery.json`, and both that file and `.cache/tsconfig/` are
8
+ * generated. A fresh clone has neither, so `tsc` stops at TS6053 and an editor
9
+ * leaves every file in an inferred project until something writes them. This
10
+ * is that something, for a clone, a CI job or a `typecheck` script.
11
+ *
12
+ * **Not the whole dev init.** `dev.ts` runs `setupPlugins()` first because a
13
+ * plugin's `setup()` may add import-map entries, but a setup also does work
14
+ * (analytics registers a shutdown hook and starts loading its data), and
15
+ * nothing a setup adds today changes what this writes: the one plugin that
16
+ * touches the import map, plugin-vue, maps a served URL, which the paths sync
17
+ * skips. The projects come from each plugin's `tsconfig.project`, which is on
18
+ * the config and needs no setup.
19
+ *
20
+ * **It checks its own result.** `syncTSConfigProjects` logs a failure rather
21
+ * than throwing, so a dev boot never dies over a tsconfig, and that would let
22
+ * this exit 0 having written nothing: a step a CI job trusts, passing when it
23
+ * did not work. So the chain file is read back, and every project it lists
24
+ * has to exist.
25
+ *
26
+ * Returns the exit code.
27
+ */
28
+ export async function writeTypes(): Promise<number> {
29
+ try {
30
+ const { initConfig } = await import('@bakery-framework/core/core/config')
31
+ const { syncTSConfigPaths, syncTSConfigProjects } = await import(
32
+ '@bakery-framework/core/compiler/tsconfig-sync'
33
+ )
34
+
35
+ await initConfig()
36
+ await syncTSConfigPaths()
37
+ await syncTSConfigProjects()
38
+
39
+ const chain = Bun.file(`${process.cwd()}/tsconfig.bakery.json`)
40
+ if (!(await chain.exists())) {
41
+ throw new Error('tsconfig.bakery.json was not written')
42
+ }
43
+ const { references } = (await chain.json()) as {
44
+ references?: { path: string }[]
45
+ }
46
+ for (const { path } of references ?? []) {
47
+ if (!(await Bun.file(`${process.cwd()}/${path}`).exists())) {
48
+ throw new Error(`${path} is listed in tsconfig.bakery.json but missing`)
49
+ }
50
+ }
51
+ return 0
52
+ } catch (error: any) {
53
+ serveLog.UNHANDLED_ERR({ error: `bakery --types: ${errorMsg(error)}` })
54
+ return 1
55
+ }
56
+ }