0

Create a new project

by
Published Apr 8, 2025

Allows to create a new project with the provided configuration. It only requires the project `name` but more configuration can be provided to override the defaults.

Script vercel Verified

The script

Submitted by hugo697 Bun
Verified 428 days ago
1
//native
2
type Vercel = {
3
  token: string;
4
};
5
/**
6
 * Create a new project
7
 * Allows to create a new project with the provided configuration. It only requires the project `name` but more configuration can be provided to override the defaults.
8
 */
9
export async function main(
10
  auth: Vercel,
11
  teamId: string | undefined,
12
  slug: string | undefined,
13
  body: {
14
    buildCommand?: string;
15
    commandForIgnoringBuildStep?: string;
16
    devCommand?: string;
17
    environmentVariables?: {
18
      key: string;
19
      target:
20
        | "production"
21
        | "preview"
22
        | "development"
23
        | "production"
24
        | "preview"
25
        | "development"[];
26
      gitBranch?: string;
27
      type?: "system" | "secret" | "encrypted" | "plain" | "sensitive";
28
      value: string;
29
    }[];
30
    framework?:
31
      | "blitzjs"
32
      | "nextjs"
33
      | "gatsby"
34
      | "remix"
35
      | "react-router"
36
      | "astro"
37
      | "hexo"
38
      | "eleventy"
39
      | "docusaurus-2"
40
      | "docusaurus"
41
      | "preact"
42
      | "solidstart-1"
43
      | "solidstart"
44
      | "dojo"
45
      | "ember"
46
      | "vue"
47
      | "scully"
48
      | "ionic-angular"
49
      | "angular"
50
      | "polymer"
51
      | "svelte"
52
      | "sveltekit"
53
      | "sveltekit-1"
54
      | "ionic-react"
55
      | "create-react-app"
56
      | "gridsome"
57
      | "umijs"
58
      | "sapper"
59
      | "saber"
60
      | "stencil"
61
      | "nuxtjs"
62
      | "redwoodjs"
63
      | "hugo"
64
      | "jekyll"
65
      | "brunch"
66
      | "middleman"
67
      | "zola"
68
      | "hydrogen"
69
      | "vite"
70
      | "vitepress"
71
      | "vuepress"
72
      | "parcel"
73
      | "fasthtml"
74
      | "sanity-v3"
75
      | "sanity"
76
      | "storybook";
77
    gitRepository?: { repo: string; type: "github" | "gitlab" | "bitbucket" };
78
    installCommand?: string;
79
    name: string;
80
    skipGitConnectDuringLink?: false | true;
81
    outputDirectory?: string;
82
    publicSource?: false | true;
83
    rootDirectory?: string;
84
    serverlessFunctionRegion?: string;
85
    serverlessFunctionZeroConfigFailover?: false | true;
86
    oidcTokenConfig?: { enabled: false | true; issuerMode?: "team" | "global" };
87
    enableAffectedProjectsDeployments?: false | true;
88
  },
89
) {
90
  const url = new URL(`https://api.vercel.com/v11/projects`);
91
  for (const [k, v] of [
92
    ["teamId", teamId],
93
    ["slug", slug],
94
  ]) {
95
    if (v !== undefined && v !== "" && k !== undefined) {
96
      url.searchParams.append(k, v);
97
    }
98
  }
99
  const response = await fetch(url, {
100
    method: "POST",
101
    headers: {
102
      "Content-Type": "application/json",
103
      Authorization: "Bearer " + auth.token,
104
    },
105
    body: JSON.stringify(body),
106
  });
107
  if (!response.ok) {
108
    const text = await response.text();
109
    throw new Error(`${response.status} ${text}`);
110
  }
111
  return await response.json();
112
}
113