@codemation/cli 0.0.1
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/README.md +148 -0
- package/bin/codemation.js +24 -0
- package/bin/codemation.ts +5 -0
- package/dist/CliBin-vjSSUDWE.js +2304 -0
- package/dist/bin.d.ts +1 -0
- package/dist/bin.js +9 -0
- package/dist/index.d.ts +23456 -0
- package/dist/index.js +4 -0
- package/package.json +56 -0
- package/src/CliBin.ts +17 -0
- package/src/CliProgramFactory.ts +118 -0
- package/src/Program.ts +157 -0
- package/src/bin.ts +6 -0
- package/src/bootstrap/CodemationCliApplicationSession.ts +60 -0
- package/src/build/ConsumerBuildArtifactsPublisher.ts +77 -0
- package/src/build/ConsumerBuildOptionsParser.ts +26 -0
- package/src/commands/BuildCommand.ts +31 -0
- package/src/commands/DbMigrateCommand.ts +19 -0
- package/src/commands/DevCommand.ts +391 -0
- package/src/commands/ServeWebCommand.ts +72 -0
- package/src/commands/ServeWorkerCommand.ts +40 -0
- package/src/commands/UserCreateCommand.ts +25 -0
- package/src/commands/UserListCommand.ts +59 -0
- package/src/commands/devCommandLifecycle.types.ts +32 -0
- package/src/consumer/ConsumerCliTsconfigPreparation.ts +26 -0
- package/src/consumer/ConsumerEnvLoader.ts +47 -0
- package/src/consumer/ConsumerOutputBuilder.ts +898 -0
- package/src/consumer/Loader.ts +8 -0
- package/src/consumer/consumerBuildOptions.types.ts +12 -0
- package/src/database/ConsumerDatabaseConnectionResolver.ts +18 -0
- package/src/database/DatabaseMigrationsApplyService.ts +76 -0
- package/src/database/HostPackageRootResolver.ts +26 -0
- package/src/database/PrismaMigrateDeployInvoker.ts +24 -0
- package/src/dev/Builder.ts +45 -0
- package/src/dev/ConsumerEnvDotenvFilePredicate.ts +12 -0
- package/src/dev/DevAuthSettingsLoader.ts +27 -0
- package/src/dev/DevBootstrapSummaryFetcher.ts +15 -0
- package/src/dev/DevCliBannerRenderer.ts +106 -0
- package/src/dev/DevConsumerPublishBootstrap.ts +30 -0
- package/src/dev/DevHttpProbe.ts +54 -0
- package/src/dev/DevLock.ts +98 -0
- package/src/dev/DevNextHostEnvironmentBuilder.ts +49 -0
- package/src/dev/DevSessionPortsResolver.ts +23 -0
- package/src/dev/DevSessionServices.ts +29 -0
- package/src/dev/DevSourceRestartCoordinator.ts +48 -0
- package/src/dev/DevSourceWatcher.ts +102 -0
- package/src/dev/DevTrackedProcessTreeKiller.ts +107 -0
- package/src/dev/DevelopmentGatewayNotifier.ts +35 -0
- package/src/dev/Factory.ts +7 -0
- package/src/dev/LoopbackPortAllocator.ts +20 -0
- package/src/dev/Runner.ts +7 -0
- package/src/dev/RuntimeToolEntrypointResolver.ts +47 -0
- package/src/dev/WatchRootsResolver.ts +26 -0
- package/src/index.ts +12 -0
- package/src/path/CliPathResolver.ts +41 -0
- package/src/runtime/ListenPortResolver.ts +35 -0
- package/src/runtime/SourceMapNodeOptions.ts +12 -0
- package/src/runtime/TypeScriptRuntimeConfigurator.ts +8 -0
- package/src/user/CliDatabaseUrlDescriptor.ts +33 -0
- package/src/user/LocalUserCreator.ts +29 -0
- package/src/user/UserAdminCliBootstrap.ts +67 -0
- package/src/user/UserAdminCliOptionsParser.ts +24 -0
- package/src/user/UserAdminConsumerDotenvLoader.ts +24 -0
- package/tsconfig.json +10 -0
package/README.md
ADDED
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
# `@codemation/cli`
|
|
2
|
+
|
|
3
|
+
The **Codemation command-line** package: parse arguments, wire a small composition root, and run **build**, **dev**, **serve**, and **user** subcommands against a **consumer project** (your app that defines `codemation.config.ts` and workflows).
|
|
4
|
+
|
|
5
|
+
It is intentionally **thin**: no DI container. [`CliProgramFactory`](./src/CliProgramFactory.ts) is the single place the object graph is constructed; command classes receive dependencies via constructors.
|
|
6
|
+
|
|
7
|
+
---
|
|
8
|
+
|
|
9
|
+
## How it fits in the monorepo
|
|
10
|
+
|
|
11
|
+
The CLI **orchestrates** other packages. It does not embed the full Next UI or engine—it **spawns** or **calls into** them as needed.
|
|
12
|
+
|
|
13
|
+
```text
|
|
14
|
+
Consumer project (your repo)
|
|
15
|
+
├── codemation.config.ts
|
|
16
|
+
├── src/workflows/…
|
|
17
|
+
└── .codemation/output/
|
|
18
|
+
├── build/ ← emitted JS + index.js (after promote)
|
|
19
|
+
├── staging/… ← transient during a build
|
|
20
|
+
└── current.json ← manifest (from publish step, not from ensureBuilt alone)
|
|
21
|
+
▲
|
|
22
|
+
│ paths + env
|
|
23
|
+
│
|
|
24
|
+
┌────────┴────────────────────────────────────────────────────────────┐
|
|
25
|
+
│ @codemation/cli │
|
|
26
|
+
│ │
|
|
27
|
+
│ bin/codemation.js │
|
|
28
|
+
│ │ │
|
|
29
|
+
│ ▼ │
|
|
30
|
+
│ CliBin.run() │
|
|
31
|
+
│ │ │
|
|
32
|
+
│ ▼ │
|
|
33
|
+
│ CliProgramFactory.create() ──► CliProgram.run() (Commander.js) │
|
|
34
|
+
│ │ │ │
|
|
35
|
+
│ │ ├── build → BuildCommand │
|
|
36
|
+
│ │ ├── dev → DevCommand │
|
|
37
|
+
│ │ ├── serve web → ServeWebCommand│
|
|
38
|
+
│ │ ├── serve worker → ServeWorker… │
|
|
39
|
+
│ │ └── user create → UserCreate… │
|
|
40
|
+
│ │ │
|
|
41
|
+
└────────┼────────────────────────────────────────────────────────────┘
|
|
42
|
+
│
|
|
43
|
+
│ uses / spawns
|
|
44
|
+
▼
|
|
45
|
+
┌────────────────────┬─────────────────────┬────────────────────────────┐
|
|
46
|
+
│ @codemation/host │ @codemation/next-host│ @codemation/dev-gateway │
|
|
47
|
+
│ (plugin discovery, │ (production: │ (dev: HTTP gateway binary) │
|
|
48
|
+
│ logging, workflow │ `pnpm exec next │ │
|
|
49
|
+
│ path helpers) │ start` cwd) │ │
|
|
50
|
+
└─────────┬──────────┴──────────┬──────────┴─────────────┬────────────────┘
|
|
51
|
+
│ │ │
|
|
52
|
+
│ │ │
|
|
53
|
+
▼ │ ▼
|
|
54
|
+
┌───────────────────┐ │ ┌─────────────────────┐
|
|
55
|
+
│ Engine & types │ │ │ @codemation/ │
|
|
56
|
+
│ via host (not a │ │ │ runtime-dev │
|
|
57
|
+
│ direct cli dep) │ │ │ (dev child process) │
|
|
58
|
+
└───────────────────┘ │ └─────────────────────┘
|
|
59
|
+
│
|
|
60
|
+
▼
|
|
61
|
+
┌───────────────────┐
|
|
62
|
+
│ @codemation/ │
|
|
63
|
+
│ worker-cli │
|
|
64
|
+
│ (`serve worker`) │
|
|
65
|
+
└───────────────────┘
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
**Reading the diagram**
|
|
69
|
+
|
|
70
|
+
- **Vertical flow**: the binary loads `CliProgramFactory`, builds `CliProgram`, then Commander dispatches to a **command class** (`commands/*`).
|
|
71
|
+
- **Horizontal row**: shared **libraries** the CLI imports for discovery, logging, and path logic; **next-host** is where `serve web` runs the production Next server; **dev-gateway** + **runtime-dev** are the dev-time split (gateway + disposable runtime child).
|
|
72
|
+
- **Consumer tree**: `ConsumerOutputBuilder` transpiles sources into `.codemation/output/build` and writes the entry `index.js`; `ConsumerBuildArtifactsPublisher` writes plugins and updates the manifest consumed by the host at runtime.
|
|
73
|
+
|
|
74
|
+
For **framework author vs consumer** dev modes (`CODEMATION_DEV_MODE`), see [`docs/development-modes.md`](../../docs/development-modes.md) at the repo root.
|
|
75
|
+
|
|
76
|
+
---
|
|
77
|
+
|
|
78
|
+
## Entry points
|
|
79
|
+
|
|
80
|
+
| Entry | Role |
|
|
81
|
+
| ------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
82
|
+
| `bin/codemation.js` (package `"bin"`) | Production entry: loads `reflect-metadata`, runs [`CliBin`](./src/CliBin.ts). |
|
|
83
|
+
| `src/bin.ts` | Bundled bin artifact used by `tsdown` for the same behavior. |
|
|
84
|
+
| Programmatic | Import [`CliProgramFactory`](./src/CliProgramFactory.ts) and `create()`, or compose `CliProgram` with test doubles. Public exports are in [`src/index.ts`](./src/index.ts). |
|
|
85
|
+
|
|
86
|
+
---
|
|
87
|
+
|
|
88
|
+
## Commands (overview)
|
|
89
|
+
|
|
90
|
+
| Command | Purpose |
|
|
91
|
+
| -------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
92
|
+
| `codemation dev` (default) | Dev session: ports, lock, optional UI proxy, spawn **dev-gateway** + **runtime-dev**, watch consumer sources and restart on change. |
|
|
93
|
+
| `codemation build` | Emit consumer output under `.codemation/output/build`, discover plugins, write manifest. |
|
|
94
|
+
| `codemation serve web` | Run consumer build if needed, then **`next start`** from `@codemation/next-host` with env pointing at the manifest. |
|
|
95
|
+
| `codemation serve worker` | Spawn **`@codemation/worker-cli`** in the consumer root. |
|
|
96
|
+
| `codemation user create` | Create/update a DB user when auth is local (uses consumer config / `DATABASE_URL`). Dispatches `UpsertLocalBootstrapUserCommand` via the host `CommandBus` (password minimum 8 characters, same as invite acceptance). |
|
|
97
|
+
| `codemation user list` | List users via `ListUserAccountsQuery` and the host `QueryBus` (same auth/DB requirements as `user create`). |
|
|
98
|
+
|
|
99
|
+
Programmatic bootstrap: [`CodemationCliApplicationSession`](./src/bootstrap/CodemationCliApplicationSession.ts) opens `CodemationApplication` with `bootCli` (no HTTP/WebSocket); use `getCommandBus()` for other admin commands later.
|
|
100
|
+
|
|
101
|
+
Use `codemation --help` and `codemation <command> --help` for flags (`--consumer-root`, build targets, etc.).
|
|
102
|
+
|
|
103
|
+
---
|
|
104
|
+
|
|
105
|
+
## Consumer build pipeline (summary)
|
|
106
|
+
|
|
107
|
+
1. **`ConsumerOutputBuilder.ensureBuilt()`** discovers config and workflows, transpiles with TypeScript, stages under `.codemation/output/staging/<version>-<uuid>/`, then **renames** to `.codemation/output/build/` (atomic promote).
|
|
108
|
+
2. **Watch** (dev): debounced chokidar rebuilds; incremental builds copy forward from the last promoted `build/` when possible.
|
|
109
|
+
3. **Publish** (`ConsumerBuildArtifactsPublisher`): writes `plugins.js` and **`current.json`** manifest (build version, paths). The host reads the manifest path from env when you run `serve web` or dev.
|
|
110
|
+
|
|
111
|
+
---
|
|
112
|
+
|
|
113
|
+
## Production-oriented build flags
|
|
114
|
+
|
|
115
|
+
`codemation build` and `codemation serve web` (consumer build step) accept:
|
|
116
|
+
|
|
117
|
+
| Flag | Purpose |
|
|
118
|
+
| ----------------------------- | ------------------------------------------------------------- |
|
|
119
|
+
| `--no-source-maps` | Omit `.js.map` next to emitted workflow modules. |
|
|
120
|
+
| `--target es2020` \| `es2022` | ECMAScript target for emitted workflow JS (default `es2022`). |
|
|
121
|
+
|
|
122
|
+
Programmatically, map the same flags with [`ConsumerBuildOptionsParser`](./src/build/ConsumerBuildOptionsParser.ts) or pass [`ConsumerBuildOptions`](./src/consumer/consumerBuildOptions.types.ts) into [`ConsumerOutputBuilder`](./src/consumer/ConsumerOutputBuilder.ts).
|
|
123
|
+
|
|
124
|
+
---
|
|
125
|
+
|
|
126
|
+
## Tests
|
|
127
|
+
|
|
128
|
+
Unit tests live under `test/` (Vitest).
|
|
129
|
+
|
|
130
|
+
```bash
|
|
131
|
+
pnpm --filter @codemation/cli test
|
|
132
|
+
```
|
|
133
|
+
|
|
134
|
+
From the repository root they are also included in the shared unit suite:
|
|
135
|
+
|
|
136
|
+
```bash
|
|
137
|
+
pnpm run test:unit
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
### What is covered
|
|
141
|
+
|
|
142
|
+
- **`ConsumerBuildOptionsParser`**: maps CLI flags (`--no-source-maps`, `--target`) to `ConsumerBuildOptions`.
|
|
143
|
+
- **`ConsumerOutputBuilder` + build options**: default build emits `.js.map` for transpiled workflows; `sourceMaps: false` omits them.
|
|
144
|
+
- **`ConsumerOutputBuilder`**
|
|
145
|
+
- **Full build** (`ensureBuilt`): stage under `.codemation/output/staging/…`, then promote to `.codemation/output/build/`.
|
|
146
|
+
- **Watch + incremental**: after a full build, a single workflow file change triggers a rebuild promoted to the same `build/` path (chokidar + debounce; tests set `CHOKIDAR_USEPOLLING`).
|
|
147
|
+
|
|
148
|
+
Tests use a temporary consumer fixture (`codemation.config.ts` + `src/workflows`) and do not mock TypeScript transpilation or host discovery helpers.
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { spawn } from "node:child_process";
|
|
3
|
+
import path from "node:path";
|
|
4
|
+
import process from "node:process";
|
|
5
|
+
import { fileURLToPath } from "node:url";
|
|
6
|
+
|
|
7
|
+
const thisDirectory = path.dirname(fileURLToPath(import.meta.url));
|
|
8
|
+
const entrypointPath = path.resolve(thisDirectory, "..", "dist", "bin.js");
|
|
9
|
+
const childProcess = spawn(process.execPath, [entrypointPath, ...process.argv.slice(2)], {
|
|
10
|
+
stdio: "inherit",
|
|
11
|
+
env: process.env,
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
for (const signal of ["SIGINT", "SIGTERM", "SIGQUIT"]) {
|
|
15
|
+
process.on(signal, () => {
|
|
16
|
+
if (childProcess.exitCode === null) {
|
|
17
|
+
childProcess.kill(signal);
|
|
18
|
+
}
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
childProcess.on("exit", (code) => {
|
|
23
|
+
process.exit(code ?? 0);
|
|
24
|
+
});
|