Graduate file editing from experimental (#599)
This commit is contained in:
@@ -7,6 +7,7 @@ import type {
|
||||
CreateAppParams,
|
||||
RenameBranchParams,
|
||||
CopyAppParams,
|
||||
EditAppFileReturnType,
|
||||
} from "../ipc_types";
|
||||
import fs from "node:fs";
|
||||
import path from "node:path";
|
||||
@@ -32,7 +33,10 @@ import fixPath from "fix-path";
|
||||
import killPort from "kill-port";
|
||||
import util from "util";
|
||||
import log from "electron-log";
|
||||
import { getSupabaseProjectName } from "../../supabase_admin/supabase_management_client";
|
||||
import {
|
||||
deploySupabaseFunctions,
|
||||
getSupabaseProjectName,
|
||||
} from "../../supabase_admin/supabase_management_client";
|
||||
import { createLoggedHandler } from "./safe_handle";
|
||||
import { getLanguageModelProviders } from "../shared/language_model_helpers";
|
||||
import { startProxy } from "../utils/start_proxy_server";
|
||||
@@ -41,6 +45,7 @@ import { createFromTemplate } from "./createFromTemplate";
|
||||
import { gitCommit } from "../utils/git_utils";
|
||||
import { safeSend } from "../utils/safe_sender";
|
||||
import { normalizePath } from "../../../shared/normalizePath";
|
||||
import { isServerFunction } from "@/supabase_admin/supabase_utils";
|
||||
|
||||
async function copyDir(
|
||||
source: string,
|
||||
@@ -604,7 +609,7 @@ export function registerAppHandlers() {
|
||||
filePath,
|
||||
content,
|
||||
}: { appId: number; filePath: string; content: string },
|
||||
): Promise<void> => {
|
||||
): Promise<EditAppFileReturnType> => {
|
||||
const app = await db.query.apps.findFirst({
|
||||
where: eq(apps.id, appId),
|
||||
});
|
||||
@@ -641,12 +646,26 @@ export function registerAppHandlers() {
|
||||
message: `Updated ${filePath}`,
|
||||
});
|
||||
}
|
||||
|
||||
return;
|
||||
} catch (error: any) {
|
||||
logger.error(`Error writing file ${filePath} for app ${appId}:`, error);
|
||||
throw new Error(`Failed to write file: ${error.message}`);
|
||||
}
|
||||
|
||||
if (isServerFunction(filePath) && app.supabaseProjectId) {
|
||||
try {
|
||||
await deploySupabaseFunctions({
|
||||
supabaseProjectId: app.supabaseProjectId,
|
||||
functionName: path.basename(path.dirname(filePath)),
|
||||
content: content,
|
||||
});
|
||||
} catch (error) {
|
||||
logger.error(`Error deploying Supabase function ${filePath}:`, error);
|
||||
return {
|
||||
warning: `File saved, but failed to deploy Supabase function: ${filePath}: ${error}`,
|
||||
};
|
||||
}
|
||||
}
|
||||
return {};
|
||||
},
|
||||
);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user