@wolfstar/cli 0.1.0-next-20260904111115
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/LICENSE +201 -0
- package/README.md +151 -0
- package/dist/args-Ch1KXUMn.js +24 -0
- package/dist/args-Ch1KXUMn.js.map +1 -0
- package/dist/build-Ct6zabKg.js +22 -0
- package/dist/build-Ct6zabKg.js.map +1 -0
- package/dist/build-DU76s-Ec.js +39 -0
- package/dist/build-DU76s-Ec.js.map +1 -0
- package/dist/builders-BzLMIm9Y.js +44 -0
- package/dist/builders-BzLMIm9Y.js.map +1 -0
- package/dist/cli.d.ts +1 -0
- package/dist/cli.js +58 -0
- package/dist/cli.js.map +1 -0
- package/dist/codegen-DjPOn7cp.js +95 -0
- package/dist/codegen-DjPOn7cp.js.map +1 -0
- package/dist/codegen-mYkL-GBf.js +36 -0
- package/dist/codegen-mYkL-GBf.js.map +1 -0
- package/dist/commands-BkGKs_Bg.js +88 -0
- package/dist/commands-BkGKs_Bg.js.map +1 -0
- package/dist/commands-Dw2LFWV-.js +233 -0
- package/dist/commands-Dw2LFWV-.js.map +1 -0
- package/dist/dev-DWg8l23a.js +604 -0
- package/dist/dev-DWg8l23a.js.map +1 -0
- package/dist/dev-QUxuLcXj.js +30 -0
- package/dist/dev-QUxuLcXj.js.map +1 -0
- package/dist/errors-Bket6XFn.js +50 -0
- package/dist/errors-Bket6XFn.js.map +1 -0
- package/dist/external-Bk4EESdT.js +59 -0
- package/dist/external-Bk4EESdT.js.map +1 -0
- package/dist/index.d.ts +66 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +5 -0
- package/dist/info-B-8rAIn6.js +106 -0
- package/dist/info-B-8rAIn6.js.map +1 -0
- package/dist/info-DRTYYvVB.js +30 -0
- package/dist/info-DRTYYvVB.js.map +1 -0
- package/dist/none-DEo7zEr9.js +50 -0
- package/dist/none-DEo7zEr9.js.map +1 -0
- package/dist/output-mode-ChrOf0LO.js +46 -0
- package/dist/output-mode-ChrOf0LO.js.map +1 -0
- package/dist/plain-CEe4X_Cz.js +43 -0
- package/dist/plain-CEe4X_Cz.js.map +1 -0
- package/dist/prepare-BXcm2Ukp.js +3 -0
- package/dist/prepare-CVf88_Or.js +36 -0
- package/dist/prepare-CVf88_Or.js.map +1 -0
- package/dist/prepare-D5NZ0w4t.js +68 -0
- package/dist/prepare-D5NZ0w4t.js.map +1 -0
- package/dist/process-supervisor-CJOdmp0W.js +128 -0
- package/dist/process-supervisor-CJOdmp0W.js.map +1 -0
- package/dist/project-DHF3qdm-.js +66 -0
- package/dist/project-DHF3qdm-.js.map +1 -0
- package/dist/tsc-BqZfDTD0.js +133 -0
- package/dist/tsc-BqZfDTD0.js.map +1 -0
- package/dist/tsc-CovVAtfo.js +3 -0
- package/dist/tsdown-DlAs0rSI.js +104 -0
- package/dist/tsdown-DlAs0rSI.js.map +1 -0
- package/dist/tui-BTRFsLQR.js +770 -0
- package/dist/tui-BTRFsLQR.js.map +1 -0
- package/dist/tunnel-B8Id4-lR.js +205 -0
- package/dist/tunnel-B8Id4-lR.js.map +1 -0
- package/dist/version-DN6Uho-Y.js +30 -0
- package/dist/version-DN6Uho-Y.js.map +1 -0
- package/dist/vite-D3vYFsqa.js +93 -0
- package/dist/vite-D3vYFsqa.js.map +1 -0
- package/package.json +95 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright 2022 Wolfstar Project
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
package/README.md
ADDED
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
<div align="center">
|
|
2
|
+
|
|
3
|
+
# @wolfstar/cli
|
|
4
|
+
|
|
5
|
+
**The `stars` command line interface for [`@wolfstar/http-framework`](../http-framework) projects.**
|
|
6
|
+
|
|
7
|
+
[](https://github.com/wolfstar-project/stars-components/blob/main/LICENSE)
|
|
8
|
+
[](https://www.npmjs.com/package/@wolfstar/cli)
|
|
9
|
+
|
|
10
|
+
</div>
|
|
11
|
+
|
|
12
|
+
## Description
|
|
13
|
+
|
|
14
|
+
`stars` is a small, fast CLI that owns the developer workflow of a bot built with `@wolfstar/http-framework`. Like
|
|
15
|
+
Nuxt splits `nuxt.config`/`defineNuxtConfig` (owned by the `nuxt` framework) from `nuxi` (a separate CLI package that
|
|
16
|
+
calls into it), the typed `stars.config.*` schema and loader live in [`@wolfstar/http-framework`](../http-framework)
|
|
17
|
+
(`@wolfstar/http-framework/config`) — this package only consumes it to drive its commands:
|
|
18
|
+
|
|
19
|
+
- `stars dev` builds the project, starts the bot, restarts it on changes and shows what is happening in an interactive terminal UI (or plain logs).
|
|
20
|
+
- `stars build` runs the configured build tool once.
|
|
21
|
+
- `stars info` prints the resolved configuration and environment (`--json` for scripts).
|
|
22
|
+
- `stars codegen` runs the configured code generators (`--check` for CI).
|
|
23
|
+
- `stars prepare` generates the auto imports declaration file (`--check` for CI).
|
|
24
|
+
- `stars commands` inspects and cleans the application commands Discord has deployed.
|
|
25
|
+
|
|
26
|
+
Everything is driven by a typed `stars.config.ts` file.
|
|
27
|
+
|
|
28
|
+
## Installation
|
|
29
|
+
|
|
30
|
+
```sh
|
|
31
|
+
pnpm add -D @wolfstar/cli
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
Projects scaffolded with [`@wolfstar/create-http-framework`](../create-http-framework) come with `@wolfstar/cli`, a `stars.config.ts` file and `dev`/`build` scripts already wired up.
|
|
35
|
+
|
|
36
|
+
## Configuration
|
|
37
|
+
|
|
38
|
+
`stars.config.{ts,mts,cts,js,mjs,cjs}` is defined and loaded by [`@wolfstar/http-framework`](../http-framework#project-configuration-starsconfig), not by this package — see its README for the full option reference (`root`, `entry`, `build`, `dev`, `codegen`) and the `defineConfig` helper. `stars` looks for it in the working directory (`--config <file>` overrides it, `--cwd <dir>` changes the working directory) and passes `ConfigError`s from the framework through as exit code `2`, with the offending option path and a hint printed to the terminal.
|
|
39
|
+
|
|
40
|
+
```ts
|
|
41
|
+
// stars.config.ts
|
|
42
|
+
import { defineConfig } from '@wolfstar/http-framework/config';
|
|
43
|
+
|
|
44
|
+
export default defineConfig({
|
|
45
|
+
entry: 'src/main.ts',
|
|
46
|
+
build: { tool: 'tsdown' }
|
|
47
|
+
});
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
`stars dev`'s URL needs no configuration either — it is detected from `HTTP_PORT` (env var, `.env.local`/`.env`, or `dev.env`) or `3000`, the same way Vite's and Nuxt's dev servers do, and `localhost` is swapped for `127.0.0.1` at runtime if that is what is actually reachable. Set `dev.url` only to override it.
|
|
51
|
+
|
|
52
|
+
The resolved configuration is also available programmatically, exactly as the commands see it (re-exported from this package for convenience, or import it directly from `@wolfstar/http-framework/config`):
|
|
53
|
+
|
|
54
|
+
```ts
|
|
55
|
+
import { loadStarsConfig } from '@wolfstar/cli';
|
|
56
|
+
|
|
57
|
+
const config = await loadStarsConfig({ cwd: process.cwd() });
|
|
58
|
+
console.log(config.entry, config.build.output);
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
## Commands
|
|
62
|
+
|
|
63
|
+
```sh
|
|
64
|
+
stars dev [--no-tui] [--config <file>] [--cwd <dir>]
|
|
65
|
+
stars build [--config <file>] [--cwd <dir>]
|
|
66
|
+
stars info [--json] [--config <file>] [--cwd <dir>]
|
|
67
|
+
stars codegen [--check] [--json] [--config <file>] [--cwd <dir>]
|
|
68
|
+
stars prepare [--check] [--json] [--config <file>] [--cwd <dir>]
|
|
69
|
+
stars commands [list|clean] [--guild <id>] [--name <name>] [--yes] [--json]
|
|
70
|
+
stars --help | --version
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
### `stars dev`
|
|
74
|
+
|
|
75
|
+
Watches the sources through the configured build tool (`tsdown` programmatically with your `tsdown.config.*`, `tsc -b --watch`, or a plain file watcher for JavaScript projects), starts the bot after the first successful build and restarts it after every following one. Failed builds keep the previous process running and wait for the next change; a crashed bot waits for the next change or a manual restart.
|
|
76
|
+
|
|
77
|
+
The bot runs as a child `node` process with `STARS_DEV=1` in its environment. Because `stars dev` already restarts the whole process, leave the framework's own `hmr` option disabled while using it.
|
|
78
|
+
|
|
79
|
+
**Interactive UI** (default on a TTY): an [Ink](https://github.com/vadimdemedes/ink) (React) application in the
|
|
80
|
+
terminal's alternate screen — lifecycle and uptime, restart counter and reason, build state, URL, health, type
|
|
81
|
+
checking and tunnel status, plus the filtered logs.
|
|
82
|
+
|
|
83
|
+
| Key | Action |
|
|
84
|
+
| ---------------------- | --------------------------------------------------------- |
|
|
85
|
+
| `r` | restart the bot |
|
|
86
|
+
| `c` | clear the logs |
|
|
87
|
+
| `f` | cycle the source filter (all › app › build › stars) |
|
|
88
|
+
| `e` | cycle the level filter (all › warnings › errors) |
|
|
89
|
+
| `↑` `↓` / `j` `k` | scroll one line (`PgUp`/`PgDn` one page, `End` to follow) |
|
|
90
|
+
| `h` / `?` | toggle help |
|
|
91
|
+
| `q` / `Esc` / `Ctrl+C` | quit |
|
|
92
|
+
|
|
93
|
+
**Plain mode** prints prefixed lines instead and is selected by `--no-tui`, `STARS_TUI=plain`, or automatically when stdout is not a terminal, in CI, or with `TERM=dumb`. Both modes honour `NO_COLOR`/`FORCE_COLOR`, `STARS_REDUCED_MOTION=1` disables the spinner, and both stop the bot cleanly on `SIGINT`/`SIGTERM`. `SIGUSR2` restarts the bot (not on Windows).
|
|
94
|
+
|
|
95
|
+
### `stars commands`
|
|
96
|
+
|
|
97
|
+
Lists what Discord currently has deployed, which is not necessarily what the project registers today: renamed and
|
|
98
|
+
removed commands stay until something deletes them.
|
|
99
|
+
|
|
100
|
+
```sh
|
|
101
|
+
stars commands list # global commands
|
|
102
|
+
stars commands list --guild 1234 # a guild's commands
|
|
103
|
+
stars commands clean # wizard: pick from a checklist, then confirm
|
|
104
|
+
stars commands clean --name ping # delete one, asking first
|
|
105
|
+
stars commands clean --guild 1234 --yes
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
It reads `DISCORD_TOKEN` and `DISCORD_APPLICATION_ID` (or `APPLICATION_ID`) from the environment or the project's
|
|
109
|
+
`.env`, the same place the bot reads them from. `clean` deletes deployed commands, so on a terminal it opens a wizard —
|
|
110
|
+
a checklist of what is deployed, then a confirmation — and refuses to run without `--yes` (or `--name`) anywhere
|
|
111
|
+
else.
|
|
112
|
+
|
|
113
|
+
### Type checking, tunnel and logs
|
|
114
|
+
|
|
115
|
+
Three `dev` options round out the dev loop (all documented in
|
|
116
|
+
[`@wolfstar/http-framework`](../http-framework#project-configuration-starsconfig)):
|
|
117
|
+
|
|
118
|
+
- `dev.typecheck: true` runs a type checker next to the bot and reports type errors on the UI's `tsc` channel,
|
|
119
|
+
without ever blocking a build or a restart — useful when building with `tsdown`, which does not type-check.
|
|
120
|
+
`dev.typecheck.checker` picks which one: `tsc` (the project's TypeScript, watch mode), `golar` (`golar tsc`, watch
|
|
121
|
+
mode), `tsz` (the tsc-compatible checker, re-run after every build since it has no watch mode), or `auto` — the
|
|
122
|
+
default, which uses `golar` when the project depends on it and `tsc` otherwise.
|
|
123
|
+
- `dev.tunnel: true` opens a `cloudflared` quick tunnel so Discord can reach the bot's interactions endpoint from the
|
|
124
|
+
internet; a string is an https URL you already serve, which the CLI only probes. `dev.tunnel.updateEndpoint` writes
|
|
125
|
+
the URL to the Discord application, and is opt-in because it edits a live application.
|
|
126
|
+
- `dev.logFile` (default `.stars/dev.log`) mirrors the session's logs to disk, so a run can be read back after the
|
|
127
|
+
terminal UI is gone. Set it to `false` to disable it.
|
|
128
|
+
|
|
129
|
+
### Experimental flags
|
|
130
|
+
|
|
131
|
+
`experimental` in `stars.config.*` turns on work that is still landing (see the
|
|
132
|
+
[framework README](../http-framework#experimental-flags) for the full reference):
|
|
133
|
+
|
|
134
|
+
| Flag | What it changes |
|
|
135
|
+
| -------------------- | ------------------------------------------------------------------------------------------------------ |
|
|
136
|
+
| `enableVite` | Builds through the project's own `vite` (and allows `build.tool: 'vite'`) instead of `tsdown` |
|
|
137
|
+
| `enableExternalVite` | The project runs Vite itself; `stars dev` only watches the build output and restarts the bot |
|
|
138
|
+
| `enableNitro` | Declared, not implemented: `stars dev`/`stars build` fail with `EXPERIMENT_UNAVAILABLE` until it lands |
|
|
139
|
+
|
|
140
|
+
`stars info` prints which flags are on.
|
|
141
|
+
|
|
142
|
+
### Exit codes
|
|
143
|
+
|
|
144
|
+
| Code | Meaning |
|
|
145
|
+
| ----- | ---------------------------------------------------- |
|
|
146
|
+
| `0` | success |
|
|
147
|
+
| `1` | generic error (including `codegen --check` failures) |
|
|
148
|
+
| `2` | invalid or missing configuration |
|
|
149
|
+
| `3` | build failed |
|
|
150
|
+
| `130` | interrupted with `SIGINT` |
|
|
151
|
+
| `143` | terminated with `SIGTERM`/`SIGHUP` |
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { resolve } from "node:path";
|
|
2
|
+
|
|
3
|
+
//#region src/lib/args.ts
|
|
4
|
+
/**
|
|
5
|
+
* Arguments shared by every command that reads the project configuration.
|
|
6
|
+
*/
|
|
7
|
+
const projectArgs = {
|
|
8
|
+
config: {
|
|
9
|
+
type: "string",
|
|
10
|
+
alias: "c",
|
|
11
|
+
description: "Path to the configuration file (defaults to stars.config.* in the working directory)"
|
|
12
|
+
},
|
|
13
|
+
cwd: {
|
|
14
|
+
type: "string",
|
|
15
|
+
description: "Working directory to run from (defaults to the current directory)"
|
|
16
|
+
}
|
|
17
|
+
};
|
|
18
|
+
function resolveCwd(args) {
|
|
19
|
+
return args.cwd ? resolve(process.cwd(), args.cwd) : process.cwd();
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
//#endregion
|
|
23
|
+
export { resolveCwd as n, projectArgs as t };
|
|
24
|
+
//# sourceMappingURL=args-Ch1KXUMn.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"args-Ch1KXUMn.js","names":[],"sources":["../src/lib/args.ts"],"sourcesContent":["import type { ArgsDef } from 'citty';\nimport { resolve } from 'node:path';\n\n/**\n * Arguments shared by every command that reads the project configuration.\n */\nexport const projectArgs = {\n\tconfig: {\n\t\ttype: 'string',\n\t\talias: 'c',\n\t\tdescription: 'Path to the configuration file (defaults to stars.config.* in the working directory)'\n\t},\n\tcwd: {\n\t\ttype: 'string',\n\t\tdescription: 'Working directory to run from (defaults to the current directory)'\n\t}\n} as const satisfies ArgsDef;\n\nexport interface ProjectArgs {\n\tconfig?: string;\n\tcwd?: string;\n}\n\nexport function resolveCwd(args: ProjectArgs): string {\n\treturn args.cwd ? resolve(process.cwd(), args.cwd) : process.cwd();\n}\n"],"mappings":";;;;;;AAMA,MAAa,cAAc;CAC1B,QAAQ;EACP,MAAM;EACN,OAAO;EACP,aAAa;CACd;CACA,KAAK;EACJ,MAAM;EACN,aAAa;CACd;AACD;AAOA,SAAgB,WAAW,MAA2B;CACrD,OAAO,KAAK,MAAM,QAAQ,QAAQ,IAAI,GAAG,KAAK,GAAG,IAAI,QAAQ,IAAI;AAClE"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { t as projectArgs } from "./args-Ch1KXUMn.js";
|
|
2
|
+
import { defineCommand } from "citty";
|
|
3
|
+
|
|
4
|
+
//#region src/commands/build.ts
|
|
5
|
+
var build_default = defineCommand({
|
|
6
|
+
meta: {
|
|
7
|
+
name: "build",
|
|
8
|
+
description: "Build the project once with the configured build tool"
|
|
9
|
+
},
|
|
10
|
+
args: { ...projectArgs },
|
|
11
|
+
async run({ args }) {
|
|
12
|
+
const { runBuild } = await import("./build-DU76s-Ec.js");
|
|
13
|
+
await runBuild({
|
|
14
|
+
config: args.config,
|
|
15
|
+
cwd: args.cwd
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
//#endregion
|
|
21
|
+
export { build_default as default };
|
|
22
|
+
//# sourceMappingURL=build-Ct6zabKg.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"build-Ct6zabKg.js","names":[],"sources":["../src/commands/build.ts"],"sourcesContent":["import { defineCommand } from 'citty';\nimport { projectArgs } from '../lib/args.js';\n\nexport default defineCommand({\n\tmeta: {\n\t\tname: 'build',\n\t\tdescription: 'Build the project once with the configured build tool'\n\t},\n\targs: { ...projectArgs },\n\tasync run({ args }) {\n\t\tconst { runBuild } = await import('../lib/tasks/build.js');\n\t\tawait runBuild({ config: args.config, cwd: args.cwd });\n\t}\n});\n"],"mappings":";;;;AAGA,oBAAe,cAAc;CAC5B,MAAM;EACL,MAAM;EACN,aAAa;CACd;CACA,MAAM,EAAE,GAAG,YAAY;CACvB,MAAM,IAAI,EAAE,QAAQ;EACnB,MAAM,EAAE,aAAa,MAAM,OAAO;EAClC,MAAM,SAAS;GAAE,QAAQ,KAAK;GAAQ,KAAK,KAAK;EAAI,CAAC;CACtD;AACD,CAAC"}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { n as ExitCode, t as CliError } from "./errors-Bket6XFn.js";
|
|
2
|
+
import { i as shouldUseColor } from "./output-mode-ChrOf0LO.js";
|
|
3
|
+
import { n as resolveCwd } from "./args-Ch1KXUMn.js";
|
|
4
|
+
import { n as createBuilder, t as assertSupportedExperiments } from "./builders-BzLMIm9Y.js";
|
|
5
|
+
import { t as prepareAutoImports } from "./prepare-D5NZ0w4t.js";
|
|
6
|
+
import { displayPath, loadStarsConfig } from "@wolfstar/http-framework/config";
|
|
7
|
+
import { createColors } from "colorette";
|
|
8
|
+
|
|
9
|
+
//#region src/lib/tasks/build.ts
|
|
10
|
+
async function runBuild(options) {
|
|
11
|
+
const stdout = options.stdout ?? process.stdout;
|
|
12
|
+
const colors = createColors({ useColor: shouldUseColor() });
|
|
13
|
+
const config = await loadStarsConfig({
|
|
14
|
+
cwd: resolveCwd(options),
|
|
15
|
+
configFile: options.config
|
|
16
|
+
});
|
|
17
|
+
assertSupportedExperiments(config);
|
|
18
|
+
await prepareAutoImports(config);
|
|
19
|
+
if (config.build.tool === "none") {
|
|
20
|
+
stdout.write(`${colors.dim("stars")} nothing to build, ${displayPath(config.root, config.entry)} runs as-is (build.tool is 'none')\n`);
|
|
21
|
+
return;
|
|
22
|
+
}
|
|
23
|
+
const builder = await createBuilder(config);
|
|
24
|
+
builder.on("log", (level, text) => {
|
|
25
|
+
const paint = level === "error" ? colors.red : level === "warn" ? colors.yellow : (value) => value;
|
|
26
|
+
stdout.write(`${paint(text)}\n`);
|
|
27
|
+
});
|
|
28
|
+
stdout.write(`${colors.dim("stars")} building with ${colors.bold(config.build.tool)}…\n`);
|
|
29
|
+
const outcome = await builder.build();
|
|
30
|
+
if (!outcome.ok) throw new CliError(`Build failed${outcome.message ? `: ${outcome.message}` : ""}`, {
|
|
31
|
+
code: "BUILD_FAILED",
|
|
32
|
+
exitCode: ExitCode.BuildFailed
|
|
33
|
+
});
|
|
34
|
+
stdout.write(`${colors.dim("stars")} ${colors.green(`built in ${outcome.durationMs}ms`)} → ${displayPath(config.root, config.build.output)}\n`);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
//#endregion
|
|
38
|
+
export { runBuild };
|
|
39
|
+
//# sourceMappingURL=build-DU76s-Ec.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"build-DU76s-Ec.js","names":[],"sources":["../src/lib/tasks/build.ts"],"sourcesContent":["import { createColors } from 'colorette';\nimport type { ProjectArgs } from '../args.js';\nimport { resolveCwd } from '../args.js';\nimport { assertSupportedExperiments, createBuilder } from '../builders/index.js';\nimport { loadStarsConfig } from '@wolfstar/http-framework/config';\nimport { displayPath } from '@wolfstar/http-framework/config';\nimport { CliError, ExitCode } from '../errors.js';\nimport { shouldUseColor } from '../output-mode.js';\nimport { prepareAutoImports } from './prepare.js';\n\nexport interface BuildTaskOptions extends ProjectArgs {\n\tstdout?: NodeJS.WritableStream;\n}\n\nexport async function runBuild(options: BuildTaskOptions): Promise<void> {\n\tconst stdout = options.stdout ?? process.stdout;\n\tconst colors = createColors({ useColor: shouldUseColor() });\n\tconst config = await loadStarsConfig({ cwd: resolveCwd(options), configFile: options.config });\n\tassertSupportedExperiments(config);\n\tawait prepareAutoImports(config);\n\n\tif (config.build.tool === 'none') {\n\t\tstdout.write(`${colors.dim('stars')} nothing to build, ${displayPath(config.root, config.entry)} runs as-is (build.tool is 'none')\\n`);\n\t\treturn;\n\t}\n\n\tconst builder = await createBuilder(config);\n\tbuilder.on('log', (level, text) => {\n\t\tconst paint = level === 'error' ? colors.red : level === 'warn' ? colors.yellow : (value: string) => value;\n\t\tstdout.write(`${paint(text)}\\n`);\n\t});\n\n\tstdout.write(`${colors.dim('stars')} building with ${colors.bold(config.build.tool)}…\\n`);\n\tconst outcome = await builder.build();\n\tif (!outcome.ok) {\n\t\tthrow new CliError(`Build failed${outcome.message ? `: ${outcome.message}` : ''}`, { code: 'BUILD_FAILED', exitCode: ExitCode.BuildFailed });\n\t}\n\n\tstdout.write(`${colors.dim('stars')} ${colors.green(`built in ${outcome.durationMs}ms`)} → ${displayPath(config.root, config.build.output)}\\n`);\n}\n"],"mappings":";;;;;;;;;AAcA,eAAsB,SAAS,SAA0C;CACxE,MAAM,SAAS,QAAQ,UAAU,QAAQ;CACzC,MAAM,SAAS,aAAa,EAAE,UAAU,eAAe,EAAE,CAAC;CAC1D,MAAM,SAAS,MAAM,gBAAgB;EAAE,KAAK,WAAW,OAAO;EAAG,YAAY,QAAQ;CAAO,CAAC;CAC7F,2BAA2B,MAAM;CACjC,MAAM,mBAAmB,MAAM;CAE/B,IAAI,OAAO,MAAM,SAAS,QAAQ;EACjC,OAAO,MAAM,GAAG,OAAO,IAAI,OAAO,EAAE,qBAAqB,YAAY,OAAO,MAAM,OAAO,KAAK,EAAE,qCAAqC;EACrI;CACD;CAEA,MAAM,UAAU,MAAM,cAAc,MAAM;CAC1C,QAAQ,GAAG,QAAQ,OAAO,SAAS;EAClC,MAAM,QAAQ,UAAU,UAAU,OAAO,MAAM,UAAU,SAAS,OAAO,UAAU,UAAkB;EACrG,OAAO,MAAM,GAAG,MAAM,IAAI,EAAE,GAAG;CAChC,CAAC;CAED,OAAO,MAAM,GAAG,OAAO,IAAI,OAAO,EAAE,iBAAiB,OAAO,KAAK,OAAO,MAAM,IAAI,EAAE,IAAI;CACxF,MAAM,UAAU,MAAM,QAAQ,MAAM;CACpC,IAAI,CAAC,QAAQ,IACZ,MAAM,IAAI,SAAS,eAAe,QAAQ,UAAU,KAAK,QAAQ,YAAY,MAAM;EAAE,MAAM;EAAgB,UAAU,SAAS;CAAY,CAAC;CAG5I,OAAO,MAAM,GAAG,OAAO,IAAI,OAAO,EAAE,GAAG,OAAO,MAAM,YAAY,QAAQ,WAAW,GAAG,EAAE,KAAK,YAAY,OAAO,MAAM,OAAO,MAAM,MAAM,EAAE,GAAG;AAC/I"}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { t as CliError } from "./errors-Bket6XFn.js";
|
|
2
|
+
|
|
3
|
+
//#region src/lib/builders/index.ts
|
|
4
|
+
/**
|
|
5
|
+
* Fails on experiments the CLI cannot honour yet, before a command gets far enough to look like it worked.
|
|
6
|
+
*
|
|
7
|
+
* Called by `stars dev`/`stars build` up front, since a project whose build tool needs no build at all would
|
|
8
|
+
* otherwise return early and never reach {@link createBuilder}.
|
|
9
|
+
*/
|
|
10
|
+
function assertSupportedExperiments(config) {
|
|
11
|
+
if (config.experimental.enableNitro) throw new CliError("`experimental.enableNitro` is not implemented yet", {
|
|
12
|
+
code: "EXPERIMENT_UNAVAILABLE",
|
|
13
|
+
hint: "Nitro needs the framework's Fetch adapter (wolfstar-project/stars-components#81); until it lands, use `build.tool` 'tsdown', 'vite' or 'tsc'."
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
async function createBuilder(config) {
|
|
17
|
+
assertSupportedExperiments(config);
|
|
18
|
+
if (config.experimental.enableExternalVite) {
|
|
19
|
+
const { ExternalBuilder } = await import("./external-Bk4EESdT.js");
|
|
20
|
+
return new ExternalBuilder(config);
|
|
21
|
+
}
|
|
22
|
+
switch (config.build.tool) {
|
|
23
|
+
case "tsdown": {
|
|
24
|
+
const { TsdownBuilder } = await import("./tsdown-DlAs0rSI.js");
|
|
25
|
+
return new TsdownBuilder(config);
|
|
26
|
+
}
|
|
27
|
+
case "vite": {
|
|
28
|
+
const { ViteBuilder } = await import("./vite-D3vYFsqa.js");
|
|
29
|
+
return new ViteBuilder(config);
|
|
30
|
+
}
|
|
31
|
+
case "tsc": {
|
|
32
|
+
const { TscBuilder } = await import("./tsc-CovVAtfo.js");
|
|
33
|
+
return new TscBuilder(config);
|
|
34
|
+
}
|
|
35
|
+
case "none": {
|
|
36
|
+
const { NoneBuilder } = await import("./none-DEo7zEr9.js");
|
|
37
|
+
return new NoneBuilder(config);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
//#endregion
|
|
43
|
+
export { createBuilder as n, assertSupportedExperiments as t };
|
|
44
|
+
//# sourceMappingURL=builders-BzLMIm9Y.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"builders-BzLMIm9Y.js","names":[],"sources":["../src/lib/builders/index.ts"],"sourcesContent":["import type { ResolvedStarsConfig } from '@wolfstar/http-framework/config';\nimport { CliError } from '../errors.js';\nimport type { Builder } from './types.js';\n\n/**\n * Fails on experiments the CLI cannot honour yet, before a command gets far enough to look like it worked.\n *\n * Called by `stars dev`/`stars build` up front, since a project whose build tool needs no build at all would\n * otherwise return early and never reach {@link createBuilder}.\n */\nexport function assertSupportedExperiments(config: ResolvedStarsConfig): void {\n\tif (config.experimental.enableNitro) {\n\t\tthrow new CliError('`experimental.enableNitro` is not implemented yet', {\n\t\t\tcode: 'EXPERIMENT_UNAVAILABLE',\n\t\t\thint: \"Nitro needs the framework's Fetch adapter (wolfstar-project/stars-components#81); until it lands, use `build.tool` 'tsdown', 'vite' or 'tsc'.\"\n\t\t});\n\t}\n}\n\nexport async function createBuilder(config: ResolvedStarsConfig): Promise<Builder> {\n\tassertSupportedExperiments(config);\n\n\t// The project runs its own build, so the CLI only watches what it writes (see `ExternalBuilder`).\n\tif (config.experimental.enableExternalVite) {\n\t\tconst { ExternalBuilder } = await import('./external.js');\n\t\treturn new ExternalBuilder(config);\n\t}\n\n\tswitch (config.build.tool) {\n\t\tcase 'tsdown': {\n\t\t\tconst { TsdownBuilder } = await import('./tsdown.js');\n\t\t\treturn new TsdownBuilder(config);\n\t\t}\n\t\tcase 'vite': {\n\t\t\tconst { ViteBuilder } = await import('./vite.js');\n\t\t\treturn new ViteBuilder(config);\n\t\t}\n\t\tcase 'tsc': {\n\t\t\tconst { TscBuilder } = await import('./tsc.js');\n\t\t\treturn new TscBuilder(config);\n\t\t}\n\t\tcase 'none': {\n\t\t\tconst { NoneBuilder } = await import('./none.js');\n\t\t\treturn new NoneBuilder(config);\n\t\t}\n\t}\n}\n\nexport type { Builder, BuilderEvents, BuildOutcome } from './types.js';\n"],"mappings":";;;;;;;;;AAUA,SAAgB,2BAA2B,QAAmC;CAC7E,IAAI,OAAO,aAAa,aACvB,MAAM,IAAI,SAAS,qDAAqD;EACvE,MAAM;EACN,MAAM;CACP,CAAC;AAEH;AAEA,eAAsB,cAAc,QAA+C;CAClF,2BAA2B,MAAM;CAGjC,IAAI,OAAO,aAAa,oBAAoB;EAC3C,MAAM,EAAE,oBAAoB,MAAM,OAAO;EACzC,OAAO,IAAI,gBAAgB,MAAM;CAClC;CAEA,QAAQ,OAAO,MAAM,MAArB;EACC,KAAK,UAAU;GACd,MAAM,EAAE,kBAAkB,MAAM,OAAO;GACvC,OAAO,IAAI,cAAc,MAAM;EAChC;EACA,KAAK,QAAQ;GACZ,MAAM,EAAE,gBAAgB,MAAM,OAAO;GACrC,OAAO,IAAI,YAAY,MAAM;EAC9B;EACA,KAAK,OAAO;GACX,MAAM,EAAE,eAAe,MAAM,OAAO;GACpC,OAAO,IAAI,WAAW,MAAM;EAC7B;EACA,KAAK,QAAQ;GACZ,MAAM,EAAE,gBAAgB,MAAM,OAAO;GACrC,OAAO,IAAI,YAAY,MAAM;EAC9B;CACD;AACD"}
|
package/dist/cli.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {}
|
package/dist/cli.js
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { i as formatError, r as exitCodeOf } from "./errors-Bket6XFn.js";
|
|
3
|
+
import { t as readOwnPackageJson } from "./version-DN6Uho-Y.js";
|
|
4
|
+
import { defineCommand, renderUsage, runCommand } from "citty";
|
|
5
|
+
|
|
6
|
+
//#region src/cli.ts
|
|
7
|
+
const packageJson = readOwnPackageJson();
|
|
8
|
+
const subCommands = {
|
|
9
|
+
dev: () => import("./dev-QUxuLcXj.js").then((module) => module.default),
|
|
10
|
+
build: () => import("./build-Ct6zabKg.js").then((module) => module.default),
|
|
11
|
+
info: () => import("./info-DRTYYvVB.js").then((module) => module.default),
|
|
12
|
+
codegen: () => import("./codegen-mYkL-GBf.js").then((module) => module.default),
|
|
13
|
+
prepare: () => import("./prepare-CVf88_Or.js").then((module) => module.default),
|
|
14
|
+
commands: () => import("./commands-BkGKs_Bg.js").then((module) => module.default)
|
|
15
|
+
};
|
|
16
|
+
const main = defineCommand({
|
|
17
|
+
meta: {
|
|
18
|
+
name: "stars",
|
|
19
|
+
version: packageJson.version,
|
|
20
|
+
description: packageJson.description
|
|
21
|
+
},
|
|
22
|
+
subCommands
|
|
23
|
+
});
|
|
24
|
+
const rawArgs = process.argv.slice(2);
|
|
25
|
+
if (rawArgs.includes("--version") || rawArgs.includes("-V")) {
|
|
26
|
+
console.log(packageJson.version);
|
|
27
|
+
process.exit(0);
|
|
28
|
+
}
|
|
29
|
+
if (rawArgs.length === 0 || rawArgs.includes("--help") || rawArgs.includes("-h")) {
|
|
30
|
+
const command = await resolveHelpTarget(rawArgs.filter((argument) => !argument.startsWith("-")));
|
|
31
|
+
console.log(await (command ? renderUsage(command, main) : renderUsage(main)));
|
|
32
|
+
process.exit(0);
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Walks the command names of `stars <command> [<subcommand>] --help` so nested commands (`stars commands clean`)
|
|
36
|
+
* render their own usage instead of their parent's.
|
|
37
|
+
*/
|
|
38
|
+
async function resolveHelpTarget(names) {
|
|
39
|
+
const [first, ...rest] = names;
|
|
40
|
+
if (!first || !Object.hasOwn(subCommands, first)) return null;
|
|
41
|
+
let command = await subCommands[first]();
|
|
42
|
+
for (const name of rest) {
|
|
43
|
+
const child = (typeof command.subCommands === "function" ? await command.subCommands() : await command.subCommands)?.[name];
|
|
44
|
+
if (!child) break;
|
|
45
|
+
command = typeof child === "function" ? await child() : child;
|
|
46
|
+
}
|
|
47
|
+
return command;
|
|
48
|
+
}
|
|
49
|
+
try {
|
|
50
|
+
await runCommand(main, { rawArgs });
|
|
51
|
+
} catch (error) {
|
|
52
|
+
console.error(formatError(error));
|
|
53
|
+
process.exit(exitCodeOf(error));
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
//#endregion
|
|
57
|
+
export { };
|
|
58
|
+
//# sourceMappingURL=cli.js.map
|
package/dist/cli.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cli.js","names":[],"sources":["../src/cli.ts"],"sourcesContent":["#!/usr/bin/env node\n\nimport { defineCommand, renderUsage, runCommand, type CommandDef } from 'citty';\nimport { exitCodeOf, formatError } from './lib/errors.js';\nimport { readOwnPackageJson } from './lib/version.js';\n\nconst packageJson = readOwnPackageJson();\n\n// citty types each command by its own arguments; the registry needs the erased form.\n// oxlint-disable-next-line typescript/no-explicit-any\ntype AnyCommand = CommandDef<any>;\n\nconst subCommands: Record<string, () => Promise<AnyCommand>> = {\n\tdev: () => import('./commands/dev.js').then((module) => module.default),\n\tbuild: () => import('./commands/build.js').then((module) => module.default),\n\tinfo: () => import('./commands/info.js').then((module) => module.default),\n\tcodegen: () => import('./commands/codegen.js').then((module) => module.default),\n\tprepare: () => import('./commands/prepare.js').then((module) => module.default),\n\tcommands: () => import('./commands/commands.js').then((module) => module.default)\n};\n\nconst main = defineCommand({\n\tmeta: {\n\t\tname: 'stars',\n\t\tversion: packageJson.version,\n\t\tdescription: packageJson.description\n\t},\n\tsubCommands\n});\n\nconst rawArgs = process.argv.slice(2);\n\nif (rawArgs.includes('--version') || rawArgs.includes('-V')) {\n\tconsole.log(packageJson.version);\n\tprocess.exit(0);\n}\n\nif (rawArgs.length === 0 || rawArgs.includes('--help') || rawArgs.includes('-h')) {\n\t// citty's showUsage logs through consola, which is muted in some environments; render and print directly.\n\tconst command = await resolveHelpTarget(rawArgs.filter((argument) => !argument.startsWith('-')));\n\tconsole.log(await (command ? renderUsage(command, main) : renderUsage(main)));\n\tprocess.exit(0);\n}\n\n/**\n * Walks the command names of `stars <command> [<subcommand>] --help` so nested commands (`stars commands clean`)\n * render their own usage instead of their parent's.\n */\nasync function resolveHelpTarget(names: string[]): Promise<AnyCommand | null> {\n\tconst [first, ...rest] = names;\n\tif (!first || !Object.hasOwn(subCommands, first)) return null;\n\n\tlet command = await subCommands[first]!();\n\tfor (const name of rest) {\n\t\tconst resolved = typeof command.subCommands === 'function' ? await command.subCommands() : await command.subCommands;\n\t\tconst child: unknown = (resolved as Record<string, unknown> | undefined)?.[name];\n\t\tif (!child) break;\n\t\tcommand = (typeof child === 'function' ? await child() : child) as AnyCommand;\n\t}\n\n\treturn command;\n}\n\ntry {\n\tawait runCommand(main, { rawArgs });\n} catch (error) {\n\tconsole.error(formatError(error));\n\tprocess.exit(exitCodeOf(error));\n}\n"],"mappings":";;;;;;AAMA,MAAM,cAAc,mBAAmB;AAMvC,MAAM,cAAyD;CAC9D,WAAW,OAAO,oBAAoB,CAAC,MAAM,WAAW,OAAO,OAAO;CACtE,aAAa,OAAO,sBAAsB,CAAC,MAAM,WAAW,OAAO,OAAO;CAC1E,YAAY,OAAO,qBAAqB,CAAC,MAAM,WAAW,OAAO,OAAO;CACxE,eAAe,OAAO,wBAAwB,CAAC,MAAM,WAAW,OAAO,OAAO;CAC9E,eAAe,OAAO,wBAAwB,CAAC,MAAM,WAAW,OAAO,OAAO;CAC9E,gBAAgB,OAAO,yBAAyB,CAAC,MAAM,WAAW,OAAO,OAAO;AACjF;AAEA,MAAM,OAAO,cAAc;CAC1B,MAAM;EACL,MAAM;EACN,SAAS,YAAY;EACrB,aAAa,YAAY;CAC1B;CACA;AACD,CAAC;AAED,MAAM,UAAU,QAAQ,KAAK,MAAM,CAAC;AAEpC,IAAI,QAAQ,SAAS,WAAW,KAAK,QAAQ,SAAS,IAAI,GAAG;CAC5D,QAAQ,IAAI,YAAY,OAAO;CAC/B,QAAQ,KAAK,CAAC;AACf;AAEA,IAAI,QAAQ,WAAW,KAAK,QAAQ,SAAS,QAAQ,KAAK,QAAQ,SAAS,IAAI,GAAG;CAEjF,MAAM,UAAU,MAAM,kBAAkB,QAAQ,QAAQ,aAAa,CAAC,SAAS,WAAW,GAAG,CAAC,CAAC;CAC/F,QAAQ,IAAI,OAAO,UAAU,YAAY,SAAS,IAAI,IAAI,YAAY,IAAI,EAAE;CAC5E,QAAQ,KAAK,CAAC;AACf;;;;;AAMA,eAAe,kBAAkB,OAA6C;CAC7E,MAAM,CAAC,OAAO,GAAG,QAAQ;CACzB,IAAI,CAAC,SAAS,CAAC,OAAO,OAAO,aAAa,KAAK,GAAG,OAAO;CAEzD,IAAI,UAAU,MAAM,YAAY,MAAM,CAAE;CACxC,KAAK,MAAM,QAAQ,MAAM;EAExB,MAAM,SADW,OAAO,QAAQ,gBAAgB,aAAa,MAAM,QAAQ,YAAY,IAAI,MAAM,QAAQ,YACzE,GAA2C;EAC3E,IAAI,CAAC,OAAO;EACZ,UAAW,OAAO,UAAU,aAAa,MAAM,MAAM,IAAI;CAC1D;CAEA,OAAO;AACR;AAEA,IAAI;CACH,MAAM,WAAW,MAAM,EAAE,QAAQ,CAAC;AACnC,SAAS,OAAO;CACf,QAAQ,MAAM,YAAY,KAAK,CAAC;CAChC,QAAQ,KAAK,WAAW,KAAK,CAAC;AAC/B"}
|