mirror of
https://github.com/webstudio-is/webstudio.git
synced 2026-11-09 14:03:33 +09:00
Ref https://remix.run/docs/en/1.15.0/guides/constraints#server-code-pruning Remix use NAME.server.ts extension to enforce omitting module from client bundles. Though we heavily used `/server` in packages which had no affect and blocked us in using a few node apis which were not polifilled with empty modules while bundling for client. Here I replaced `/server` with `/index.server` and removed all legacy server entry points which are not longer necessary with new typescript resolution.
54 lines
1.2 KiB
TypeScript
54 lines
1.2 KiB
TypeScript
import { db } from "@webstudio-is/project/index.server";
|
|
import { prisma } from "@webstudio-is/prisma-client";
|
|
import type { AppContext } from "@webstudio-is/trpc-interface/index.server";
|
|
import {
|
|
createBuild,
|
|
loadBuildByProjectId,
|
|
} from "@webstudio-is/project-build/index.server";
|
|
|
|
/**
|
|
* Conceptually publishing is cloning all data that affects user site
|
|
* and referencing it under a new tree id.
|
|
*/
|
|
export const publish = async (
|
|
{
|
|
projectId,
|
|
domain,
|
|
}: {
|
|
projectId: string | null;
|
|
domain: string | null;
|
|
},
|
|
context: AppContext
|
|
) => {
|
|
if (projectId === null) {
|
|
throw new Error("Project ID required");
|
|
}
|
|
if (domain === null) {
|
|
throw new Error("Domain required");
|
|
}
|
|
|
|
const project = await db.project.loadById(projectId, context);
|
|
if (project === null) {
|
|
throw new Error(`Project "${projectId}" not found`);
|
|
}
|
|
|
|
const devBuild = await loadBuildByProjectId(projectId, "dev");
|
|
|
|
await prisma.$transaction(async (client) => {
|
|
await createBuild(
|
|
{ projectId: project.id, env: "prod", sourceBuild: devBuild },
|
|
context,
|
|
client
|
|
);
|
|
});
|
|
|
|
const updatedProject = await db.project.updateDomain(
|
|
{
|
|
id: projectId,
|
|
domain,
|
|
},
|
|
context
|
|
);
|
|
return updatedProject;
|
|
};
|