Skip to main content

命令行接口 (CLI)

¥Command Line Interface (CLI)

Strapi 配备了功能齐全的命令行接口 (CLI),可让你在几秒钟内构建和管理你的项目。CLI 可与 yarnnpm 包管理器配合使用。

¥Strapi comes with a full featured Command Line Interface (CLI) which lets you scaffold and manage your project in seconds. The CLI works with both the yarn and npm package managers.

提醒

诸如 strapi admin:create-user 之类的交互式命令不会显示带有 npm 的提示。请考虑使用 yarn 包管理器。

¥Interactive commands such as strapi admin:create-user don't display prompts with npm. Please consider using the yarn package manager.

注意

建议仅在本地安装 Strapi,这需要在以下所有 strapi 命令前添加用于项目设置的包管理器(例如 npm run strapi helpyarn strapi help)或专用节点包执行器(例如 npx strapi help)。

¥It is recommended to install Strapi locally only, which requires prefixing all of the following strapi commands with the package manager used for the project setup (e.g npm run strapi help or yarn strapi help) or a dedicated node package executor (e.g. npx strapi help).

要使用 npm 传递选项,请使用以下语法:npm run strapi <command> -- --<option>

¥To pass options with npm use the syntax: npm run strapi <command> -- --<option>.

要使用 yarn 传递选项,请使用以下语法:yarn strapi <command> --<option>

¥To pass options with yarn use the syntax: yarn strapi <command> --<option>

ℹ️ Strapi v4 CLI commands removed from Strapi 5:

Strapi v4 中的 strapi installstrapi uninstallstrapi newstrapi watch-admin 命令已在 Strapi 5 中删除:

¥The strapi install, strapi uninstall, strapi new, and strapi watch-admin commands from Strapi v4 have been removed in Strapi 5:

Strapi v4 命令Strapi 5 等效
strapi install [plugin]使用与插件相对应的 npx 命令(在 Marketplace 上找到,参见 市场
strapi new使用等效的 yarn 或 npx 命令创建一个新的 Strapi 项目(参见 CLI 安装指南
strapi watch-adminyarn developnpm run develop 始终以 "watch-admin" 模式启动 Strapi 服务器。要在 Strapi 5 中禁用此功能,请运行 yarn develop --no-watch-adminnpm run develop --no-watch-admin

strapi develop

别名:dev

¥Alias: dev

启动一个启用自动重新加载的 Strapi 应用。

¥Start a Strapi application with auto-reloading enabled.

Strapi 在运行时修改/创建文件,并且在创建新文件时需要重新启动。为了实现这一点,strapi develop 添加了一个文件监视程序,并在必要时重新启动应用。

¥Strapi modifies/creates files at runtime and needs to restart when new files are created. To achieve this, strapi develop adds a file watcher and restarts the application when necessary.

Strapi 还添加了中间件来支持管理面板的 HMR(热模块更换)。这允许你自定义管理面板,而无需重新启动应用或运行单独的服务器。

¥Strapi also adds middlewares to support HMR (Hot Module Replacement) for the administration panel. This allows you to customize the administration panel without having to restart the application or run a separate server.

strapi develop
options: [--no-build |--no-watch-admin |--browser |--debug |--silent]
  • strapi evolve --open
    启动启用自动重新加载的应用并在运行管理面板的情况下打开默认浏览器。

    ¥strapi develop --open
    Starts your application with auto-reloading enabled & open your default browser with the administration panel running.

  • strapi evolve --no-watch-admin
    在对管理面板代码进行更改时防止服务器自动重新加载。

    ¥strapi develop --no-watch-admin
    Prevents the server from auto-reload when changes are made to the admin panel code.

  • [已弃用] strapi evolve --no-build
    在启用自动重新加载的情况下启动你的应用并跳过管理面板构建过程

    ¥[DEPRECATED] strapi develop --no-build
    Starts your application with the auto-reloading enabled and skip the administration panel build process

  • [已弃用] strapi evolve --watch-admin
    启动你的应用,启用自动重新加载和前端开发服务器。它允许你自定义管理面板。

    ¥[DEPRECATED] strapi develop --watch-admin
    Starts your application with the auto-reloading enabled and the front-end development server. It allows you to customize the administration panel.

  • [已弃用] strapi evolve --watch-admin --browser 'google chrome'
    在启用自动重新加载和前端开发服务器的情况下启动你的应用。它允许你自定义管理面板。私有字段和 s 不会在有效负载中发送。

    ¥[DEPRECATED] strapi develop --watch-admin --browser 'google chrome'
    Starts your application with the auto-reloading enabled and the front-end development server. It allows you to customize the administration panel. Provide a browser name to use instead of the default one, false means stop opening the browser.

警告

你永远不应该使用此命令在生产环境中运行 Strapi 应用。

¥You should never use this command to run a Strapi application in production.

strapi start

启动一个禁用自动重新加载的 Strapi 应用。

¥Start a Strapi application with auto-reloading disabled.

此命令用于运行 Strapi 应用,无需重新启动和文件写入,主要用于生产。某些功能(例如内容类型生成器)在 strapi start 模式下被禁用,因为它们需要重新启动应用。start 命令可以以 环境变量 开头,以自定义应用启动。

¥This command is to run a Strapi application without restarts and file writes, primarily for use in production. Certain features such as the Content-type Builder are disabled in the strapi start mode because they require application restarts. The start command can be prefaced with environment variables to customize the application start.

strapi build

构建你的管理面板。

¥Builds your admin panel.

strapi build
选项类型描述
-d, --debug*启用带有详细日志的调试模式(默认值:false)
--minify*最小化输出(默认值:true)
--no-optimization*
--silent*不记录任何内容(默认值:false)
--sourcemaps*生成源映射(默认值:false)
--stats*以前发布的内容可以取消发布。

strapi login

登录 Strapi Cloud(参见 Cloud CLI 文档)。

¥Logs in to Strapi Cloud (see Cloud CLI documentation).

strapi logout

从 Strapi Cloud 注销(参见 Cloud CLI 文档)。

¥Logs out from Strapi Cloud (see Cloud CLI documentation).

strapi deploy

部署到 Strapi Cloud(参见 Cloud CLI 文档)。

¥Deploys to Strapi Cloud (see Cloud CLI documentation).

strapi export

导出你的项目数据。默认设置创建一个 .tar 文件,使用 gzip 压缩并使用 aes-128-ecb 加密。

¥Exports your project data. The default settings create a .tar file, compressed using gzip and encrypted using aes-128-ecb.

strapi export

该存档包含 configurationentitieslinksschemas 等文件夹,数据存储在 JSON 行 文件中。使用 --no-encrypt --no-compress 生成可读的 .tar,以便检查或转换为其他格式。

¥The archive contains folders such as configuration, entities, links, and schemas with data stored in JSON lines files. Use --no-encrypt --no-compress to generate a readable .tar that can be inspected or converted to other formats.

导出的文件将使用 export_YYYYMMDDHHMMSS 格式以及当前日期和时间戳自动命名。或者,你可以使用 -f--file 标志指定文件名。下表提供了作为命令行标志的所有可用选项:

¥The exported file is automatically named using the format export_YYYYMMDDHHMMSS with the current date and timestamp. Alternately, you can specify the filename using the -f or --file flag. The following table provides all of the available options as command line flags:

选项类型描述
--no-encrypt*禁用文件加密并禁用 key 选项。
--no-compress*禁用文件压缩。
-k
--key
string将加密密钥作为 export 命令的一部分传递。
--key 选项不能与 --no-encrypt 结合使用。
-f
--file
string指定导出文件名。请勿包含文件扩展名。
--excludestring使用逗号分隔的数据类型排除数据。可用的类型有:contentfilesconfig
--onlystring仅包含这些数据。可用的类型有:contentfilesconfig
-h
--help
*显示 strapi export 命令的帮助。

示例

¥Examples

Examples of strapi export:
# export your data with the default options and the filename myData, which results in a file named myData.tar.gz.enc.
strapi export -f myData

# export your data without encryption.
strapi export --no-encrypt

strapi import

导入数据 进入你的项目。导入的数据必须来自另一个 Strapi 应用。你必须传递 --file 选项来指定导入操作的文件名和位置。

¥Imports data into your project. The imported data must originate from another Strapi application. You must pass the --file option to specify the filename and location for the import action.

strapi import

该命令接受 strapi export 生成的存档。压缩 (.gz) 和加密 (.enc) 是从文件名中检测出来的,因此提供纯文本 .tar 也是有效的。

¥The command accepts archives generated by strapi export. Compression (.gz) and encryption (.enc) are detected from the filename, so providing a plain .tar is also valid.

选项类型描述
-k, --keystring在命令中提供加密密钥,而不是随后的提示。
-f--filestring要导入的数据的路径和文件名以及扩展名。
-h--help*显示 strapi import 帮助命令。

示例

¥Examples

Example of strapi import:

# import your data with the default parameters and pass an encryption key:
strapi import -f your-filepath-and-filename --key my-key

strapi transfer

2 个 Strapi 实例之间的 传输数据。此命令主要用于本地实例和一个远程实例或 2 个远程实例之间的使用。transfer 命令需要一个传输令牌,该令牌是在目标实例管理面板中生成的。有关创建 Transfer 令牌的详细文档,请参阅 用户指南

¥Transfers data between 2 Strapi instances. This command is primarily intended for use between a local instance and a remote instance or 2 remote instances. The transfer command requires a Transfer token, which is generated in the destination instance Admin panel. See the User Guide for detailed documentation on creating Transfer tokens.

提醒

目标 Strapi 实例应使用 start 命令而不是 develop 命令运行。

¥The destination Strapi instance should be running with the start command and not the develop command.

选项描述
--to [destinationURL]目标 Strapi 实例上 /admin 端点的完整 URL
(例如 --to https://my-beautiful-strapi-website/admin
--to-token [transferToken]传输远程 Strapi 目标的令牌
--from [sourceURL]用于从中提取数据的远程 Strapi 实例的 /admin 端点的完整 URL(例如 --from https://my-beautiful-strapi-website/admin
‑‑from‑token从 Strapi 源实例传输令牌。
--force自动回答 "yes" 所有提示,包括潜在的破坏性请求,并以非交互方式运行。
--exclude使用逗号分隔的数据类型排除数据。可用的类型有:contentfilesconfig
--only仅包含这些数据。可用的类型有:contentfilesconfig
-h--help显示 strapi transfer 的命令。
提醒

--to--from 为必填项,但目前不允许两者都输入或都不输入。

¥Either --to or --from is required, but it's not currently allowed to enter both or neither.

示例

¥Example

strapi transfer --to http://example.com/admin --to-token my-transfer-token

strapi report

打印出对调试有用且报告问题时所需的调试信息。

¥Prints out debug information useful for debugging and required when reporting an issue.

选项描述
-u--uuid包括项目 UUID
-d--dependencies包括项目依赖
--all记录所有数据

示例

¥Examples

要在输出中包含项目 UUID 和依赖:

¥To include the project UUID and dependencies in the output:

strapi report --uuid --dependencies

要记录所有内容,请使用 --all 选项:

¥To log everything, use the --all option:

strapi report --all

strapi configuration:dump

别名:config:dump

¥Alias: config:dump

将配置转储到文件或标准输出以帮助你迁移到生产环境。

¥Dumps configurations to a file or stdout to help you migrate to production.

转储格式将是 JSON 数组。

¥The dump format will be a JSON array.

strapi configuration:dump

Options:
-f, --file <file> Output file, default output is stdout
-p, --pretty Format the output JSON with indentation and line breaks (default: false)

示例

¥Examples

  • strapi configuration:dump -f dump.json

  • strapi config:dump --file dump.json

  • strapi config:dump > dump.json

所有这些例子都是等价的。

¥All these examples are equivalent.

提醒

配置应用时,你经常输入第三方服务(例如身份验证提供者)的凭据。请注意,这些凭据也将转储到此命令的输出中。如有疑问,你应该避免将转储文件提交到版本控制系统中。你可以探索以下一些方法:

¥When configuring your application you often enter credentials for third party services (e.g authentication providers). Be aware that those credentials will also be dumped into the output of this command. In case of doubt, you should avoid committing the dump file into a versioning system. Here are some methods you can explore:

  • 将文件直接复制到所需的环境并在那里运行恢复命令。

    ¥Copy the file directly to the environment you want and run the restore command there.

  • 将文件放在安全位置,并在部署时使用正确的凭据下载它。

    ¥Put the file in a secure location and download it at deploy time with the right credentials.

  • 在提交之前对文件进行加密,并在运行恢复命令时对其进行解密。

    ¥Encrypt the file before committing and decrypt it when running the restore command.

strapi configuration:restore

别名:config:restore

¥Alias: config:restore

将配置转储恢复到你的应用中。

¥Restores a configuration dump into your application.

输入格式必须是 JSON 数组。

¥The input format must be a JSON array.

strapi configuration:restore

Options:
-f, --file <file> Input file, default input is stdin
-s, --strategy <strategy> Strategy name, one of: "replace", "merge", "keep". Defaults to: "replace"

示例

¥Examples

  • strapi configuration:restore -f dump.json

  • strapi config:restore --file dump.json -s replace

  • cat dump.json | strapi config:restore

  • strapi config:restore < dump.json

所有这些例子都是等价的。

¥All these examples are equivalent.

策略

¥Strategies

运行恢复命令时,你可以选择三种不同的策略:

¥When running the restore command, you can choose from three different strategies:

  • 代替:将创建丢失的密钥并替换现有的密钥。

    ¥replace: Will create missing keys and replace existing ones.

  • 合并:将创建丢失的键并将现有键与其新值合并。

    ¥merge: Will create missing keys and merge existing keys with their new value.

  • 保持:将创建丢失的密钥并按原样保留现有密钥。

    ¥keep: Will create missing keys and keep existing keys as is.

strapi admin:create-user

别名 admin:create

¥Alias admin:create

创建管理员。管理员的名字、姓氏、电子邮件和密码可以是:

¥Creates an administrator. Administrator's first name, last name, email, and password can be:

  • 作为选项传递

    ¥passed as options

  • 或者如果你调用命令而不传递任何选项,则以交互方式设置。

    ¥or set interactively if you call the command without passing any option.

示例

¥Example


strapi admin:create-user --firstname=Kai --lastname=Doe --email=chef@strapi.io --password=Gourmet1234

选项

¥Options

选项类型描述必需的
-f, --名字string管理员的名字是的
-l, --姓氏string管理员的姓氏
-e, --电子邮件string管理员的电子邮件是的
-p, --密码string管理员的新密码
-h,--帮助显示命令的帮助

strapi admin:reset-user-password

别名 admin:reset-password

¥Alias admin:reset-password

重置管理员用户的密码。你可以将电子邮件和新密码作为选项传递,或者如果调用命令而不传递选项,则可以交互设置它们。

¥Reset an admin user's password. You can pass the email and new password as options or set them interactively if you call the command without passing the options.

示例

¥Example


strapi admin:reset-user-password --email=chef@strapi.io --password=Gourmet1234

选项

¥Options

选项类型描述
-e, --电子邮件string用户电子邮件
-p, --密码string用户的新密码
-h,--帮助显示命令的帮助

strapi generate

生成 API:controllerscontent-typespoliciesmiddlewaresservicesmigrations

¥Generate APIs, controllers, content-types, policies, middlewares, services, and migrations.

strapi generate

该命令显示一个交互式菜单,其中包含以下选项:

¥The command displays an interactive menu with the following options:

  • api - 生成包含控制器和服务的新 API

    ¥api - Generate a new API with controller and service

  • controller - 生成新的控制器

    ¥controller - Generate a new controller

  • content-type - 生成包含架构的新内容类型

    ¥content-type - Generate a new content type with schema

  • policy - 生成新的策略

    ¥policy - Generate a new policy

  • 中间件 - 生成新的中间件

    ¥middleware - Generate a new middleware

  • migration - 生成新的数据库迁移

    ¥migration - Generate a new database migration

  • service - 生成新的服务

    ¥service - Generate a new service

strapi generate GIF

生成器会自动检测 TypeScript 或 JavaScript,并创建具有正确扩展名(.ts.js)的文件。生成的文件包含带注释的示例。单复数名称必须不同,并使用短横线分隔 (kebab-case) 格式。

¥The generator detects TypeScript or JavaScript automatically and creates files with the correct extension (.ts or .js). Generated files include commented examples. Singular and plural names must be different and use kebab-case format.

API 生成器

¥API generator

创建一个包含 controllerservice 文件的 API。

¥Creates an API with controller and service files.

生成的文件:controllers/[name].js|tsservices/[name].js|tsroutes/[name].js|ts(仅限标准 API)

¥Generated file: controllers/[name].js|ts, services/[name].js|ts, and routes/[name].js|ts (standard APIs only)

内容类型生成器

¥Content-type generator

创建一个包含可选 API 文件的内容类型架构。

¥Creates a content type schema with optional API files.

可用属性类型

¥Available attribute types

类型描述
string短文本
text长文本
richtext富文本编辑器
email电子邮件字段
password密码字段
integer整数
biginteger大整数
float十进制数
decimal精确十进制
date仅限日期
time仅时间
datetime日期和时间
timestampUnix 时间戳
boolean真/假
jsonJSON 数据
enumeration预定义值
media文件上传

生成的文件

¥Generated files

条件生成的文件
仅限内容类型content-types/[name]/schema.json
使用 API 引导程序

控制器生成器

¥Controller generator

创建包含基本操作结构的 controller 文件。

¥Creates a controller file with basic action structure.

生成的文件:controllers/[name].js|ts

¥Generated file: controllers/[name].js|ts

服务生成器

¥Service generator

创建一个具有基本结构的 service 文件。

¥Creates a service file with basic structure.

生成的文件:services/[name].js|ts

¥Generated file: services/[name].js|ts

策略生成器

¥Policy generator

创建用于访问控制的 policy 文件。

¥Creates a policy file for access control.

生成的文件:policies/[name].js|ts

¥Generated file: policies/[name].js|ts

中间件生成器

¥Middleware generator

创建用于请求处理的 中间件 文件。

¥Creates a middleware file for request processing.

生成的文件:middlewares/[name].js|ts

¥Generated file: middlewares/[name].js|ts

迁移生成器

¥Migration generator

创建一个带时间戳的 migration 文件。

¥Creates a timestamped migration file.

生成的文件:database/migrations/[timestamp].[name].js|ts

¥Generated file: database/migrations/[timestamp].[name].js|ts

配置选项

¥Configuration options

strapi generate 交互式 CLI 可能根据所选的 Strapi 元素提供各种配置选项:

¥The strapi generate interactive CLI may offer various configuration options depending on the chosen Strapi element to generate:

目标选择

¥Destination choices

创建内容类型、控制器、策略、中间件或服务时,你可以选择其目标:

¥When creating a content-type, controller, policy, middleware, or service, you can choose its destination:

选项描述
新 API创建一个新的 API 文件夹
现有 API添加到现有 API 文件夹
现有插件添加到现有插件文件夹
添加到项目根目录(仅限策略和中间件)

内容类型特定选项

¥Content-type specific options

创建内容类型时,你可以选择创建集合类型或单个类型(有关差异,请参阅 内容类型生成器 文档):

¥When creating a content-type, you can choose to create a collection type or a single type (see Content-Type Builder documentation for differences):

类型描述示例
集合类型多个条目文章、用户
单一类型单个条目主页,设置

你还必须定义各种类型的名称。下表解释了它们的区别。只需手动定义显示名称,你可以按 Enter 键接受单数和复数名称的默认建议名称。API 端点的单复数名称很重要(详情请参阅 REST API 文档):

¥You will also have to define various types of names. The following table explains their differences. Only the display name needs to be manually defined, and you can press Enter to accept the default suggested name for the singular and plural names. Singular and plural names matter for API endpoints (see REST API documentation for details):

字段格式描述示例
显示名称用户可读管理面板中显示的名称博客文章
单数名称短横线分隔用于 API 端点blog-post
复数名称短横线分隔用于集合blog-posts

strapi openapi 生成

¥strapi openapi generate

适用于你的 Strapi 应用的 生成 OpenAPI 规范

¥Generate OpenAPI specifications for your Strapi application.

strapi openapi generate
选项类型默认描述
--outputstring./openapi-spec.json生成规范的输出文件路径

示例

¥Examples

# Generate OpenAPI specification (default)
yarn strapi openapi generate

# Generate with custom output path
yarn strapi openapi generate --output ./docs/api-spec.json

strapi templates:generate

从当前 Strapi 项目创建模板。

¥Create a template from the current Strapi project.

strapi templates:generate <path>
  • Strapi templates:generate <path>
    <path> 生成 Strapi 模板

    ¥strapi templates:generate <path>
    Generates a Strapi template at <path>

    示例:strapi templates:generate ../strapi-template-name 会将所需的文件和文件夹复制到 ../strapi-template-name 内的 template 目录中

    ¥Example: strapi templates:generate ../strapi-template-name will copy the required files and folders to a template directory inside ../strapi-template-name

strapi ts:generate-types

为项目模式生成 TypeScript 类型。

¥Generate TypeScript typings for the project schemas.

strapi ts:generate-types
  • strapi ts:generate-types --debug
    在启用调试模式的情况下生成类型,显示生成的模式的详细表格。

    ¥strapi ts:generate-types --debug
    Generate typings with the debug mode enabled, displaying a detailed table of the generated schemas.

  • Strapi ts:generate-types --silent 或 Strapi ts:generate-types -s
    在启用静默模式的情况下生成类型,完全删除终端中的所有日志。不能与 debug 结合使用

    ¥strapi ts:generate-types --silent or strapi ts:generate-types -s
    Generate typings with the silent mode enabled, completely removing all the logs in the terminal. Cannot be combined with debug

  • Strapi ts:generate-types --out-dir <path> 或 Strapi ts:generate-types -o <path- --GT-BASE---
    生成指定将在其中创建文件的输出目录的类型。

    ¥strapi ts:generate-types --out-dir <path> or strapi ts:generate-types -o <path>
    Generate typings specifying the output directory in which the file will be created.

提醒

Strapi 要求在 types 目录中生成项目类型才能正常工作。大多数情况下不应使用 --out-dir 选项。但是,对于更改内容结构后生成第二个副本以比较现有类型和更新类型之间的差异等情况可能很有用。

¥Strapi requires the project types to be generated in the types directory for them to work. The --out-dir option should not be used for most cases. However, it can be useful for cases such as generating a second copy to compare the difference between your existing and updated types after changing your content structure.

strapi routes:lis

显示所有可用 routes 的列表。

¥Display a list of all the available routes.

strapi routes:list

strapi policies:list

显示所有已注册的 policies 的列表。

¥Display a list of all the registered policies.

strapi policies:list

strapi middlewares:list

显示所有已注册的 middlewares 的列表。

¥Display a list of all the registered middlewares.

strapi middlewares:list

strapi content-types:list

显示所有现有 content-types 的列表。

¥Display a list of all the existing content-types.

strapi content-types:list

strapi hooks:list

显示所有可用钩子的列表。

¥Display a list of all the available hooks.

strapi hooks:list

strapi controllers:list

显示所有已注册的 controllers 的列表。

¥Display a list of all the registered controllers.

strapi controllers:list

strapi services:list

显示所有已注册的 services 的列表。

¥Display a list of all the registered services.

strapi services:list

strapi telemetry:disable

禁用项目的数据收集(参见 使用信息)。

¥Disable data collection for the project (see Usage Information).

strapi telemetry:disable

strapi telemetry:enable

禁用项目后重新启用数据收集(参见 使用信息)。

¥Re-enable data collection for the project after it was disabled (see Usage Information).

strapi telemetry:enable

strapi console

启动服务器并实时执行应用中的命令。

¥Start the server and evaluate commands in your application in real time.

strapi console

console 命令会编译并加载应用,在后台启动服务器,然后打开 Node.js 文件 REPL。REPL 会根据应用名称提供提示符,并通过全局 strapi 对象提供对所有 Strapi API 的访问。按两次 Ctrl-C 关闭 REPL 可正常停止服务器。

¥The console command compiles and loads your application, starts the server in the background, then opens a Node.js REPL. The REPL provides a prompt based on your application's name and gives access to all Strapi APIs through the global strapi object. Closing the REPL by pressing Ctrl-C twice gracefully stops the server.

可用助手

¥Available helpers

strapi 对象公开以下 getter 和方法以便与你的应用交互:

¥The strapi object exposes the following getters and methods to interact with your application:

  • strapi.servicesstrapi.service(uid) 用于使用 services

    ¥strapi.services and strapi.service(uid) to use services

  • strapi.controllersstrapi.controller(uid) 用于调用 controllers

    ¥strapi.controllers and strapi.controller(uid) to call controllers

  • strapi.contentTypesstrapi.contentType(uid) 用于检查 content-types

    ¥strapi.contentTypes and strapi.contentType(uid) to inspect content-types

  • strapi.components 用于列出组件

    ¥strapi.components to list components

  • strapi.policiesstrapi.policy(name) 用于 policies

    ¥strapi.policies and strapi.policy(name) for policies

  • strapi.middlewaresstrapi.middleware(name) 用于 middlewares

    ¥strapi.middlewares and strapi.middleware(name) for middlewares

  • strapi.pluginsstrapi.plugin(name) 用于插件

    ¥strapi.plugins and strapi.plugin(name) for plugins

  • strapi.hooksstrapi.hook(name) 用于钩子函数

    ¥strapi.hooks and strapi.hook(name) for hooks

  • strapi.apisstrapi.api(name) 用于 API

    ¥strapi.apis and strapi.api(name) for APIs

  • strapi.db 可直接通过 查询引擎 API 查询数据库,例如:

    ¥strapi.db to directly query the database through the Query Engine API, for example as follows:

    await strapi.db.query('api::article.article').findMany();

使用此环境测试代码并检查你的项目,并直接访问所有 Strapi API。

¥Use this environment to test code and inspect your project with direct access to all Strapi APIs.

注意

Strapi 使用名为 异步本地存储 的 Node.js 功能使上下文在任何地方都可用。

¥Strapi uses a Node.js feature called AsyncLocalStorage to make the context available anywhere.

strapi version

将构建统计信息打印到控制台(默认值:false)如果此命令是全局安装的 strapi,它将输出当前全局安装的版本,或者如果从包含 Strapi 项目的给定文件夹运行该命令,它将输出 Strapi 项目中的当前 Strapi 版本。

¥Print the currently installed Strapi version. It will output the current globally installed version if this command is strapi is installed globally, or the current version of Strapi within a Strapi project if the command is run from a given folder containing a Strapi project.

strapi version

strapi help

列出 CLI 命令。

¥List CLI commands.

strapi help