Skip to content

fairdataihub/vercel

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Vercel Account Management Scripts 🚀

A collection of TypeScript scripts for managing your Vercel account, including actions like deleting old deployments, managing projects, and automating common Vercel operations.

Current Scripts

Delete Old Deployments

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.

Getting Started 🚀

1. Install Dependencies

yarn install

2. Set Up Environment Variables

Create 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"

Getting Your Vercel Token

  1. Go to Vercel Settings > Tokens
  2. Create a new token with appropriate permissions
  3. Copy the token to your .env file

Getting Your Team ID (Optional)

If you're working with a team account:

  1. Go to your team settings on Vercel
  2. The Team ID can be found in the URL or team settings
  3. Add it to your .env file

3. Run Scripts

Run the delete old deployments script (development mode):

yarn delete-old-deployments

Note: Make sure to set TARGET_ENVIRONMENT in your .env file to either production or preview depending on which deployments you want to clean up.

Project Structure 📁

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)

Available Scripts 📝

  • yarn delete-old-deployments - Delete old deployments from all projects

Usage Examples

Running the Delete Old Deployments Script

Run the script to clean up old deployments from all projects:

npm run dev src/delete-old-deployments.ts

The script will:

  1. Fetch all projects in your Vercel account/team
  2. For each project, retrieve deployments filtered by TARGET_ENVIRONMENT
  3. Keep the latest deployment and delete all older ones
  4. 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

Common Use Cases

  • 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

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 (production or preview, 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 up
  • preview - Only preview deployments are cleaned up

Vercel SDK Documentation

For more information about the Vercel SDK and available methods, refer to the Vercel SDK Documentation.

License 📄

This project is licensed under the MIT License.

About

don't worry about it

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published