This repository was archived by the owner on Feb 27, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdelete-benchmark-projects.ts
More file actions
94 lines (78 loc) · 2.14 KB
/
delete-benchmark-projects.ts
File metadata and controls
94 lines (78 loc) · 2.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
#!/usr/bin/env node
import { parseArgs } from 'util'
import { getBenchmarkProjects } from './util.ts'
import constants from './constants.json' with { type: 'json' }
import { Vercel } from '@vercel/sdk'
import assert from 'assert'
const { teamId: TEAM_ID } = constants
const VERCEL_TOKEN = process.env.VERCEL_TOKEN
assert(VERCEL_TOKEN, 'VERCEL_TOKEN is not set in .env')
const vercel = new Vercel({ bearerToken: VERCEL_TOKEN })
type Args = {
limit?: string
filter?: string[]
dryRun?: boolean
}
async function deleteProject(projectId: string) {
const response = await fetch(
`https://api.vercel.com/v9/projects/${projectId}?teamId=${TEAM_ID}`,
{
method: 'DELETE',
headers: {
Authorization: `Bearer ${VERCEL_TOKEN}`,
},
},
)
if (!response.ok) {
const body = await response.text()
throw new Error(`HTTP ${response.status} ${response.statusText}: ${body}`)
}
}
async function deleteBenchmarkProjects({
limit = '100',
filter = [],
dryRun = false,
}: Args) {
const projectsToDelete = await getBenchmarkProjects(vercel, {
limit,
filters: filter,
})
if (!projectsToDelete.length) {
console.log('No benchmark projects found to delete.')
return
}
console.log(
`Found ${projectsToDelete.length} benchmark project(s): ${projectsToDelete.map((project) => project.name).join(', ')}`,
)
if (dryRun) {
console.log('Dry run enabled. No projects were deleted.')
return
}
let deletedCount = 0
let failedCount = 0
for (const project of projectsToDelete) {
try {
await deleteProject(project.id)
deletedCount++
console.log(`[deleted] ${project.name}`)
} catch (error) {
failedCount++
console.error(`[failed] ${project.name}`, error)
}
}
console.log(`Done. Deleted ${deletedCount} project(s). Failed: ${failedCount}.`)
if (failedCount > 0) {
process.exitCode = 1
}
}
const args = parseArgs({
options: {
limit: { type: 'string' },
filter: { type: 'string', multiple: true },
dryRun: { type: 'boolean' },
},
}).values
deleteBenchmarkProjects(args).catch((error) => {
console.error(error)
process.exit(1)
})