@mastra/deployer-netlify 0.0.0-commonjs-20250227130920
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 +23 -0
- package/CHANGELOG.md +962 -0
- package/LICENSE +44 -0
- package/README.md +86 -0
- package/dist/_tsup-dts-rollup.d.cts +38 -0
- package/dist/_tsup-dts-rollup.d.ts +38 -0
- package/dist/index.cjs +140 -0
- package/dist/index.d.cts +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +138 -0
- package/eslint.config.js +6 -0
- package/package.json +48 -0
- package/src/helpers.ts +76 -0
- package/src/index.ts +96 -0
- package/tsconfig.json +5 -0
- package/vitest.config.ts +8 -0
package/src/index.ts
ADDED
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import { existsSync, mkdirSync, writeFileSync } from 'fs';
|
|
2
|
+
import { join } from 'path';
|
|
3
|
+
|
|
4
|
+
import { Deployer } from '@mastra/deployer';
|
|
5
|
+
import { execa } from 'execa';
|
|
6
|
+
|
|
7
|
+
import { getOrCreateSite } from './helpers.js';
|
|
8
|
+
|
|
9
|
+
export class NetlifyDeployer extends Deployer {
|
|
10
|
+
protected scope: string;
|
|
11
|
+
protected projectName: string;
|
|
12
|
+
protected token: string;
|
|
13
|
+
|
|
14
|
+
constructor({ scope, projectName, token }: { scope: string; projectName: string; token: string }) {
|
|
15
|
+
super({ name: 'NETLIFY' });
|
|
16
|
+
|
|
17
|
+
this.scope = scope;
|
|
18
|
+
this.projectName = projectName;
|
|
19
|
+
this.token = token;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
writeFiles({ dir }: { dir: string }): void {
|
|
23
|
+
if (!existsSync(join(dir, 'netlify/functions/api'))) {
|
|
24
|
+
mkdirSync(join(dir, 'netlify/functions/api'), { recursive: true });
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
// TODO ENV KEYS
|
|
28
|
+
writeFileSync(
|
|
29
|
+
join(dir, 'netlify.toml'),
|
|
30
|
+
`[functions]
|
|
31
|
+
node_bundler = "esbuild"
|
|
32
|
+
directory = "netlify/functions"
|
|
33
|
+
|
|
34
|
+
[[redirects]]
|
|
35
|
+
force = true
|
|
36
|
+
from = "/*"
|
|
37
|
+
status = 200
|
|
38
|
+
to = "/.netlify/functions/api/:splat"
|
|
39
|
+
`,
|
|
40
|
+
);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
async deploy(outputDirectory: string): Promise<void> {
|
|
44
|
+
const site = await getOrCreateSite({ token: this.token, name: this.projectName || `mastra`, scope: this.scope });
|
|
45
|
+
|
|
46
|
+
// @ts-expect-error - seems to be fine
|
|
47
|
+
const p2 = execa(
|
|
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
|
+
],
|
|
61
|
+
{
|
|
62
|
+
cwd: join(outputDirectory, this.outputDir),
|
|
63
|
+
},
|
|
64
|
+
);
|
|
65
|
+
|
|
66
|
+
p2.stdout.pipe(process.stdout);
|
|
67
|
+
await p2;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
async prepare(outputDirectory: string): Promise<void> {
|
|
71
|
+
await super.prepare(outputDirectory);
|
|
72
|
+
|
|
73
|
+
this.writeFiles({ dir: join(outputDirectory, this.outputDir) });
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
async bundle(entryFile: string, outputDirectory: string): Promise<void> {
|
|
77
|
+
return this._bundle(
|
|
78
|
+
this.getEntry(),
|
|
79
|
+
entryFile,
|
|
80
|
+
outputDirectory,
|
|
81
|
+
join(outputDirectory, this.outputDir, 'netlify', 'functions', 'api'),
|
|
82
|
+
);
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
private getEntry(): string {
|
|
86
|
+
return `
|
|
87
|
+
import { handle } from 'hono/netlify'
|
|
88
|
+
import { mastra } from '#mastra';
|
|
89
|
+
import { createHonoServer } from '#server';
|
|
90
|
+
|
|
91
|
+
const app = await createHonoServer(mastra);
|
|
92
|
+
|
|
93
|
+
export default handle(app)
|
|
94
|
+
`;
|
|
95
|
+
}
|
|
96
|
+
}
|
package/tsconfig.json
ADDED