1
1
/* eslint no-console: ["error", { allow: ["time", "timeEnd"] }] */
2
2
3
- import { nanoid } from "nanoid" ;
4
3
import type { Database } from "@webstudio-is/postrest/index.server" ;
5
4
import {
6
5
AuthorizationError ,
7
6
authorizeProject ,
8
7
type AppContext ,
9
8
} from "@webstudio-is/trpc-interface/index.server" ;
10
9
import { db as authDb } from "@webstudio-is/authorization-token/index.server" ;
11
- import {
12
- type Deployment ,
13
- type Resource ,
14
- type StyleSource ,
15
- type Prop ,
16
- type DataSource ,
17
- type Instance ,
18
- type Breakpoint ,
19
- type StyleSourceSelection ,
20
- type StyleDecl ,
10
+ import type {
11
+ Deployment ,
12
+ Resource ,
13
+ StyleSource ,
14
+ Prop ,
15
+ DataSource ,
16
+ Instance ,
17
+ Breakpoint ,
18
+ StyleSourceSelection ,
19
+ StyleDecl ,
21
20
Pages ,
22
- initialBreakpoints ,
23
- elementComponent ,
24
21
} from "@webstudio-is/sdk" ;
25
22
import type { Build , CompactBuild } from "../types" ;
26
23
import { parseDeployment } from "./deployment" ;
27
- import { serializePages } from "./pages" ;
28
- import { createDefaultPages } from "../shared/pages-utils" ;
29
24
import type { MarketplaceProduct } from "../shared//marketplace" ;
30
25
import { breakCyclesMutable } from "../shared/graph-utils" ;
26
+ import { createPages } from "../template" ;
27
+ import { serializeStyles } from "./styles" ;
28
+ import { serializeStyleSourceSelections } from "./style-source-selections" ;
31
29
32
30
const parseCompactData = < Item > ( serialized : string ) =>
33
31
JSON . parse ( serialized ) as Item [ ] ;
@@ -222,35 +220,6 @@ export const loadApprovedProdBuildByProjectId = async (
222
220
return parseCompactBuild ( build . data [ 0 ] ) ;
223
221
} ;
224
222
225
- const createNewPageInstances = ( ) : Build [ "instances" ] => {
226
- const instanceId = nanoid ( ) ;
227
- return [
228
- [
229
- instanceId ,
230
- {
231
- type : "instance" ,
232
- id : instanceId ,
233
- component : elementComponent ,
234
- tag : "body" ,
235
- children : [ ] ,
236
- } ,
237
- ] ,
238
- ] ;
239
- } ;
240
-
241
- const createInitialBreakpoints = ( ) : [ Breakpoint [ "id" ] , Breakpoint ] [ ] => {
242
- return initialBreakpoints . map ( ( breakpoint ) => {
243
- const id = nanoid ( ) ;
244
- return [
245
- id ,
246
- {
247
- ...breakpoint ,
248
- id,
249
- } ,
250
- ] ;
251
- } ) ;
252
- } ;
253
-
254
223
/*
255
224
* We create "dev" build in two cases:
256
225
* 1. when we create a new project
@@ -263,16 +232,21 @@ export const createBuild = async (
263
232
} ,
264
233
context : AppContext
265
234
) : Promise < void > => {
266
- const newInstances = createNewPageInstances ( ) ;
267
- const [ rootInstanceId ] = newInstances [ 0 ] ;
268
- const defaultPages = createDefaultPages ( { rootInstanceId } ) ;
269
-
235
+ const data = createPages ( ) ;
270
236
const newBuild = await context . postgrest . client . from ( "Build" ) . insert ( {
271
237
id : crypto . randomUUID ( ) ,
272
238
projectId : props . projectId ,
273
- pages : serializePages ( defaultPages ) ,
274
- breakpoints : serializeData < Breakpoint > ( new Map ( createInitialBreakpoints ( ) ) ) ,
275
- instances : serializeData < Instance > ( new Map ( newInstances ) ) ,
239
+ pages : serializeConfig < Pages > ( data . pages ) ,
240
+ breakpoints : serializeData < Breakpoint > ( data . breakpoints ) ,
241
+ styles : serializeStyles ( data . styles ) ,
242
+ styleSources : serializeData < StyleSource > ( data . styleSources ) ,
243
+ styleSourceSelections : serializeStyleSourceSelections (
244
+ data . styleSourceSelections
245
+ ) ,
246
+ props : serializeData < Prop > ( data . props ) ,
247
+ dataSources : serializeData < DataSource > ( data . dataSources ) ,
248
+ resources : serializeData < Resource > ( data . resources ) ,
249
+ instances : serializeData < Instance > ( data . instances ) ,
276
250
} ) ;
277
251
if ( newBuild . error ) {
278
252
throw newBuild . error ;
0 commit comments