@mastra/deployer-netlify 0.0.1-alpha.28 → 0.0.1-alpha.3
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 +0 -198
- package/dist/deployer-netlify.cjs.development.js +551 -0
- package/dist/deployer-netlify.cjs.development.js.map +1 -0
- package/dist/deployer-netlify.cjs.production.min.js +2 -0
- package/dist/deployer-netlify.cjs.production.min.js.map +1 -0
- package/dist/deployer-netlify.esm.js +547 -0
- package/dist/deployer-netlify.esm.js.map +1 -0
- package/dist/helpers.d.ts +6 -0
- package/dist/helpers.d.ts.map +1 -0
- package/dist/index.d.ts +2 -4
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +5 -116
- package/package.json +18 -9
- package/tsconfig.json +6 -1
- package/vitest.config.ts +1 -1
- package/README.md +0 -86
package/dist/index.js
CHANGED
|
@@ -1,119 +1,8 @@
|
|
|
1
|
-
import { MastraDeployer } from '@mastra/core';
|
|
2
|
-
import { execa } from 'execa';
|
|
3
|
-
import { existsSync, mkdirSync, writeFileSync, renameSync } from 'fs';
|
|
4
|
-
import { join } from 'path';
|
|
5
1
|
|
|
6
|
-
|
|
2
|
+
'use strict'
|
|
7
3
|
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
method: "POST",
|
|
13
|
-
headers: {
|
|
14
|
-
Authorization: `Bearer ${token}`,
|
|
15
|
-
"Content-Type": "application/json"
|
|
16
|
-
},
|
|
17
|
-
body: JSON.stringify({
|
|
18
|
-
name,
|
|
19
|
-
account_slug: scope,
|
|
20
|
-
// Optional - if not provided, creates in user's default account
|
|
21
|
-
force_ssl: true
|
|
22
|
-
// Enable HTTPS
|
|
23
|
-
})
|
|
24
|
-
});
|
|
25
|
-
const data = await response.json();
|
|
26
|
-
if (!response.ok) {
|
|
27
|
-
console.error(JSON.stringify(data));
|
|
28
|
-
throw new Error(`Failed to create site: ${data.message || "Unknown error"}`);
|
|
29
|
-
}
|
|
30
|
-
return {
|
|
31
|
-
id: data.id,
|
|
32
|
-
name: data.name,
|
|
33
|
-
url: data.ssl_url || data.url,
|
|
34
|
-
adminUrl: data.admin_url
|
|
35
|
-
};
|
|
4
|
+
if (process.env.NODE_ENV === 'production') {
|
|
5
|
+
module.exports = require('./deployer-netlify.cjs.production.min.js')
|
|
6
|
+
} else {
|
|
7
|
+
module.exports = require('./deployer-netlify.cjs.development.js')
|
|
36
8
|
}
|
|
37
|
-
async function findNetlifySite({ token, name, scope }) {
|
|
38
|
-
const response = await fetch(`https://api.netlify.com/api/v1/${scope}/sites?filter=all&name=${name}`, {
|
|
39
|
-
headers: {
|
|
40
|
-
Authorization: `Bearer ${token}`,
|
|
41
|
-
"Content-Type": "application/json"
|
|
42
|
-
}
|
|
43
|
-
});
|
|
44
|
-
const data = await response.json();
|
|
45
|
-
if (!response.ok) {
|
|
46
|
-
throw new Error(`Failed to search sites: ${data.message || "Unknown error"}`);
|
|
47
|
-
}
|
|
48
|
-
return data.find((site) => site.name === name);
|
|
49
|
-
}
|
|
50
|
-
async function getOrCreateSite({ token, name, scope }) {
|
|
51
|
-
let existingSite;
|
|
52
|
-
try {
|
|
53
|
-
existingSite = await findNetlifySite({ token, name, scope });
|
|
54
|
-
} catch (e) {
|
|
55
|
-
}
|
|
56
|
-
if (existingSite) {
|
|
57
|
-
return existingSite;
|
|
58
|
-
}
|
|
59
|
-
return createNetlifySite({ token, name, scope });
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
// src/index.ts
|
|
63
|
-
var NetlifyDeployer = class extends MastraDeployer {
|
|
64
|
-
constructor({ scope, env, projectName }) {
|
|
65
|
-
super({ scope, env, projectName });
|
|
66
|
-
}
|
|
67
|
-
writeFiles({ dir }) {
|
|
68
|
-
if (!existsSync(join(dir, "netlify/functions/api"))) {
|
|
69
|
-
mkdirSync(join(dir, "netlify/functions/api"), { recursive: true });
|
|
70
|
-
}
|
|
71
|
-
writeFileSync(
|
|
72
|
-
join(dir, "netlify.toml"),
|
|
73
|
-
`
|
|
74
|
-
[functions]
|
|
75
|
-
node_bundler = "esbuild"
|
|
76
|
-
directory = "/netlify/functions"
|
|
77
|
-
|
|
78
|
-
[[redirects]]
|
|
79
|
-
force = true
|
|
80
|
-
from = "/*"
|
|
81
|
-
status = 200
|
|
82
|
-
to = "/.netlify/functions/api/:splat"
|
|
83
|
-
`
|
|
84
|
-
);
|
|
85
|
-
this.writeIndex({ dir });
|
|
86
|
-
}
|
|
87
|
-
async deploy({ dir, token }) {
|
|
88
|
-
const site = await getOrCreateSite({ token, name: this.projectName || `mastra`, scope: this.scope });
|
|
89
|
-
const p2 = execa(
|
|
90
|
-
"netlify",
|
|
91
|
-
["deploy", "--site", site.id, "--auth", token, "--dir", ".", "--functions", "./netlify/functions"],
|
|
92
|
-
{
|
|
93
|
-
cwd: dir
|
|
94
|
-
}
|
|
95
|
-
);
|
|
96
|
-
p2.stdout.pipe(process.stdout);
|
|
97
|
-
await p2;
|
|
98
|
-
}
|
|
99
|
-
writeIndex({ dir }) {
|
|
100
|
-
["mastra.mjs", "hono.mjs", "server.mjs"].forEach((file) => {
|
|
101
|
-
renameSync(join(dir, file), join(dir, `netlify/functions/api/${file}`));
|
|
102
|
-
});
|
|
103
|
-
writeFileSync(
|
|
104
|
-
join(dir, "netlify/functions/api/api.mts"),
|
|
105
|
-
`
|
|
106
|
-
export default async (req, context) => {
|
|
107
|
-
const { app } = await import('./hono.mjs');
|
|
108
|
-
// Pass the request directly to Hono
|
|
109
|
-
return app.fetch(req, {
|
|
110
|
-
// Optional context passing if needed
|
|
111
|
-
env: { context }
|
|
112
|
-
})
|
|
113
|
-
}
|
|
114
|
-
`
|
|
115
|
-
);
|
|
116
|
-
}
|
|
117
|
-
};
|
|
118
|
-
|
|
119
|
-
export { NetlifyDeployer };
|
package/package.json
CHANGED
|
@@ -1,14 +1,21 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mastra/deployer-netlify",
|
|
3
|
-
"version": "0.0.1-alpha.
|
|
3
|
+
"version": "0.0.1-alpha.3",
|
|
4
4
|
"description": "",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
7
|
+
"module": "dist/deployer-netlify.esm.js",
|
|
7
8
|
"types": "dist/index.d.ts",
|
|
8
9
|
"exports": {
|
|
9
10
|
".": {
|
|
10
|
-
"
|
|
11
|
-
|
|
11
|
+
"import": {
|
|
12
|
+
"types": "./dist/index.d.ts",
|
|
13
|
+
"default": "./dist/deployer-netlify.esm.js"
|
|
14
|
+
},
|
|
15
|
+
"require": {
|
|
16
|
+
"types": "./dist/index.d.ts",
|
|
17
|
+
"default": "./dist/index.js"
|
|
18
|
+
}
|
|
12
19
|
},
|
|
13
20
|
"./package.json": "./package.json"
|
|
14
21
|
},
|
|
@@ -21,20 +28,22 @@
|
|
|
21
28
|
"execa": "^9.3.1",
|
|
22
29
|
"netlify-cli": "^18.0.1",
|
|
23
30
|
"zod": "^3.24.1",
|
|
24
|
-
"@mastra/core": "0.1.27-alpha.
|
|
25
|
-
"@mastra/deployer": "0.0.1-alpha.
|
|
31
|
+
"@mastra/core": "0.1.27-alpha.67",
|
|
32
|
+
"@mastra/deployer": "0.0.1-alpha.3"
|
|
26
33
|
},
|
|
27
34
|
"devDependencies": {
|
|
28
35
|
"@babel/preset-env": "^7.26.0",
|
|
29
36
|
"@babel/preset-typescript": "^7.26.0",
|
|
30
37
|
"@tsconfig/recommended": "^1.0.7",
|
|
38
|
+
"@types/jsdom": "^21.1.7",
|
|
31
39
|
"@types/node": "^22.9.0",
|
|
32
|
-
"
|
|
33
|
-
"
|
|
40
|
+
"@types/pg": "^8.11.10",
|
|
41
|
+
"dts-cli": "^2.0.5",
|
|
42
|
+
"vitest": "^2.1.8"
|
|
34
43
|
},
|
|
35
44
|
"scripts": {
|
|
36
|
-
"build": "
|
|
37
|
-
"dev": "
|
|
45
|
+
"build": "dts build",
|
|
46
|
+
"build:dev": "dts watch",
|
|
38
47
|
"test": "vitest run"
|
|
39
48
|
}
|
|
40
49
|
}
|
package/tsconfig.json
CHANGED
|
@@ -1,5 +1,10 @@
|
|
|
1
1
|
{
|
|
2
|
-
"extends": "../../tsconfig.
|
|
2
|
+
"extends": "../../tsconfig.json",
|
|
3
|
+
"compilerOptions": {
|
|
4
|
+
"moduleResolution": "bundler",
|
|
5
|
+
"outDir": "./dist",
|
|
6
|
+
"rootDir": "./src"
|
|
7
|
+
},
|
|
3
8
|
"include": ["src/**/*"],
|
|
4
9
|
"exclude": ["node_modules", "**/*.test.ts"]
|
|
5
10
|
}
|
package/vitest.config.ts
CHANGED
package/README.md
DELETED
|
@@ -1,86 +0,0 @@
|
|
|
1
|
-
# @mastra/deployer-netlify
|
|
2
|
-
|
|
3
|
-
A Netlify deployer for Mastra applications.
|
|
4
|
-
|
|
5
|
-
## Features
|
|
6
|
-
|
|
7
|
-
- Deploy Mastra applications to Netlify Functions
|
|
8
|
-
- Automatic site creation and configuration
|
|
9
|
-
- Serverless function support with Edge Functions
|
|
10
|
-
- Zero-configuration deployments
|
|
11
|
-
|
|
12
|
-
## Installation
|
|
13
|
-
|
|
14
|
-
```bash
|
|
15
|
-
pnpm add @mastra/deployer-netlify
|
|
16
|
-
```
|
|
17
|
-
|
|
18
|
-
## Usage
|
|
19
|
-
|
|
20
|
-
The Netlify deployer is used as part of the Mastra framework:
|
|
21
|
-
|
|
22
|
-
```typescript
|
|
23
|
-
import { Mastra } from '@mastra/core';
|
|
24
|
-
import { NetlifyDeployer } from '@mastra/deployer-netlify';
|
|
25
|
-
|
|
26
|
-
const deployer = new NetlifyDeployer({
|
|
27
|
-
scope: 'your-team-id',
|
|
28
|
-
projectName: 'your-project-name',
|
|
29
|
-
});
|
|
30
|
-
|
|
31
|
-
const mastra = new Mastra({
|
|
32
|
-
deployer,
|
|
33
|
-
// ... other Mastra configuration options
|
|
34
|
-
});
|
|
35
|
-
```
|
|
36
|
-
|
|
37
|
-
## Configuration
|
|
38
|
-
|
|
39
|
-
### Constructor Options
|
|
40
|
-
|
|
41
|
-
- `scope` (required): Your Netlify team ID
|
|
42
|
-
- `projectName`: Name of your Netlify site (will be created if it doesn't exist)
|
|
43
|
-
|
|
44
|
-
## Project Structure
|
|
45
|
-
|
|
46
|
-
The deployer automatically creates the following structure:
|
|
47
|
-
|
|
48
|
-
```
|
|
49
|
-
your-project/
|
|
50
|
-
├── netlify/
|
|
51
|
-
│ └── functions/
|
|
52
|
-
│ └── api/
|
|
53
|
-
└── netlify.toml
|
|
54
|
-
```
|
|
55
|
-
|
|
56
|
-
### netlify.toml Configuration
|
|
57
|
-
|
|
58
|
-
The deployer creates a `netlify.toml` with the following defaults:
|
|
59
|
-
|
|
60
|
-
```toml
|
|
61
|
-
[functions]
|
|
62
|
-
node_bundler = "esbuild"
|
|
63
|
-
directory = "/netlify/functions"
|
|
64
|
-
|
|
65
|
-
[[redirects]]
|
|
66
|
-
force = true
|
|
67
|
-
from = "/*"
|
|
68
|
-
status = 200
|
|
69
|
-
to = "/.netlify/functions/api/:splat"
|
|
70
|
-
```
|
|
71
|
-
|
|
72
|
-
## Environment Variables
|
|
73
|
-
|
|
74
|
-
Environment variables are handled automatically through:
|
|
75
|
-
|
|
76
|
-
- `.env` files in your project
|
|
77
|
-
- Environment variables passed through the Mastra configuration
|
|
78
|
-
- Netlify's environment variable UI
|
|
79
|
-
|
|
80
|
-
## Deployment Process
|
|
81
|
-
|
|
82
|
-
The deployer will:
|
|
83
|
-
|
|
84
|
-
1. Create a new site if it doesn't exist
|
|
85
|
-
2. Configure the site with your environment variables
|
|
86
|
-
3. Deploy your application to Netlify Functions
|