@elysiumjs/styx 0.8.2 → 0.9.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.
Files changed (54) hide show
  1. package/CHANGELOG.md +110 -0
  2. package/README.md +52 -41
  3. package/dist/assets.d.ts +31 -0
  4. package/dist/cli/app.d.ts +15 -0
  5. package/dist/cli/route.d.ts +51 -0
  6. package/dist/cli.d.ts +2 -0
  7. package/dist/cli.js +200 -0
  8. package/dist/commands/index.d.ts +1 -0
  9. package/dist/commands/routes_generate.command.d.ts +11 -0
  10. package/dist/config.d.ts +5 -0
  11. package/dist/create/code.d.ts +77 -0
  12. package/dist/create/create.command.d.ts +60 -0
  13. package/dist/create/names.d.ts +42 -0
  14. package/dist/create/versions.d.ts +7 -0
  15. package/dist/index.js +9 -3
  16. package/dist/routes/collect.d.ts +20 -0
  17. package/dist/routes/render.d.ts +39 -0
  18. package/package.json +13 -10
  19. package/stubs/http.controller.stub +1 -1
  20. package/stubs/ws.controller.stub +1 -1
  21. package/templates/feature-hephaestus/.specs +7 -0
  22. package/templates/feature-hephaestus/hephaestus.config.ts +7 -0
  23. package/templates/feature-prettier/.prettierignore +5 -0
  24. package/templates/feature-prettier/.prettierrc +23 -0
  25. package/templates/feature-prettier/.specs +13 -0
  26. package/templates/plugin-sentry/.env.example +2 -0
  27. package/templates/plugin-sentry/.specs +12 -0
  28. package/templates/shared-module/commands/.gitkeep +0 -0
  29. package/templates/shared-module/controllers/http/.gitkeep +0 -0
  30. package/templates/shared-module/controllers/wamp/.gitkeep +0 -0
  31. package/templates/shared-module/controllers/ws/.gitkeep +0 -0
  32. package/templates/shared-module/jobs/.gitkeep +0 -0
  33. package/templates/shared-module/middlewares/.gitkeep +0 -0
  34. package/templates/shared-module/models/.gitkeep +0 -0
  35. package/templates/shared-module/repositories/.gitkeep +0 -0
  36. package/templates/shared-module/services/.gitkeep +0 -0
  37. package/templates/shared-module/utils/.gitkeep +0 -0
  38. package/templates/shared-module/validators/.gitkeep +0 -0
  39. package/templates/template-multi/.gitattributes +15 -0
  40. package/templates/template-multi/README.md +20 -0
  41. package/templates/template-multi/gitignore +45 -0
  42. package/templates/template-multi/index.ts +10 -0
  43. package/templates/template-multi/package.json +8 -0
  44. package/templates/template-multi/src/modules/.gitkeep +0 -0
  45. package/templates/template-multi/tsconfig.json +32 -0
  46. package/templates/template-multi/types.d.ts +5 -0
  47. package/templates/template-single/.gitattributes +15 -0
  48. package/templates/template-single/README.md +20 -0
  49. package/templates/template-single/gitignore +45 -0
  50. package/templates/template-single/index.ts +10 -0
  51. package/templates/template-single/package.json +8 -0
  52. package/templates/template-single/tsconfig.json +32 -0
  53. package/templates/template-single/types.d.ts +5 -0
  54. package/dist/styx.js +0 -11
package/CHANGELOG.md CHANGED
@@ -1,5 +1,115 @@
1
1
  # @elysiumjs/styx
2
2
 
3
+ ## 0.9.1
4
+
5
+ ### Patch Changes
6
+
7
+ - Updated dependencies [[`651a755`](https://github.com/na2axl/elysiumjs/commit/651a7557173ce2c6155bcfa8d90cf388ac419821)]:
8
+ - @elysiumjs/core@0.12.0
9
+ - @elysiumjs/runtime-bun@0.1.1
10
+
11
+ ## 0.9.0
12
+
13
+ ### Minor Changes
14
+
15
+ - [#10](https://github.com/na2axl/elysiumjs/pull/10) [`0057b67`](https://github.com/na2axl/elysiumjs/commit/0057b67df0e3abecab8a9accff6b55a6a64c21df) Thanks [@na2axl](https://github.com/na2axl)! - `styx routes:generate` writes the route types of an app to `src/routes.gen.ts`: an `AppRoutes` type for Eden (`treaty<AppRoutes>(url)`), built from the controllers of every module. Request types come from the method parameters decorated with `@Http.param`, `@Http.query` and `@Http.body`, and response types from the method return types. The file holds types only; requests are served by the decorated controllers. New projects run the command in their `typecheck` script and keep the file out of git.
16
+
17
+ `Http.describe(controller)` reports the routes of an HTTP controller, and `Application.moduleGraph()` builds the module graph of an app class without booting it.
18
+
19
+ - [#9](https://github.com/na2axl/elysiumjs/pull/9) [`8a30cc3`](https://github.com/na2axl/elysiumjs/commit/8a30cc35a82438fe9da08fcea91ef9b46f3430f1) Thanks [@na2axl](https://github.com/na2axl)! - Styx is a global command: install it with `bun add -g @elysiumjs/styx`, then run `styx create my-app` to start a project (template, runtime, modules, plugins and features, from prompts or options). Inside a project, the global `styx` hands every command to the project's own Styx. The code generators (`make:*`, `module:*`) run without starting the app, and new projects install Styx as a dev dependency.
20
+
21
+ When a project installs `@elysiumjs/hephaestus` as a dev dependency, Styx provides its commands. Standalone `styx` executables are built with Hephaestus (`bun run build:bin`), with the stubs and templates embedded. The Hephaestus asset embedder includes dotfiles.
22
+
23
+ `create-elysium` runs `styx create`; the project templates live in `@elysiumjs/styx`.
24
+
25
+ - [#16](https://github.com/na2axl/elysiumjs/pull/16) [`ac96e55`](https://github.com/na2axl/elysiumjs/commit/ac96e55874b0ffe350b287c4278cd85afecb7576) Thanks [@na2axl](https://github.com/na2axl)! - Redis, databases, logs, jobs and builds on Bun, Node.js and Cloudflare Workers.
26
+
27
+ Breaking:
28
+
29
+ - The level shortcuts of `InteractsWithConsole` (`info`, `success`, `warning`, `error` and `debug`) write a tag (`[I]`, `[S]`, `[W]`, `[E]` and `[D]`, in color) before the message, which `InteractsWithConsole.useTags()` changes. `trace()` writes to stderr.
30
+ - Outside Bun, a Drizzle connection needs a `driver`. Without one, the `connection` and `client` props are a Bun SQL connection, which is only available on Bun; elsewhere the connection throws `MissingDriverError`, which names the drivers.
31
+
32
+ Added:
33
+
34
+ - Redis adapters (`@elysiumjs/redis`): `ioredis(create)` plugs an ioredis client into the Redis port on Node.js, and `upstash({ token, url?, fetch? })` talks to Upstash over its REST API, for Workers (no pub/sub). `bunRedis` explains which adapter to use when it runs outside Bun.
35
+ - Drizzle drivers (`@elysiumjs/mnemosyne-drizzle`): a `DrizzleDriver` port set with the `driver` prop of a connection, and drivers on subpaths so that only the chosen database client is imported: `/bun-sql` (`bunSql()`), `/postgres-js` (`postgresJs()`), `/node-postgres` (`nodePostgres()`) and `/hyperdrive` (`hyperdrive({ binding, driver })`, a client per Worker invocation over a Cloudflare Hyperdrive binding). `DrizzleModule` closes connections through their driver, and `migration:run` runs on any driver.
36
+ - `InteractsWithConsole.write()` and `Runtime.write()` take the level of the line (`OutputLevel`), which the level shortcuts pass. On Cloudflare Workers, a line is written with the console method of its level, so Workers Logs keep it.
37
+ - `JsonConsoleLogger` (`@elysiumjs/hermes`): JSON lines through the console of the runtime (warnings and errors on stderr), with levels, error serialization and `child()`. `HermesModule.with({ transport: 'console' | 'pino' })` picks it, and it is the default on Workers. `RequestLogInterceptor` writes one structured line per request: method, route, status, duration, client address and request id.
38
+ - Scheduled jobs (`@elysiumjs/heracles`): `@Schedule(cron, { timezone, args })` on a job class, a five-field cron parser (`Cron`, with lists, ranges, steps and names), and a `Scheduler` that dispatches the jobs on time on Bun and Node.js, taking a Redis lock per tick when a Redis connection is set. The `heracles:schedule` command runs it.
39
+ - `@elysiumjs/heracles-workers`: `CloudflareQueueTransport` sends jobs to a Cloudflare Queue (dispatch delays become `delaySeconds`), and `HeraclesWorkersModule` consumes them in the Worker's `queue` handler (ack on success, retry with a delay up to the job's retries) and dispatches the `@Schedule()` jobs whose expression is the cron of a trigger.
40
+ - Queue handlers (`@elysiumjs/runtime-workers`) can settle a message themselves with `ack()` or `retry({ delaySeconds })`; the messages they leave are acked when no handler failed on them.
41
+ - `styx build --target node` (`@elysiumjs/hephaestus`) bundles the app into one ES module for Node.js, with decorator metadata emitted at build time, run with `node dist/server.js serve`. `styx build --target workers` runs from the CLI, resolves packages to their browser entry, and leaves Node.js modules imported by bare names to workerd (`nodejs_compat`).
42
+ - `styx create` (`@elysiumjs/styx`) takes `--runtime bun|node|workers`, `--database`, `--cache` and `--package-manager bun|npm|pnpm`. Each runtime gets its entry, tsconfig types, scripts and drivers: postgres.js and ioredis on Node.js; Hyperdrive, Upstash, console logs and a `wrangler.jsonc` on Workers.
43
+
44
+ - [#12](https://github.com/na2axl/elysiumjs/pull/12) [`98a16aa`](https://github.com/na2axl/elysiumjs/commit/98a16aae889d46f7a9fb5573188f4cbe3629dd3b) Thanks [@na2axl](https://github.com/na2axl)! - `createWorker(app)` from `@elysiumjs/runtime-workers` builds an application and returns the handlers a Cloudflare Worker exports: `fetch` serves the routes, `queue` hands each batch to the service methods marked `@Workers.queue(name)`, and `scheduled` calls the methods marked `@Workers.cron(expression)`. Each invocation runs with its own env and execution context: `Workers.env()`, `Workers.context()` and `Workers.binding(name)` read them, and `WorkersModule` provides them, and the bindings it lists, as request-scoped services injected with `@Workers.inject(name)`. `KeyvWorkersKV` stores mnemosyne caches in a KV namespace. `bun run check:wrangler` runs a sample Worker in `wrangler dev`.
45
+
46
+ `MnemosyneModule` takes other Keyv stores in `cache.stores`, read with `Cache.store(name)`.
47
+
48
+ `styx build --target workers` (Hephaestus `hephaestus:build --target workers`, `WorkersBuilder`) bundles a Worker with its routes compiled ahead of time and refuses a bundle that generates code at runtime.
49
+
50
+ In core, `Application.boot()` initialises the modules once, for hosts that handle more than requests; `Kernel.serviceClasses(node)` lists the service classes of a module; console output falls back to `console` where the host has no output streams; and a singleton depending on a request-scoped service throws `ScopeMismatchError` even when it is built outside a request.
51
+
52
+ ### Patch Changes
53
+
54
+ - [#20](https://github.com/na2axl/elysiumjs/pull/20) [`87299fd`](https://github.com/na2axl/elysiumjs/commit/87299fd9da82d1a408ced1891c0c3d42991444e5) Thanks [@na2axl](https://github.com/na2axl)! - The framework event bus is `Lifecycle`: `Lifecycle.on`, `Lifecycle.once`, `Lifecycle.emit`, `Lifecycle.off`, `@Lifecycle.on()` and `@Lifecycle.once()`, with the `LifecycleEvent` and `LifecycleHandler` types. It carries the framework's own signals (`elysium:error`, app and server lifecycle, heracles queue events) and in-process listeners.
55
+
56
+ - [#22](https://github.com/na2axl/elysiumjs/pull/22) [`bee66bd`](https://github.com/na2axl/elysiumjs/commit/bee66bdc874b8f23fea356f7d3adf7555a48ca64) Thanks [@na2axl](https://github.com/na2axl)! - Decorators take their main identifier first and their options second.
57
+
58
+ - `@Http.controller(path, options)` and the route decorators `@Http.get(path, options)`, `post`, `put`, `patch`, `del`, `head`, `options`, `trace` and `sse`. The path defaults to `/`. `@Http.custom(method, path, options)` takes its method first. The options are `HttpControllerOptions` and `HttpRouteOptions`.
59
+ - `@Websocket.controller(path, options)`, where the options are those of the websocket server.
60
+ - `@Flow.controller(name, options)`, and `@Flow.step(name, options)` or `@Flow.step(options)` for a step named after its method.
61
+ - `@Lifecycle.on(event, options)` and `@Lifecycle.once(event, options)`, like their function forms `Lifecycle.on(event, handler)`.
62
+ - The styx controller stubs generate the same forms.
63
+
64
+ - [#13](https://github.com/na2axl/elysiumjs/pull/13) [`1ea417e`](https://github.com/na2axl/elysiumjs/commit/1ea417e3583250bc2f975d795f398b7ff736115d) Thanks [@na2axl](https://github.com/na2axl)! - Hardening of the runtimes, the container and the CLI, checked by a conformance suite that runs on Bun, Node.js and workerd.
65
+
66
+ Breaking changes:
67
+
68
+ - `Runtime` gains the required `argv()`, `write(stream, text)` and `terminal()` members: core reaches the host's arguments, output streams and terminal only through the runtime. Custom runtimes must implement them.
69
+ - The third parameter of `InteractsWithConsole.write` is now `'stdout' | 'stderr'`.
70
+ - The WebSocket options are narrowed to `idleTimeout`, `maxPayloadLength` and `perMessageDeflate`, and the `bun` WebSocket types are replaced by `ElysiumWebSocket`.
71
+ - Redis connections are `RedisConnection`s, a port any Redis client can implement, instead of `Bun.RedisClient`.
72
+ - `styx create @scope/name` creates the project in `name/`, and refuses project and module names with upper-case letters.
73
+ - Queue handlers no longer reject the batch: after the handlers ran, each message is acked or retried on its own. `@Workers.queue(name, { each: true })` receives one message at a time, so a failure retries only that message.
74
+
75
+ Fixes:
76
+
77
+ - Request-scoped services are destroyed when the request ends, also on failure, and an async `onInit` is awaited. A second dispose of a request scope waits for the one in progress, so a Worker's `waitUntil` covers an async `onDestroy`.
78
+ - A failed module or service `onInit` no longer breaks later requests: the boot is retried, and the module's event listeners are unwired.
79
+ - `@elysiumjs/runtime-node` serves through `node:http`, keeping the Host header authoritative.
80
+ - `styx create` validates names before creating files, ships `.gitignore`, declares the dependencies of created projects and imports their default controllers.
81
+
82
+ - [#14](https://github.com/na2axl/elysiumjs/pull/14) [`0956186`](https://github.com/na2axl/elysiumjs/commit/0956186db0ca5a83c0a6636aeb2a4c81a0033de4) Thanks [@na2axl](https://github.com/na2axl)! - The request pipeline: problem details, exception filters, interceptors, typed configuration, HTTP security options and an HTTP test client, checked on Bun, Node.js, workerd and AOT-compiled Workers.
83
+
84
+ Breaking changes:
85
+
86
+ - Error responses are RFC 9457 problem details (`application/problem+json`). Request validation errors answer 422 with an `errors` list of JSON pointers (`problems.validationStatus: 400` keeps 400). Server errors only show their message and stack in development. Thrown statuses (`c.status(...)`) are sent as they are.
87
+ - Client errors (4xx) are no longer reported to `onError`, the `elysium:error` event or the trace.
88
+ - `Runtime.serve` may return a handle with `close()`, which the application calls on shutdown.
89
+ - Request bodies are limited to 1 MiB by default (`http.bodyLimit`), also when chunked.
90
+ - The environment schema is validated when the app is built or run, with every error reported at once, instead of in the constructor.
91
+
92
+ Features:
93
+
94
+ - `DomainError`, with `status`, `type`, `title`, `detail` and extensions, and shortcuts such as `DomainError.notFound()`.
95
+ - Exception filters (`@Catch()`, `filters` on routes, controllers, modules and the app) and interceptors (`interceptors` on the same levels), with `TimingInterceptor`, `TransformInterceptor` and mnemosyne's `CacheInterceptor`.
96
+ - Typed configuration: `Secret` values, module `envSchema`s merged into the app's, `InvalidEnvironmentError`.
97
+ - `http` options: CORS, security headers, body limits and trusted proxies (`ctx.ip`). Runtimes report the client address through `clientAddress`.
98
+ - `createTestingHttpApp` and `createHttpClient` send requests to an app in memory, with `expectStatus()`.
99
+
100
+ Fixes:
101
+
102
+ - App-level `onRequest` middlewares run in the request scope.
103
+ - On Workers, the request scope of a streamed response is disposed when the body ends, not when `fetch` returns.
104
+ - `KeyvWorkersKV.clear()` stays within an operation budget (`maxOperations`).
105
+ - The Node.js bridge treats a destroyed socket as a client abort.
106
+ - Heracles performance metrics report through the Redis port (`connection` or `client`), not a Bun client.
107
+ - `styx routes:generate` names anonymous default controllers after their file; `styx create` pins `@elysiumjs/*` packages to the versions it was released with; invalid names are reported as Elysium errors.
108
+
109
+ - Updated dependencies [[`6bc48fe`](https://github.com/na2axl/elysiumjs/commit/6bc48febd51f7090c582e73f349eaeff7261241c), [`e9c3d98`](https://github.com/na2axl/elysiumjs/commit/e9c3d98dd2714b69100215f7c8a80046da463148), [`557a3ca`](https://github.com/na2axl/elysiumjs/commit/557a3cab7af8053a8bab9944e492e5022d91aa82), [`ccc3f5b`](https://github.com/na2axl/elysiumjs/commit/ccc3f5bb904d1bf52d8c72ebf7ea8d10f617a8c4), [`6789879`](https://github.com/na2axl/elysiumjs/commit/678987976ecfd46b534b65276e0de3f448977562), [`87299fd`](https://github.com/na2axl/elysiumjs/commit/87299fd9da82d1a408ced1891c0c3d42991444e5), [`bee66bd`](https://github.com/na2axl/elysiumjs/commit/bee66bdc874b8f23fea356f7d3adf7555a48ca64), [`0057b67`](https://github.com/na2axl/elysiumjs/commit/0057b67df0e3abecab8a9accff6b55a6a64c21df), [`632d77b`](https://github.com/na2axl/elysiumjs/commit/632d77b561fc43ade605fb69b06ac1b9b9a2ffc4), [`1ea417e`](https://github.com/na2axl/elysiumjs/commit/1ea417e3583250bc2f975d795f398b7ff736115d), [`0956186`](https://github.com/na2axl/elysiumjs/commit/0956186db0ca5a83c0a6636aeb2a4c81a0033de4), [`fbcc7da`](https://github.com/na2axl/elysiumjs/commit/fbcc7dad127db29da42e7a4a5c2124966731cd88), [`ac96e55`](https://github.com/na2axl/elysiumjs/commit/ac96e55874b0ffe350b287c4278cd85afecb7576), [`98a16aa`](https://github.com/na2axl/elysiumjs/commit/98a16aae889d46f7a9fb5573188f4cbe3629dd3b)]:
110
+ - @elysiumjs/core@0.11.0
111
+ - @elysiumjs/runtime-bun@0.1.0
112
+
3
113
  ## 0.8.2
4
114
 
5
115
  ### Patch Changes
package/README.md CHANGED
@@ -1,78 +1,89 @@
1
1
  # @elysiumjs/styx
2
2
 
3
- CLI tool for Elysium.js framework.
3
+ The command line tool of the Elysium.js framework. It creates projects, generates code and runs your app's commands.
4
4
 
5
5
  ## Installation
6
6
 
7
+ Install it globally to create projects and use it anywhere:
8
+
7
9
  ```bash
8
- bun install @elysiumjs/styx
10
+ bun add -g @elysiumjs/styx
9
11
  ```
10
12
 
11
- ## Usage
12
-
13
- The `styx` command needs to be run inside an Elysium.js project. It loads `src/app.ts` (or `index.ts`) and starts the exported `Application` subclass.
13
+ 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.
14
14
 
15
- Add `StyxModule` to the modules of your application to get the commands below. It is only active in development (`NODE_ENV=development`, the default), so the `make:*` and `module:*` commands are absent in production. The `migration:*` commands come from your database module (`DrizzleModule`) and stay available in production.
15
+ 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.
16
16
 
17
- ```ts
18
- import { Application } from '@elysiumjs/core';
19
- import { StyxModule } from '@elysiumjs/styx';
17
+ ## Creating a project
20
18
 
21
- @Application.register({
22
- modules: [StyxModule /* , your other modules */]
23
- })
24
- export class App extends Application {}
19
+ ```bash
20
+ styx create my-app
25
21
  ```
26
22
 
27
- To create new items:
23
+ Without options, it asks for the template (single or multi module), the runtime, the modules, plugins and features. Options skip the prompts:
28
24
 
29
25
  ```bash
30
- bun styx make:command [options]
31
- bun styx make:controller [options]
32
- bun styx make:job [options]
33
- bun styx make:middleware [options]
34
- bun styx make:model [options]
35
- bun styx make:repository [options]
36
- bun styx make:service [options]
37
- bun styx make:validator [options]
26
+ styx create my-app --template multi --modules users,billing --features prettier,hephaestus --git false
38
27
  ```
39
28
 
40
- To manage migrations:
29
+ `--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.
41
30
 
42
- ```bash
43
- bun styx migration:generate [options]
44
- bun styx migration:run [options]
45
- ```
31
+ ## Generating code
46
32
 
47
- To manage modules:
33
+ The generators write files from stubs and never start your app, so they work before the app can boot:
48
34
 
49
35
  ```bash
50
- bun styx module:new [options]
51
- bun styx module:rename [options]
36
+ styx make:command --name SendReport
37
+ styx make:controller --name UserController
38
+ styx make:job --name ImportUsers
39
+ styx make:middleware --name AuthMiddleware
40
+ styx make:model --name User
41
+ styx make:repository --name UserRepository
42
+ styx make:service --name UserService
43
+ styx make:validator --name CreateUser
44
+ styx module:new --name billing
45
+ styx module:rename --module billing --name payments
52
46
  ```
53
47
 
54
- To start the Elysium.js project:
48
+ In a multi module project, pass `--module <name>`. Run `styx help <command>` for every option.
55
49
 
56
- ```bash
57
- bun styx serve
58
- ```
50
+ ## Typed clients
59
51
 
60
- To execute a custom command:
52
+ `styx routes:generate` writes the route types of the app to `src/routes.gen.ts` (set `routes` in `.elysiumrc` or pass `--out` to change it). The file exports `AppRoutes`, for Eden:
61
53
 
62
- ```bash
63
- bun styx <command>
54
+ ```ts
55
+ import type { AppRoutes } from './routes.gen';
56
+
57
+ import { treaty } from '@elysia/eden';
58
+
59
+ const api = treaty<AppRoutes>('http://localhost:3000');
60
+ const { data } = await api.users({ id }).get();
64
61
  ```
65
62
 
66
- To show all available commands:
63
+ 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. The file holds types only and is written again by `typecheck` in new projects, so keep it out of git.
64
+
65
+ ## Running the app
66
+
67
+ Every other command loads the project's app (`src/app.ts` or `index.ts`) and runs there:
67
68
 
68
69
  ```bash
69
- bun styx list
70
+ styx serve
71
+ styx migration:generate
72
+ styx migration:run
73
+ styx <your command>
70
74
  ```
71
75
 
72
- To get help for a specific command:
76
+ These need `@elysiumjs/styx` in the project's dev dependencies.
77
+
78
+ ## Build tools
79
+
80
+ When the project installs `@elysiumjs/hephaestus` (as a dev dependency), its `hephaestus:*` commands are available through `styx` without adding anything to the app.
81
+
82
+ ## Listing commands
73
83
 
74
84
  ```bash
75
- bun styx help <command>
85
+ styx list
86
+ styx help <command>
76
87
  ```
77
88
 
78
89
  ## Contributing
@@ -0,0 +1,31 @@
1
+ /**
2
+ * The files Styx ships beside its code: the code generator stubs (`stubs/`) and the project
3
+ * templates of `styx create` (`templates/`). They are read from the package folder, or from the
4
+ * asset loader that Hephaestus embeds in the standalone executables.
5
+ */
6
+ /**
7
+ * The asset loader generated by Hephaestus (`AssetEmbedder`), keyed by the path in the package.
8
+ * @author Axel Nana <axel.nana@workbud.com>
9
+ */
10
+ export type EmbeddedAssets = {
11
+ getAssetString(path: string): string | null;
12
+ listAssets(): string[];
13
+ };
14
+ /**
15
+ * Uses the assets embedded in a standalone executable. Called by its entry point.
16
+ * @author Axel Nana <axel.nana@workbud.com>
17
+ * @param assets The asset loader generated by Hephaestus.
18
+ */
19
+ export declare const useEmbeddedAssets: (assets: EmbeddedAssets | undefined) => void;
20
+ /**
21
+ * Reads an asset as text.
22
+ * @author Axel Nana <axel.nana@workbud.com>
23
+ * @param path The path of the asset in the package, such as `stubs/job.stub`.
24
+ */
25
+ export declare const readAsset: (path: string) => Promise<string>;
26
+ /**
27
+ * Lists the assets under a folder, with their paths relative to it.
28
+ * @author Axel Nana <axel.nana@workbud.com>
29
+ * @param folder The folder in the package, such as `templates/template-single`.
30
+ */
31
+ export declare const listAssets: (folder: string) => Promise<string[]>;
@@ -0,0 +1,15 @@
1
+ import type { ModuleClass } from '@elysiumjs/core';
2
+ import { Module } from '@elysiumjs/core';
3
+ /**
4
+ * The commands Styx runs itself: `create`, the code generators and `routes:generate`.
5
+ * @author Axel Nana <axel.nana@workbud.com>
6
+ */
7
+ export declare class StyxCliModule extends Module {
8
+ }
9
+ /**
10
+ * Runs a command of the global `styx` CLI, without loading any project.
11
+ * @author Axel Nana <axel.nana@workbud.com>
12
+ * @param argv The command and its arguments.
13
+ * @param tools Modules of build tools found in the project (such as Hephaestus).
14
+ */
15
+ export declare const runCli: (argv: string[], tools?: ModuleClass[]) => Promise<void>;
@@ -0,0 +1,51 @@
1
+ /**
2
+ * What the `styx` command does with its arguments.
3
+ * - `version`: print the version.
4
+ * - `cli`: run Styx's own commands (`create`, the code generators) without loading a project.
5
+ * - `handoff`: run the project's own Styx, so the project's versions are used.
6
+ * - `app`: load the project's app and run the command there (`serve`, the app's commands).
7
+ * - `error`: say why the command cannot run here.
8
+ * @author Axel Nana <axel.nana@workbud.com>
9
+ */
10
+ export type Route = {
11
+ kind: 'version';
12
+ } | {
13
+ kind: 'cli';
14
+ argv: string[];
15
+ } | {
16
+ kind: 'handoff';
17
+ cli: string;
18
+ argv: string[];
19
+ } | {
20
+ kind: 'app';
21
+ project: string;
22
+ argv: string[];
23
+ } | {
24
+ kind: 'error';
25
+ message: string;
26
+ };
27
+ /** Where the `styx` command runs. */
28
+ export type RouteContext = {
29
+ /** The project folder (holding `.elysiumrc`), when inside one. */
30
+ project?: string;
31
+ /** The entry of the project's own Styx, when the project installs it. */
32
+ projectCli?: string;
33
+ /** The entry of the running Styx. */
34
+ self: string;
35
+ };
36
+ /** Code generators: they write files and never load the app. */
37
+ export declare const isGenerator: (command: string | undefined) => boolean;
38
+ /**
39
+ * Commands that read the app's code without booting it, with the project's own packages.
40
+ * `build` runs `hephaestus:build`.
41
+ */
42
+ export declare const isAppTool: (command: string | undefined) => boolean;
43
+ /** Commands Styx runs itself inside a project: the code generators and the app tools. */
44
+ export declare const isCliCommand: (command: string | undefined) => boolean;
45
+ /**
46
+ * Decides what `styx` does with its arguments.
47
+ * @author Axel Nana <axel.nana@workbud.com>
48
+ * @param argv The arguments, without the executable and script.
49
+ * @param context Where the command runs.
50
+ */
51
+ export declare const route: (argv: string[], context: RouteContext) => Route;
package/dist/cli.d.ts ADDED
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env bun
2
+ export {};