@mastra/deployer-vercel 0.0.1-alpha.33 → 0.0.1-alpha.35
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/CHANGELOG.md +20 -0
- package/dist/index.d.ts +14 -20
- package/dist/index.js +70 -58
- package/package.json +5 -3
- package/src/index.ts +75 -64
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,25 @@
|
|
|
1
1
|
# @mastra/deployer-vercel
|
|
2
2
|
|
|
3
|
+
## 0.0.1-alpha.35
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Updated dependencies [e27fe69]
|
|
8
|
+
- @mastra/deployer@0.0.1-alpha.30
|
|
9
|
+
|
|
10
|
+
## 0.0.1-alpha.34
|
|
11
|
+
|
|
12
|
+
### Patch Changes
|
|
13
|
+
|
|
14
|
+
- 38b7f66: Update deployer logic
|
|
15
|
+
- Updated dependencies [2f17a5f]
|
|
16
|
+
- Updated dependencies [0696eeb]
|
|
17
|
+
- Updated dependencies [cb290ee]
|
|
18
|
+
- Updated dependencies [b4d7416]
|
|
19
|
+
- Updated dependencies [38b7f66]
|
|
20
|
+
- @mastra/core@0.2.0-alpha.84
|
|
21
|
+
- @mastra/deployer@0.0.1-alpha.29
|
|
22
|
+
|
|
3
23
|
## 0.0.1-alpha.33
|
|
4
24
|
|
|
5
25
|
### Patch Changes
|
package/dist/index.d.ts
CHANGED
|
@@ -1,27 +1,21 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Deployer } from '@mastra/deployer';
|
|
2
2
|
|
|
3
|
-
declare class VercelDeployer extends
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
3
|
+
declare class VercelDeployer extends Deployer {
|
|
4
|
+
private teamId;
|
|
5
|
+
private projectName;
|
|
6
|
+
private token;
|
|
7
|
+
constructor({ teamId, projectName, token }: {
|
|
8
|
+
teamId: string;
|
|
7
9
|
projectName: string;
|
|
10
|
+
token: string;
|
|
8
11
|
});
|
|
9
|
-
writeFiles(
|
|
10
|
-
dir: string;
|
|
11
|
-
}): void;
|
|
12
|
+
writeFiles(outputDirectory: string): void;
|
|
12
13
|
private getProjectId;
|
|
13
|
-
syncEnv
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
deploy({ dir, token }: {
|
|
19
|
-
dir: string;
|
|
20
|
-
token: string;
|
|
21
|
-
}): Promise<void>;
|
|
22
|
-
writeIndex({ dir }: {
|
|
23
|
-
dir: string;
|
|
24
|
-
}): void;
|
|
14
|
+
private syncEnv;
|
|
15
|
+
prepare(outputDirectory: string): Promise<void>;
|
|
16
|
+
private getEntry;
|
|
17
|
+
bundle(mastraDir: string, outputDirectory: string): Promise<void>;
|
|
18
|
+
deploy(outputDirectory: string): Promise<void>;
|
|
25
19
|
}
|
|
26
20
|
|
|
27
21
|
export { VercelDeployer };
|
package/dist/index.js
CHANGED
|
@@ -1,17 +1,25 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Deployer } from '@mastra/deployer';
|
|
2
|
+
import { getBundler } from '@mastra/deployer/build';
|
|
3
|
+
import virtual from '@rollup/plugin-virtual';
|
|
2
4
|
import * as child_process from 'child_process';
|
|
3
5
|
import { writeFileSync, readFileSync } from 'fs';
|
|
4
6
|
import { join } from 'path';
|
|
7
|
+
import process from 'process';
|
|
5
8
|
|
|
6
9
|
// src/index.ts
|
|
7
|
-
var VercelDeployer = class extends
|
|
8
|
-
|
|
9
|
-
|
|
10
|
+
var VercelDeployer = class extends Deployer {
|
|
11
|
+
teamId;
|
|
12
|
+
projectName;
|
|
13
|
+
token;
|
|
14
|
+
constructor({ teamId, projectName, token }) {
|
|
15
|
+
super({ name: "VERCEL" });
|
|
16
|
+
this.teamId = teamId;
|
|
17
|
+
this.projectName = projectName;
|
|
18
|
+
this.token = token;
|
|
10
19
|
}
|
|
11
|
-
writeFiles(
|
|
12
|
-
this.writeIndex({ dir });
|
|
20
|
+
writeFiles(outputDirectory) {
|
|
13
21
|
writeFileSync(
|
|
14
|
-
join(
|
|
22
|
+
join(outputDirectory, "vercel.json"),
|
|
15
23
|
JSON.stringify(
|
|
16
24
|
{
|
|
17
25
|
version: 2,
|
|
@@ -44,18 +52,11 @@ var VercelDeployer = class extends MastraDeployer {
|
|
|
44
52
|
throw new Error("Could not find project ID. Make sure the project has been deployed first.");
|
|
45
53
|
}
|
|
46
54
|
}
|
|
47
|
-
async syncEnv(
|
|
48
|
-
const envFiles = this.getEnvFiles();
|
|
49
|
-
const envVars = [];
|
|
50
|
-
for (const file of envFiles) {
|
|
51
|
-
const vars = this.parseEnvFile(file);
|
|
52
|
-
envVars.push(...vars);
|
|
53
|
-
}
|
|
55
|
+
async syncEnv(envVars) {
|
|
54
56
|
console.log("Syncing environment variables...");
|
|
55
|
-
const vercelEnvVars = envVars.map((
|
|
56
|
-
const [key, value] = envVar.split("=");
|
|
57
|
+
const vercelEnvVars = Array.from(envVars.entries()).map(([key, value]) => {
|
|
57
58
|
if (!key || !value) {
|
|
58
|
-
throw new Error(`Invalid environment variable format: ${
|
|
59
|
+
throw new Error(`Invalid environment variable format: ${key || value}`);
|
|
59
60
|
}
|
|
60
61
|
return {
|
|
61
62
|
key,
|
|
@@ -65,15 +66,18 @@ var VercelDeployer = class extends MastraDeployer {
|
|
|
65
66
|
};
|
|
66
67
|
});
|
|
67
68
|
try {
|
|
68
|
-
const projectId = this.getProjectId({ dir });
|
|
69
|
-
const response = await fetch(
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
69
|
+
const projectId = this.getProjectId({ dir: process.cwd() });
|
|
70
|
+
const response = await fetch(
|
|
71
|
+
`https://api.vercel.com/v10/projects/${projectId}/env?teamId=${this.teamId}&upsert=true`,
|
|
72
|
+
{
|
|
73
|
+
method: "POST",
|
|
74
|
+
headers: {
|
|
75
|
+
Authorization: `Bearer ${this.token}`,
|
|
76
|
+
"Content-Type": "application/json"
|
|
77
|
+
},
|
|
78
|
+
body: JSON.stringify(vercelEnvVars)
|
|
79
|
+
}
|
|
80
|
+
);
|
|
77
81
|
if (!response.ok) {
|
|
78
82
|
const error = await response.json();
|
|
79
83
|
throw new Error(`Failed to sync environment variables: ${error.message}`);
|
|
@@ -88,53 +92,61 @@ var VercelDeployer = class extends MastraDeployer {
|
|
|
88
92
|
throw error;
|
|
89
93
|
}
|
|
90
94
|
}
|
|
91
|
-
async
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
95
|
+
async prepare(outputDirectory) {
|
|
96
|
+
await super.prepare(outputDirectory);
|
|
97
|
+
await this.writeFiles(outputDirectory);
|
|
98
|
+
}
|
|
99
|
+
getEntry() {
|
|
100
|
+
return `
|
|
101
|
+
import { handle } from 'hono/vercel'
|
|
102
|
+
import { mastra } from '#mastra';
|
|
103
|
+
import { createHonoServer } from '#server';
|
|
104
|
+
|
|
105
|
+
const app = await createHonoServer(mastra);
|
|
106
|
+
|
|
107
|
+
export const GET = handle(app);
|
|
108
|
+
export const POST = handle(app);
|
|
109
|
+
`;
|
|
110
|
+
}
|
|
111
|
+
async bundle(mastraDir, outputDirectory) {
|
|
112
|
+
const bundler = await getBundler({
|
|
113
|
+
input: "#entry",
|
|
114
|
+
plugins: [virtual({ "#entry": this.getEntry() })]
|
|
115
|
+
});
|
|
116
|
+
await bundler.write({
|
|
117
|
+
inlineDynamicImports: true,
|
|
118
|
+
file: `${outputDirectory}/index.mjs`,
|
|
119
|
+
format: "es"
|
|
120
|
+
});
|
|
121
|
+
}
|
|
122
|
+
async deploy(outputDirectory) {
|
|
123
|
+
const envVars = await this.loadEnvVars();
|
|
98
124
|
const commandArgs = [
|
|
99
125
|
"--scope",
|
|
100
|
-
this.
|
|
126
|
+
this.teamId,
|
|
101
127
|
"--cwd",
|
|
102
|
-
|
|
103
|
-
"deploy",
|
|
128
|
+
outputDirectory,
|
|
104
129
|
"--token",
|
|
105
|
-
token,
|
|
130
|
+
this.token,
|
|
131
|
+
"deploy",
|
|
106
132
|
"--yes",
|
|
107
133
|
...this.projectName ? ["--name", this.projectName] : []
|
|
108
134
|
];
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
}
|
|
112
|
-
child_process.execSync(`vercel ${commandArgs.join(" ")}`, {
|
|
113
|
-
cwd: dir,
|
|
135
|
+
child_process.execSync(`npx vercel ${commandArgs.join(" ")}`, {
|
|
136
|
+
cwd: outputDirectory,
|
|
114
137
|
env: {
|
|
115
|
-
...this.env,
|
|
138
|
+
// ...this.env,
|
|
116
139
|
PATH: process.env.PATH
|
|
117
140
|
},
|
|
118
141
|
stdio: "inherit"
|
|
119
142
|
});
|
|
120
|
-
|
|
121
|
-
if (envVars.
|
|
122
|
-
await this.syncEnv(
|
|
143
|
+
this.logger.info("Deployment started on Vercel. You can wait for it to finish or exit this command.");
|
|
144
|
+
if (envVars.size > 0) {
|
|
145
|
+
await this.syncEnv(envVars);
|
|
123
146
|
} else {
|
|
124
|
-
|
|
147
|
+
this.logger.info("\nAdd your ENV vars to .env or your vercel dashboard.\n");
|
|
125
148
|
}
|
|
126
149
|
}
|
|
127
|
-
writeIndex({ dir }) {
|
|
128
|
-
writeFileSync(
|
|
129
|
-
join(dir, "index.mjs"),
|
|
130
|
-
`
|
|
131
|
-
import { handle } from 'hono/vercel'
|
|
132
|
-
import { app } from './hono.mjs';
|
|
133
|
-
export const GET = handle(app);
|
|
134
|
-
export const POST = handle(app);
|
|
135
|
-
`
|
|
136
|
-
);
|
|
137
|
-
}
|
|
138
150
|
};
|
|
139
151
|
|
|
140
152
|
export { VercelDeployer };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mastra/deployer-vercel",
|
|
3
|
-
"version": "0.0.1-alpha.
|
|
3
|
+
"version": "0.0.1-alpha.35",
|
|
4
4
|
"description": "",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -16,8 +16,10 @@
|
|
|
16
16
|
"author": "",
|
|
17
17
|
"license": "ISC",
|
|
18
18
|
"dependencies": {
|
|
19
|
-
"@
|
|
20
|
-
"
|
|
19
|
+
"@rollup/plugin-virtual": "^3.0.2",
|
|
20
|
+
"fs-extra": "^11.2.0",
|
|
21
|
+
"@mastra/core": "0.2.0-alpha.84",
|
|
22
|
+
"@mastra/deployer": "0.0.1-alpha.30"
|
|
21
23
|
},
|
|
22
24
|
"devDependencies": {
|
|
23
25
|
"@babel/preset-env": "^7.26.0",
|
package/src/index.ts
CHANGED
|
@@ -1,7 +1,10 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Deployer } from '@mastra/deployer';
|
|
2
|
+
import { getBundler } from '@mastra/deployer/build';
|
|
3
|
+
import virtual from '@rollup/plugin-virtual';
|
|
2
4
|
import * as child_process from 'child_process';
|
|
3
5
|
import { readFileSync, writeFileSync } from 'fs';
|
|
4
6
|
import { join } from 'path';
|
|
7
|
+
import process from 'process';
|
|
5
8
|
|
|
6
9
|
interface EnvVar {
|
|
7
10
|
key: string;
|
|
@@ -15,16 +18,22 @@ interface VercelError {
|
|
|
15
18
|
code: string;
|
|
16
19
|
}
|
|
17
20
|
|
|
18
|
-
export class VercelDeployer extends
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
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' });
|
|
22
28
|
|
|
23
|
-
|
|
24
|
-
this.
|
|
29
|
+
this.teamId = teamId;
|
|
30
|
+
this.projectName = projectName;
|
|
31
|
+
this.token = token;
|
|
32
|
+
}
|
|
25
33
|
|
|
34
|
+
writeFiles(outputDirectory: string): void {
|
|
26
35
|
writeFileSync(
|
|
27
|
-
join(
|
|
36
|
+
join(outputDirectory, 'vercel.json'),
|
|
28
37
|
JSON.stringify(
|
|
29
38
|
{
|
|
30
39
|
version: 2,
|
|
@@ -59,23 +68,15 @@ export class VercelDeployer extends MastraDeployer {
|
|
|
59
68
|
}
|
|
60
69
|
}
|
|
61
70
|
|
|
62
|
-
async syncEnv(
|
|
63
|
-
const envFiles = this.getEnvFiles();
|
|
64
|
-
const envVars: string[] = [];
|
|
65
|
-
|
|
66
|
-
for (const file of envFiles) {
|
|
67
|
-
const vars = this.parseEnvFile(file);
|
|
68
|
-
envVars.push(...vars);
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
+
private async syncEnv(envVars: Map<string, string>) {
|
|
71
72
|
console.log('Syncing environment variables...');
|
|
72
73
|
|
|
73
74
|
// Transform env vars into the format expected by Vercel API
|
|
74
|
-
const vercelEnvVars: EnvVar[] = envVars.map(
|
|
75
|
-
const [key, value] = envVar.split('=');
|
|
75
|
+
const vercelEnvVars: EnvVar[] = Array.from(envVars.entries()).map(([key, value]) => {
|
|
76
76
|
if (!key || !value) {
|
|
77
|
-
throw new Error(`Invalid environment variable format: ${
|
|
77
|
+
throw new Error(`Invalid environment variable format: ${key || value}`);
|
|
78
78
|
}
|
|
79
|
+
|
|
79
80
|
return {
|
|
80
81
|
key,
|
|
81
82
|
value,
|
|
@@ -85,16 +86,19 @@ export class VercelDeployer extends MastraDeployer {
|
|
|
85
86
|
});
|
|
86
87
|
|
|
87
88
|
try {
|
|
88
|
-
const projectId = this.getProjectId({ dir });
|
|
89
|
+
const projectId = this.getProjectId({ dir: process.cwd() });
|
|
89
90
|
|
|
90
|
-
const response = await fetch(
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
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),
|
|
95
100
|
},
|
|
96
|
-
|
|
97
|
-
});
|
|
101
|
+
);
|
|
98
102
|
|
|
99
103
|
if (!response.ok) {
|
|
100
104
|
const error = (await response.json()) as VercelError;
|
|
@@ -112,63 +116,70 @@ export class VercelDeployer extends MastraDeployer {
|
|
|
112
116
|
}
|
|
113
117
|
}
|
|
114
118
|
|
|
115
|
-
async
|
|
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';
|
|
119
129
|
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
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(mastraDir: string, outputDirectory: string): Promise<void> {
|
|
138
|
+
const bundler = await getBundler({
|
|
139
|
+
input: '#entry',
|
|
140
|
+
plugins: [virtual({ '#entry': this.getEntry() })],
|
|
141
|
+
});
|
|
142
|
+
|
|
143
|
+
await bundler.write({
|
|
144
|
+
inlineDynamicImports: true,
|
|
145
|
+
file: `${outputDirectory}/index.mjs`,
|
|
146
|
+
format: 'es',
|
|
147
|
+
});
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
async deploy(outputDirectory: string): Promise<void> {
|
|
151
|
+
const envVars = await this.loadEnvVars();
|
|
124
152
|
|
|
125
153
|
// Create the command array with base arguments
|
|
126
154
|
const commandArgs = [
|
|
127
155
|
'--scope',
|
|
128
|
-
this.
|
|
156
|
+
this.teamId as string,
|
|
129
157
|
'--cwd',
|
|
130
|
-
|
|
131
|
-
'deploy',
|
|
158
|
+
outputDirectory,
|
|
132
159
|
'--token',
|
|
133
|
-
token,
|
|
160
|
+
this.token,
|
|
161
|
+
'deploy',
|
|
134
162
|
'--yes',
|
|
135
163
|
...(this.projectName ? ['--name', this.projectName] : []),
|
|
136
164
|
];
|
|
137
165
|
|
|
138
|
-
// Add env vars to initial deployment
|
|
139
|
-
for (const envVar of envVars) {
|
|
140
|
-
commandArgs.push('--env', envVar);
|
|
141
|
-
}
|
|
142
|
-
|
|
143
166
|
// Run the Vercel deploy command
|
|
144
|
-
child_process.execSync(`vercel ${commandArgs.join(' ')}`, {
|
|
145
|
-
cwd:
|
|
167
|
+
child_process.execSync(`npx vercel ${commandArgs.join(' ')}`, {
|
|
168
|
+
cwd: outputDirectory,
|
|
146
169
|
env: {
|
|
147
|
-
...this.env,
|
|
170
|
+
// ...this.env,
|
|
148
171
|
PATH: process.env.PATH,
|
|
149
172
|
},
|
|
150
173
|
stdio: 'inherit',
|
|
151
174
|
});
|
|
152
175
|
|
|
153
|
-
|
|
176
|
+
this.logger.info('Deployment started on Vercel. You can wait for it to finish or exit this command.');
|
|
154
177
|
|
|
155
|
-
if (envVars.
|
|
178
|
+
if (envVars.size > 0) {
|
|
156
179
|
// Sync environment variables for future deployments
|
|
157
|
-
await this.syncEnv(
|
|
180
|
+
await this.syncEnv(envVars);
|
|
158
181
|
} else {
|
|
159
|
-
|
|
182
|
+
this.logger.info('\nAdd your ENV vars to .env or your vercel dashboard.\n');
|
|
160
183
|
}
|
|
161
184
|
}
|
|
162
|
-
|
|
163
|
-
writeIndex({ dir }: { dir: string }): void {
|
|
164
|
-
writeFileSync(
|
|
165
|
-
join(dir, 'index.mjs'),
|
|
166
|
-
`
|
|
167
|
-
import { handle } from 'hono/vercel'
|
|
168
|
-
import { app } from './hono.mjs';
|
|
169
|
-
export const GET = handle(app);
|
|
170
|
-
export const POST = handle(app);
|
|
171
|
-
`,
|
|
172
|
-
);
|
|
173
|
-
}
|
|
174
185
|
}
|