@fugood/bricks-project 2.21.0-beta.16-1 → 2.21.0-beta.17-1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/compile/index.ts CHANGED
@@ -28,16 +28,23 @@ import type {
28
28
  Subspace,
29
29
  } from '../types'
30
30
 
31
- const compileProperty = (property, result = {}) => {
31
+ const compileProperty = (property, errorReference: string, result = {}) => {
32
32
  if (Array.isArray(property)) {
33
- return property.map((p) => compileProperty(p, result))
33
+ return property.map((p) => compileProperty(p, errorReference))
34
34
  }
35
- if (property?.__typename === 'DataLink' && property.data?.())
36
- return `PROPERTY_BANK#${property.data().id}`
37
- if (typeof property === 'function') return property()?.id // defined type instance getter
38
- if (typeof property === 'object') {
35
+ if (property?.__typename === 'DataLink') {
36
+ const data = property.data?.()
37
+ if (!data?.id) throw new Error(`Invalid DataLink reference ${errorReference}`)
38
+ return `PROPERTY_BANK#${data.id}`
39
+ }
40
+ if (typeof property === 'function') {
41
+ const instance = property()
42
+ if (!instance?.id) throw new Error(`Invalid ID reference ${errorReference}`)
43
+ return instance?.id // defined type instance getter
44
+ }
45
+ if (property && typeof property === 'object') {
39
46
  return Object.entries(property).reduce((acc, [key, value]) => {
40
- acc[key] = compileProperty(value, {})
47
+ acc[key] = compileProperty(value, errorReference)
41
48
  return acc
42
49
  }, result)
43
50
  }
@@ -48,8 +55,13 @@ const convertOutletKey = (templateKey: string, key: string) => {
48
55
  return `${templateKey}_${_.snakeCase(key).toUpperCase()}`
49
56
  }
50
57
 
51
- const compileOutlets = (templateKey: string, outlets: { [key: string]: () => Data }) => {
58
+ const compileOutlets = (
59
+ templateKey: string,
60
+ outlets: { [key: string]: () => Data },
61
+ errorReference: string,
62
+ ) => {
52
63
  return Object.entries(outlets).reduce((acc, [key, data]) => {
64
+ if (!data()?.id) throw new Error(`Invalid data reference ${errorReference}`)
53
65
  acc[convertOutletKey(templateKey, key)] = data().id
54
66
  return acc
55
67
  }, {})
@@ -61,8 +73,13 @@ const convertEventKey = (templateKey: string, key: string) => {
61
73
 
62
74
  const basicAnimationEvents = ['show', 'standby', 'breatheStart']
63
75
 
64
- const compileAnimations = (templateKey: string, animations: { [key: string]: Animation }) => {
76
+ const compileAnimations = (
77
+ templateKey: string,
78
+ animations: { [key: string]: Animation },
79
+ errorReference: string,
80
+ ) => {
65
81
  return Object.entries(animations).reduce((acc, [key, animation]) => {
82
+ if (!animation?.id) throw new Error(`Invalid animation reference ${errorReference}`)
66
83
  acc[convertEventKey(basicAnimationEvents.includes(key) ? 'BRICK' : templateKey, key)] =
67
84
  `ANIMATION#${animation.id}`
68
85
  return acc
@@ -75,9 +92,9 @@ const compileActionParam = (templateKey: string, actionName: string, paramName:
75
92
  const compileEvents = (
76
93
  templateKey: string,
77
94
  eventMap: { [key: string]: Array<EventAction> },
78
- options = { camelCase: false },
95
+ options = { camelCase: false, errorReference: '' },
79
96
  ) => {
80
- const { camelCase } = options
97
+ const { camelCase, errorReference } = options
81
98
  return Object.entries(eventMap).reduce((acc, [key, events]) => {
82
99
  acc[convertEventKey(templateKey, key)] = events.map((event) => {
83
100
  const { handler, action } = event
@@ -93,7 +110,7 @@ const compileEvents = (
93
110
  handlerKey = instance?.id
94
111
  handlerTemplateKey = instance?.templateKey
95
112
  }
96
- if (!handlerKey) throw new Error(`Invalid handler: ${handler}`)
113
+ if (!handlerKey) throw new Error(`Invalid handler: ${handler} ${errorReference}`)
97
114
 
98
115
  const parameterList: Array<object> = []
99
116
  if (Object.hasOwn(action, 'params')) {
@@ -104,7 +121,7 @@ const compileEvents = (
104
121
  ? compileActionParam(handlerTemplateKey, action.__actionName, input)
105
122
  : input,
106
123
  [camelCase ? 'resultFromSender' : 'result_from_sender']:
107
- mapping || compileProperty(value),
124
+ mapping || compileProperty(value, errorReference),
108
125
  }
109
126
  if (mapping) param[camelCase ? 'resultDataMapping' : 'result_data_mapping'] = true
110
127
  parameterList.push(param)
@@ -116,7 +133,7 @@ const compileEvents = (
116
133
  const param = {
117
134
  [camelCase ? 'inputToReceiver' : 'input_to_receiver']: input().id,
118
135
  [camelCase ? 'resultFromSender' : 'result_from_sender']:
119
- mapping || compileProperty(value),
136
+ mapping || compileProperty(value, errorReference),
120
137
  }
121
138
  if (mapping) param[camelCase ? 'resultDataMapping' : 'result_data_mapping'] = true
122
139
  parameterList.push(param)
@@ -133,17 +150,22 @@ const compileEvents = (
133
150
  }, {})
134
151
  }
135
152
 
136
- const compileSwitchConds = (templateKey, conds) =>
137
- (conds || []).map((item: any) => {
153
+ const compileSwitchConds = (templateKey, conds, errorReference) =>
154
+ (conds || []).map((item: any, index) => {
138
155
  const result: any = { method: item.method }
156
+ if (!item.cond) return result
139
157
  if (item.cond.__typename === 'SwitchCondData') {
140
158
  const cond = item.cond as SwitchCondData
141
159
  result.type = 'property_bank'
160
+ if (!cond.data().id)
161
+ throw new Error(`Invalid data reference in conds index: ${index} ${errorReference}`)
142
162
  result.key = cond.data().id
143
163
  result.value = cond.value
144
164
  } else if (item.cond.__typename === 'SwitchCondPropertyBankByItemKey') {
145
165
  const cond = item.cond as SwitchCondPropertyBankByItemKey
146
166
  result.type = 'property_bank_by_item_key'
167
+ if (!cond.data().id)
168
+ throw new Error(`Invalid data reference in conds index: ${index} ${errorReference}`)
147
169
  result.key = cond.data().id
148
170
  result.value = cond.value
149
171
  } else if (item.cond.__typename === 'SwitchCondInnerStateOutlet') {
@@ -155,6 +177,8 @@ const compileSwitchConds = (templateKey, conds) =>
155
177
  const cond = item.cond as SwitchCondInnerStateCurrentCanvas
156
178
  result.type = 'inner_state'
157
179
  result.key = 'current_canvas'
180
+ if (!cond.value().id)
181
+ throw new Error(`Invalid canvas reference in conds index: ${index} ${errorReference}`)
158
182
  result.value = cond.value().id
159
183
  }
160
184
  return result
@@ -312,7 +336,10 @@ export const compile = async (app: Application) => {
312
336
  animationRunType: animationDef.runType,
313
337
  property: animationDef.property,
314
338
  type: animationTypeMap[animationDef.config.__type],
315
- config: compileProperty(_.omit(animationDef.config, '__type')),
339
+ config: compileProperty(
340
+ _.omit(animationDef.config, '__type'),
341
+ `(animation: ${animation.id}, subspace ${subspace.id})`,
342
+ ),
316
343
  }
317
344
  } else if (animation.__typename === 'AnimationCompose') {
318
345
  const animationDef = animation as AnimationComposeDef
@@ -321,27 +348,49 @@ export const compile = async (app: Application) => {
321
348
  description: animationDef.description,
322
349
  animationRunType: animationDef.runType,
323
350
  compose_type: animationDef.composeType,
324
- item_list: animationDef.items.map((item) => ({ animation_id: item().id })),
351
+ item_list: animationDef.items.map((item, index) => {
352
+ const animation = item()
353
+ if (!animation?.id)
354
+ throw new Error(
355
+ `Invalid animation index: ${index} (animation: ${animation.id}, subspace ${subspace.id})`,
356
+ )
357
+ return { animation_id: animation.id }
358
+ }),
325
359
  }
326
360
  }
327
361
  return map
328
362
  }, {}),
329
363
  brick_map: subspace.bricks.reduce((map, brick) => {
330
- const property = compileProperty(brick.property || {})
364
+ const property = compileProperty(
365
+ brick.property || {},
366
+ `(brick: ${brick.id}, subspace ${subspace.id})`,
367
+ )
331
368
  if (brick.templateKey === 'BRICK_ITEMS') {
332
369
  const brickItems = brick as BrickItems
333
- const buildList = (itemBrick) => ({
370
+ const buildList = (itemBrick, index, key) => ({
334
371
  title: itemBrick.title,
335
372
  brickId: itemBrick.brickId,
336
373
  brickIdPrefix: itemBrick.brickIdPrefix,
337
374
  templateKey: itemBrick.templateKey,
338
375
  frame: itemBrick.frame,
339
- property: compileProperty(itemBrick.property),
376
+ property: compileProperty(
377
+ itemBrick.property,
378
+ `(brick: ${brick.id}, ${key}: ${index}, subspace ${subspace.id})`,
379
+ ),
340
380
  propertyMapping: itemBrick.propertyMapping,
341
- animation: compileAnimations(itemBrick.templateKey, itemBrick.animation || {}),
342
- outlet: compileOutlets(itemBrick.templateKey, itemBrick.outlets || {}),
381
+ animation: compileAnimations(
382
+ itemBrick.templateKey,
383
+ itemBrick.animation || {},
384
+ `(brick: ${brick.id}, ${key}: ${index}, subspace ${subspace.id})`,
385
+ ),
386
+ outlet: compileOutlets(
387
+ itemBrick.templateKey,
388
+ itemBrick.outlets || {},
389
+ `(brick: ${brick.id}, ${key}: ${index}, subspace ${subspace.id})`,
390
+ ),
343
391
  eventMap: compileEvents(itemBrick.templateKey, itemBrick.eventMap || {}, {
344
392
  camelCase: true,
393
+ errorReference: `(brick: ${brick.id}, ${key}: ${index}, subspace ${subspace.id})`,
345
394
  }),
346
395
  stateGroup: itemBrick.stateGroup.reduce((acc, stateGroup) => {
347
396
  acc[stateGroup.id] = {
@@ -350,26 +399,46 @@ export const compile = async (app: Application) => {
350
399
  override: stateGroup.override,
351
400
  break: stateGroup.break,
352
401
  commented: stateGroup.disabled,
353
- conds: compileSwitchConds(itemBrick.templateKey, stateGroup.conds || []),
354
- property: compileProperty(stateGroup.property),
355
- animation: compileAnimations(itemBrick.templateKey, stateGroup.animation || {}),
356
- outlet: compileOutlets(itemBrick.templateKey, stateGroup.outlets || {}),
402
+ conds: compileSwitchConds(
403
+ itemBrick.templateKey,
404
+ stateGroup.conds || [],
405
+ `(brick: ${brick.id}, ${key}: ${index}, switch: ${stateGroup.id}, subspace ${subspace.id})`,
406
+ ),
407
+ property: compileProperty(
408
+ stateGroup.property,
409
+ `(brick: ${brick.id}, ${key}: ${index}, switch: ${stateGroup.id}, subspace ${subspace.id})`,
410
+ ),
411
+ animation: compileAnimations(
412
+ itemBrick.templateKey,
413
+ stateGroup.animation || {},
414
+ `(brick: ${brick.id}, ${key}: ${index}, switch: ${stateGroup.id}, subspace ${subspace.id})`,
415
+ ),
416
+ outlet: compileOutlets(
417
+ itemBrick.templateKey,
418
+ stateGroup.outlets || {},
419
+ `(brick: ${brick.id}, ${key}: ${index}, switch: ${stateGroup.id}, subspace ${subspace.id})`,
420
+ ),
357
421
  eventMap: compileEvents(itemBrick.templateKey, stateGroup.eventMap || {}, {
358
422
  camelCase: true,
423
+ errorReference: `(brick: ${brick.id}, ${key}: ${index}, switch: ${stateGroup.id}, subspace ${subspace.id})`,
359
424
  }),
360
425
  }
361
426
  return acc
362
427
  }, {}),
363
428
  })
364
429
  if (Array.isArray(brickItems.brickList)) {
365
- const brickList = (brickItems.brickList || []).map(buildList)
430
+ const brickList = (brickItems.brickList || []).map((item, index) =>
431
+ buildList(item, index, 'brickList'),
432
+ )
366
433
  property.brickList = brickList
367
434
  } else {
368
435
  // Not supported Data for brickList
369
436
  throw new Error('Not supported Data for brickList directly')
370
437
  }
371
438
  if (Array.isArray(brickItems.brickDetails)) {
372
- const brickDetails = (brickItems.brickDetails || []).map(buildList)
439
+ const brickDetails = (brickItems.brickDetails || []).map((item, index) =>
440
+ buildList(item, index, 'brickDetails'),
441
+ )
373
442
  property.brickDetails = brickDetails
374
443
  } else {
375
444
  // Not supported Data for brickList
@@ -381,9 +450,20 @@ export const compile = async (app: Application) => {
381
450
  title: brick.title,
382
451
  description: brick.description,
383
452
  property,
384
- animation: compileAnimations(brick.templateKey, brick.animation || {}),
385
- event_map: compileEvents(brick.templateKey, brick.events || {}),
386
- outlet: compileOutlets(brick.templateKey, brick.outlets || {}),
453
+ animation: compileAnimations(
454
+ brick.templateKey,
455
+ brick.animation || {},
456
+ `(brick: ${brick.id}, subspace ${subspace.id})`,
457
+ ),
458
+ event_map: compileEvents(brick.templateKey, brick.events || {}, {
459
+ camelCase: false,
460
+ errorReference: `(brick: ${brick.id}, subspace ${subspace.id})`,
461
+ }),
462
+ outlet: compileOutlets(
463
+ brick.templateKey,
464
+ brick.outlets || {},
465
+ `(brick: ${brick.id}, subspace ${subspace.id})`,
466
+ ),
387
467
  state_group: brick.switches?.reduce((acc, switchCase) => {
388
468
  acc[switchCase.id] = {
389
469
  title: switchCase.title,
@@ -391,11 +471,29 @@ export const compile = async (app: Application) => {
391
471
  break: switchCase.break,
392
472
  override: switchCase.override,
393
473
  commented: switchCase.disabled,
394
- conds: compileSwitchConds(brick.templateKey, switchCase.conds || []),
395
- property: compileProperty(switchCase.property),
396
- outlet: compileOutlets(brick.templateKey, switchCase.outlets || {}),
397
- event_map: compileEvents(brick.templateKey, switchCase.events || {}),
398
- animation: compileAnimations(brick.templateKey, switchCase.animation || {}),
474
+ conds: compileSwitchConds(
475
+ brick.templateKey,
476
+ switchCase.conds || [],
477
+ `(brick: ${brick.id}, switch: ${switchCase.id}, subspace ${subspace.id})`,
478
+ ),
479
+ property: compileProperty(
480
+ switchCase.property,
481
+ `(brick: ${brick.id}, switch: ${switchCase.id}, subspace ${subspace.id})`,
482
+ ),
483
+ outlet: compileOutlets(
484
+ brick.templateKey,
485
+ switchCase.outlets || {},
486
+ `(brick: ${brick.id}, switch: ${switchCase.id}, subspace ${subspace.id})`,
487
+ ),
488
+ event_map: compileEvents(brick.templateKey, switchCase.events || {}, {
489
+ camelCase: false,
490
+ errorReference: `(brick: ${brick.id}, switch: ${switchCase.id}, subspace ${subspace.id})`,
491
+ }),
492
+ animation: compileAnimations(
493
+ brick.templateKey,
494
+ switchCase.animation || {},
495
+ `(brick: ${brick.id}, switch: ${switchCase.id}, subspace ${subspace.id})`,
496
+ ),
399
497
  }
400
498
  return acc
401
499
  }, {}),
@@ -407,8 +505,14 @@ export const compile = async (app: Application) => {
407
505
  map[canvas.id] = {
408
506
  title: canvas.title,
409
507
  description: canvas.description,
410
- property: compileProperty(canvas.property),
411
- event_map: compileEvents('CANVAS', canvas.events || {}),
508
+ property: compileProperty(
509
+ canvas.property,
510
+ `(canvas: ${canvas.id}, subspace ${subspace.id})`,
511
+ ),
512
+ event_map: compileEvents('CANVAS', canvas.events || {}, {
513
+ camelCase: false,
514
+ errorReference: `(canvas: ${canvas.id}, subspace ${subspace.id})`,
515
+ }),
412
516
  state_group: canvas.switches?.reduce((acc, switchCase) => {
413
517
  acc[switchCase.id] = {
414
518
  title: switchCase.title,
@@ -416,21 +520,51 @@ export const compile = async (app: Application) => {
416
520
  break: switchCase.break,
417
521
  override: switchCase.override,
418
522
  commented: switchCase.disabled,
419
- conds: compileSwitchConds('CANVAS', switchCase.conds || []),
420
- property: compileProperty(switchCase.property),
421
- event_map: compileEvents('CANVAS', switchCase.events || {}),
422
- animation: compileAnimations('CANVAS', switchCase.animation || {}),
523
+ conds: compileSwitchConds(
524
+ 'CANVAS',
525
+ switchCase.conds || [],
526
+ `(canvas: ${canvas.id}, switch: ${switchCase.id}, subspace ${subspace.id})`,
527
+ ),
528
+ property: compileProperty(
529
+ switchCase.property,
530
+ `(canvas: ${canvas.id}, switch: ${switchCase.id}, subspace ${subspace.id})`,
531
+ ),
532
+ event_map: compileEvents('CANVAS', switchCase.events || {}, {
533
+ camelCase: false,
534
+ errorReference: `(canvas: ${canvas.id}, switch: ${switchCase.id}, subspace ${subspace.id})`,
535
+ }),
536
+ animation: compileAnimations(
537
+ 'CANVAS',
538
+ switchCase.animation || {},
539
+ `(canvas: ${canvas.id}, switch: ${switchCase.id}, subspace ${subspace.id})`,
540
+ ),
423
541
  }
424
542
  return acc
425
543
  }, {}),
426
- item_list: canvas.items.map((item) => ({
427
- type: typeof item.item === 'function' ? 'brick' : 'subspace',
428
- ...(typeof item.item === 'function'
429
- ? { brick_id: (item.item as () => Brick)()?.id }
430
- : { subspace_id: item.item }),
431
- frame: compileFrame(item.frame),
432
- hidden: item.hidden,
433
- })),
544
+ item_list: canvas.items.map((item, index) => {
545
+ let itemPayload = {}
546
+ if (typeof item.item === 'function') {
547
+ const brick = (item.item as () => Brick)()
548
+ if (!brick?.id)
549
+ throw new Error(
550
+ `Invalid canvas item index: ${index}, brick not found (canvas: ${canvas.id}, subspace ${subspace.id})`,
551
+ )
552
+ itemPayload = { brick_id: brick.id }
553
+ } else {
554
+ const subspaceId = item.item
555
+ if (!app.subspaces.some((s) => s.id === subspaceId))
556
+ throw new Error(
557
+ `Invalid canvas item index: ${index}, subspace not found (canvas: ${canvas.id}, subspace ${subspace.id})`,
558
+ )
559
+ itemPayload = { subspace_id: subspaceId }
560
+ }
561
+ return {
562
+ type: typeof item.item === 'function' ? 'brick' : 'subspace',
563
+ ...itemPayload,
564
+ frame: compileFrame(item.frame),
565
+ hidden: item.hidden,
566
+ }
567
+ }),
434
568
  }
435
569
  return map
436
570
  }, {}),
@@ -444,9 +578,19 @@ export const compile = async (app: Application) => {
444
578
  run_mode: generator.localSyncRunMode,
445
579
  }
446
580
  : undefined,
447
- property: compileProperty(generator.property || {}),
448
- event_map: compileEvents(generator.templateKey, generator.events || {}),
449
- outlet: compileOutlets(generator.templateKey, generator.outlets || {}),
581
+ property: compileProperty(
582
+ generator.property || {},
583
+ `(generator: ${generator.id}, subspace ${subspace.id})`,
584
+ ),
585
+ event_map: compileEvents(generator.templateKey, generator.events || {}, {
586
+ camelCase: false,
587
+ errorReference: `(generator: ${generator.id}, subspace ${subspace.id})`,
588
+ }),
589
+ outlet: compileOutlets(
590
+ generator.templateKey,
591
+ generator.outlets || {},
592
+ `(generator: ${generator.id}, subspace ${subspace.id})`,
593
+ ),
450
594
  state_group: generator.switches?.reduce((acc, switchCase) => {
451
595
  acc[switchCase.id] = {
452
596
  title: switchCase.title,
@@ -454,11 +598,29 @@ export const compile = async (app: Application) => {
454
598
  break: switchCase.break,
455
599
  override: switchCase.override,
456
600
  commented: switchCase.disabled,
457
- conds: compileSwitchConds(generator.templateKey, switchCase.conds || []),
458
- property: compileProperty(switchCase.property),
459
- outlet: compileOutlets(generator.templateKey, switchCase.outlets || {}),
460
- event_map: compileEvents(generator.templateKey, switchCase.events || {}),
461
- animation: compileAnimations(generator.templateKey, switchCase.animation || {}),
601
+ conds: compileSwitchConds(
602
+ generator.templateKey,
603
+ switchCase.conds || [],
604
+ `(generator: ${generator.id}, switch: ${switchCase.id}, subspace ${subspace.id})`,
605
+ ),
606
+ property: compileProperty(
607
+ switchCase.property,
608
+ `(generator: ${generator.id}, switch: ${switchCase.id}, subspace ${subspace.id})`,
609
+ ),
610
+ outlet: compileOutlets(
611
+ generator.templateKey,
612
+ switchCase.outlets || {},
613
+ `(generator: ${generator.id}, switch: ${switchCase.id}, subspace ${subspace.id})`,
614
+ ),
615
+ event_map: compileEvents(generator.templateKey, switchCase.events || {}, {
616
+ camelCase: false,
617
+ errorReference: `(generator: ${generator.id}, switch: ${switchCase.id}, subspace ${subspace.id})`,
618
+ }),
619
+ animation: compileAnimations(
620
+ generator.templateKey,
621
+ switchCase.animation || {},
622
+ `(generator: ${generator.id}, switch: ${switchCase.id}, subspace ${subspace.id})`,
623
+ ),
462
624
  }
463
625
  return acc
464
626
  }, {}),
@@ -482,8 +644,11 @@ export const compile = async (app: Application) => {
482
644
  schema: data.schema,
483
645
  type: data.type,
484
646
  ...compileKind(data.kind),
485
- value: data.value,
486
- event_map: compileEvents('PROPERTY_BANK', data.events || {}),
647
+ value: compileProperty(data.value, `(data: ${data.id}, subspace ${subspace.id})`),
648
+ event_map: compileEvents('PROPERTY_BANK', data.events || {}, {
649
+ camelCase: false,
650
+ errorReference: `(data: ${data.id}, subspace ${subspace.id})`,
651
+ }),
487
652
  }
488
653
  return map
489
654
  }, {}),
@@ -654,8 +819,13 @@ export const compile = async (app: Application) => {
654
819
  return map
655
820
  }, {}),
656
821
  action_map: subspace.actions || undefined,
657
- event_map: compileEvents('', subspace.events || {}),
658
- routing: subspace.dataRouting.reduce((acc, data) => {
822
+ event_map: compileEvents('', subspace.events || {}, {
823
+ camelCase: false,
824
+ errorReference: `(subspace ${subspace.id})`,
825
+ }),
826
+ routing: subspace.dataRouting.reduce((acc, data, index) => {
827
+ if (!data?.id)
828
+ throw new Error(`Invalid data routing index: ${index} (subspace ${subspace.id})`)
659
829
  acc[data.id] = { enabled_routing: true }
660
830
  return acc
661
831
  }, {}),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fugood/bricks-project",
3
- "version": "2.21.0-beta.16-1",
3
+ "version": "2.21.0-beta.17-1",
4
4
  "main": "index.ts",
5
5
  "scripts": {
6
6
  "build": "node scripts/build.js"
package/tools/pull.ts CHANGED
@@ -4,9 +4,14 @@ import { pullApplicationProject, pullModuleProject } from '../api'
4
4
 
5
5
  const cwd = process.cwd()
6
6
 
7
- const unstagedChanges = await $`cd ${cwd} && git diff --name-only --diff-filter=ACMR`.text()
8
- if (unstagedChanges)
9
- throw new Error('Unstaged changes found, please commit or stash your changes before deploying')
7
+ const { exitCode } = await $`cd ${cwd} && git status`.nothrow()
8
+ const isGitRepo = exitCode === 0
9
+
10
+ if (isGitRepo) {
11
+ const unstagedChanges = await $`cd ${cwd} && git diff --name-only --diff-filter=ACMR`.text()
12
+ if (unstagedChanges)
13
+ throw new Error('Unstaged changes found, please commit or stash your changes before deploying')
14
+ }
10
15
 
11
16
  const app = await Bun.file(`${cwd}/application.json`).json()
12
17
  const stage = app.stage || 'production'
@@ -15,9 +20,6 @@ const { files, lastCommitId } =
15
20
  ? await pullModuleProject(stage, app.id)
16
21
  : await pullApplicationProject(stage, app.id)
17
22
 
18
- const { exitCode } = await $`cd ${cwd} && git status`.nothrow()
19
- const isGitRepo = exitCode === 0
20
-
21
23
  let useMain = false
22
24
  if (isGitRepo) {
23
25
  const found = (await $`cd ${cwd} && git rev-list -1 ${lastCommitId}`.nothrow().text())
@@ -45,11 +47,23 @@ if (isGitRepo) {
45
47
  if (confirmContinue !== 'y') throw new Error('Pull cancelled')
46
48
  }
47
49
 
50
+ const prettierConfig = await Bun.file(`${cwd}/.prettierrc`)
51
+ .json()
52
+ .catch(() => ({
53
+ trailingComma: 'all',
54
+ tabWidth: 2,
55
+ semi: false,
56
+ singleQuote: true,
57
+ printWidth: 100,
58
+ }))
59
+
48
60
  await Promise.all(
49
61
  files.map(async (file) =>
50
62
  Bun.write(
51
63
  `${cwd}/${file.name}`,
52
- file.formatable ? await format(file.input, { parser: 'typescript' }) : file.input,
64
+ file.formatable
65
+ ? await format(file.input, { parser: 'typescript', ...prettierConfig })
66
+ : file.input,
53
67
  ),
54
68
  ),
55
69
  )