@mastra/deployer-vercel 0.0.0-storage-20250225005900 → 0.0.0-trigger-playground-ui-package-20250506151043
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/{LICENSE → LICENSE.md} +3 -1
- package/README.md +4 -2
- package/dist/_tsup-dts-rollup.d.cts +23 -0
- package/dist/_tsup-dts-rollup.d.ts +7 -5
- package/dist/index.cjs +234 -0
- package/dist/index.d.cts +1 -0
- package/dist/index.js +109 -44
- package/package.json +27 -15
- package/.turbo/turbo-build.log +0 -19
- package/CHANGELOG.md +0 -917
- package/src/index.ts +0 -176
- package/tsconfig.json +0 -5
- package/vitest.config.ts +0 -8
package/src/index.ts
DELETED
|
@@ -1,176 +0,0 @@
|
|
|
1
|
-
import { Deployer } from '@mastra/deployer';
|
|
2
|
-
import { getBundler } from '@mastra/deployer/build';
|
|
3
|
-
import virtual from '@rollup/plugin-virtual';
|
|
4
|
-
import * as child_process from 'child_process';
|
|
5
|
-
import { readFileSync, writeFileSync } from 'fs';
|
|
6
|
-
import { join } from 'path';
|
|
7
|
-
import process from 'process';
|
|
8
|
-
|
|
9
|
-
interface EnvVar {
|
|
10
|
-
key: string;
|
|
11
|
-
value: string;
|
|
12
|
-
target: ('production' | 'preview' | 'development')[];
|
|
13
|
-
type: 'plain' | 'secret';
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
interface VercelError {
|
|
17
|
-
message: string;
|
|
18
|
-
code: string;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
export class VercelDeployer extends Deployer {
|
|
22
|
-
private teamId: string;
|
|
23
|
-
private projectName: string;
|
|
24
|
-
private token: string;
|
|
25
|
-
|
|
26
|
-
constructor({ teamId, projectName, token }: { teamId: string; projectName: string; token: string }) {
|
|
27
|
-
super({ name: 'VERCEL' });
|
|
28
|
-
|
|
29
|
-
this.teamId = teamId;
|
|
30
|
-
this.projectName = projectName;
|
|
31
|
-
this.token = token;
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
writeFiles(outputDirectory: string): void {
|
|
35
|
-
writeFileSync(
|
|
36
|
-
join(outputDirectory, this.outputDir, 'vercel.json'),
|
|
37
|
-
JSON.stringify(
|
|
38
|
-
{
|
|
39
|
-
version: 2,
|
|
40
|
-
installCommand: 'npm install --omit=dev',
|
|
41
|
-
builds: [
|
|
42
|
-
{
|
|
43
|
-
src: 'index.mjs',
|
|
44
|
-
use: '@vercel/node',
|
|
45
|
-
config: { includeFiles: ['**'] },
|
|
46
|
-
},
|
|
47
|
-
],
|
|
48
|
-
routes: [
|
|
49
|
-
{
|
|
50
|
-
src: '/(.*)',
|
|
51
|
-
dest: 'index.mjs',
|
|
52
|
-
},
|
|
53
|
-
],
|
|
54
|
-
},
|
|
55
|
-
null,
|
|
56
|
-
2,
|
|
57
|
-
),
|
|
58
|
-
);
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
private getProjectId({ dir }: { dir: string }): string {
|
|
62
|
-
const projectJsonPath = join(dir, '.vercel', 'project.json');
|
|
63
|
-
try {
|
|
64
|
-
const projectJson = JSON.parse(readFileSync(projectJsonPath, 'utf-8'));
|
|
65
|
-
return projectJson.projectId;
|
|
66
|
-
} catch (error) {
|
|
67
|
-
throw new Error('Could not find project ID. Make sure the project has been deployed first.');
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
private async syncEnv(envVars: Map<string, string>) {
|
|
72
|
-
console.log('Syncing environment variables...');
|
|
73
|
-
|
|
74
|
-
// Transform env vars into the format expected by Vercel API
|
|
75
|
-
const vercelEnvVars: EnvVar[] = Array.from(envVars.entries()).map(([key, value]) => {
|
|
76
|
-
if (!key || !value) {
|
|
77
|
-
throw new Error(`Invalid environment variable format: ${key || value}`);
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
return {
|
|
81
|
-
key,
|
|
82
|
-
value,
|
|
83
|
-
target: ['production', 'preview', 'development'],
|
|
84
|
-
type: 'plain',
|
|
85
|
-
};
|
|
86
|
-
});
|
|
87
|
-
|
|
88
|
-
try {
|
|
89
|
-
const projectId = this.getProjectId({ dir: process.cwd() });
|
|
90
|
-
|
|
91
|
-
const response = await fetch(
|
|
92
|
-
`https://api.vercel.com/v10/projects/${projectId}/env?teamId=${this.teamId}&upsert=true`,
|
|
93
|
-
{
|
|
94
|
-
method: 'POST',
|
|
95
|
-
headers: {
|
|
96
|
-
Authorization: `Bearer ${this.token}`,
|
|
97
|
-
'Content-Type': 'application/json',
|
|
98
|
-
},
|
|
99
|
-
body: JSON.stringify(vercelEnvVars),
|
|
100
|
-
},
|
|
101
|
-
);
|
|
102
|
-
|
|
103
|
-
if (!response.ok) {
|
|
104
|
-
const error = (await response.json()) as VercelError;
|
|
105
|
-
throw new Error(`Failed to sync environment variables: ${error.message}`);
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
console.log('✓ Successfully synced environment variables');
|
|
109
|
-
} catch (error) {
|
|
110
|
-
if (error instanceof Error) {
|
|
111
|
-
console.error('Failed to sync environment variables:', error.message);
|
|
112
|
-
} else {
|
|
113
|
-
console.error('Failed to sync environment variables:', error);
|
|
114
|
-
}
|
|
115
|
-
throw error;
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
async prepare(outputDirectory: string): Promise<void> {
|
|
120
|
-
await super.prepare(outputDirectory);
|
|
121
|
-
await this.writeFiles(outputDirectory);
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
private getEntry(): string {
|
|
125
|
-
return `
|
|
126
|
-
import { handle } from 'hono/vercel'
|
|
127
|
-
import { mastra } from '#mastra';
|
|
128
|
-
import { createHonoServer } from '#server';
|
|
129
|
-
|
|
130
|
-
const app = await createHonoServer(mastra);
|
|
131
|
-
|
|
132
|
-
export const GET = handle(app);
|
|
133
|
-
export const POST = handle(app);
|
|
134
|
-
`;
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
async bundle(entryFile: string, outputDirectory: string): Promise<void> {
|
|
138
|
-
return this._bundle(this.getEntry(), entryFile, outputDirectory);
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
async deploy(outputDirectory: string): Promise<void> {
|
|
142
|
-
const envVars = await this.loadEnvVars();
|
|
143
|
-
|
|
144
|
-
// Create the command array with base arguments
|
|
145
|
-
const commandArgs = [
|
|
146
|
-
'--scope',
|
|
147
|
-
this.teamId as string,
|
|
148
|
-
'--cwd',
|
|
149
|
-
join(outputDirectory, this.outputDir),
|
|
150
|
-
'--token',
|
|
151
|
-
this.token,
|
|
152
|
-
'deploy',
|
|
153
|
-
'--yes',
|
|
154
|
-
...(this.projectName ? ['--name', this.projectName] : []),
|
|
155
|
-
];
|
|
156
|
-
|
|
157
|
-
// Run the Vercel deploy command
|
|
158
|
-
child_process.execSync(`npx vercel ${commandArgs.join(' ')}`, {
|
|
159
|
-
cwd: join(outputDirectory, this.outputDir),
|
|
160
|
-
env: {
|
|
161
|
-
// ...this.env,
|
|
162
|
-
PATH: process.env.PATH,
|
|
163
|
-
},
|
|
164
|
-
stdio: 'inherit',
|
|
165
|
-
});
|
|
166
|
-
|
|
167
|
-
this.logger.info('Deployment started on Vercel. You can wait for it to finish or exit this command.');
|
|
168
|
-
|
|
169
|
-
if (envVars.size > 0) {
|
|
170
|
-
// Sync environment variables for future deployments
|
|
171
|
-
await this.syncEnv(envVars);
|
|
172
|
-
} else {
|
|
173
|
-
this.logger.info('\nAdd your ENV vars to .env or your vercel dashboard.\n');
|
|
174
|
-
}
|
|
175
|
-
}
|
|
176
|
-
}
|
package/tsconfig.json
DELETED