@elysiumjs/styx

中文文档
0.17.1发布于 2026/11/13Apache-2.0TypeScriptES Module近 30 天下载 3676

The command line tool of the Elysium.js framework: creates projects, generates code and runs app commands.

原始使用文档
文档目录9 节
  1. Installation
  2. Creating a project
  3. Generating code
  4. Typed clients
  5. Running the app
  6. Build tools
  7. Listing commands
  8. Contributing
  9. License

@elysiumjs/styx

The command line tool of the Elysium.js framework. It creates projects, generates code and runs your app's commands.

Installation

Install it globally to create projects and use it anywhere:

bun add -g @elysiumjs/styx

Projects also install it as a dev dependency (styx create does this). Inside a project, the global styx hands every command to the project's own copy, so each project runs the Styx version it was written for.

Standalone executables, which need neither Bun nor the package files, are built with bun run build:bin (current platform) or bun run build:bin --all (Linux, macOS and Windows). They embed the code stubs and project templates with Hephaestus.

Creating a project

styx create my-app

Without options, it asks for the template (single or multi module), the runtime, the modules, plugins and features. Options skip the prompts:

styx create my-app --template multi --modules users,billing --features prettier,hephaestus --git false

--install false writes the files without installing dependencies, --force replaces a folder that is not empty, and --yes takes the defaults for every option not given. bun create elysium my-app runs the same command.

Generating code

The generators write files from stubs and never start your app, so they work before the app can boot:

styx make:command --name SendReport
styx make:controller --name UserController
styx make:job --name ImportUsers
styx make:middleware --name AuthMiddleware
styx make:model --name User
styx make:repository --name UserRepository
styx make:seeder --name CountriesSeeder
styx make:service --name UserService
styx make:validator --name CreateUser
styx make:view --name Post
styx module:new --name billing
styx module:rename --module billing --name payments

In a multi module project, pass --module <name>. Run styx help <command> for every option.

Files and module folders are named in kebab-case: styx make:service --name UserProfileService writes services/user-profile.service.ts. A validator holds only its schema unless you ask for its methods with --authorize and --validate, and a model declares supportTenancy only with --support-tenancy.

Typed clients

styx routes:generate writes the route types of the app to src/routes.gen.ts (set routes in .elysiumrc or pass --out, absolute or relative to the project, to change it). The file exports AppRoutes, for Eden:

import type { AppRoutes } from './routes.gen';

import { treaty } from '@elysia/eden';

const api = treaty<AppRoutes>('http://localhost:3000');
const { data } = await api.users({ id }).get();

The types come from the controller methods: the parameters decorated with @Http.param, @Http.query and @Http.body give the request types, and the return type gives the response type, so annotate the return type of methods that return different shapes. A route whose response is a view (PostView, PostView.list or PostView.page) takes its response type from the schema of the view. A view that no project file exports gives the route an unknown response, since the handler returns what the view renders, not what clients receive. The file holds types only and is written again by typecheck in new projects, so keep it out of git.

styx routes:check fails when a route declares no schema for its success response, so that clients and the OpenAPI document know what it returns. Set the response option of the route, either one schema or a map of statuses with at least one 2xx status. Server-sent events routes and routes answering 204 are left out. Run it in CI next to typecheck.

Every controller the modules of the app list is included, whatever declares it, as long as a file of the project exports it. When a decorator adds routes that are not methods of the class, or answers something else than the method returns, a route types contributor types them: a global service tagged Http.RouteTypes, active in development. Flow controllers are typed this way by AriadneModule.

@Service.register({ tags: [Http.RouteTypes], global: true, env: Environments.local })
export class PingRouteTypes implements HttpRouteTypesContributor {
    public supports(controller: Function) {
        return isPingable(controller);
    }

    public route(controller: Function, route: HttpRouteDescription, ref: HttpRouteTypeRef) {
        if (route.name === 'ping') return { response: '{ pong: true }' };
        return ref.method
            ? {
                    response: `Reply<ReturnType<${ref.method}>>`,
                    imports: [{ from: './reply', names: ['Reply'] }]
                }
            : undefined;
    }
}

A contributor gives the type text of params, query, body and response, and leaves out the parts the method gives. A controller that no file exports, such as one a factory builds, is included when a contributor gives every type of its routes.

Running the app

Every other command loads the project's app (src/app.ts or index.ts) and runs there:

styx serve
styx migration:generate
styx migration:run
styx <your command>

These need @elysiumjs/styx in the project's dev dependencies.

Build tools

When the project installs @elysiumjs/hephaestus (as a dev dependency), its hephaestus:* commands are available through styx without adding anything to the app.

Listing commands

styx list
styx help <command>

Contributing

Issues for bugs and questions are welcome on GitHub. Pull requests are welcome too; they are reviewed to keep the framework consistent with its design.

License

This project is licensed under the Apache License, Version 2.0. See the LICENSE file for more information.

版本与发布记录

@elysiumjs/styx 共发布 32 个版本,首次发布于 2025/04/25;过去 12 个月发布了 25 个版本。

版本发布日期距今
0.17.1latest2026/11/13今天
0.17.02026/11/13今天
0.16.02026/11/13今天
0.15.02026/11/121 天前
0.14.22026/11/112 天前
0.14.12026/11/112 天前

关于 @elysiumjs/styx 的常见问题

@elysiumjs/styx 是什么?

The command line tool of the Elysium.js framework: creates projects, generates code and runs app commands.

如何安装 @elysiumjs/styx?

在项目目录运行 npm install @elysiumjs/styx,或使用 pnpm add / yarn add / bun add。它还提供命令行工具 styx,可以用 npx styx 直接运行。

@elysiumjs/styx 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@elysiumjs/styx 支持 ESM 还是 CommonJS?

以 ES Module 形式发布,推荐使用 import 引入。在 CommonJS 项目中,Node.js 20.19+ / 22.12+ 可以直接 require() 不含顶层 await 的 ES Module,更早的版本需要改用动态 import()。

@elysiumjs/styx 可以商用吗?

@elysiumjs/styx 使用 Apache-2.0 许可。宽松许可:允许商业使用、修改和再分发,并附带明确的专利授权;分发时需保留许可与 NOTICE 文件,修改过的文件要注明改动。以上为概括,不构成法律意见,请以许可原文为准。

@elysiumjs/styx 的下载量有多少?

根据 npm 官方下载统计,@elysiumjs/styx 在 2026/10/14 – 2026/11/12 这 30 天内被下载 3,676 次,日均约 123 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@elysiumjs/styx 还在维护吗?

最新版本 0.17.1 发布于 2026/11/13(今天);至今共发布 32 个版本,其中过去 12 个月发布了 25 个;首次发布于 2025/04/25。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。