This script automates the complete setup of Contentful spaces for your app, including app definition creation, space creation, team assignments, and app installations.
- Creates App Definitions (staging and production) in your Contentful organization
- Creates Two Spaces: Production and Staging environments
- Assigns Teams to both spaces with admin privileges
- Installs the App in both spaces
- Provides Configuration Links to finish app setup
-
Copy the example environment file:
cp .env-example .env
-
Fill in your Contentful credentials in
.env:CONTENTFUL_ACCESS_TOKEN=your_access_token_here CONTENTFUL_ORGANIZATION_ID=your_org_id_here CONTENTFUL_TEAM_ID=your_team_id_here CONTENTFUL_APP_NAME=Your App Name CONTENTFUL_ENVIRONMENT=master
- Go to Contentful Web App
- Navigate to Settings → API keys → Content management tokens
- Generate a new personal access token
- Copy the token to
CONTENTFUL_ACCESS_TOKENin your.envfile
- In Contentful, go to your organization settings
- The organization ID is in the URL:
app.contentful.com/account/organizations/{ORGANIZATION_ID} - Copy this ID to
CONTENTFUL_ORGANIZATION_IDin your.envfile
- Go to Settings → Teams
- Click on the team you want to assign
- The team ID is in the URL:
app.contentful.com/account/organizations/{ORG_ID}/teams/{TEAM_ID} - Copy this ID to
CONTENTFUL_TEAM_IDin your.envfile
For testing purposes, the script includes a teardown function that completely removes all created resources.
-
Uncomment the teardown section at the bottom of the file
scripts/setup.ts:// FOR TESTING - uncomment to undo setup await teardown({ client, organizationId, spaceIdStaging: stagingSpace.sys.id, spaceIdProduction: productionSpace.sys.id, appDefinitionIdStaging: appDefinitionStaging.sys.id, appDefinitionIdProduction: appDefinitionProduction.sys.id, });
-
Run the setup script as normal:
npm run setup
-
Navigate to the scripts directory:
cd scripts -
Install dependencies:
npm install
-
Configure your
.envfile (see Configuration section above) -
Run the setup script:
npm run setup
- Staging:
{appName} (staging) - Production:
{appName} (production) - Location: Your Contentful organization
- Status: Created but needs configuration
- Production:
{appName} (production) - Staging:
{appName} (staging) - Team Access: Admin privileges for all members in specified team
- App Installation: Your app installed in both spaces
After running the script successfully:
- Configure your app definitions using the provided links
- Set up app locations (entry field, page, etc.)
- Configure app parameters if needed