//native
type Vercel = {
token: string;
};
/**
* Create a new project
* 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.
*/
export async function main(
auth: Vercel,
teamId: string | undefined,
slug: string | undefined,
body: {
buildCommand?: string;
commandForIgnoringBuildStep?: string;
devCommand?: string;
environmentVariables?: {
key: string;
target:
| "production"
| "preview"
| "development"
| "production"
| "preview"
| "development"[];
gitBranch?: string;
type?: "system" | "secret" | "encrypted" | "plain" | "sensitive";
value: string;
}[];
framework?:
| "blitzjs"
| "nextjs"
| "gatsby"
| "remix"
| "react-router"
| "astro"
| "hexo"
| "eleventy"
| "docusaurus-2"
| "docusaurus"
| "preact"
| "solidstart-1"
| "solidstart"
| "dojo"
| "ember"
| "vue"
| "scully"
| "ionic-angular"
| "angular"
| "polymer"
| "svelte"
| "sveltekit"
| "sveltekit-1"
| "ionic-react"
| "create-react-app"
| "gridsome"
| "umijs"
| "sapper"
| "saber"
| "stencil"
| "nuxtjs"
| "redwoodjs"
| "hugo"
| "jekyll"
| "brunch"
| "middleman"
| "zola"
| "hydrogen"
| "vite"
| "vitepress"
| "vuepress"
| "parcel"
| "fasthtml"
| "sanity-v3"
| "sanity"
| "storybook";
gitRepository?: { repo: string; type: "github" | "gitlab" | "bitbucket" };
installCommand?: string;
name: string;
skipGitConnectDuringLink?: false | true;
outputDirectory?: string;
publicSource?: false | true;
rootDirectory?: string;
serverlessFunctionRegion?: string;
serverlessFunctionZeroConfigFailover?: false | true;
oidcTokenConfig?: { enabled: false | true; issuerMode?: "team" | "global" };
enableAffectedProjectsDeployments?: false | true;
},
) {
const url = new URL(`https://api.vercel.com/v11/projects`);
for (const [k, v] of [
["teamId", teamId],
["slug", slug],
]) {
if (v !== undefined && v !== "" && k !== undefined) {
url.searchParams.append(k, v);
}
}
const response = await fetch(url, {
method: "POST",
headers: {
"Content-Type": "application/json",
Authorization: "Bearer " + auth.token,
},
body: JSON.stringify(body),
});
if (!response.ok) {
const text = await response.text();
throw new Error(`${response.status} ${text}`);
}
return await response.json();
}
Submitted by hugo697 428 days ago