Skip to content

Commit b3babe7

Browse files
deploy working
1 parent aa18558 commit b3babe7

5 files changed

Lines changed: 73 additions & 6 deletions

File tree

package-lock.json

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -435,7 +435,9 @@
435435
"vscode-material-icons": "^0.1.1",
436436
"web-tree-sitter": "^0.22.6",
437437
"workerpool": "^9.2.0",
438-
"zod": "^3.23.8"
438+
"zod": "^3.23.8",
439+
"form-data": "^4.0.0",
440+
"node-fetch": "^2.7.0"
439441
},
440442
"devDependencies": {
441443
"@changesets/cli": "^2.27.10",

src/core/prompts/tools/pearai-deploy-webapp.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,13 @@ Deploy a web application to Netlify. This tool can be used for both new deployme
1010
<parameter>
1111
<name>zip_file_path</name>
1212
<type>string</type>
13-
<description>Path to the zip file containing the web application files</description>
13+
<description>Absoulute path to the zip file containing the web application files</description>
1414
<required>true</required>
1515
</parameter>
1616
<parameter>
1717
<name>env_file_path</name>
1818
<type>string</type>
19-
<description>Path to the environment file containing deployment configuration</description>
19+
<description>Absoulute path to the environment file containing deployment configuration</description>
2020
<required>true</required>
2121
</parameter>
2222
<parameter>

src/core/tools/pearaiDeployWebappTool.ts

Lines changed: 60 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,11 @@ import { formatResponse } from "../prompts/responses"
66
import { getReadablePath } from "../../utils/path"
77
import { isPathOutsideWorkspace } from "../../utils/pathUtils"
88
import { fileExistsAtPath } from "../../utils/fs"
9+
import FormData from "form-data"
10+
import fetch from "node-fetch"
11+
import * as vscode from "vscode"
12+
13+
const SERVER_URL = "https://server.trypear.ai/pearai-server-api2"
914

1015
export async function pearaiDeployWebappTool(
1116
cline: Cline,
@@ -78,11 +83,63 @@ export async function pearaiDeployWebappTool(
7883
return
7984
}
8085

81-
// TODO: Implement actual deployment logic here
82-
// For now, just simulate a successful deployment
86+
// Read files
87+
const zipContent = await fs.readFile(zip_file_path)
88+
const envContent = await fs.readFile(env_file_path)
89+
90+
// Prepare form data
91+
const form = new FormData()
92+
form.append("zip_file", zipContent, {
93+
filename: "dist.zip",
94+
contentType: "application/zip",
95+
})
96+
form.append("env_file", envContent, {
97+
filename: ".env",
98+
contentType: "text/plain",
99+
})
100+
if (site_id) {
101+
form.append("site_id", site_id)
102+
}
103+
if (isStatic) {
104+
form.append("static", "true")
105+
}
106+
107+
// Get auth token from extension context
108+
const authToken = await vscode.commands.executeCommand("pearai-roo-cline.getPearAIApiKey")
109+
if (!authToken) {
110+
vscode.commands.executeCommand("pearai-roo-cline.PearAIKeysNotFound", undefined)
111+
vscode.window.showErrorMessage("PearAI API key not found.", "Login to PearAI").then(async (selection) => {
112+
if (selection === "Login to PearAI") {
113+
const extensionUrl = `${vscode.env.uriScheme}://pearai.pearai/auth`
114+
const callbackUri = await vscode.env.asExternalUri(vscode.Uri.parse(extensionUrl))
115+
vscode.env.openExternal(
116+
await vscode.env.asExternalUri(
117+
vscode.Uri.parse(`https://trypear.ai/signin?callback=${callbackUri.toString()}`),
118+
),
119+
)
120+
}
121+
})
122+
throw new Error("PearAI API key not found. Please login to PearAI.")
123+
}
124+
125+
// Make POST request to deployment endpoint
126+
const endpoint = site_id ? `${SERVER_URL}/redeploy-netlify` : `${SERVER_URL}/deploy-netlify`
127+
const response = await fetch(endpoint, {
128+
method: "POST",
129+
headers: {
130+
Authorization: `Bearer ${authToken}`,
131+
},
132+
body: form,
133+
})
134+
135+
if (!response.ok) {
136+
throw new Error(`Deployment failed with status ${response.status}: ${await response.text()}`)
137+
}
138+
139+
const result = await response.text()
83140
pushToolResult(
84141
formatResponse.toolResult(
85-
`Successfully deployed webapp${site_id ? ` to site ${site_id}` : " (new site)"}${isStatic ? " (static deployment)" : ""}`
142+
`Successfully deployed webapp${site_id ? ` to site ${site_id}` : " (new site)"}${isStatic ? " (static deployment)" : ""}\n\n${result}`
86143
)
87144
)
88145

src/extension.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,12 @@ export async function activate(context: vscode.ExtensionContext) {
182182
}),
183183
)
184184

185+
context.subscriptions.push(
186+
vscode.commands.registerCommand("pearai-roo-cline.getPearAIApiKey", async () => {
187+
return await context.secrets.get("pearaiApiKey")
188+
}),
189+
)
190+
185191
/*
186192
We use the text document content provider API to show the left side for diff view by creating a virtual document for the original content. This makes it readonly so users know to edit the right side if they want to keep their changes.
187193

0 commit comments

Comments
 (0)