@contentful/app-scripts

中文文档
4.1.16发布于 2026/10/26MITTypeScriptCommonJS近 30 天下载 13.4万

A collection of scripts for building Contentful Apps

原始使用文档
文档目录15 节
  1. 📥 Installation
  2. ⚙️ Usage
  3. 💻 CLI
  4. 👩‍💻 Programmatic
  5. 📜 API
  6. Generate Function
  7. Create App Definition
  8. Upload a bundle to an App Definition
  9. Activate an AppBundle
  10. Open Settings of an AppDefinition
  11. Clean up bundles
  12. Install the AppDefinition into a specific space / environme…
  13. Tracking
  14. Build Contentful Function source
  15. Upsert App Actions

@contentful/app-scripts

This project makes it easier to perform some recurrent operations in Contentful's App Framework.

📥 Installation

Locally:

npm i @contentful/app-scripts

Globally:

npm i -g @contentful/app-scripts

⚙️ Usage

💻 CLI

When installed

$ contentful-app-scripts create-app-definition

Otherwise

$ npx @contentful/app-scripts create-app-definition

👩‍💻 Programmatic

const { createAppDefinition } = require('@contentful/app-scripts');
const { myCustomLogic } = require('./my-custom-logic')(async function main() {
  myCustomLogic();

  await createAppDefinition.interactive();
})();

📜 API

Scripts exported from this module will all be in the following shape

interface Script<Result, Options> {
  // query the user or local cache for required information
  interactive: () => Result;
  // run by automation (`--ci` flag), they would need all the information upfront
  nonInteractive: (...options: Options) => Result;
}

:warning: Please note

Both interactive and nonInteractive version of the same script is meant to return the same result.

Generate Function

Allows generating a new function template from our function examples. Automatically updates contentful-app-manifest.json and merges scripts/dependencies from package.json into existing project.

Interactive mode:

In the interactive mode, the CLI will ask for all required options.

Example

$ npx --no-install @contentful/app-scripts generate-function

Non-interactive mode:

When passing the --ci argument the command will fail when the required variables are not set as arguments.

Example

$ npx --no-install @contentful/app-scripts generate-function --ci \
    --name <name> \
    --example <example> \
    --language <javascript/typescript> \

Options:

ArgumentDescriptionDefault value
--nameThe name of your function.
--exampleThe name of the example as listed in our function examples
--languageChoice of javascript or typescript

Create App Definition

Allows creating a new AppDefinition provided a Content Management Token (more details here).

It only runs in interactive mode.

Example

$ npx --no-install @contentful/app-scripts create-app-definition

Upload a bundle to an App Definition

Allows you to upload a build directory and create a new AppBundle that is bound to an AppDefinition. It runs in interactive or non-interactive mode.

Note: The command will automatically activate the bundle. To skip the activation you can pass the --skip-activation argument in interactive and non-interactive mode and then manually activate it.

Interactive mode:

In the interactive mode, the CLI will ask for all required options.

Example

$ npx --no-install @contentful/app-scripts upload

Non-interactive mode:

When passing the --ci argument the command will fail when the required variables are not set as arguments.

Example

$ npx --no-install @contentful/app-scripts upload --ci \
    --bundle-dir ./built \
    --organization-id some-org-id \
    --definition-id some-app-def-id \
    --token $MY_CONTENTFUL_PAT

Options:

ArgumentDescriptionDefault value
--bundle-dirThe directory of your build folder (e.g.: ./build)
--organization-idThe ID of your organization
--definition-idThe ID of the app to which to add the bundle
--tokenA personal access token
--skip-activation(optional) Boolean flag to skip the automatic activation of the AppBundlefalse
--comment(optional) A comment which will be associated with the created AppBundle. Can be used to differentiate bundles.
--host(optional) Contentful CMA-endpoint to useapi.contentful.com

Note: You can also pass all arguments in interactive mode to skip being asked for it.

Activate an AppBundle

Allows you to activate an AppBundle for an AppDefinition. When activated the app will serve the newly activated AppBundle.

Interactive mode:

In the interactive mode, the CLI will ask for all required options.

Example

$ npx --no-install @contentful/app-scripts activate

Non-interactive mode:

When passing the --ci argument adding all variables as arguments is required.

Example

$ npx --no-install @contentful/app-scripts activate --ci \
    --bundle-id some-bundle-id \
    --organization-id some-org-id \
    --definition-id some-app-def-id \
    --token $MY_CONTENTFUL_PAT

Options:

ArgumentDescriptionDefault value
--bundle-idThe ID of the AppBundle you want to activate
--organization-idThe ID of your organization
--definition-idThe ID of the app to which to add the bundle
--tokenA personal access token
--host(optional) Contentful CMA-endpoint to useapi.contentful.com

Note: You can also pass all arguments in interactive mode to skip being asked for it.

Open Settings of an AppDefinition

It opens the settings in the contentful web app so that you can use the UI to change the settings of an AppDefinition.

Example

$ npx --no-install @contentful/app-scripts open-settings --definition-id some-definition-id

You can also execute this command without the argument if the environment variable (CONTENTFUL_APP_DEF_ID) has been set.

Example

$ CONTENTFUL_APP_DEF_ID=some-definition-id npx --no-install @contentful/app-scripts open-settings

Options:

ArgumentDescriptionDefault value
--definition-idThe ID of the app to which to add the bundle
--host(optional) Contentful CMA-endpoint to useapi.contentful.com

Note: You can also pass all arguments in interactive mode to skip being asked for it.

Clean up bundles

Allows you to clean the list of previous bundles. It fetches the list and deletes all bundles except the 50 newest ones. You can adjust the amount you want to keep by passing --keep <amount> to the argument, if not passed, the default is 50.

Interactive mode:

In the interactive mode, the CLI will ask for all required options.

Example

$ npx --no-install @contentful/app-scripts bundle-cleanup

You can also execute this command without the argument if the environment variable (CONTENTFUL_APP_DEF_ID) and (CONTENTFUL_ORG_ID) has been set.

Non-interactive mode:

When passing the --ci argument adding all variables as arguments is required

Example

$ npx --no-install @contentful/app-scripts bundle-cleanup --ci \
    --organization-id some-org-id \
    --definition-id some-app-def-id \
    --token $MY_CONTENTFUL_PAT
    --keep 30

Options:

ArgumentDescriptionDefault value
--organization-idThe ID of your organization
--definition-idThe ID of the app to which to add the bundle
--tokenA personal access token
--keep(optional) The amount of bundles to keep50
--host(optional) Contentful CMA-endpoint to useapi.contentful.com

Note: You can also pass all arguments in interactive mode to skip being asked for it.

Install the AppDefinition into a specific space / environment

It opens a dialog to select the space and environment where the app associated with the given AppDefinition should be installed.

Example

$ npx --no-install @contentful/app-scripts install --definition-id some-definition-id

You can also execute this command without the argument if the environment variable (CONTENTFUL_APP_DEF_ID) has been set.

Example

$ CONTENTFUL_APP_DEF_ID=some-definition-id npx --no-install @contentful/app-scripts install

By default, the script will install the app into the default host URL: app.contentful.com. If you want to install the app into a different host URL, you can set the argument --host to the desired host URL.

Example

$ npx --no-install @contentful/app-scripts install --definition-id some-definition-id --host api.eu.contentful.com

Options:

ArgumentDescriptionDefault value
--definition-idThe ID of the app to which to add the bundle
--host(optional) Contentful CMA-endpoint to useapi.contentful.com

Note: You can also pass all arguments in interactive mode to skip being asked for it.

Tracking

We gather depersonalized usage data of our CLI tools in order to improve experience. If you do not want your data to be gathered, you can opt out by providing an env variable DISABLE_ANALYTICS set to any value:

Example

DISABLE_ANALYTICS=true npx create-contentful-app

Build Contentful Function source

Builds the source code for a Contentful Function into an App Framework compatible bundle.

Interactive mode:

In the interactive mode, the CLI will prompt for custom configuration, but none of the options are required.

Example

$ npx --no-install @contentful/app-scripts build-functions

Non-interactive mode:

When passing the --ci argument adding all variables as arguments is required

Example

$ npx --no-install @contentful/app-scripts build-functions --ci \
    --manifest-file path/to/contentful/app/manifest.json \
    --esbuild-config path/to/custom/esbuild/config.js \
    --watch

Options:

Options: -e, --esbuild-config custom esbuild config file path -m, --manifest-file Contentful app manifest file path -w, --watch watch for changes -h, --help display help for command

Upsert App Actions

Creates or updates Actions for an App using the configuration in a Contentful App Manifest file. Created resources will be synced back to your manifest file.

Interactive mode:

In the interactive mode, the CLI will ask for all required options.

Example

$ npx --no-install @contentful/app-scripts upsert-actions

Non-interactive mode:

When passing the --ci argument adding all variables as arguments is required.

Example

$ npx --no-install @contentful/app-scripts upsert-actions --ci \
    --manifest-file path/to/contentful-app-manifest.json \
    --organization-id some-org-id \
    --definition-id some-app-def-id \
    --token $MY_CONTENTFUL_PAT

Options:

ArgumentDescriptionDefault value
--manifest-fileThe path to the Contentful app manifest filecontentful-app-manifest.json
--organization-idThe ID of the organization which the app is defined in
--definition-idThe ID of the app to which to add the actions
--tokenA personal access token
--host(optional) Contentful CMA-endpoint to useapi.contentful.com

Note: You can also pass all arguments in interactive mode to skip being asked for it.

版本与发布记录

@contentful/app-scripts 共发布 570 个版本,首次发布于 2021/04/08;过去 12 个月发布了 30 个版本。

版本发布日期距今
4.1.16latest2026/10/2615 天前
4.1.152026/10/2318 天前
4.1.142026/10/061 个月前
4.1.132026/10/031 个月前
4.1.122026/09/131 个月前
4.1.112026/09/111 个月前

其他发布通道:canary → 2.5.12-alpha.9。

关于 @contentful/app-scripts 的常见问题

@contentful/app-scripts 是什么?

A collection of scripts for building Contentful Apps

如何安装 @contentful/app-scripts?

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

@contentful/app-scripts 支持 TypeScript 吗?

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

@contentful/app-scripts 支持 ESM 还是 CommonJS?

以 CommonJS 形式发布,可以直接 require();在 ES Module 项目中也可以用 import 引入(Node.js 会把 module.exports 作为默认导出)。

@contentful/app-scripts 需要什么版本的 Node.js?

package.json 的 engines 字段要求 Node.js >=20。版本不符时 npm 默认只给出警告,开启 engine-strict 后会拒绝安装。

@contentful/app-scripts 可以商用吗?

@contentful/app-scripts 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@contentful/app-scripts 的下载量有多少?

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

@contentful/app-scripts 还在维护吗?

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