A collection of TypeScript scripts for managing your Vercel account, including actions like deleting old deployments, managing projects, and automating common Vercel operations.
The delete-old-deployments.ts script automatically cleans up old deployments from all projects in your Vercel account or team. It keeps the latest deployment and deletes all older ones, helping you manage deployment history and reduce clutter.
yarn installCreate a .env file in the root directory:
VERCEL_TOKEN=your_vercel_token_here
VERCEL_TEAM_ID=your_team_id_here # Optional, omit for personal account
TARGET_ENVIRONMENT=preview # Options: "production" or "preview"- Go to Vercel Settings > Tokens
- Create a new token with appropriate permissions
- Copy the token to your
.envfile
If you're working with a team account:
- Go to your team settings on Vercel
- The Team ID can be found in the URL or team settings
- Add it to your
.envfile
Run the delete old deployments script (development mode):
yarn delete-old-deploymentsNote: Make sure to set TARGET_ENVIRONMENT in your .env file to either production or preview depending on which deployments you want to clean up.
fairdataihub-vercel/
├── src/
│ ├── delete-old-deployments.ts # Script to delete old deployments
│ └── env.ts # Environment variable validation with Zod
├── build.ts # Build configurations for tsup
├── biome.json # Biome linter and formatter configuration
├── tsconfig.json # TypeScript configuration
├── package.json # Project metadata and scripts
└── .env # Environment variables (create this file)yarn delete-old-deployments- Delete old deployments from all projects
Run the script to clean up old deployments from all projects:
npm run dev src/delete-old-deployments.tsThe script will:
- Fetch all projects in your Vercel account/team
- For each project, retrieve deployments filtered by
TARGET_ENVIRONMENT - Keep the latest deployment and delete all older ones
- Show progress for each project and deployment
Example output:
=== Vercel Account Management Scripts ===
Environment: preview
Team ID: team_abc123
📋 Fetching list of projects...
✅ Successfully fetched 5 project(s)
🔄 Processing 5 project(s)...
📦 [1/5] Processing project: my-app (ID: prj_abc123)
Found 10 deployment(s) for preview environment
Processing 9 deployment(s) (excluding latest)
🔍 [1/9] Processing deployment: dpl_xyz789
⏳ Waiting 3421 milliseconds before next request...
🔄 Deleting deployment: dpl_xyz789
✅ Successfully deleted deployment: dpl_xyz789
...
✨ Completed processing project: my-app
- Bulk delete old deployments - Automatically clean up deployment history across all projects
- Reduce deployment clutter - Keep only the latest deployment and remove older ones
Environment variables are validated at runtime using Zod schemas in src/env.ts. Required variables:
VERCEL_TOKEN- Your Vercel API token (required)VERCEL_TEAM_ID- Your Vercel team ID (optional, omit for personal account)TARGET_ENVIRONMENT- Deployment environment to process (productionorpreview, default:preview)
The application will fail at startup with clear error messages if required variables are missing or invalid.
Important: The TARGET_ENVIRONMENT variable determines which deployments are processed:
production- Only production deployments are cleaned uppreview- Only preview deployments are cleaned up
For more information about the Vercel SDK and available methods, refer to the Vercel SDK Documentation.
This project is licensed under the MIT License.