@fugood/bricks-project 2.21.0-beta.14.test0 → 2.21.0-beta.14.test10
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/api/index.ts +1 -1
- package/api/instance.ts +180 -0
- package/compile/action-name-map.ts +502 -0
- package/compile/index.ts +208 -71
- package/compile/util.ts +2 -2
- package/index.ts +4 -9
- package/package.json +3 -1
- package/tools/deploy.ts +24 -0
- package/tools/postinstall.ts +12 -0
- package/tools/preview-main.mjs +51 -0
- package/tools/preview.ts +37 -0
- package/tools/pull.ts +51 -0
- package/types/bricks.ts +77 -76
- package/types/canvas.ts +4 -4
- package/types/common.ts +12 -9
- package/types/data-calc.ts +34 -1
- package/types/data.ts +43 -3
- package/types/generators.ts +151 -145
- package/types/subspace.ts +21 -6
- package/types/switch.ts +10 -7
- package/types/system.ts +58 -57
- package/utils/calc.ts +118 -0
- package/utils/data.ts +397 -0
- package/{uuid.ts → utils/id.ts} +26 -10
- package/api/application.ts +0 -65
package/compile/index.ts
CHANGED
|
@@ -1,9 +1,13 @@
|
|
|
1
1
|
import _ from 'lodash'
|
|
2
|
-
import { parse as parseAST
|
|
2
|
+
import { parse as parseAST } from 'acorn'
|
|
3
|
+
import type { ExportNamedDeclaration, FunctionDeclaration } from 'acorn'
|
|
3
4
|
import escodegen from 'escodegen'
|
|
4
|
-
import {
|
|
5
|
+
import { generateCalulationMap } from './util'
|
|
6
|
+
import { templateActionNameMap } from './action-name-map'
|
|
7
|
+
import type {
|
|
5
8
|
Application,
|
|
6
9
|
Data,
|
|
10
|
+
Animation,
|
|
7
11
|
AnimationDef,
|
|
8
12
|
AnimationComposeDef,
|
|
9
13
|
EventAction,
|
|
@@ -19,14 +23,16 @@ import {
|
|
|
19
23
|
DataCommand,
|
|
20
24
|
Brick,
|
|
21
25
|
Generator,
|
|
26
|
+
Canvas,
|
|
27
|
+
Subspace,
|
|
22
28
|
} from '../types'
|
|
23
|
-
import { generateCalulationMap } from './util'
|
|
24
29
|
|
|
25
30
|
const compileProperty = (property, result = {}) => {
|
|
26
31
|
if (Array.isArray(property)) {
|
|
27
32
|
return property.map((p) => compileProperty(p, result))
|
|
28
33
|
}
|
|
29
|
-
if (property?.__typename === 'DataLink' && property.data?.())
|
|
34
|
+
if (property?.__typename === 'DataLink' && property.data?.())
|
|
35
|
+
return `PROPERTY_BANK#${property.data().id}`
|
|
30
36
|
if (typeof property === 'function') return property()?.id // defined type instance getter
|
|
31
37
|
if (typeof property === 'object') {
|
|
32
38
|
return Object.entries(property).reduce((acc, [key, value]) => {
|
|
@@ -54,14 +60,17 @@ const convertEventKey = (templateKey: string, key: string) => {
|
|
|
54
60
|
|
|
55
61
|
const basicAnimationEvents = ['show', 'standby', 'breatheStart']
|
|
56
62
|
|
|
57
|
-
const compileAnimations = (templateKey: string, animations: { [key: string]:
|
|
63
|
+
const compileAnimations = (templateKey: string, animations: { [key: string]: Animation }) => {
|
|
58
64
|
return Object.entries(animations).reduce((acc, [key, animation]) => {
|
|
59
65
|
acc[convertEventKey(basicAnimationEvents.includes(key) ? 'BRICK' : templateKey, key)] =
|
|
60
|
-
`ANIMATION#${animation
|
|
66
|
+
`ANIMATION#${animation.id}`
|
|
61
67
|
return acc
|
|
62
68
|
}, {})
|
|
63
69
|
}
|
|
64
70
|
|
|
71
|
+
const compileActionParam = (templateKey: string, actionName: string, paramName: string) =>
|
|
72
|
+
templateActionNameMap[templateKey]?.[actionName]?.[paramName] || paramName
|
|
73
|
+
|
|
65
74
|
const compileEvents = (
|
|
66
75
|
templateKey: string,
|
|
67
76
|
eventMap: { [key: string]: Array<EventAction> },
|
|
@@ -72,35 +81,46 @@ const compileEvents = (
|
|
|
72
81
|
acc[convertEventKey(templateKey, key)] = events.map((event) => {
|
|
73
82
|
const { handler, action } = event
|
|
74
83
|
|
|
84
|
+
let handlerKey
|
|
85
|
+
let handlerTemplateKey
|
|
86
|
+
if (handler === 'system' || typeof handler === 'string') {
|
|
87
|
+
if (handler.startsWith('SUBSPACE_')) handlerKey = handler
|
|
88
|
+
else handlerKey = handler.toUpperCase()
|
|
89
|
+
if (handlerKey === 'SYSTEM') handlerTemplateKey = 'SYSTEM'
|
|
90
|
+
} else if (typeof handler === 'function') {
|
|
91
|
+
const instance = handler() as Brick | Generator
|
|
92
|
+
handlerKey = instance?.id
|
|
93
|
+
handlerTemplateKey = instance?.templateKey
|
|
94
|
+
}
|
|
95
|
+
if (!handlerKey) throw new Error(`Invalid handler: ${handler}`)
|
|
96
|
+
|
|
75
97
|
const parameterList: Array<object> = []
|
|
76
98
|
if (Object.hasOwn(action, 'params')) {
|
|
77
99
|
const actionDef = action as ActionWithParams
|
|
78
100
|
;(actionDef.params || []).forEach(({ input, value, mapping }) => {
|
|
79
|
-
|
|
80
|
-
[camelCase ? 'inputToReceiver' : 'input_to_receiver']:
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
101
|
+
const param = {
|
|
102
|
+
[camelCase ? 'inputToReceiver' : 'input_to_receiver']: handlerTemplateKey
|
|
103
|
+
? compileActionParam(handlerTemplateKey, action.__actionName, input)
|
|
104
|
+
: input,
|
|
105
|
+
[camelCase ? 'resultFromSender' : 'result_from_sender']:
|
|
106
|
+
mapping || compileProperty(value),
|
|
107
|
+
}
|
|
108
|
+
if (mapping) param[camelCase ? 'resultDataMapping' : 'result_data_mapping'] = true
|
|
109
|
+
parameterList.push(param)
|
|
84
110
|
})
|
|
85
111
|
} else if (Object.hasOwn(action, 'dataParams')) {
|
|
86
112
|
const actionDef = action as ActionWithDataParams
|
|
87
113
|
;(actionDef.dataParams || []).forEach(({ input, value, mapping }) => {
|
|
88
114
|
if (!input) return
|
|
89
|
-
|
|
115
|
+
const param = {
|
|
90
116
|
[camelCase ? 'inputToReceiver' : 'input_to_receiver']: input().id,
|
|
91
|
-
[camelCase ? 'resultFromSender' : 'result_from_sender']:
|
|
92
|
-
|
|
93
|
-
}
|
|
117
|
+
[camelCase ? 'resultFromSender' : 'result_from_sender']:
|
|
118
|
+
mapping || compileProperty(value),
|
|
119
|
+
}
|
|
120
|
+
if (mapping) param[camelCase ? 'resultDataMapping' : 'result_data_mapping'] = true
|
|
121
|
+
parameterList.push(param)
|
|
94
122
|
})
|
|
95
123
|
}
|
|
96
|
-
let handlerKey
|
|
97
|
-
if (handler === 'system' || typeof handler === 'string') {
|
|
98
|
-
if (handler.startsWith('SUBSPACE_')) handlerKey = handler
|
|
99
|
-
else handlerKey = handler.toUpperCase()
|
|
100
|
-
} else if (typeof handler === 'function') {
|
|
101
|
-
handlerKey = (handler() as Brick | Generator)?.id
|
|
102
|
-
}
|
|
103
|
-
if (!handlerKey) throw new Error(`Invalid handler: ${handler}`)
|
|
104
124
|
return {
|
|
105
125
|
handler: handlerKey,
|
|
106
126
|
action: action.__actionName,
|
|
@@ -115,22 +135,23 @@ const compileEvents = (
|
|
|
115
135
|
const compileSwitchConds = (templateKey, conds) =>
|
|
116
136
|
(conds || []).map((item: any) => {
|
|
117
137
|
const result: any = { method: item.method }
|
|
118
|
-
if (item.__typename === 'SwitchCondData') {
|
|
119
|
-
const cond = item as SwitchCondData
|
|
138
|
+
if (item.cond.__typename === 'SwitchCondData') {
|
|
139
|
+
const cond = item.cond as SwitchCondData
|
|
120
140
|
result.type = 'property_bank'
|
|
121
141
|
result.key = cond.data().id
|
|
122
142
|
result.value = cond.value
|
|
123
|
-
} else if (item.__typename === 'SwitchCondPropertyBankByItemKey') {
|
|
124
|
-
const cond = item as SwitchCondPropertyBankByItemKey
|
|
143
|
+
} else if (item.cond.__typename === 'SwitchCondPropertyBankByItemKey') {
|
|
144
|
+
const cond = item.cond as SwitchCondPropertyBankByItemKey
|
|
125
145
|
result.type = 'property_bank_by_item_key'
|
|
126
146
|
result.key = cond.data().id
|
|
127
147
|
result.value = cond.value
|
|
128
|
-
} else if (item.__typename === 'SwitchCondInnerStateOutlet') {
|
|
148
|
+
} else if (item.cond.__typename === 'SwitchCondInnerStateOutlet') {
|
|
149
|
+
const cond = item.cond
|
|
129
150
|
result.type = 'inner_state'
|
|
130
|
-
result.key = convertOutletKey(templateKey,
|
|
131
|
-
result.value =
|
|
132
|
-
} else if (item.__typename === 'SwitchCondInnerStateCurrentCanvas') {
|
|
133
|
-
const cond = item as SwitchCondInnerStateCurrentCanvas
|
|
151
|
+
result.key = convertOutletKey(templateKey, cond.outlet)
|
|
152
|
+
result.value = cond.value
|
|
153
|
+
} else if (item.cond.__typename === 'SwitchCondInnerStateCurrentCanvas') {
|
|
154
|
+
const cond = item.cond as SwitchCondInnerStateCurrentCanvas
|
|
134
155
|
result.type = 'inner_state'
|
|
135
156
|
result.key = 'current_canvas'
|
|
136
157
|
result.value = cond.value().id
|
|
@@ -167,6 +188,62 @@ const animationTypeMap = {
|
|
|
167
188
|
AnimationDecayConfig: 'decay',
|
|
168
189
|
}
|
|
169
190
|
|
|
191
|
+
const compileFrame = (frame: Canvas['items'][number]['frame']) => ({
|
|
192
|
+
x: frame.x,
|
|
193
|
+
y: frame.y,
|
|
194
|
+
width: frame.width,
|
|
195
|
+
height: frame.height,
|
|
196
|
+
standby_mode: frame.standbyMode,
|
|
197
|
+
standby_frame: frame.standbyFrame,
|
|
198
|
+
standby_opacity: frame.standbyOpacity,
|
|
199
|
+
standby_delay: frame.standbyDelay,
|
|
200
|
+
standby_delay_random: frame.standbyDelayRandom,
|
|
201
|
+
standby_easing: frame.standbyEasing,
|
|
202
|
+
showing_delay: frame.showingDelay,
|
|
203
|
+
render_out_of_viewport: frame.renderOutOfViewport,
|
|
204
|
+
})
|
|
205
|
+
|
|
206
|
+
const compileKind = (kind: Data['kind']) => {
|
|
207
|
+
const { type, ...rest } = kind || {}
|
|
208
|
+
if (!type) return {}
|
|
209
|
+
return { kind: type, ...rest }
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
const compileRemoteUpdate = (remoteUpdate: Data['remoteUpdate']) => {
|
|
213
|
+
if (!remoteUpdate) return {}
|
|
214
|
+
if (remoteUpdate.type === 'auto') return { enable_remote_update: true }
|
|
215
|
+
return {
|
|
216
|
+
enable_remote_update: true,
|
|
217
|
+
...(remoteUpdate.type === 'device-specific' ? { use_remote_id_prefix: true } : {}),
|
|
218
|
+
...(remoteUpdate.type === 'global-data' ? { global_remote_update_prop: remoteUpdate.id } : {}),
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
const compileModule = (subspace: Subspace) => {
|
|
223
|
+
if (!subspace.module) return {}
|
|
224
|
+
return {
|
|
225
|
+
module: {
|
|
226
|
+
link: true,
|
|
227
|
+
id: subspace.module.id,
|
|
228
|
+
version: subspace.module.version,
|
|
229
|
+
},
|
|
230
|
+
selected_requirements: subspace.module.selectedRequirements?.reduce((acc, requirement) => {
|
|
231
|
+
acc[requirement.subspace] = {
|
|
232
|
+
id: requirement.id,
|
|
233
|
+
version: requirement.version,
|
|
234
|
+
}
|
|
235
|
+
return acc
|
|
236
|
+
}, {}),
|
|
237
|
+
requirements: subspace.module.requirements?.reduce((acc, requirement) => {
|
|
238
|
+
acc[requirement.subspace] = {
|
|
239
|
+
id: requirement.id,
|
|
240
|
+
version: requirement.version,
|
|
241
|
+
}
|
|
242
|
+
return acc
|
|
243
|
+
}, {}),
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
|
|
170
247
|
export const compile = (app: Application) => {
|
|
171
248
|
const config = {
|
|
172
249
|
title: app.name,
|
|
@@ -179,6 +256,11 @@ export const compile = (app: Application) => {
|
|
|
179
256
|
height: subspace.layout?.height,
|
|
180
257
|
resize_mode: subspace.layout?.resizeMode,
|
|
181
258
|
},
|
|
259
|
+
local_sync: subspace.localSyncChangeCanvas
|
|
260
|
+
? {
|
|
261
|
+
change_canvas: subspace.localSyncChangeCanvas,
|
|
262
|
+
}
|
|
263
|
+
: undefined,
|
|
182
264
|
animation_map: subspace.animations.reduce((map, animation) => {
|
|
183
265
|
if (animation.__typename === 'Animation') {
|
|
184
266
|
const animationDef = animation as AnimationDef
|
|
@@ -212,22 +294,29 @@ export const compile = (app: Application) => {
|
|
|
212
294
|
brickIdPrefix: itemBrick.brickIdPrefix,
|
|
213
295
|
templateKey: itemBrick.templateKey,
|
|
214
296
|
property: compileProperty(itemBrick.property),
|
|
297
|
+
propertyMapping: itemBrick.propertyMapping,
|
|
215
298
|
animation: compileAnimations(itemBrick.templateKey, itemBrick.animation || {}),
|
|
216
299
|
outlet: compileOutlets(itemBrick.templateKey, itemBrick.outlets || {}),
|
|
217
300
|
eventMap: compileEvents(itemBrick.templateKey, itemBrick.eventMap || {}, {
|
|
218
301
|
camelCase: true,
|
|
219
302
|
}),
|
|
220
|
-
stateGroup: itemBrick.stateGroup.
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
303
|
+
stateGroup: itemBrick.stateGroup.reduce((acc, stateGroup) => {
|
|
304
|
+
acc[stateGroup.id] = {
|
|
305
|
+
title: stateGroup.title,
|
|
306
|
+
description: stateGroup.description,
|
|
307
|
+
override: stateGroup.override,
|
|
308
|
+
break: stateGroup.break,
|
|
309
|
+
commented: stateGroup.disabled,
|
|
310
|
+
conds: compileSwitchConds(itemBrick.templateKey, stateGroup.conds || []),
|
|
311
|
+
property: compileProperty(stateGroup.property),
|
|
312
|
+
animation: compileAnimations(itemBrick.templateKey, stateGroup.animation || {}),
|
|
313
|
+
outlet: compileOutlets(itemBrick.templateKey, stateGroup.outlets || {}),
|
|
314
|
+
eventMap: compileEvents(itemBrick.templateKey, stateGroup.eventMap || {}, {
|
|
315
|
+
camelCase: true,
|
|
316
|
+
}),
|
|
317
|
+
}
|
|
318
|
+
return acc
|
|
319
|
+
}, {}),
|
|
231
320
|
})
|
|
232
321
|
if (Array.isArray(brickItems.brickList)) {
|
|
233
322
|
const brickList = (brickItems.brickList || []).map(buildList)
|
|
@@ -252,7 +341,7 @@ export const compile = (app: Application) => {
|
|
|
252
341
|
animation: compileAnimations(brick.templateKey, brick.animation || {}),
|
|
253
342
|
event_map: compileEvents(brick.templateKey, brick.events || {}),
|
|
254
343
|
outlet: compileOutlets(brick.templateKey, brick.outlets || {}),
|
|
255
|
-
state_group: brick.switches
|
|
344
|
+
state_group: brick.switches?.reduce((acc, switchCase) => {
|
|
256
345
|
acc[switchCase.id] = {
|
|
257
346
|
title: switchCase.title,
|
|
258
347
|
description: switchCase.description,
|
|
@@ -277,7 +366,7 @@ export const compile = (app: Application) => {
|
|
|
277
366
|
description: canvas.description,
|
|
278
367
|
property: compileProperty(canvas.property),
|
|
279
368
|
event_map: compileEvents('CANVAS', canvas.events || {}),
|
|
280
|
-
state_group: canvas.switches
|
|
369
|
+
state_group: canvas.switches?.reduce((acc, switchCase) => {
|
|
281
370
|
acc[switchCase.id] = {
|
|
282
371
|
title: switchCase.title,
|
|
283
372
|
description: switchCase.description,
|
|
@@ -291,7 +380,13 @@ export const compile = (app: Application) => {
|
|
|
291
380
|
}
|
|
292
381
|
return acc
|
|
293
382
|
}, {}),
|
|
294
|
-
item_list:
|
|
383
|
+
item_list: canvas.items.map((item) => ({
|
|
384
|
+
type: typeof item.item === 'function' ? 'brick' : 'subspace',
|
|
385
|
+
...(typeof item.item === 'function'
|
|
386
|
+
? { brick_id: (item.item as () => Brick)()?.id }
|
|
387
|
+
: { subspace_id: item.item }),
|
|
388
|
+
frame: compileFrame(item.frame),
|
|
389
|
+
})),
|
|
295
390
|
}
|
|
296
391
|
return map
|
|
297
392
|
}, {}),
|
|
@@ -300,10 +395,15 @@ export const compile = (app: Application) => {
|
|
|
300
395
|
template_key: generator.templateKey,
|
|
301
396
|
title: generator.title,
|
|
302
397
|
description: generator.description,
|
|
398
|
+
local_sync: generator.localSyncRunMode
|
|
399
|
+
? {
|
|
400
|
+
run_mode: generator.localSyncRunMode,
|
|
401
|
+
}
|
|
402
|
+
: undefined,
|
|
303
403
|
property: compileProperty(generator.property || {}),
|
|
304
404
|
event_map: compileEvents(generator.templateKey, generator.events || {}),
|
|
305
405
|
outlet: compileOutlets(generator.templateKey, generator.outlets || {}),
|
|
306
|
-
state_group: generator.switches
|
|
406
|
+
state_group: generator.switches?.reduce((acc, switchCase) => {
|
|
307
407
|
acc[switchCase.id] = {
|
|
308
408
|
title: switchCase.title,
|
|
309
409
|
description: switchCase.description,
|
|
@@ -325,10 +425,19 @@ export const compile = (app: Application) => {
|
|
|
325
425
|
map[data.id] = {
|
|
326
426
|
title: data.title,
|
|
327
427
|
description: data.description,
|
|
428
|
+
linked: data.metadata?.linked,
|
|
429
|
+
linkedFrom: data.metadata?.linkedFrom,
|
|
430
|
+
local_sync: data.localSyncUpdateMode
|
|
431
|
+
? {
|
|
432
|
+
update_mode: data.localSyncUpdateMode,
|
|
433
|
+
}
|
|
434
|
+
: undefined,
|
|
328
435
|
persist_data: data.persistData,
|
|
436
|
+
...compileRemoteUpdate(data.remoteUpdate),
|
|
329
437
|
routing: data.routing,
|
|
330
438
|
schema: data.schema,
|
|
331
439
|
type: data.type,
|
|
440
|
+
...compileKind(data.kind),
|
|
332
441
|
value: data.value,
|
|
333
442
|
event_map: compileEvents('PROPERTY_BANK', data.events || {}),
|
|
334
443
|
}
|
|
@@ -343,36 +452,49 @@ export const compile = (app: Application) => {
|
|
|
343
452
|
calc.type = 'general'
|
|
344
453
|
const mapCalc = dataCalc as DataCalculationMap
|
|
345
454
|
|
|
346
|
-
const generateInputPorts = (inputs
|
|
455
|
+
const generateInputPorts = (inputs) =>
|
|
347
456
|
inputs.reduce((acc, port) => {
|
|
348
|
-
if (!port.
|
|
457
|
+
if (!acc[port.key]) acc[port.key] = null
|
|
349
458
|
|
|
350
|
-
|
|
351
|
-
let
|
|
459
|
+
let sourceId
|
|
460
|
+
let sourceNode = port.source()
|
|
461
|
+
if (sourceNode?.__typename === 'DataCalculationData')
|
|
462
|
+
sourceId = (sourceNode as DataCalculationData).data().id
|
|
463
|
+
if (sourceNode?.__typename === 'DataCommand') sourceId = sourceNode.id
|
|
352
464
|
|
|
465
|
+
if (!sourceId) return acc
|
|
353
466
|
if (!acc[port.key]) acc[port.key] = []
|
|
467
|
+
|
|
354
468
|
acc[port.key].push({
|
|
355
|
-
id:
|
|
469
|
+
id: sourceId,
|
|
356
470
|
port: port.sourceKey,
|
|
357
|
-
|
|
471
|
+
disable_trigger_command: !port.trigger ? true : undefined,
|
|
358
472
|
})
|
|
359
473
|
return acc
|
|
360
474
|
}, {})
|
|
361
475
|
|
|
362
476
|
const generateOutputPorts = (outputs) =>
|
|
363
477
|
outputs.reduce((acc, port) => {
|
|
364
|
-
if (!port.
|
|
478
|
+
if (!acc[port.key]) acc[port.key] = null
|
|
365
479
|
|
|
480
|
+
let targetId
|
|
481
|
+
let targetNode = port.target()
|
|
482
|
+
if (targetNode?.__typename === 'DataCalculationData')
|
|
483
|
+
targetId = (targetNode as DataCalculationData).data().id
|
|
484
|
+
if (targetNode?.__typename === 'DataCommand') targetId = targetNode.id
|
|
485
|
+
|
|
486
|
+
if (!targetId) return acc
|
|
366
487
|
if (!acc[port.key]) acc[port.key] = []
|
|
488
|
+
|
|
367
489
|
acc[port.key].push({
|
|
368
|
-
id:
|
|
490
|
+
id: targetId,
|
|
369
491
|
port: port.targetKey,
|
|
370
492
|
})
|
|
371
493
|
return acc
|
|
372
494
|
}, {})
|
|
373
495
|
|
|
374
496
|
const getNodeId = (node) => {
|
|
375
|
-
if (node.__typename === 'DataCalculationData') return node.data.id
|
|
497
|
+
if (node.__typename === 'DataCalculationData') return node.data().id
|
|
376
498
|
if (node.__typename === 'DataCommand') return node.id
|
|
377
499
|
throw new Error(`Invalid node: ${JSON.stringify(node)}`)
|
|
378
500
|
}
|
|
@@ -385,7 +507,7 @@ export const compile = (app: Application) => {
|
|
|
385
507
|
description: dataNode.description,
|
|
386
508
|
type: 'data-node',
|
|
387
509
|
properties: {},
|
|
388
|
-
in: generateInputPorts(dataNode.inputs
|
|
510
|
+
in: generateInputPorts(dataNode.inputs),
|
|
389
511
|
out: generateOutputPorts(dataNode.outputs),
|
|
390
512
|
}
|
|
391
513
|
} else if (node.__typename === 'DataCommand') {
|
|
@@ -396,8 +518,8 @@ export const compile = (app: Application) => {
|
|
|
396
518
|
const args = commandNode.inputs.filter(
|
|
397
519
|
(input) =>
|
|
398
520
|
typeof input.source !== 'function' ||
|
|
399
|
-
input.source()?.__typename !== 'DataCalculationData' &&
|
|
400
|
-
|
|
521
|
+
(input.source()?.__typename !== 'DataCalculationData' &&
|
|
522
|
+
input.source()?.__typename !== 'DataCommand'),
|
|
401
523
|
)
|
|
402
524
|
const inputs = commandNode.inputs.filter(
|
|
403
525
|
(input) =>
|
|
@@ -416,7 +538,7 @@ export const compile = (app: Application) => {
|
|
|
416
538
|
return acc
|
|
417
539
|
}, {}),
|
|
418
540
|
},
|
|
419
|
-
in: generateInputPorts(inputs
|
|
541
|
+
in: generateInputPorts(inputs),
|
|
420
542
|
out: generateOutputPorts(commandNode.outputs),
|
|
421
543
|
}
|
|
422
544
|
}
|
|
@@ -439,14 +561,20 @@ export const compile = (app: Application) => {
|
|
|
439
561
|
const scriptCalc = dataCalc as DataCalculationScript
|
|
440
562
|
calc.type = 'script'
|
|
441
563
|
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
564
|
+
let code: string
|
|
565
|
+
try {
|
|
566
|
+
const program = parseAST(scriptCalc.code, { sourceType: 'module', ecmaVersion: 2020 })
|
|
567
|
+
// export function main() { ... }
|
|
568
|
+
const declarationBody = (
|
|
569
|
+
(program.body[0] as ExportNamedDeclaration).declaration as FunctionDeclaration
|
|
570
|
+
)?.body
|
|
571
|
+
code = escodegen.generate(declarationBody)
|
|
572
|
+
} catch (e) {
|
|
573
|
+
code = scriptCalc.code || ''
|
|
574
|
+
}
|
|
448
575
|
calc.script_config = {
|
|
449
|
-
|
|
576
|
+
note: scriptCalc.note,
|
|
577
|
+
code,
|
|
450
578
|
enable_async: scriptCalc.enableAsync,
|
|
451
579
|
inputs: scriptCalc.inputs.reduce((acc, input) => {
|
|
452
580
|
acc[input.data().id] = input.key
|
|
@@ -465,21 +593,30 @@ export const compile = (app: Application) => {
|
|
|
465
593
|
error: scriptCalc.error?.().id,
|
|
466
594
|
}
|
|
467
595
|
|
|
468
|
-
Object.assign(
|
|
469
|
-
|
|
470
|
-
|
|
596
|
+
Object.assign(
|
|
597
|
+
calc,
|
|
598
|
+
generateCalulationMap(calc.script_config, {
|
|
599
|
+
snapshotMode: process.env.BRICKS_SNAPSHOT_MODE === '1',
|
|
600
|
+
}),
|
|
601
|
+
)
|
|
471
602
|
}
|
|
472
603
|
map[dataCalc.id] = calc
|
|
473
604
|
return map
|
|
474
605
|
}, {}),
|
|
475
|
-
action_map: subspace.actions ||
|
|
606
|
+
action_map: subspace.actions || undefined,
|
|
476
607
|
event_map: compileEvents('', subspace.events || {}),
|
|
608
|
+
routing: subspace.dataRouting.reduce((acc, data) => {
|
|
609
|
+
acc[data.id] = { enabled_routing: true }
|
|
610
|
+
return acc
|
|
611
|
+
}, {}),
|
|
612
|
+
...compileModule(subspace),
|
|
477
613
|
}
|
|
478
614
|
return subspaceMap
|
|
479
615
|
}, {}),
|
|
480
616
|
root_subspace_id: app.rootSubspace.id,
|
|
481
617
|
fonts: app.fonts,
|
|
482
618
|
...compileApplicationSettings(app.settings),
|
|
619
|
+
test_map: app.metadata?.TEMP_test_map || {},
|
|
483
620
|
}
|
|
484
621
|
return config
|
|
485
622
|
}
|
package/compile/util.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { makeId } from '../
|
|
1
|
+
import { makeId } from '../utils/id'
|
|
2
2
|
|
|
3
3
|
type ScriptConfig = {
|
|
4
4
|
inputs: Record<string, string>
|
|
@@ -87,7 +87,7 @@ export const generateCalulationMap = (config: ScriptConfig, opts?: { snapshotMod
|
|
|
87
87
|
{
|
|
88
88
|
id: key,
|
|
89
89
|
port: 'value',
|
|
90
|
-
|
|
90
|
+
disable_trigger_command: config.disabled_triggers?.[key] ? true : undefined,
|
|
91
91
|
},
|
|
92
92
|
],
|
|
93
93
|
},
|
package/index.ts
CHANGED
|
@@ -1,10 +1,5 @@
|
|
|
1
|
-
export * from './types'
|
|
1
|
+
export type * from './types'
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
export {
|
|
6
|
-
|
|
7
|
-
export const linkData: ((dataGetter: () => Data) => DataLink) = (dataGetter) => ({
|
|
8
|
-
__typename: 'DataLink',
|
|
9
|
-
data: dataGetter,
|
|
10
|
-
})
|
|
3
|
+
export { makeId } from './utils/id'
|
|
4
|
+
export { generateDataCalculationMapEditorInfo } from './utils/calc'
|
|
5
|
+
export { linkData, useSystemData } from './utils/data'
|
package/package.json
CHANGED
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fugood/bricks-project",
|
|
3
|
-
"version": "2.21.0-beta.14.
|
|
3
|
+
"version": "2.21.0-beta.14.test10",
|
|
4
4
|
"main": "index.ts",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"build": "node scripts/build.js"
|
|
7
7
|
},
|
|
8
8
|
"dependencies": {
|
|
9
|
+
"@types/escodegen": "^0.0.10",
|
|
10
|
+
"@types/lodash": "^4.17.12",
|
|
9
11
|
"acorn": "^8.13.0",
|
|
10
12
|
"escodegen": "^2.1.0",
|
|
11
13
|
"lodash": "^4.17.4",
|
package/tools/deploy.ts
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { $ } from 'bun'
|
|
2
|
+
import { deployApp, deployModule } from '../api'
|
|
3
|
+
|
|
4
|
+
const cwd = process.cwd()
|
|
5
|
+
|
|
6
|
+
const unstagedChanges = await $`cd ${cwd} && git diff --name-only --diff-filter=ACMR`.text()
|
|
7
|
+
if (unstagedChanges) throw new Error('Unstaged changes found, please commit or stash your changes before deploying')
|
|
8
|
+
|
|
9
|
+
const commitId = (await $`cd ${cwd} && git rev-parse HEAD`.text()).trim()
|
|
10
|
+
const app = await Bun.file(`${cwd}/application.json`).json()
|
|
11
|
+
const stage = app.stage || 'production'
|
|
12
|
+
const config = await Bun.file(`${cwd}/.bricks/build/application-config.json`).json()
|
|
13
|
+
|
|
14
|
+
// ask for confirmation
|
|
15
|
+
const confirm = prompt('Are you sure you want to deploy? (y/n)')
|
|
16
|
+
if (confirm !== 'y') throw new Error('Deployment cancelled')
|
|
17
|
+
|
|
18
|
+
if (!app.type || app.type === 'application') {
|
|
19
|
+
await deployApp(stage, app.id, config, commitId)
|
|
20
|
+
console.log('App deployed')
|
|
21
|
+
} else if (app.type === 'module') {
|
|
22
|
+
await deployModule(stage, app.id, config, commitId)
|
|
23
|
+
console.log('Module deployed')
|
|
24
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { $ } from 'bun'
|
|
2
|
+
|
|
3
|
+
const cwd = process.cwd()
|
|
4
|
+
|
|
5
|
+
const libFiles = ['types', 'utils', 'index.ts']
|
|
6
|
+
|
|
7
|
+
await $`mkdir -p ${cwd}/project`
|
|
8
|
+
for (const file of libFiles) {
|
|
9
|
+
await $`cp -r ${__dirname}/../${file} ${cwd}/project`
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
console.log('Copied files to project/')
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
// eslint-disable-next-line import/no-extraneous-dependencies
|
|
2
|
+
import { app, BrowserWindow } from 'electron'
|
|
3
|
+
import { readFile } from 'fs/promises'
|
|
4
|
+
import { watchFile } from 'fs'
|
|
5
|
+
|
|
6
|
+
const cwd = process.cwd()
|
|
7
|
+
|
|
8
|
+
let config = JSON.parse(await readFile(`${cwd}/.bricks/build/application-config.json`))
|
|
9
|
+
|
|
10
|
+
const stage = process.env.BRICKS_STAGE || 'production'
|
|
11
|
+
|
|
12
|
+
const previewUrlMap = {
|
|
13
|
+
production: 'https://control.bricks.tools/applicationPreview.html',
|
|
14
|
+
beta: 'https://control-beta.bricks.tools/applicationPreview.html',
|
|
15
|
+
development: 'http://localhost:3006/dev-applicationPreview.html',
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
const previewUrl = previewUrlMap[stage]
|
|
19
|
+
if (!previewUrl) throw new Error(`Invalid BRICKS_STAGE: ${stage}`)
|
|
20
|
+
|
|
21
|
+
app.on('ready', () => {
|
|
22
|
+
const mainWindow = new BrowserWindow({ width: 1280, height: 768 })
|
|
23
|
+
mainWindow.loadURL(previewUrl)
|
|
24
|
+
|
|
25
|
+
const sendConfig = () => {
|
|
26
|
+
const payload = {
|
|
27
|
+
type: 'config',
|
|
28
|
+
configFile: { _originTitle: 'Test', ...config, title: Math.random().toString() },
|
|
29
|
+
workspace: { billing: { lock: {}, plan: 'free' } },
|
|
30
|
+
}
|
|
31
|
+
mainWindow.webContents.executeJavaScript(
|
|
32
|
+
`window.postMessage(JSON.stringify(${JSON.stringify(payload)}))`,
|
|
33
|
+
)
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
mainWindow.webContents.once('dom-ready', sendConfig)
|
|
37
|
+
|
|
38
|
+
watchFile(
|
|
39
|
+
`${cwd}/.bricks/build/application-config.json`,
|
|
40
|
+
{
|
|
41
|
+
bigint: false,
|
|
42
|
+
persistent: true,
|
|
43
|
+
interval: 1000,
|
|
44
|
+
},
|
|
45
|
+
async () => {
|
|
46
|
+
console.log('Detected config changed')
|
|
47
|
+
config = JSON.parse(await readFile(`${cwd}/.bricks/build/application-config.json`))
|
|
48
|
+
sendConfig()
|
|
49
|
+
},
|
|
50
|
+
)
|
|
51
|
+
})
|
package/tools/preview.ts
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { $ } from 'bun'
|
|
2
|
+
import { watch } from 'fs'
|
|
3
|
+
import { parseArgs } from 'util'
|
|
4
|
+
import { debounce } from 'lodash'
|
|
5
|
+
|
|
6
|
+
const { values } = parseArgs({
|
|
7
|
+
args: Bun.argv,
|
|
8
|
+
options: {
|
|
9
|
+
'skip-typecheck': {
|
|
10
|
+
type: 'boolean',
|
|
11
|
+
},
|
|
12
|
+
},
|
|
13
|
+
strict: true,
|
|
14
|
+
allowPositionals: true,
|
|
15
|
+
})
|
|
16
|
+
|
|
17
|
+
const useTypecheck = !values['skip-typecheck']
|
|
18
|
+
|
|
19
|
+
const compile = async () => {
|
|
20
|
+
if (useTypecheck) await $`bun typecheck`
|
|
21
|
+
await $`bun compile`
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
await compile()
|
|
25
|
+
|
|
26
|
+
const compileDebounced = debounce(compile, 500)
|
|
27
|
+
|
|
28
|
+
const cwd = process.cwd()
|
|
29
|
+
|
|
30
|
+
watch(`${cwd}/subspaces`, { recursive: true }, async (event, filename) => {
|
|
31
|
+
console.log(`Detected ${event} in ${filename}`)
|
|
32
|
+
compileDebounced()
|
|
33
|
+
})
|
|
34
|
+
|
|
35
|
+
const app = await Bun.file(`${cwd}/application.json`).json()
|
|
36
|
+
|
|
37
|
+
await $`BRICKS_STAGE=${app.stage || 'production'} bunx electron ${__dirname}/preview-main.mjs`
|