Files
webstudio/apps/builder/app/shared/db/misc.server.ts
T
Bogdan Chadkin e1fa2075a5 Enforce server constraints for packages (#1507)
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.
2023-04-22 09:14:14 +07:00

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;
};