@mastra/deployer-netlify 0.0.1-alpha.7 → 0.1.0-alpha.34
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 +234 -0
- package/README.md +86 -0
- package/dist/index.d.ts +15 -13
- package/dist/index.js +145 -5
- package/package.json +10 -18
- package/src/index.ts +73 -39
- package/tsconfig.json +1 -6
- package/vitest.config.ts +1 -1
- 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/src/index.ts
CHANGED
|
@@ -1,13 +1,23 @@
|
|
|
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 { execa } from 'execa';
|
|
3
|
-
import { existsSync, mkdirSync,
|
|
5
|
+
import { existsSync, mkdirSync, writeFileSync } from 'fs';
|
|
4
6
|
import { join } from 'path';
|
|
5
7
|
|
|
6
8
|
import { getOrCreateSite } from './helpers.js';
|
|
7
9
|
|
|
8
|
-
export class NetlifyDeployer extends
|
|
9
|
-
|
|
10
|
-
|
|
10
|
+
export class NetlifyDeployer extends Deployer {
|
|
11
|
+
protected scope: string;
|
|
12
|
+
protected projectName: string;
|
|
13
|
+
protected token: string;
|
|
14
|
+
|
|
15
|
+
constructor({ scope, projectName, token }: { scope: string; projectName: string; token: string }) {
|
|
16
|
+
super({ name: 'NETLIFY' });
|
|
17
|
+
|
|
18
|
+
this.scope = scope;
|
|
19
|
+
this.projectName = projectName;
|
|
20
|
+
this.token = token;
|
|
11
21
|
}
|
|
12
22
|
|
|
13
23
|
writeFiles({ dir }: { dir: string }): void {
|
|
@@ -18,30 +28,38 @@ export class NetlifyDeployer extends MastraDeployer {
|
|
|
18
28
|
// TODO ENV KEYS
|
|
19
29
|
writeFileSync(
|
|
20
30
|
join(dir, 'netlify.toml'),
|
|
21
|
-
`
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
directory = "/netlify/functions"
|
|
25
|
-
|
|
26
|
-
[[redirects]]
|
|
27
|
-
force = true
|
|
28
|
-
from = "/*"
|
|
29
|
-
status = 200
|
|
30
|
-
to = "/.netlify/functions/api/:splat"
|
|
31
|
-
`,
|
|
32
|
-
);
|
|
31
|
+
`[functions]
|
|
32
|
+
node_bundler = "esbuild"
|
|
33
|
+
directory = "netlify/functions"
|
|
33
34
|
|
|
34
|
-
|
|
35
|
+
[[redirects]]
|
|
36
|
+
force = true
|
|
37
|
+
from = "/*"
|
|
38
|
+
status = 200
|
|
39
|
+
to = "/.netlify/functions/api/:splat"
|
|
40
|
+
`,
|
|
41
|
+
);
|
|
35
42
|
}
|
|
36
43
|
|
|
37
|
-
async deploy(
|
|
38
|
-
const site = await getOrCreateSite({ token, name: this.projectName || `mastra`, scope: this.scope });
|
|
44
|
+
async deploy(outputDirectory: string): Promise<void> {
|
|
45
|
+
const site = await getOrCreateSite({ token: this.token, name: this.projectName || `mastra`, scope: this.scope });
|
|
39
46
|
|
|
40
47
|
const p2 = execa(
|
|
41
|
-
'
|
|
42
|
-
[
|
|
48
|
+
'npx',
|
|
49
|
+
[
|
|
50
|
+
'netlify-cli',
|
|
51
|
+
'deploy',
|
|
52
|
+
'--site',
|
|
53
|
+
site.id,
|
|
54
|
+
'--auth',
|
|
55
|
+
this.token,
|
|
56
|
+
'--dir',
|
|
57
|
+
'.',
|
|
58
|
+
'--functions',
|
|
59
|
+
'./netlify/functions',
|
|
60
|
+
],
|
|
43
61
|
{
|
|
44
|
-
cwd:
|
|
62
|
+
cwd: outputDirectory,
|
|
45
63
|
},
|
|
46
64
|
);
|
|
47
65
|
|
|
@@ -49,23 +67,39 @@ export class NetlifyDeployer extends MastraDeployer {
|
|
|
49
67
|
await p2;
|
|
50
68
|
}
|
|
51
69
|
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
70
|
+
async prepare(outputDirectory: string): Promise<void> {
|
|
71
|
+
await super.prepare(outputDirectory);
|
|
72
|
+
|
|
73
|
+
// Prepare the deployment directory
|
|
74
|
+
if (!existsSync(join(outputDirectory, 'netlify/functions/api'))) {
|
|
75
|
+
mkdirSync(join(outputDirectory, 'netlify/functions/api'), { recursive: true });
|
|
76
|
+
}
|
|
77
|
+
this.writeFiles({ dir: outputDirectory });
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
async bundle(mastraDir: string, outputDirectory: string): Promise<void> {
|
|
81
|
+
const bundler = await getBundler({
|
|
82
|
+
input: '#entry',
|
|
83
|
+
external: [/^@opentelemetry\//],
|
|
84
|
+
plugins: [virtual({ '#entry': this.getEntry() })],
|
|
55
85
|
});
|
|
56
86
|
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
87
|
+
await bundler.write({
|
|
88
|
+
inlineDynamicImports: true,
|
|
89
|
+
file: join(outputDirectory, 'netlify', 'functions', 'api', 'index.mjs'),
|
|
90
|
+
format: 'es',
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
private getEntry(): string {
|
|
95
|
+
return `
|
|
96
|
+
import { handle } from 'hono/netlify'
|
|
97
|
+
import { mastra } from '#mastra';
|
|
98
|
+
import { createHonoServer } from '#server';
|
|
99
|
+
|
|
100
|
+
const app = await createHonoServer(mastra);
|
|
101
|
+
|
|
102
|
+
export default handle(app)
|
|
103
|
+
`;
|
|
70
104
|
}
|
|
71
105
|
}
|
package/tsconfig.json
CHANGED
|
@@ -1,10 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
-
"extends": "../../tsconfig.json",
|
|
3
|
-
"compilerOptions": {
|
|
4
|
-
"moduleResolution": "bundler",
|
|
5
|
-
"outDir": "./dist",
|
|
6
|
-
"rootDir": "./src"
|
|
7
|
-
},
|
|
2
|
+
"extends": "../../tsconfig.node.json",
|
|
8
3
|
"include": ["src/**/*"],
|
|
9
4
|
"exclude": ["node_modules", "**/*.test.ts"]
|
|
10
5
|
}
|