@mastra/deployer-vercel 0.0.0-storage-20250225005900
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/.turbo/turbo-build.log +19 -0
- package/CHANGELOG.md +917 -0
- package/LICENSE +44 -0
- package/README.md +95 -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 +37 -0
- package/src/index.ts +176 -0
- package/tsconfig.json +5 -0
- package/vitest.config.ts +8 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
Elastic License 2.0 (ELv2)
|
|
2
|
+
|
|
3
|
+
**Acceptance**
|
|
4
|
+
By using the software, you agree to all of the terms and conditions below.
|
|
5
|
+
|
|
6
|
+
**Copyright License**
|
|
7
|
+
The licensor grants you a non-exclusive, royalty-free, worldwide, non-sublicensable, non-transferable license to use, copy, distribute, make available, and prepare derivative works of the software, in each case subject to the limitations and conditions below
|
|
8
|
+
|
|
9
|
+
**Limitations**
|
|
10
|
+
You may not provide the software to third parties as a hosted or managed service, where the service provides users with access to any substantial set of the features or functionality of the software.
|
|
11
|
+
|
|
12
|
+
You may not move, change, disable, or circumvent the license key functionality in the software, and you may not remove or obscure any functionality in the software that is protected by the license key.
|
|
13
|
+
|
|
14
|
+
You may not alter, remove, or obscure any licensing, copyright, or other notices of the licensor in the software. Any use of the licensor’s trademarks is subject to applicable law.
|
|
15
|
+
|
|
16
|
+
**Patents**
|
|
17
|
+
The licensor grants you a license, under any patent claims the licensor can license, or becomes able to license, to make, have made, use, sell, offer for sale, import and have imported the software, in each case subject to the limitations and conditions in this license. This license does not cover any patent claims that you cause to be infringed by modifications or additions to the software. If you or your company make any written claim that the software infringes or contributes to infringement of any patent, your patent license for the software granted under these terms ends immediately. If your company makes such a claim, your patent license ends immediately for work on behalf of your company.
|
|
18
|
+
|
|
19
|
+
**Notices**
|
|
20
|
+
You must ensure that anyone who gets a copy of any part of the software from you also gets a copy of these terms.
|
|
21
|
+
|
|
22
|
+
If you modify the software, you must include in any modified copies of the software prominent notices stating that you have modified the software.
|
|
23
|
+
|
|
24
|
+
**No Other Rights**
|
|
25
|
+
These terms do not imply any licenses other than those expressly granted in these terms.
|
|
26
|
+
|
|
27
|
+
**Termination**
|
|
28
|
+
If you use the software in violation of these terms, such use is not licensed, and your licenses will automatically terminate. If the licensor provides you with a notice of your violation, and you cease all violation of this license no later than 30 days after you receive that notice, your licenses will be reinstated retroactively. However, if you violate these terms after such reinstatement, any additional violation of these terms will cause your licenses to terminate automatically and permanently.
|
|
29
|
+
|
|
30
|
+
**No Liability**
|
|
31
|
+
As far as the law allows, the software comes as is, without any warranty or condition, and the licensor will not be liable to you for any damages arising out of these terms or the use or nature of the software, under any kind of legal claim.
|
|
32
|
+
|
|
33
|
+
**Definitions**
|
|
34
|
+
The _licensor_ is the entity offering these terms, and the _software_ is the software the licensor makes available under these terms, including any portion of it.
|
|
35
|
+
|
|
36
|
+
_you_ refers to the individual or entity agreeing to these terms.
|
|
37
|
+
|
|
38
|
+
_your company_ is any legal entity, sole proprietorship, or other kind of organization that you work for, plus all organizations that have control over, are under the control of, or are under common control with that organization. _control_ means ownership of substantially all the assets of an entity, or the power to direct its management and policies by vote, contract, or otherwise. Control can be direct or indirect.
|
|
39
|
+
|
|
40
|
+
_your licenses_ are all the licenses granted to you for the software under these terms.
|
|
41
|
+
|
|
42
|
+
_use_ means anything you do with the software requiring one of your licenses.
|
|
43
|
+
|
|
44
|
+
_trademark_ means trademarks, service marks, and similar rights.
|
package/README.md
ADDED
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
# @mastra/deployer-vercel
|
|
2
|
+
|
|
3
|
+
A Vercel deployer for Mastra applications.
|
|
4
|
+
|
|
5
|
+
## Features
|
|
6
|
+
|
|
7
|
+
- Deploy Mastra applications to Vercel
|
|
8
|
+
- Zero-configuration serverless deployments
|
|
9
|
+
- Automatic environment variable synchronization
|
|
10
|
+
- Support for production, preview, and development environments
|
|
11
|
+
- Instant global deployments with Edge Functions
|
|
12
|
+
|
|
13
|
+
## Installation
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
pnpm add @mastra/deployer-vercel
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
## Usage
|
|
20
|
+
|
|
21
|
+
The Vercel deployer is used as part of the Mastra framework:
|
|
22
|
+
|
|
23
|
+
```typescript
|
|
24
|
+
import { Mastra } from '@mastra/core';
|
|
25
|
+
import { VercelDeployer } from '@mastra/deployer-vercel';
|
|
26
|
+
|
|
27
|
+
const deployer = new VercelDeployer({
|
|
28
|
+
scope: 'your-team-id',
|
|
29
|
+
projectName: 'your-project-name',
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
const mastra = new Mastra({
|
|
33
|
+
deployer,
|
|
34
|
+
// ... other Mastra configuration options
|
|
35
|
+
});
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
## Configuration
|
|
39
|
+
|
|
40
|
+
### Constructor Options
|
|
41
|
+
|
|
42
|
+
- `scope` (required): Your Vercel team ID or username
|
|
43
|
+
- `projectName`: Name of your Vercel project (will be created if it doesn't exist)
|
|
44
|
+
|
|
45
|
+
## Project Structure
|
|
46
|
+
|
|
47
|
+
The deployer creates:
|
|
48
|
+
|
|
49
|
+
```
|
|
50
|
+
your-project/
|
|
51
|
+
├── vercel.json # Deployment configuration
|
|
52
|
+
└── index.mjs # Application entry point
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
### vercel.json Configuration
|
|
56
|
+
|
|
57
|
+
Default configuration:
|
|
58
|
+
|
|
59
|
+
```json
|
|
60
|
+
{
|
|
61
|
+
"version": 2,
|
|
62
|
+
"installCommand": "npm install --omit=dev",
|
|
63
|
+
"builds": [
|
|
64
|
+
{
|
|
65
|
+
"src": "index.mjs",
|
|
66
|
+
"use": "@vercel/node",
|
|
67
|
+
"config": {
|
|
68
|
+
"includeFiles": ["**"]
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
],
|
|
72
|
+
"routes": [
|
|
73
|
+
{
|
|
74
|
+
"src": "/(.*)",
|
|
75
|
+
"dest": "index.mjs"
|
|
76
|
+
}
|
|
77
|
+
]
|
|
78
|
+
}
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
## Environment Variables
|
|
82
|
+
|
|
83
|
+
Environment variables are handled automatically through:
|
|
84
|
+
|
|
85
|
+
- `.env` files in your project
|
|
86
|
+
- Environment variables passed through the Mastra configuration
|
|
87
|
+
- Vercel's environment variable UI
|
|
88
|
+
|
|
89
|
+
## Deployment Process
|
|
90
|
+
|
|
91
|
+
The deployer:
|
|
92
|
+
|
|
93
|
+
1. Configures your project with the necessary files
|
|
94
|
+
2. Deploys to Vercel using the CLI
|
|
95
|
+
3. Synchronizes environment variables for future deployments
|
|
@@ -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
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@mastra/deployer-vercel",
|
|
3
|
+
"version": "0.0.0-storage-20250225005900",
|
|
4
|
+
"description": "",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "dist/index.js",
|
|
7
|
+
"types": "dist/index.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"types": "./dist/index.d.ts",
|
|
11
|
+
"default": "./dist/index.js"
|
|
12
|
+
},
|
|
13
|
+
"./package.json": "./package.json"
|
|
14
|
+
},
|
|
15
|
+
"keywords": [],
|
|
16
|
+
"author": "",
|
|
17
|
+
"license": "ISC",
|
|
18
|
+
"dependencies": {
|
|
19
|
+
"@rollup/plugin-virtual": "^3.0.2",
|
|
20
|
+
"fs-extra": "^11.2.0",
|
|
21
|
+
"@mastra/core": "^0.0.0-storage-20250225005900",
|
|
22
|
+
"@mastra/deployer": "^0.0.0-storage-20250225005900"
|
|
23
|
+
},
|
|
24
|
+
"devDependencies": {
|
|
25
|
+
"@microsoft/api-extractor": "^7.49.2",
|
|
26
|
+
"@types/node": "^22.13.1",
|
|
27
|
+
"tsup": "^8.0.1",
|
|
28
|
+
"typescript": "^5.7.3",
|
|
29
|
+
"vercel": "^39.3.0",
|
|
30
|
+
"vitest": "^3.0.4"
|
|
31
|
+
},
|
|
32
|
+
"scripts": {
|
|
33
|
+
"build": "tsup src/index.ts --format esm --experimental-dts --clean --treeshake",
|
|
34
|
+
"build:watch": "pnpm build --watch",
|
|
35
|
+
"test": "vitest run"
|
|
36
|
+
}
|
|
37
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,176 @@
|
|
|
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
ADDED