@mastra/deployer-netlify 0.0.1-alpha.23 → 0.0.1-alpha.27
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 +29 -0
- package/dist/index.d.ts +4 -2
- package/dist/index.js +116 -5
- package/package.json +3 -3
- package/dist/deployer-netlify.cjs.development.js +0 -551
- package/dist/deployer-netlify.cjs.development.js.map +0 -1
- package/dist/deployer-netlify.cjs.production.min.js +0 -2
- package/dist/deployer-netlify.cjs.production.min.js.map +0 -1
- package/dist/deployer-netlify.esm.js +0 -547
- package/dist/deployer-netlify.esm.js.map +0 -1
- package/dist/helpers.d.ts +0 -6
- package/dist/helpers.d.ts.map +0 -1
- package/dist/index.d.ts.map +0 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,34 @@
|
|
|
1
1
|
# @mastra/deployer-netlify
|
|
2
2
|
|
|
3
|
+
## 0.0.1-alpha.27
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Updated dependencies [327ece7]
|
|
8
|
+
- @mastra/core@0.1.27-alpha.80
|
|
9
|
+
- @mastra/deployer@0.0.1-alpha.25
|
|
10
|
+
|
|
11
|
+
## 0.0.1-alpha.26
|
|
12
|
+
|
|
13
|
+
### Patch Changes
|
|
14
|
+
|
|
15
|
+
- Updated dependencies [21fe536]
|
|
16
|
+
- @mastra/core@0.1.27-alpha.79
|
|
17
|
+
- @mastra/deployer@0.0.1-alpha.24
|
|
18
|
+
|
|
19
|
+
## 0.0.1-alpha.25
|
|
20
|
+
|
|
21
|
+
### Patch Changes
|
|
22
|
+
|
|
23
|
+
- Updated dependencies [88f18d7]
|
|
24
|
+
- @mastra/deployer@0.0.1-alpha.23
|
|
25
|
+
|
|
26
|
+
## 0.0.1-alpha.24
|
|
27
|
+
|
|
28
|
+
### Patch Changes
|
|
29
|
+
|
|
30
|
+
- 44c7c26: Rebuild
|
|
31
|
+
|
|
3
32
|
## 0.0.1-alpha.23
|
|
4
33
|
|
|
5
34
|
### Patch Changes
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { MastraDeployer } from '@mastra/core';
|
|
2
|
-
|
|
2
|
+
|
|
3
|
+
declare class NetlifyDeployer extends MastraDeployer {
|
|
3
4
|
constructor({ scope, env, projectName }: {
|
|
4
5
|
projectName: string;
|
|
5
6
|
env?: Record<string, any>;
|
|
@@ -16,4 +17,5 @@ export declare class NetlifyDeployer extends MastraDeployer {
|
|
|
16
17
|
dir: string;
|
|
17
18
|
}): void;
|
|
18
19
|
}
|
|
19
|
-
|
|
20
|
+
|
|
21
|
+
export { NetlifyDeployer };
|
package/dist/index.js
CHANGED
|
@@ -1,8 +1,119 @@
|
|
|
1
|
+
import { MastraDeployer } from '@mastra/core';
|
|
2
|
+
import { execa } from 'execa';
|
|
3
|
+
import { existsSync, mkdirSync, writeFileSync, renameSync } from 'fs';
|
|
4
|
+
import { join } from 'path';
|
|
1
5
|
|
|
2
|
-
|
|
6
|
+
// src/index.ts
|
|
3
7
|
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
+
// src/helpers.ts
|
|
9
|
+
async function createNetlifySite({ token, name, scope }) {
|
|
10
|
+
console.log(token, name, scope);
|
|
11
|
+
const response = await fetch("https://api.netlify.com/api/v1/sites", {
|
|
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
|
+
};
|
|
8
36
|
}
|
|
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,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mastra/deployer-netlify",
|
|
3
|
-
"version": "0.0.1-alpha.
|
|
3
|
+
"version": "0.0.1-alpha.27",
|
|
4
4
|
"description": "",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -21,8 +21,8 @@
|
|
|
21
21
|
"execa": "^9.3.1",
|
|
22
22
|
"netlify-cli": "^18.0.1",
|
|
23
23
|
"zod": "^3.24.1",
|
|
24
|
-
"@mastra/
|
|
25
|
-
"@mastra/
|
|
24
|
+
"@mastra/core": "0.1.27-alpha.80",
|
|
25
|
+
"@mastra/deployer": "0.0.1-alpha.25"
|
|
26
26
|
},
|
|
27
27
|
"devDependencies": {
|
|
28
28
|
"@babel/preset-env": "^7.26.0",
|