@celljs/cli 4.2.0 → 4.4.0
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 +32 -25
- package/agent/guide.md +16 -5
- package/docs/coding-agents.md +79 -0
- package/docs/components.md +157 -0
- package/docs/deployment.md +111 -0
- package/docs/frontend.md +180 -0
- package/docs/getting-started.md +159 -0
- package/docs/packages.md +94 -0
- package/docs/project.md +181 -0
- package/docs/testing.md +78 -0
- package/docs/web.md +168 -0
- package/lib/agent/agent-guide.js +1 -1
- package/lib/agent/agent-guide.js.map +1 -1
- package/lib/build/single-compile.spec.js +2 -2
- package/lib/build/single-compile.spec.js.map +1 -1
- package/lib/check/project-checker.d.ts +20 -0
- package/lib/check/project-checker.d.ts.map +1 -1
- package/lib/check/project-checker.js +87 -23
- package/lib/check/project-checker.js.map +1 -1
- package/lib/check/project-checker.spec.js +19 -3
- package/lib/check/project-checker.spec.js.map +1 -1
- package/lib/cli/build-command.js +2 -2
- package/lib/cli/build-command.js.map +1 -1
- package/lib/cli/cell-cli.spec.js +12 -12
- package/lib/cli/cell-cli.spec.js.map +1 -1
- package/lib/cli/config-command.d.ts +3 -3
- package/lib/cli/config-command.d.ts.map +1 -1
- package/lib/cli/config-command.js +12 -8
- package/lib/cli/config-command.js.map +1 -1
- package/lib/cli/config-command.spec.js +38 -26
- package/lib/cli/config-command.spec.js.map +1 -1
- package/lib/cli/dev-command.js +2 -2
- package/lib/cli/dev-command.js.map +1 -1
- package/lib/cli/dev-command.spec.js +7 -7
- package/lib/cli/dev-command.spec.js.map +1 -1
- package/lib/cli/docs-command.d.ts +3 -2
- package/lib/cli/docs-command.d.ts.map +1 -1
- package/lib/cli/docs-command.js +3 -2
- package/lib/cli/docs-command.js.map +1 -1
- package/lib/cli/info-command.spec.js +28 -26
- package/lib/cli/info-command.spec.js.map +1 -1
- package/lib/cli/mcp-command.spec.js +5 -5
- package/lib/cli/mcp-command.spec.js.map +1 -1
- package/lib/cli/preview-command.js +3 -3
- package/lib/cli/preview-command.js.map +1 -1
- package/lib/config/config-build.spec.js +4 -4
- package/lib/config/config-build.spec.js.map +1 -1
- package/lib/config/config-explainer.d.ts +16 -11
- package/lib/config/config-explainer.d.ts.map +1 -1
- package/lib/config/config-explainer.js +31 -29
- package/lib/config/config-explainer.js.map +1 -1
- package/lib/docs/docs-index.d.ts +4 -1
- package/lib/docs/docs-index.d.ts.map +1 -1
- package/lib/docs/docs-index.js +6 -1
- package/lib/docs/docs-index.js.map +1 -1
- package/lib/docs/docs-index.spec.js +14 -4
- package/lib/docs/docs-index.spec.js.map +1 -1
- package/lib/info/project-inspector.d.ts +6 -5
- package/lib/info/project-inspector.d.ts.map +1 -1
- package/lib/info/project-inspector.js +11 -16
- package/lib/info/project-inspector.js.map +1 -1
- package/lib/mcp/dev-mcp-endpoint.js +3 -3
- package/lib/mcp/dev-mcp-endpoint.js.map +1 -1
- package/lib/mcp/dev-mcp-endpoint.spec.js +2 -2
- package/lib/mcp/dev-mcp-endpoint.spec.js.map +1 -1
- package/lib/mcp/project-mcp-tools.js +3 -3
- package/lib/mcp/project-mcp-tools.js.map +1 -1
- package/lib/modules/module-host.spec.js +1 -1
- package/lib/modules/module-host.spec.js.map +1 -1
- package/lib/preset/builtin-presets.d.ts +1 -1
- package/lib/preset/builtin-presets.d.ts.map +1 -1
- package/lib/preset/builtin-presets.js +1 -1
- package/lib/preset/builtin-presets.js.map +1 -1
- package/lib/preset/cloudflare/cloudflare.spec.js +2 -2
- package/lib/preset/cloudflare/cloudflare.spec.js.map +1 -1
- package/lib/preset/serverless-presets.spec.js +3 -3
- package/lib/preset/serverless-presets.spec.js.map +1 -1
- package/lib/preset/serverless-scripts.js +2 -2
- package/lib/preset/serverless-scripts.js.map +1 -1
- package/lib/preset/vercel/vercel-preset.js +2 -2
- package/lib/preset/vercel/vercel-preset.js.map +1 -1
- package/lib/testing/create-test-app.spec.js +5 -5
- package/lib/testing/create-test-app.spec.js.map +1 -1
- package/package.json +9 -8
- package/src/agent/agent-guide.ts +1 -1
- package/src/check/project-checker.ts +93 -22
- package/src/cli/build-command.ts +2 -2
- package/src/cli/config-command.ts +12 -8
- package/src/cli/dev-command.ts +2 -2
- package/src/cli/docs-command.ts +3 -2
- package/src/cli/preview-command.ts +3 -3
- package/src/config/config-explainer.ts +36 -32
- package/src/docs/docs-index.ts +7 -1
- package/src/info/project-inspector.ts +16 -23
- package/src/mcp/dev-mcp-endpoint.ts +3 -3
- package/src/mcp/project-mcp-tools.ts +3 -3
- package/src/preset/builtin-presets.ts +1 -1
- package/src/preset/serverless-scripts.ts +2 -2
- package/src/preset/vercel/vercel-preset.ts +2 -2
- package/templates/backend/cell.yml +5 -3
- package/templates/backend/src/node/home-controller.ts +1 -1
- package/templates/backend/template.json +1 -1
- package/templates/fullstack/cell.yml +7 -6
- package/templates/fullstack/src/browser/module.ts +1 -1
- package/templates/fullstack/src/browser/{home.view.tsx → pages/index.tsx} +3 -7
- package/templates/fullstack/src/node/greeting-server.ts +1 -1
package/docs/frontend.md
ADDED
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
# Frontend and RPC
|
|
2
|
+
|
|
3
|
+
A Cell application can have a React frontend in the same project as its backend. `cell dev` serves both on one port (HMR for the frontend, hot reload for the backend), and `cell build` puts the frontend into `.cell/output/public/`, served by the backend through `@celljs/serve-static` or by the platform's CDN (Cloudflare, Vercel).
|
|
4
|
+
|
|
5
|
+
```bash
|
|
6
|
+
npx @celljs/cli init fullstack my-app
|
|
7
|
+
```
|
|
8
|
+
|
|
9
|
+
The fullstack template depends on `@celljs/react` (which adds the `frontend` build target), `@celljs/rpc` and `@celljs/serve-static`.
|
|
10
|
+
|
|
11
|
+
## Pages
|
|
12
|
+
|
|
13
|
+
Pages are the files of `src/browser/pages/`; the default export of each is the page component.
|
|
14
|
+
|
|
15
|
+
```text
|
|
16
|
+
src/browser/pages/
|
|
17
|
+
├── _layout.tsx around every page below it
|
|
18
|
+
├── index.tsx /
|
|
19
|
+
├── about.tsx /about
|
|
20
|
+
└── users/
|
|
21
|
+
├── index.tsx /users
|
|
22
|
+
└── [id].tsx /users/:id
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
```tsx
|
|
26
|
+
// src/browser/pages/users/[id].tsx
|
|
27
|
+
import { Link, useParams } from '@celljs/react';
|
|
28
|
+
|
|
29
|
+
export default function User() {
|
|
30
|
+
const { id } = useParams();
|
|
31
|
+
return <><h1>User {id}</h1><Link to="/users">All users</Link></>;
|
|
32
|
+
}
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
```tsx
|
|
36
|
+
// src/browser/pages/_layout.tsx
|
|
37
|
+
import { NavLink } from '@celljs/react';
|
|
38
|
+
import type { PropsWithChildren } from 'react';
|
|
39
|
+
|
|
40
|
+
export default function Layout({ children }: PropsWithChildren) {
|
|
41
|
+
return <><nav><NavLink to="/">Home</NavLink> <NavLink to="/users">Users</NavLink></nav>{children}</>;
|
|
42
|
+
}
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
- `[...rest].tsx` matches the rest of the path: `pages/[...rest].tsx` is the page for unknown URLs.
|
|
46
|
+
- `_layout.tsx` gets the page as `children`. Layouts nest, outermost first, and stay mounted while the user moves between their pages; pages without one get the `@DefaultLayout`.
|
|
47
|
+
- Files and directories whose name starts with `_`, and tests, are not pages: keep the components of a page next to it in `_components/`.
|
|
48
|
+
- Every page is a chunk of its own, loaded when it is visited. Two files for one path (`about.tsx` and `about/index.tsx`) fail with `CELL_ROUTE_CONFLICT`.
|
|
49
|
+
- No imports to add anywhere: `cell dev` picks up added and removed pages. The routes are generated into `.cell/generated/frontend/routes.js`, and `npx cell info --json` lists them (`frontend.routes`).
|
|
50
|
+
|
|
51
|
+
Routing is React Router 7. `@celljs/react` re-exports what pages need: `Link`, `NavLink`, `Navigate`, `Outlet`, `useParams`, `useNavigate`, `useLocation`, `useSearchParams`, `useMatch`. `react.router.type` in `cell.yml` chooses `browser` (default) or `hash` routing. `@App`, `@DefaultLayout` and `@Router` from `@celljs/react` replace the root component, the default layout and the router; a package adds pages with `@View` (see the reference).
|
|
52
|
+
|
|
53
|
+
`src/browser/module.ts` is the DI module of the frontend: it imports the files of your frontend services (see below).
|
|
54
|
+
|
|
55
|
+
The frontend gets the configuration keys components mark public and your `app.public`; they are evaluated at build time and visible to anyone. In the browser, read it with `useValue('html.title')` in a React component, `@Value` in a DI component, or `ConfigUtil.get('html.title')` from `@celljs/core` elsewhere.
|
|
56
|
+
|
|
57
|
+
## Services in components
|
|
58
|
+
|
|
59
|
+
Frontend services (state, API clients, anything shared) are DI components, as on the backend. React components get them, and configuration, with hooks from `@celljs/react`:
|
|
60
|
+
|
|
61
|
+
```tsx
|
|
62
|
+
import { useInject, useValue } from '@celljs/react';
|
|
63
|
+
import { UserService } from './user-service'; // @Component(UserService) in a file module.ts imports
|
|
64
|
+
|
|
65
|
+
function Header() {
|
|
66
|
+
const userService = useInject<UserService>(UserService); // resolved once per component instance
|
|
67
|
+
const title = useValue<string>('app.public.title', 'My app');
|
|
68
|
+
return <header>{title}: {userService.name}</header>;
|
|
69
|
+
}
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
The shell provides the application's container through `ContainerContext`. To test a component, render it inside `<ContainerContext.Provider value={container}>` with a container of your own. Keep pages, layouts and contexts plain React components; what they use comes from the container.
|
|
73
|
+
|
|
74
|
+
## Calling the backend: RPC
|
|
75
|
+
|
|
76
|
+
Instead of writing HTTP endpoints and fetch calls for your own frontend, share an interface and call it like a local object.
|
|
77
|
+
|
|
78
|
+
```ts
|
|
79
|
+
// src/common/greeting-protocol.ts: imported by both sides
|
|
80
|
+
export const GreetingServer = Symbol('GreetingServer');
|
|
81
|
+
|
|
82
|
+
export interface GreetingServer {
|
|
83
|
+
greet(name: string): Promise<string>;
|
|
84
|
+
}
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
```ts
|
|
88
|
+
// src/node/greeting-server.ts: imported by src/node/module.ts
|
|
89
|
+
import { Rpc } from '@celljs/rpc';
|
|
90
|
+
import { GreetingServer } from '../common/greeting-protocol';
|
|
91
|
+
|
|
92
|
+
@Rpc(GreetingServer)
|
|
93
|
+
export class GreetingServerImpl implements GreetingServer {
|
|
94
|
+
async greet(name: string): Promise<string> {
|
|
95
|
+
return `Hello, ${name}!`;
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
```tsx
|
|
101
|
+
// src/browser/pages/index.tsx
|
|
102
|
+
import { RpcUtil } from '@celljs/rpc';
|
|
103
|
+
import { GreetingServer } from '../../common/greeting-protocol';
|
|
104
|
+
|
|
105
|
+
export default function Home() {
|
|
106
|
+
const [message, setMessage] = React.useState('Loading…');
|
|
107
|
+
React.useEffect(() => {
|
|
108
|
+
RpcUtil.get<GreetingServer>(GreetingServer).greet('browser').then(setMessage);
|
|
109
|
+
}, []);
|
|
110
|
+
return <h1>{message}</h1>;
|
|
111
|
+
}
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
- `@Rpc(Id)` is a component (inject services into it as usual) and also an endpoint: JSON-RPC over HTTP `POST` at `/<rpc.path>/<Id>`, by default `/api/GreetingServer` (the description of the symbol).
|
|
115
|
+
- Every method returns a Promise; arguments and results travel as JSON (JSON-RPC 2.0). Only the methods the class declares can be called. An error thrown on the server rejects the promise in the caller: an `ApplicationError` as itself, others as an `RpcError` with `status`, whose message is hidden in production unless it is a 4xx `HttpError`.
|
|
116
|
+
- Parameters typed with a class are validated when `@celljs/validation` is installed, as for controllers.
|
|
117
|
+
- In tests, `app.get(GreetingServer)` from [`createTestApp()`](./testing.md) calls the implementation directly.
|
|
118
|
+
|
|
119
|
+
### The backend calls the frontend: WebSocket
|
|
120
|
+
|
|
121
|
+
```yaml
|
|
122
|
+
rpc:
|
|
123
|
+
transport: websocket
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
Calls then go over one WebSocket connection per browser tab (`/<rpc.path>/ws`), through the same middlewares, session and security as over HTTP, and the backend can call the frontend back. Declare what the frontend offers with `@RpcClient` (an interface in `src/common/`, the class in `src/browser/`, imported by its module):
|
|
127
|
+
|
|
128
|
+
```ts
|
|
129
|
+
// src/browser/notice-client.ts
|
|
130
|
+
import { RpcClient } from '@celljs/rpc';
|
|
131
|
+
import { NoticeClient } from '../common/notice-protocol';
|
|
132
|
+
|
|
133
|
+
@RpcClient(NoticeClient)
|
|
134
|
+
export class NoticeClientImpl implements NoticeClient {
|
|
135
|
+
async notify(text: string): Promise<void> {
|
|
136
|
+
console.log(text);
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
```ts
|
|
142
|
+
// in an @Rpc service of the backend
|
|
143
|
+
import { RpcContext } from '@celljs/rpc/lib/node';
|
|
144
|
+
|
|
145
|
+
const connection = RpcContext.requireConnection(); // the caller's tab
|
|
146
|
+
await connection.client<NoticeClient>(NoticeClient).notify('order shipped');
|
|
147
|
+
connection.onClose(() => { /* the tab went away */ });
|
|
148
|
+
```
|
|
149
|
+
|
|
150
|
+
`RpcConnectionManager` (`@celljs/rpc/lib/node`) lists every open connection, to notify all tabs. Where no connection can be made (the serverless presets, a proxy without WebSocket support) calls use HTTP, and `RpcContext.requireConnection()` throws `RpcNoConnectionError`. Pages of other origins cannot connect unless `rpc.websocket.allowedOrigins` lists them. The [reference](https://cell.cellbang.com/packages/rpc) has the other keys.
|
|
151
|
+
|
|
152
|
+
### From another backend
|
|
153
|
+
|
|
154
|
+
A backend calls a service of another Cell backend with an injected proxy:
|
|
155
|
+
|
|
156
|
+
```ts
|
|
157
|
+
import { Component } from '@celljs/core';
|
|
158
|
+
import { Autorpc } from '@celljs/rpc';
|
|
159
|
+
|
|
160
|
+
@Component()
|
|
161
|
+
export class Greeter {
|
|
162
|
+
@Autorpc(GreetingServer)
|
|
163
|
+
protected readonly greetingServer: GreetingServer;
|
|
164
|
+
}
|
|
165
|
+
```
|
|
166
|
+
|
|
167
|
+
```yaml
|
|
168
|
+
rpc:
|
|
169
|
+
defaultEndpoint: "http://greetings.internal:3000{rpcPath}/{serviceIdentifier}"
|
|
170
|
+
endpoint: # per service, wins over defaultEndpoint
|
|
171
|
+
GreetingServer: "${env.GREETING_URL}"
|
|
172
|
+
```
|
|
173
|
+
|
|
174
|
+
`RpcUtil.create<T>(endpoint, Id)` makes the same proxy without the container.
|
|
175
|
+
|
|
176
|
+
## Frontend-only and backend-only projects
|
|
177
|
+
|
|
178
|
+
The targets follow the installed components: `@celljs/react` adds `frontend`, and `backend` is always there. `targets` in `cell.config.ts` sets them explicitly.
|
|
179
|
+
|
|
180
|
+
The [@celljs/react reference](https://cell.cellbang.com/packages/react) lists the annotations and configuration keys.
|
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
# Getting started
|
|
2
|
+
|
|
3
|
+
This page takes you from an empty directory to a tested, built and deployable Cell backend. It assumes Node.js `^20.19.0 || >=22.12.0` for development; the built application runs on Node.js 18 or later, Bun 1.2 or later and Deno 2.
|
|
4
|
+
|
|
5
|
+
## Create a project
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npx @celljs/cli init backend my-app # or: fullstack (React frontend + backend over RPC)
|
|
9
|
+
cd my-app
|
|
10
|
+
npm install
|
|
11
|
+
npx cell dev # http://127.0.0.1:3000, reloads on save
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
`cell init` never asks questions. Without a template name it lists the templates; a non-empty directory needs `--force`. The project it writes:
|
|
15
|
+
|
|
16
|
+
```text
|
|
17
|
+
my-app/
|
|
18
|
+
├── cell.yml # application configuration, read with @Value
|
|
19
|
+
├── package.json # scripts: dev, build, preview, check, test
|
|
20
|
+
├── tsconfig.json # experimentalDecorators + emitDecoratorMetadata
|
|
21
|
+
├── src/node/
|
|
22
|
+
│ ├── module.ts # the backend DI module: imports every file with components
|
|
23
|
+
│ └── home-controller.ts
|
|
24
|
+
├── test/app.spec.ts # bun test + createTestApp()
|
|
25
|
+
├── AGENTS.md, CLAUDE.md # guide for coding agents, matched to the installed version
|
|
26
|
+
├── .agents/skills/cell/ # the same guide as an agent skill
|
|
27
|
+
└── .mcp.json # `npx cell mcp` for agents that speak MCP
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
## Add an endpoint
|
|
31
|
+
|
|
32
|
+
Create a controller, then import its file from `src/node/module.ts`. **A file that no module imports is not loaded**, so its components do not exist.
|
|
33
|
+
|
|
34
|
+
```ts
|
|
35
|
+
// src/node/todo-controller.ts
|
|
36
|
+
import { Body, Controller, Delete, Get, Param, Post } from '@celljs/mvc/lib/node';
|
|
37
|
+
import { NotFoundError } from '@celljs/web/lib/node';
|
|
38
|
+
|
|
39
|
+
interface Todo { id: number; title: string }
|
|
40
|
+
|
|
41
|
+
@Controller('todos')
|
|
42
|
+
export class TodoController {
|
|
43
|
+
protected readonly todos = new Map<number, Todo>();
|
|
44
|
+
protected nextId = 1;
|
|
45
|
+
|
|
46
|
+
@Get()
|
|
47
|
+
list(): Todo[] {
|
|
48
|
+
return [...this.todos.values()];
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
@Get(':id')
|
|
52
|
+
get(@Param('id') id: number): Todo {
|
|
53
|
+
const todo = this.todos.get(id);
|
|
54
|
+
if (!todo) {
|
|
55
|
+
throw new NotFoundError(`No todo ${id}`); // 404
|
|
56
|
+
}
|
|
57
|
+
return todo; // objects are sent as JSON
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
@Post()
|
|
61
|
+
create(@Body('title') title: string): Todo {
|
|
62
|
+
const todo = { id: this.nextId++, title };
|
|
63
|
+
this.todos.set(todo.id, todo);
|
|
64
|
+
return todo;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
@Delete(':id')
|
|
68
|
+
remove(@Param('id') id: number): void {
|
|
69
|
+
this.todos.delete(id);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
```ts
|
|
75
|
+
// src/node/module.ts
|
|
76
|
+
import './home-controller';
|
|
77
|
+
import './todo-controller';
|
|
78
|
+
import { autoBind } from '@celljs/core';
|
|
79
|
+
|
|
80
|
+
export default autoBind();
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
`@celljs/web` is a dependency of `@celljs/mvc`; add it to `package.json` too when you import from it (`npm install @celljs/web`).
|
|
84
|
+
|
|
85
|
+
```bash
|
|
86
|
+
curl -X POST localhost:3000/todos -H 'content-type: application/json' -d '{"title":"write docs"}'
|
|
87
|
+
curl localhost:3000/todos/1
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
Move the state into a service when it grows: see [Components and dependency injection](./components.md). The controller decorators are listed in [HTTP APIs](./web.md).
|
|
91
|
+
|
|
92
|
+
## Configure it
|
|
93
|
+
|
|
94
|
+
`cell.yml` holds the application configuration: keys of the components (`server.port`, ...) at the top level, your own under `app`. Configuration is server-only; only `app.public` and keys components mark public reach the browser:
|
|
95
|
+
|
|
96
|
+
```yaml
|
|
97
|
+
app:
|
|
98
|
+
greeting: Hello from my-app
|
|
99
|
+
todos:
|
|
100
|
+
max: ${(env.TODOS_MAX ?? 100) * 1} # evaluated when the server starts; keys under app have no schema type, * 1 makes the env text a number
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
```ts
|
|
104
|
+
@Value('app.todos.max')
|
|
105
|
+
protected readonly max: number;
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
`npx cell config get app.todos.max --why` shows the merged value and every file or variable that set it. More in [Project structure and configuration](./project.md).
|
|
109
|
+
|
|
110
|
+
## Check and test
|
|
111
|
+
|
|
112
|
+
```bash
|
|
113
|
+
npx cell check # TypeScript, configuration, decorator settings, DI bindings
|
|
114
|
+
bun test # the tests under test/
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
```ts
|
|
118
|
+
// test/todo.spec.ts
|
|
119
|
+
import { afterAll, beforeAll, describe, expect, it } from 'bun:test';
|
|
120
|
+
import { join } from 'node:path';
|
|
121
|
+
import { createTestApp, type TestApp } from '@celljs/cli';
|
|
122
|
+
|
|
123
|
+
describe('todos', () => {
|
|
124
|
+
let app: TestApp;
|
|
125
|
+
beforeAll(async () => { app = await createTestApp({ root: join(__dirname, '..') }); }, 60000);
|
|
126
|
+
afterAll(() => app?.close());
|
|
127
|
+
|
|
128
|
+
it('creates a todo', async () => {
|
|
129
|
+
const res = await app.fetch('/todos', { method: 'POST', headers: { 'content-type': 'application/json' }, body: '{"title":"a"}' });
|
|
130
|
+
expect(await res.json()).toEqual({ id: 1, title: 'a' });
|
|
131
|
+
});
|
|
132
|
+
});
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
`createTestApp()` starts the whole application inside the test process without opening a port. See [Testing](./testing.md).
|
|
136
|
+
|
|
137
|
+
## Build and run
|
|
138
|
+
|
|
139
|
+
```bash
|
|
140
|
+
npx cell build # .cell/output/server/index.mjs: one file with every dependency inlined
|
|
141
|
+
npx cell preview # runs the output as production would
|
|
142
|
+
node .cell/output/server/index.mjs
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
`--single` puts the frontend into the same file, `--compile` makes an executable that needs no Node.js on the host.
|
|
146
|
+
|
|
147
|
+
## Deploy
|
|
148
|
+
|
|
149
|
+
```bash
|
|
150
|
+
npx cell deploy --preset cloudflare --dry-run # the plan, nothing is uploaded
|
|
151
|
+
npx cell deploy --preset cloudflare
|
|
152
|
+
```
|
|
153
|
+
|
|
154
|
+
The presets are `node` (default), `cli`, `cloudflare`, `fc`, `scf`, `lambda` and `vercel`. See [Building and deploying](./deployment.md).
|
|
155
|
+
|
|
156
|
+
## Next
|
|
157
|
+
|
|
158
|
+
- [Package catalog](./packages.md): which `@celljs/*` package to add for databases, caching, scheduled jobs, security, AI and more.
|
|
159
|
+
- [Working with coding agents](./coding-agents.md): the AGENTS.md, skill and MCP tools that `cell init` set up.
|
package/docs/packages.md
ADDED
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
# Package catalog
|
|
2
|
+
|
|
3
|
+
All packages are published under [`@celljs`](https://www.npmjs.com/org/celljs) with the same version; keep them on one version. Installing a component package is enough to use it: its DI modules and `cell.yml` are loaded automatically (see [components](./project.md#components)). Each name links to its reference.
|
|
4
|
+
|
|
5
|
+
## Which package do I need?
|
|
6
|
+
|
|
7
|
+
| I want to | Add |
|
|
8
|
+
| --- | --- |
|
|
9
|
+
| Write REST controllers | `@celljs/mvc` (with `@celljs/express-adapter` as the server entry; both are in the templates) |
|
|
10
|
+
| Validate request bodies | `@celljs/validation` + `class-validator` |
|
|
11
|
+
| Publish OpenAPI / Swagger UI | `@celljs/openapi` |
|
|
12
|
+
| Call my backend from my frontend with types | `@celljs/rpc` |
|
|
13
|
+
| Build a React frontend | `@celljs/react` + `@celljs/serve-static` |
|
|
14
|
+
| Use a SQL database | `@celljs/typeorm` + a driver (`mysql2`, `pg`, `better-sqlite3`, `sql.js`, ...) |
|
|
15
|
+
| Cache values in memory or Redis | `@celljs/cache` |
|
|
16
|
+
| Run cron jobs | `@celljs/schedule` |
|
|
17
|
+
| Retry failing calls with back-off | `@celljs/retry` |
|
|
18
|
+
| Separate commands, queries and events | `@celljs/cqrs` |
|
|
19
|
+
| Log with winston | `@celljs/logger` |
|
|
20
|
+
| Log users in, protect routes | `@celljs/security` |
|
|
21
|
+
| Issue and verify JWTs | `@celljs/jwt` |
|
|
22
|
+
| Sign in with GitHub, Google or another OAuth2 / OIDC provider | `@celljs/oauth2-client` (with `@celljs/security`) |
|
|
23
|
+
| Call other HTTP APIs | `@celljs/http` (`RestOperations`) |
|
|
24
|
+
| Serve or call gRPC services | `@celljs/grpc` |
|
|
25
|
+
| Talk to LLMs | `@celljs/ai-core` + `@celljs/ai-pi` |
|
|
26
|
+
| Build an agent whose tools are my services | `@celljs/ai-agent` |
|
|
27
|
+
| Run a coding agent inside my application | `@celljs/ai-coding-agent` |
|
|
28
|
+
| Build a terminal UI | `@celljs/tui` (with the `cli` preset) |
|
|
29
|
+
| Store files in Alibaba Cloud OSS / Tencent Cloud COS | `@celljs/oss` / `@celljs/cos` |
|
|
30
|
+
| Take payments with WeChat Pay, Alipay or Stripe | `@celljs/wechat-pay` / `@celljs/alipay` / `@celljs/stripe` |
|
|
31
|
+
|
|
32
|
+
## Runtime
|
|
33
|
+
|
|
34
|
+
| Package | What it provides |
|
|
35
|
+
| --- | --- |
|
|
36
|
+
| [`@celljs/core`](https://cell.cellbang.com/packages/core) | DI container, `@Component` / `@Autowired` / `@Value`, AOP, configuration, application lifecycle, logger, request context. Every application depends on it |
|
|
37
|
+
| [`@celljs/web`](https://cell.cellbang.com/packages/web) | HTTP server on `node:http`: middleware chain, body parsing, cookies, sessions, CORS, trace ids, health check, error handlers |
|
|
38
|
+
| [`@celljs/mvc`](https://cell.cellbang.com/packages/mvc) | Controllers: `@Controller`, `@Get` / `@Post` / ..., parameter decorators, JSON / text / HTML / file responses, `@Catch` |
|
|
39
|
+
| [`@celljs/express-adapter`](https://cell.cellbang.com/packages/express-adapter) | The backend entry that starts the application and listens on `server.host` / `server.port`. Despite its name it has no express dependency |
|
|
40
|
+
| [`@celljs/http`](https://cell.cellbang.com/packages/http) | HTTP client (`RestOperations`, on `fetch`) and the shared `HttpStatus`, `HttpHeaders`, `MediaType` |
|
|
41
|
+
| [`@celljs/validation`](https://cell.cellbang.com/packages/validation) | class-validator / class-transformer validation of controller and RPC parameters |
|
|
42
|
+
| [`@celljs/openapi`](https://cell.cellbang.com/packages/openapi) | OpenAPI 3.0 document and Swagger UI built from the controllers |
|
|
43
|
+
| [`@celljs/rpc`](https://cell.cellbang.com/packages/rpc) | `@Rpc` services and typed proxies (`RpcUtil.get`, `@Autorpc`) over JSON-RPC on HTTP |
|
|
44
|
+
| [`@celljs/serve-static`](https://cell.cellbang.com/packages/serve-static) | Serves the frontend build with ETags, ranges and single-page-application fallback |
|
|
45
|
+
| [`@celljs/typeorm`](https://cell.cellbang.com/packages/typeorm) | TypeORM data sources, `OrmContext` repositories and `@Transactional()` |
|
|
46
|
+
| [`@celljs/cache`](https://cell.cellbang.com/packages/cache) | Named cache managers on cache-manager (memory, Redis and other stores) |
|
|
47
|
+
| [`@celljs/schedule`](https://cell.cellbang.com/packages/schedule) | `@Scheduler` classes with `@Cron` methods |
|
|
48
|
+
| [`@celljs/retry`](https://cell.cellbang.com/packages/retry) | Retry templates with retry and back-off policies |
|
|
49
|
+
| [`@celljs/cqrs`](https://cell.cellbang.com/packages/cqrs) | Command, query and event buses, sagas and aggregates |
|
|
50
|
+
| [`@celljs/grpc`](https://cell.cellbang.com/packages/grpc) | gRPC servers and clients on `node:http2` with its own `.proto` parser, no code generation |
|
|
51
|
+
| [`@celljs/logger`](https://cell.cellbang.com/packages/logger) | winston-backed `Logger` |
|
|
52
|
+
| [`@celljs/security`](https://cell.cellbang.com/packages/security) | Form login, HTTP Basic, logout, `@Authenticated()`, `@PreAuthorize()`, policies, password hashing |
|
|
53
|
+
| [`@celljs/jwt`](https://cell.cellbang.com/packages/jwt) | `JwtService`: sign and verify JSON Web Tokens with `node:crypto` |
|
|
54
|
+
| [`@celljs/oauth2-core`](https://cell.cellbang.com/packages/oauth2-core) | OAuth 2.0 / OpenID Connect types shared by the OAuth2 packages |
|
|
55
|
+
| [`@celljs/oauth2-client`](https://cell.cellbang.com/packages/oauth2-client) | Login with OAuth2 / OIDC providers; client credentials, password and refresh-token grants |
|
|
56
|
+
| [`@celljs/oauth2-jose`](https://cell.cellbang.com/packages/oauth2-jose) | JWK sets and JWS / JWT decoding for the OAuth2 packages |
|
|
57
|
+
| [`@celljs/wechat-pay`](https://cell.cellbang.com/packages/wechat-pay) | WeChat Pay API v3 client and a verified notification endpoint |
|
|
58
|
+
| [`@celljs/alipay`](https://cell.cellbang.com/packages/alipay) | Alipay gateway client and a verified notification endpoint |
|
|
59
|
+
| [`@celljs/stripe`](https://cell.cellbang.com/packages/stripe) | Stripe client and a verified webhook endpoint |
|
|
60
|
+
|
|
61
|
+
## Frontend
|
|
62
|
+
|
|
63
|
+
| Package | What it provides |
|
|
64
|
+
| --- | --- |
|
|
65
|
+
| [`@celljs/react`](https://cell.cellbang.com/packages/react) | React frontend: pages of `src/browser/pages`, routing, layouts, hooks to the DI container, the application shell |
|
|
66
|
+
| [`@celljs/widget`](https://cell.cellbang.com/packages/widget) | Frontend infrastructure `@celljs/react` builds on: widgets, themes, locales |
|
|
67
|
+
| [`@celljs/tui`](https://cell.cellbang.com/packages/tui) | Terminal user interfaces on pi-tui, including a chat for agents |
|
|
68
|
+
|
|
69
|
+
## AI
|
|
70
|
+
|
|
71
|
+
| Package | What it provides |
|
|
72
|
+
| --- | --- |
|
|
73
|
+
| [`@celljs/ai-core`](https://cell.cellbang.com/packages/ai-core) | Provider-neutral `ChatModel`, `EmbeddingModel`, `PromptTemplate` and the routing `ProxyChatModel` |
|
|
74
|
+
| [`@celljs/ai-pi`](https://cell.cellbang.com/packages/ai-pi) | 20+ model providers through pi-ai, addressed as `pi:<provider>/<model>` |
|
|
75
|
+
| [`@celljs/ai-agent`](https://cell.cellbang.com/packages/ai-agent) | Tool-using agents whose tools are Cell components; events over SSE |
|
|
76
|
+
| [`@celljs/ai-coding-agent`](https://cell.cellbang.com/packages/ai-coding-agent) | pi coding agent sessions managed by DI |
|
|
77
|
+
|
|
78
|
+
## Cloud
|
|
79
|
+
|
|
80
|
+
| Package | What it provides |
|
|
81
|
+
| --- | --- |
|
|
82
|
+
| [`@celljs/cloud`](https://cell.cellbang.com/packages/cloud) | Shared cloud abstractions: credentials, region, account and the `ObjectStorageService` interface |
|
|
83
|
+
| [`@celljs/oss`](https://cell.cellbang.com/packages/oss) | `ObjectStorageService` on Alibaba Cloud OSS |
|
|
84
|
+
| [`@celljs/cos`](https://cell.cellbang.com/packages/cos) | `ObjectStorageService` on Tencent Cloud COS |
|
|
85
|
+
|
|
86
|
+
Deploying to Function Compute, SCF, Lambda, Vercel or Cloudflare needs no package: choose the preset ([Building and deploying](./deployment.md)).
|
|
87
|
+
|
|
88
|
+
## Toolchain
|
|
89
|
+
|
|
90
|
+
| Package | What it provides |
|
|
91
|
+
| --- | --- |
|
|
92
|
+
| [`@celljs/cli`](https://cell.cellbang.com/cli) | The `cell` command, presets, deployers, `createTestApp()`, these guides |
|
|
93
|
+
| [`@celljs/vite`](https://cell.cellbang.com/packages/vite) | The Vite plugin and `CellBuilder` behind `cell build` and `cell dev` |
|
|
94
|
+
| [`@celljs/kit`](https://cell.cellbang.com/packages/kit) | Shared types for toolchain modules and presets: `CellError`, events, `definePreset` |
|
package/docs/project.md
ADDED
|
@@ -0,0 +1,181 @@
|
|
|
1
|
+
# Project structure and configuration
|
|
2
|
+
|
|
3
|
+
## Layout
|
|
4
|
+
|
|
5
|
+
A Cell project is an npm package. Its source follows a few conventions; nothing has to be registered elsewhere.
|
|
6
|
+
|
|
7
|
+
| Path | What |
|
|
8
|
+
| --- | --- |
|
|
9
|
+
| `src/node/` | Backend code: controllers, services, middleware |
|
|
10
|
+
| `src/browser/` | Frontend code (when the project has a frontend) |
|
|
11
|
+
| `src/common/` | Code both sides import, such as RPC interfaces |
|
|
12
|
+
| `src/node/module.ts` | The backend DI module |
|
|
13
|
+
| `src/browser/module.ts` | The frontend DI module |
|
|
14
|
+
| `cell.yml`, `cell.<mode>.yml` | Application configuration |
|
|
15
|
+
| `cell.config.ts` (optional) | Toolchain configuration |
|
|
16
|
+
| `.cell/` | Generated: `generated/` (DI wiring, merged configuration) and `output/` (the build); add it to `.gitignore` |
|
|
17
|
+
|
|
18
|
+
### DI modules
|
|
19
|
+
|
|
20
|
+
A DI module is a file that imports the files declaring components and exports `autoBind()`:
|
|
21
|
+
|
|
22
|
+
```ts
|
|
23
|
+
// src/node/module.ts
|
|
24
|
+
import './todo-controller';
|
|
25
|
+
import './todo-service';
|
|
26
|
+
import { autoBind } from '@celljs/core';
|
|
27
|
+
|
|
28
|
+
export default autoBind();
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
`autoBind()` registers every class decorated so far (`@Component`, `@Controller`, `@Rpc`, ...). **A file that no module imports is never loaded**: if `cell check` reports `CELL_DI_NO_BINDING` for a class you wrote, import its file here.
|
|
32
|
+
|
|
33
|
+
The toolchain looks for these module files of the project, in this order, and loads the ones that exist:
|
|
34
|
+
|
|
35
|
+
| Target | Files (under `src/`, extension `.ts`, `.tsx`, `.js` or `.mjs`) |
|
|
36
|
+
| --- | --- |
|
|
37
|
+
| backend | `common/module`, `node/backend-module`, `node/module`, `module`, `backend-module` |
|
|
38
|
+
| frontend | `common/module`, `browser/frontend-module`, `browser/module`, `module`, `frontend-module` |
|
|
39
|
+
|
|
40
|
+
`src/common/module` and `src/module` are loaded on both sides. A package can declare other paths in the `cell.modules` field of its `package.json`.
|
|
41
|
+
|
|
42
|
+
### Components
|
|
43
|
+
|
|
44
|
+
Every dependency whose `package.json` has a `cell` field is a **component**: installing it adds its DI modules and its `cell.yml` to the application. Installing `@celljs/security` turns on login, installing `@celljs/serve-static` serves the frontend. To leave out a component that a dependency brings in, list it in `cell.config.ts`:
|
|
45
|
+
|
|
46
|
+
```ts
|
|
47
|
+
export default defineConfig({ modules: ['!@celljs/serve-static'] });
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
`npx cell info` lists the components, their DI modules, the entry and the preset Cell resolved; `--json` gives the same as data.
|
|
51
|
+
|
|
52
|
+
## Application configuration: `cell.yml`
|
|
53
|
+
|
|
54
|
+
```yaml
|
|
55
|
+
# yaml-language-server: $schema=./.cell/schema/cell.yml.json
|
|
56
|
+
server:
|
|
57
|
+
port: ${env.PORT ?? 8080} # keys of the components are at the top level
|
|
58
|
+
typeorm:
|
|
59
|
+
ormConfig:
|
|
60
|
+
- type: mysql
|
|
61
|
+
password: ${env.DB_PASSWORD}
|
|
62
|
+
app: # your own configuration goes under app
|
|
63
|
+
greeting: Hello
|
|
64
|
+
public: # only app.public reaches the browser
|
|
65
|
+
apiBase: /api
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
- Top-level keys are configuration keys; there is no `cell:`, `frontend:` or `backend:` level. Read them with `@Value('server.port')`, `@Value('app.greeting')` on a property or constructor parameter.
|
|
69
|
+
- **Every top-level key has an owner**: a component declares the keys it owns in its `cell.schema.json` (`server` belongs to `@celljs/web`, `security` to `@celljs/security`...). Writing under them overrides the component's defaults.
|
|
70
|
+
- **Your own configuration goes under `app`**, which no component takes, so an upgrade never collides with it.
|
|
71
|
+
- Mistakes are errors: a top-level key nobody owns, an option a component does not have, a wrong type — `cell build`, `cell dev` and `cell check` report `CELL_CONFIG_INVALID` with the file, the line and a "did you mean".
|
|
72
|
+
- `cell dev`, `cell build` and `cell check` write `.cell/schema/cell.yml.json`; with the `yaml-language-server` comment above as the first line of `cell.yml`, editors (the YAML extension of VS Code, ...) complete and check it.
|
|
73
|
+
|
|
74
|
+
### What the frontend sees
|
|
75
|
+
|
|
76
|
+
**Configuration is server-only by default.** The browser only receives the keys components mark public (such as `server.path`, `rpc`, `react`, the page redirects of `security`) and `app.public`. A secret never reaches the frontend bundle unless you put it under `app.public`.
|
|
77
|
+
|
|
78
|
+
- Frontend values are evaluated at build time; their expressions may refer to server keys, only the results ship.
|
|
79
|
+
- `npx cell config get <key> --target frontend` shows what the frontend gets; a server-only key is reported as such.
|
|
80
|
+
- A project may have its own `cell.schema.json` describing the keys under `app` (types, descriptions, `"x-cell-public": true`).
|
|
81
|
+
|
|
82
|
+
### Merge order
|
|
83
|
+
|
|
84
|
+
The files merge in this order: the `cell.yml` of every component (in dependency order), the project's `cell.yml`, then `cell.<mode>.yml` for each active mode. Later files win; objects merge deeply, arrays are replaced.
|
|
85
|
+
|
|
86
|
+
### Modes
|
|
87
|
+
|
|
88
|
+
| Command | Mode |
|
|
89
|
+
| --- | --- |
|
|
90
|
+
| `cell dev` | `development` |
|
|
91
|
+
| `cell build` | `production` |
|
|
92
|
+
| `createTestApp()` | `test` |
|
|
93
|
+
|
|
94
|
+
Add more with `-m <mode>` (repeatable): `cell build -m staging` also reads `cell.staging.yml`. A mode without any file is reported by `cell check` (`CELL_MODE_UNKNOWN`).
|
|
95
|
+
|
|
96
|
+
### Expressions
|
|
97
|
+
|
|
98
|
+
`${...}` is evaluated against the configuration itself plus `env` (the process environment):
|
|
99
|
+
|
|
100
|
+
```yaml
|
|
101
|
+
server:
|
|
102
|
+
endpoint: http://localhost:${server.port} # another key
|
|
103
|
+
cloud:
|
|
104
|
+
region: ${env.REGION ?? 'eu-west-1'} # environment variable with a default
|
|
105
|
+
typeorm:
|
|
106
|
+
ormConfig:
|
|
107
|
+
- port: ${env.DB_PORT ?? 5432} # the schema says integer: DB_PORT=6543 gives the number 6543
|
|
108
|
+
synchronize: ${env.DB_SYNC ?? false} # the schema says boolean: true or false only
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
- Defaults use `??`, as in JavaScript; **an empty environment variable counts as unset**. Values need no quotes.
|
|
112
|
+
- **Schema types convert**: when a key is a number or a boolean, the text an expression gives is converted, and a value that does not convert is an error naming the key. Keys without a schema (those under `app`) keep the type of the result.
|
|
113
|
+
- **Backend values are evaluated when the server starts**, so one build runs in every environment and secrets are not baked into it. Frontend values are evaluated at build time.
|
|
114
|
+
- An expression inside other text gives a string; the result of an expression is never evaluated again, even when an environment variable contains `${...}`.
|
|
115
|
+
|
|
116
|
+
### Environment variables
|
|
117
|
+
|
|
118
|
+
Override any existing key without editing files, with a variable starting with `CELL_`:
|
|
119
|
+
|
|
120
|
+
```bash
|
|
121
|
+
CELL_SERVER__PORT=8080 node .cell/output/server/index.mjs # server.port, applied at startup
|
|
122
|
+
CELL_SERVER__HOST=0.0.0.0 # listen on all interfaces (containers)
|
|
123
|
+
CELL_APP__PUBLIC__API_BASE=https://api.example.com npx cell build # app.public.apiBase of the frontend, at build time
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
- One underscore after the prefix, `__` between levels (`CELL_SERVER__PORT`). `CELL_PRESET`, `CELL_MODE`, `CELL_EVENT`, `CELL_OUT_DIR` and `CELL_DEBUG` belong to the toolchain and are never configuration; a one-segment variable that is no top-level key (another tool's `CELL_REGION`) is left alone; a name with `__` that matches no key is reported, with the right spelling for the earlier `CELL__…` / `CELL_BACKEND__…`.
|
|
127
|
+
- `__` separates levels, matched ignoring case, `_` and `-` (`ORM_CONFIG` matches `ormConfig`); array items by index.
|
|
128
|
+
- The same variables apply to both sides: the server applies them at startup; `cell build` applies them, then picks the public keys for the frontend.
|
|
129
|
+
- Only existing keys can be overridden; give a new key a default in `cell.yml` first.
|
|
130
|
+
- Values convert to the type of the value (or the schema): numbers, booleans, JSON for objects and arrays. A value that is one `${...}` is kept and evaluated: `CELL_SERVER__PORT='${env.PORT}'`.
|
|
131
|
+
- A variable that matches no key or does not fit its type is ignored with a warning; `cell check` and `cell info` report it.
|
|
132
|
+
|
|
133
|
+
### Where a value comes from
|
|
134
|
+
|
|
135
|
+
```bash
|
|
136
|
+
npx cell config get server.port --why
|
|
137
|
+
# server.port (backend) = 8080
|
|
138
|
+
# server-only, owned by @celljs/web
|
|
139
|
+
# Port the server listens on. Override with CELL_SERVER__PORT.
|
|
140
|
+
# node_modules/@celljs/web/cell.yml: 3000
|
|
141
|
+
# cell.yml: 8080
|
|
142
|
+
```
|
|
143
|
+
|
|
144
|
+
Common keys of the framework:
|
|
145
|
+
|
|
146
|
+
| Key | Default | Package |
|
|
147
|
+
| --- | --- | --- |
|
|
148
|
+
| `server.port` / `server.host` | `3000` / `127.0.0.1` | `@celljs/web` |
|
|
149
|
+
| `server.path` | `/` | `@celljs/web` (prefix of every route; public) |
|
|
150
|
+
| `web.body.limit` | `100kb` | `@celljs/web` |
|
|
151
|
+
| `web.cors` | any origin (`*`) | `@celljs/web` |
|
|
152
|
+
| `web.session` / `web.cookies` | see the README of `@celljs/web` | `@celljs/web` |
|
|
153
|
+
| `html.title` / `html.rootId` | `Cell Framework` / `cell-root` | `@celljs/core` (the generated HTML page) |
|
|
154
|
+
| `logger.level` | `info` | `@celljs/core` |
|
|
155
|
+
| `rpc.path` | `api` | `@celljs/rpc` |
|
|
156
|
+
| `serveStatic.spa` | `true` | `@celljs/serve-static` |
|
|
157
|
+
|
|
158
|
+
Each package's README lists its keys; every key with its type and description is in `.cell/schema/cell.yml.json`.
|
|
159
|
+
|
|
160
|
+
## Toolchain configuration: `cell.config.ts`
|
|
161
|
+
|
|
162
|
+
Optional, and only for the toolchain. Application configuration never goes here.
|
|
163
|
+
|
|
164
|
+
```ts
|
|
165
|
+
import { defineConfig } from '@celljs/cli';
|
|
166
|
+
|
|
167
|
+
export default defineConfig({
|
|
168
|
+
preset: 'cloudflare', // default: node
|
|
169
|
+
modules: ['!@celljs/serve-static'], // remove a component
|
|
170
|
+
build: { external: ['sharp'], sourcemap: true },
|
|
171
|
+
vite: { resolve: { alias: { '~': '/src' } } }, // merged into the Vite configuration
|
|
172
|
+
hooks: { 'build:before': 'prisma generate' }, // shell commands on toolchain events
|
|
173
|
+
fc: { region: 'cn-shanghai', memory: 512 }, // options of a preset, under its name
|
|
174
|
+
});
|
|
175
|
+
```
|
|
176
|
+
|
|
177
|
+
Unknown fields are reported with the closest valid name (`CELL_CONFIG_INVALID`, `CELL_CONFIG_UNKNOWN_OPTION`). The full reference, including toolchain modules that add Vite plugins, checks, MCP tools or output files, is the [CLI reference](../README.md).
|
|
178
|
+
|
|
179
|
+
## Generated files
|
|
180
|
+
|
|
181
|
+
`cell dev` and `cell build` write the code they generate to `.cell/generated/`: the DI modules each target loads, the merged configuration and the project model. Read them when you need to know exactly what the container contains; never edit them.
|