import { VercelCodeStorage } from '@pierre/vercel-code-storage';const store = new VercelCodeStorage({ codeStorage: { name: process.env.ORG_NAME!, key: process.env.PIERRE_PRIVATE_KEY!, }, vercel: { token: process.env.VERCEL_TOKEN!, teamId: process.env.VERCEL_TEAM_ID, projectName: 'my-vercel-project', },});const repo = await store.findOne('my-repo');if (!repo) throw new Error('repo not found');const previewUrl =
getPreviewUrl() creates a Vercel preview deployment. getPublicUrl() creates
a production deployment and returns the production alias when Vercel assigns
one; otherwise it returns the generated deployment URL.
Configuration
Required environment variables:
ORG_NAME: code.storage organization name.
PIERRE_PRIVATE_KEY: code.storage private key.
VERCEL_TOKEN: Vercel API token.
Optional environment variables:
VERCEL_TEAM_ID: Vercel team scope.
VERCEL_PROJECT_NAME: Vercel project name override.
VERCEL_ROOT_DIRECTORY: app root within the archived repo.
Quick Run
Before run, makesure to preset required environment variable. Deploy an existing code.storage repo to Vercel preview or production:
# if want preview deploymentbun examples/deploy-preview.ts my-code-storage-repo# if want production deploymentbun examples/deploy-production.ts my-code-storage-repo
API
const store = new VercelCodeStorage({ codeStorage: storageOptionsOrExistingGitStorage, vercel: { token: process.env.VERCEL_TOKEN!, teamId: process.env.VERCEL_TEAM_ID, projectName: 'my-project', },});const repo = await store.findOne('my-repo');const url = await repo.getPreviewUrl({ // App root inside the code.storage archive. rootDirectory: 'new-repo/here', // Vercel project settings. Use this for framework/build/output settings when // you want to send them in the deployment payload instead of relying only on // a vercel.json file in rootDirectory. projectSettings: { framework: 'vite',
Vercel also reads vercel.json from the selected rootDirectory when that file
exists in the archived repo.
Deployment options include:
ref: branch, tag, or commit SHA to archive from code.storage.
target: preview, production, or another Vercel target.
projectName: per-deploy Vercel project name override.
rootDirectory: app root within the archived repo; this becomes the Vercel
deployment path.
projectSettings: explicit Vercel project settings for new projects.
skipAutoDetectionConfirmation: forwarded to @vercel/client; set true to
opt into automatic framework detection for new projects.
includeGlobs, excludeGlobs, maxBlobSize: forwarded to code.storage
archive creation.
wait: set false to return after Vercel creates the deployment.
meta: extra Vercel deployment metadata.
The original code.storage Repo is available as repo.storage.
Pass a valid projectName when creating a new Vercel project. If it is omitted,
@vercel/client may derive the project name from the temporary deployment path,
and Vercel will validate that derived name.
Bun And Vercel
This SDK can be installed and run with Bun. If the repository being deployed
uses Bun-specific runtime behavior on Vercel, set the app's Bun version in its
vercel.json.
await
repo.
getPreviewUrl
();
const publicUrl = await repo.getPublicUrl();
buildCommand:
'npm run build'
,
outputDirectory: 'dist',
},
// Deployment env forwarded to Vercel for this deployment.
env: {
VITE_DEPLOYED_FROM: 'code-storage',
},
// New Vercel projects can opt into framework auto-detection explicitly.