mirror of
https://github.com/webstudio-is/webstudio.git
synced 2026-11-08 13:05:08 +09:00
47 lines
1.1 KiB
TypeScript
47 lines
1.1 KiB
TypeScript
import * as db from "./";
|
|
|
|
/**
|
|
* 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;
|
|
}) => {
|
|
if (projectId === null) {
|
|
throw new Error("Project ID required");
|
|
}
|
|
if (domain === null) {
|
|
throw new Error("Domain required");
|
|
}
|
|
|
|
const project = await db.project.loadById(projectId);
|
|
if (project === null) {
|
|
throw new Error(`Project "${projectId}" not found`);
|
|
}
|
|
|
|
const tree = await db.tree.clone(project.devTreeId);
|
|
await db.props.clone({
|
|
previousTreeId: project.devTreeId,
|
|
nextTreeId: tree.id,
|
|
});
|
|
await db.breakpoints.clone({
|
|
previousTreeId: project.devTreeId,
|
|
nextTreeId: tree.id,
|
|
});
|
|
const prodTreeIdHistory = project.prodTreeIdHistory;
|
|
if (project.prodTreeId) {
|
|
prodTreeIdHistory.push(project.prodTreeId);
|
|
}
|
|
const updatedProject = await db.project.update({
|
|
id: projectId,
|
|
domain,
|
|
prodTreeId: tree.id,
|
|
prodTreeIdHistory,
|
|
});
|
|
return updatedProject;
|
|
};
|