alioth/before/pac-auth/docs/nestcli.md
2025-05-30 09:18:01 +08:00

51 lines
2.7 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

这个输出是 NestJS CLI (`nest-cli`) 的帮助命令 `nest g -h``nest generate -h` 的结果,它解释了如何使用 `nest generate` 或其简写 `nest g` 命令来生成 NestJS 应用程序的不同部分。以下是命令和选项的详细解释:
### 命令用法
```plaintext
nest generate|g [options] <schematic> [name] [path]
```
- `nest generate``nest g`:这是用来生成新元素的命令。
- `[options]`:可选的命令行选项。
- `<schematic>`:要生成的元素类型,例如 `controller`、`service` 等。
- `[name]`:新生成元素的名称。
- `[path]`:指定一个路径,在该路径下生成元素(如果未指定,则在项目根目录生成)。
### 可用的 Schematics
列表显示了所有可用的 schematics即元素类型它们是
- `application``application`生成一个新的应用程序工作区。
- `class``cl`生成一个新的类。
- `configuration``config`生成一个 CLI 配置文件。
- `controller``co`生成一个控制器声明。
- `decorator``d`生成一个自定义装饰器。
- `filter``f`生成一个异常过滤器声明。
- `gateway``ga`生成一个网关声明(用于 NestJS 微服务)。
- `guard``gu`生成一个守卫声明。
- `interceptor``itc`生成一个拦截器声明。
- `interface``itf`生成一个接口。
- `library``lib`在 monorepo单一代码库中生成一个新的库。
- `middleware``mi`生成一个中间件声明。
- `module``mo`生成一个模块声明。
- `pipe``pi`生成一个管道声明。
- `provider``pr`生成一个服务提供者声明。
- `resolver``r`生成一个 GraphQL 解析器声明。
- `resource``res`生成一个新的 CRUD 资源。
- `service``s`生成一个服务声明。
- `sub-app``app`在 monorepo 中生成一个新的应用程序。
### 选项
- `--dry-run``-d`:模拟操作,报告将要执行的动作,但不会实际写入任何结果。
- `--project [project]``-p`:指定在哪个项目中生成文件。
- `--flat`:强制生成的元素结构为扁平化,即不创建额外的目录。
- `--no-flat`:确保为生成的元素创建目录。
- `--spec`强制生成相应的测试文件spec 文件),这是默认行为。
- `--spec-file-suffix [suffix]`:为测试文件使用自定义的后缀。
- `--skip-import`:跳过导入步骤。
- `--no-spec`:禁用生成测试文件。
- `--collection [collectionName]``-c`:使用指定的 schematics 集合。
### 帮助选项
- `--help``-h`:输出命令的使用信息。
通过这些命令和选项,你可以快速生成 NestJS 应用程序的骨架代码,从而加速开发过程。