@mastra/deployer-vercel 0.1.0-alpha.57 → 0.1.0-alpha.59
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 +16 -0
- package/dist/_tsup-dts-rollup.d.ts +21 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +144 -0
- package/package.json +3 -3
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,21 @@
|
|
|
1
1
|
# @mastra/deployer-vercel
|
|
2
2
|
|
|
3
|
+
## 0.1.0-alpha.59
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Updated dependencies [4534e77]
|
|
8
|
+
- @mastra/core@0.2.0-alpha.103
|
|
9
|
+
- @mastra/deployer@0.1.0-alpha.53
|
|
10
|
+
|
|
11
|
+
## 0.1.0-alpha.58
|
|
12
|
+
|
|
13
|
+
### Patch Changes
|
|
14
|
+
|
|
15
|
+
- Updated dependencies [a9345f9]
|
|
16
|
+
- @mastra/core@0.2.0-alpha.102
|
|
17
|
+
- @mastra/deployer@0.1.0-alpha.52
|
|
18
|
+
|
|
3
19
|
## 0.1.0-alpha.57
|
|
4
20
|
|
|
5
21
|
### Patch Changes
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { Deployer } from '@mastra/deployer';
|
|
2
|
+
|
|
3
|
+
export declare class VercelDeployer extends Deployer {
|
|
4
|
+
private teamId;
|
|
5
|
+
private projectName;
|
|
6
|
+
private token;
|
|
7
|
+
constructor({ teamId, projectName, token }: {
|
|
8
|
+
teamId: string;
|
|
9
|
+
projectName: string;
|
|
10
|
+
token: string;
|
|
11
|
+
});
|
|
12
|
+
writeFiles(outputDirectory: string): void;
|
|
13
|
+
private getProjectId;
|
|
14
|
+
private syncEnv;
|
|
15
|
+
prepare(outputDirectory: string): Promise<void>;
|
|
16
|
+
private getEntry;
|
|
17
|
+
bundle(entryFile: string, outputDirectory: string): Promise<void>;
|
|
18
|
+
deploy(outputDirectory: string): Promise<void>;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export { }
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { VercelDeployer } from './_tsup-dts-rollup.js';
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
import { Deployer } from '@mastra/deployer';
|
|
2
|
+
import '@mastra/deployer/build';
|
|
3
|
+
import '@rollup/plugin-virtual';
|
|
4
|
+
import * as child_process from 'child_process';
|
|
5
|
+
import { writeFileSync, readFileSync } from 'fs';
|
|
6
|
+
import { join } from 'path';
|
|
7
|
+
import process from 'process';
|
|
8
|
+
|
|
9
|
+
// src/index.ts
|
|
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;
|
|
19
|
+
}
|
|
20
|
+
writeFiles(outputDirectory) {
|
|
21
|
+
writeFileSync(
|
|
22
|
+
join(outputDirectory, this.outputDir, "vercel.json"),
|
|
23
|
+
JSON.stringify(
|
|
24
|
+
{
|
|
25
|
+
version: 2,
|
|
26
|
+
installCommand: "npm install --omit=dev",
|
|
27
|
+
builds: [
|
|
28
|
+
{
|
|
29
|
+
src: "index.mjs",
|
|
30
|
+
use: "@vercel/node",
|
|
31
|
+
config: { includeFiles: ["**"] }
|
|
32
|
+
}
|
|
33
|
+
],
|
|
34
|
+
routes: [
|
|
35
|
+
{
|
|
36
|
+
src: "/(.*)",
|
|
37
|
+
dest: "index.mjs"
|
|
38
|
+
}
|
|
39
|
+
]
|
|
40
|
+
},
|
|
41
|
+
null,
|
|
42
|
+
2
|
|
43
|
+
)
|
|
44
|
+
);
|
|
45
|
+
}
|
|
46
|
+
getProjectId({ dir }) {
|
|
47
|
+
const projectJsonPath = join(dir, ".vercel", "project.json");
|
|
48
|
+
try {
|
|
49
|
+
const projectJson = JSON.parse(readFileSync(projectJsonPath, "utf-8"));
|
|
50
|
+
return projectJson.projectId;
|
|
51
|
+
} catch (error) {
|
|
52
|
+
throw new Error("Could not find project ID. Make sure the project has been deployed first.");
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
async syncEnv(envVars) {
|
|
56
|
+
console.log("Syncing environment variables...");
|
|
57
|
+
const vercelEnvVars = Array.from(envVars.entries()).map(([key, value]) => {
|
|
58
|
+
if (!key || !value) {
|
|
59
|
+
throw new Error(`Invalid environment variable format: ${key || value}`);
|
|
60
|
+
}
|
|
61
|
+
return {
|
|
62
|
+
key,
|
|
63
|
+
value,
|
|
64
|
+
target: ["production", "preview", "development"],
|
|
65
|
+
type: "plain"
|
|
66
|
+
};
|
|
67
|
+
});
|
|
68
|
+
try {
|
|
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
|
+
);
|
|
81
|
+
if (!response.ok) {
|
|
82
|
+
const error = await response.json();
|
|
83
|
+
throw new Error(`Failed to sync environment variables: ${error.message}`);
|
|
84
|
+
}
|
|
85
|
+
console.log("\u2713 Successfully synced environment variables");
|
|
86
|
+
} catch (error) {
|
|
87
|
+
if (error instanceof Error) {
|
|
88
|
+
console.error("Failed to sync environment variables:", error.message);
|
|
89
|
+
} else {
|
|
90
|
+
console.error("Failed to sync environment variables:", error);
|
|
91
|
+
}
|
|
92
|
+
throw error;
|
|
93
|
+
}
|
|
94
|
+
}
|
|
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(entryFile, outputDirectory) {
|
|
112
|
+
return this._bundle(this.getEntry(), entryFile, outputDirectory);
|
|
113
|
+
}
|
|
114
|
+
async deploy(outputDirectory) {
|
|
115
|
+
const envVars = await this.loadEnvVars();
|
|
116
|
+
const commandArgs = [
|
|
117
|
+
"--scope",
|
|
118
|
+
this.teamId,
|
|
119
|
+
"--cwd",
|
|
120
|
+
join(outputDirectory, this.outputDir),
|
|
121
|
+
"--token",
|
|
122
|
+
this.token,
|
|
123
|
+
"deploy",
|
|
124
|
+
"--yes",
|
|
125
|
+
...this.projectName ? ["--name", this.projectName] : []
|
|
126
|
+
];
|
|
127
|
+
child_process.execSync(`npx vercel ${commandArgs.join(" ")}`, {
|
|
128
|
+
cwd: join(outputDirectory, this.outputDir),
|
|
129
|
+
env: {
|
|
130
|
+
// ...this.env,
|
|
131
|
+
PATH: process.env.PATH
|
|
132
|
+
},
|
|
133
|
+
stdio: "inherit"
|
|
134
|
+
});
|
|
135
|
+
this.logger.info("Deployment started on Vercel. You can wait for it to finish or exit this command.");
|
|
136
|
+
if (envVars.size > 0) {
|
|
137
|
+
await this.syncEnv(envVars);
|
|
138
|
+
} else {
|
|
139
|
+
this.logger.info("\nAdd your ENV vars to .env or your vercel dashboard.\n");
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
};
|
|
143
|
+
|
|
144
|
+
export { VercelDeployer };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mastra/deployer-vercel",
|
|
3
|
-
"version": "0.1.0-alpha.
|
|
3
|
+
"version": "0.1.0-alpha.59",
|
|
4
4
|
"description": "",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -18,8 +18,8 @@
|
|
|
18
18
|
"dependencies": {
|
|
19
19
|
"@rollup/plugin-virtual": "^3.0.2",
|
|
20
20
|
"fs-extra": "^11.2.0",
|
|
21
|
-
"@mastra/core": "^0.2.0-alpha.
|
|
22
|
-
"@mastra/deployer": "^0.1.0-alpha.
|
|
21
|
+
"@mastra/core": "^0.2.0-alpha.103",
|
|
22
|
+
"@mastra/deployer": "^0.1.0-alpha.53"
|
|
23
23
|
},
|
|
24
24
|
"devDependencies": {
|
|
25
25
|
"@microsoft/api-extractor": "^7.49.2",
|