@fugood/bricks-project 2.21.0-beta.14.test1 → 2.21.0-beta.14.test11
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 +93 -76
- package/types/canvas.ts +4 -4
- package/types/common.ts +12 -9
- package/types/data-calc.ts +33 -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
|
|
@@ -211,23 +293,31 @@ export const compile = (app: Application) => {
|
|
|
211
293
|
brickId: itemBrick.brickId,
|
|
212
294
|
brickIdPrefix: itemBrick.brickIdPrefix,
|
|
213
295
|
templateKey: itemBrick.templateKey,
|
|
296
|
+
frame: itemBrick.frame,
|
|
214
297
|
property: compileProperty(itemBrick.property),
|
|
298
|
+
propertyMapping: itemBrick.propertyMapping,
|
|
215
299
|
animation: compileAnimations(itemBrick.templateKey, itemBrick.animation || {}),
|
|
216
300
|
outlet: compileOutlets(itemBrick.templateKey, itemBrick.outlets || {}),
|
|
217
301
|
eventMap: compileEvents(itemBrick.templateKey, itemBrick.eventMap || {}, {
|
|
218
302
|
camelCase: true,
|
|
219
303
|
}),
|
|
220
|
-
stateGroup: itemBrick.stateGroup.
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
304
|
+
stateGroup: itemBrick.stateGroup.reduce((acc, stateGroup) => {
|
|
305
|
+
acc[stateGroup.id] = {
|
|
306
|
+
title: stateGroup.title,
|
|
307
|
+
description: stateGroup.description,
|
|
308
|
+
override: stateGroup.override,
|
|
309
|
+
break: stateGroup.break,
|
|
310
|
+
commented: stateGroup.disabled,
|
|
311
|
+
conds: compileSwitchConds(itemBrick.templateKey, stateGroup.conds || []),
|
|
312
|
+
property: compileProperty(stateGroup.property),
|
|
313
|
+
animation: compileAnimations(itemBrick.templateKey, stateGroup.animation || {}),
|
|
314
|
+
outlet: compileOutlets(itemBrick.templateKey, stateGroup.outlets || {}),
|
|
315
|
+
eventMap: compileEvents(itemBrick.templateKey, stateGroup.eventMap || {}, {
|
|
316
|
+
camelCase: true,
|
|
317
|
+
}),
|
|
318
|
+
}
|
|
319
|
+
return acc
|
|
320
|
+
}, {}),
|
|
231
321
|
})
|
|
232
322
|
if (Array.isArray(brickItems.brickList)) {
|
|
233
323
|
const brickList = (brickItems.brickList || []).map(buildList)
|
|
@@ -252,7 +342,7 @@ export const compile = (app: Application) => {
|
|
|
252
342
|
animation: compileAnimations(brick.templateKey, brick.animation || {}),
|
|
253
343
|
event_map: compileEvents(brick.templateKey, brick.events || {}),
|
|
254
344
|
outlet: compileOutlets(brick.templateKey, brick.outlets || {}),
|
|
255
|
-
state_group: brick.switches
|
|
345
|
+
state_group: brick.switches?.reduce((acc, switchCase) => {
|
|
256
346
|
acc[switchCase.id] = {
|
|
257
347
|
title: switchCase.title,
|
|
258
348
|
description: switchCase.description,
|
|
@@ -277,7 +367,7 @@ export const compile = (app: Application) => {
|
|
|
277
367
|
description: canvas.description,
|
|
278
368
|
property: compileProperty(canvas.property),
|
|
279
369
|
event_map: compileEvents('CANVAS', canvas.events || {}),
|
|
280
|
-
state_group: canvas.switches
|
|
370
|
+
state_group: canvas.switches?.reduce((acc, switchCase) => {
|
|
281
371
|
acc[switchCase.id] = {
|
|
282
372
|
title: switchCase.title,
|
|
283
373
|
description: switchCase.description,
|
|
@@ -291,7 +381,13 @@ export const compile = (app: Application) => {
|
|
|
291
381
|
}
|
|
292
382
|
return acc
|
|
293
383
|
}, {}),
|
|
294
|
-
item_list:
|
|
384
|
+
item_list: canvas.items.map((item) => ({
|
|
385
|
+
type: typeof item.item === 'function' ? 'brick' : 'subspace',
|
|
386
|
+
...(typeof item.item === 'function'
|
|
387
|
+
? { brick_id: (item.item as () => Brick)()?.id }
|
|
388
|
+
: { subspace_id: item.item }),
|
|
389
|
+
frame: compileFrame(item.frame),
|
|
390
|
+
})),
|
|
295
391
|
}
|
|
296
392
|
return map
|
|
297
393
|
}, {}),
|
|
@@ -300,10 +396,15 @@ export const compile = (app: Application) => {
|
|
|
300
396
|
template_key: generator.templateKey,
|
|
301
397
|
title: generator.title,
|
|
302
398
|
description: generator.description,
|
|
399
|
+
local_sync: generator.localSyncRunMode
|
|
400
|
+
? {
|
|
401
|
+
run_mode: generator.localSyncRunMode,
|
|
402
|
+
}
|
|
403
|
+
: undefined,
|
|
303
404
|
property: compileProperty(generator.property || {}),
|
|
304
405
|
event_map: compileEvents(generator.templateKey, generator.events || {}),
|
|
305
406
|
outlet: compileOutlets(generator.templateKey, generator.outlets || {}),
|
|
306
|
-
state_group: generator.switches
|
|
407
|
+
state_group: generator.switches?.reduce((acc, switchCase) => {
|
|
307
408
|
acc[switchCase.id] = {
|
|
308
409
|
title: switchCase.title,
|
|
309
410
|
description: switchCase.description,
|
|
@@ -325,10 +426,19 @@ export const compile = (app: Application) => {
|
|
|
325
426
|
map[data.id] = {
|
|
326
427
|
title: data.title,
|
|
327
428
|
description: data.description,
|
|
429
|
+
linked: data.metadata?.linked,
|
|
430
|
+
linkedFrom: data.metadata?.linkedFrom,
|
|
431
|
+
local_sync: data.localSyncUpdateMode
|
|
432
|
+
? {
|
|
433
|
+
update_mode: data.localSyncUpdateMode,
|
|
434
|
+
}
|
|
435
|
+
: undefined,
|
|
328
436
|
persist_data: data.persistData,
|
|
437
|
+
...compileRemoteUpdate(data.remoteUpdate),
|
|
329
438
|
routing: data.routing,
|
|
330
439
|
schema: data.schema,
|
|
331
440
|
type: data.type,
|
|
441
|
+
...compileKind(data.kind),
|
|
332
442
|
value: data.value,
|
|
333
443
|
event_map: compileEvents('PROPERTY_BANK', data.events || {}),
|
|
334
444
|
}
|
|
@@ -343,36 +453,49 @@ export const compile = (app: Application) => {
|
|
|
343
453
|
calc.type = 'general'
|
|
344
454
|
const mapCalc = dataCalc as DataCalculationMap
|
|
345
455
|
|
|
346
|
-
const generateInputPorts = (inputs
|
|
456
|
+
const generateInputPorts = (inputs) =>
|
|
347
457
|
inputs.reduce((acc, port) => {
|
|
348
|
-
if (!port.
|
|
458
|
+
if (!acc[port.key]) acc[port.key] = null
|
|
349
459
|
|
|
350
|
-
|
|
351
|
-
let
|
|
460
|
+
let sourceId
|
|
461
|
+
let sourceNode = port.source()
|
|
462
|
+
if (sourceNode?.__typename === 'DataCalculationData')
|
|
463
|
+
sourceId = (sourceNode as DataCalculationData).data().id
|
|
464
|
+
if (sourceNode?.__typename === 'DataCommand') sourceId = sourceNode.id
|
|
352
465
|
|
|
466
|
+
if (!sourceId) return acc
|
|
353
467
|
if (!acc[port.key]) acc[port.key] = []
|
|
468
|
+
|
|
354
469
|
acc[port.key].push({
|
|
355
|
-
id:
|
|
470
|
+
id: sourceId,
|
|
356
471
|
port: port.sourceKey,
|
|
357
|
-
|
|
472
|
+
disable_trigger_command: !port.trigger ? true : undefined,
|
|
358
473
|
})
|
|
359
474
|
return acc
|
|
360
475
|
}, {})
|
|
361
476
|
|
|
362
477
|
const generateOutputPorts = (outputs) =>
|
|
363
478
|
outputs.reduce((acc, port) => {
|
|
364
|
-
if (!port.
|
|
479
|
+
if (!acc[port.key]) acc[port.key] = null
|
|
365
480
|
|
|
481
|
+
let targetId
|
|
482
|
+
let targetNode = port.target()
|
|
483
|
+
if (targetNode?.__typename === 'DataCalculationData')
|
|
484
|
+
targetId = (targetNode as DataCalculationData).data().id
|
|
485
|
+
if (targetNode?.__typename === 'DataCommand') targetId = targetNode.id
|
|
486
|
+
|
|
487
|
+
if (!targetId) return acc
|
|
366
488
|
if (!acc[port.key]) acc[port.key] = []
|
|
489
|
+
|
|
367
490
|
acc[port.key].push({
|
|
368
|
-
id:
|
|
491
|
+
id: targetId,
|
|
369
492
|
port: port.targetKey,
|
|
370
493
|
})
|
|
371
494
|
return acc
|
|
372
495
|
}, {})
|
|
373
496
|
|
|
374
497
|
const getNodeId = (node) => {
|
|
375
|
-
if (node.__typename === 'DataCalculationData') return node.data.id
|
|
498
|
+
if (node.__typename === 'DataCalculationData') return node.data().id
|
|
376
499
|
if (node.__typename === 'DataCommand') return node.id
|
|
377
500
|
throw new Error(`Invalid node: ${JSON.stringify(node)}`)
|
|
378
501
|
}
|
|
@@ -385,7 +508,7 @@ export const compile = (app: Application) => {
|
|
|
385
508
|
description: dataNode.description,
|
|
386
509
|
type: 'data-node',
|
|
387
510
|
properties: {},
|
|
388
|
-
in: generateInputPorts(dataNode.inputs
|
|
511
|
+
in: generateInputPorts(dataNode.inputs),
|
|
389
512
|
out: generateOutputPorts(dataNode.outputs),
|
|
390
513
|
}
|
|
391
514
|
} else if (node.__typename === 'DataCommand') {
|
|
@@ -396,8 +519,8 @@ export const compile = (app: Application) => {
|
|
|
396
519
|
const args = commandNode.inputs.filter(
|
|
397
520
|
(input) =>
|
|
398
521
|
typeof input.source !== 'function' ||
|
|
399
|
-
input.source()?.__typename !== 'DataCalculationData' &&
|
|
400
|
-
|
|
522
|
+
(input.source()?.__typename !== 'DataCalculationData' &&
|
|
523
|
+
input.source()?.__typename !== 'DataCommand'),
|
|
401
524
|
)
|
|
402
525
|
const inputs = commandNode.inputs.filter(
|
|
403
526
|
(input) =>
|
|
@@ -416,7 +539,7 @@ export const compile = (app: Application) => {
|
|
|
416
539
|
return acc
|
|
417
540
|
}, {}),
|
|
418
541
|
},
|
|
419
|
-
in: generateInputPorts(inputs
|
|
542
|
+
in: generateInputPorts(inputs),
|
|
420
543
|
out: generateOutputPorts(commandNode.outputs),
|
|
421
544
|
}
|
|
422
545
|
}
|
|
@@ -439,15 +562,20 @@ export const compile = (app: Application) => {
|
|
|
439
562
|
const scriptCalc = dataCalc as DataCalculationScript
|
|
440
563
|
calc.type = 'script'
|
|
441
564
|
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
565
|
+
let code: string
|
|
566
|
+
try {
|
|
567
|
+
const program = parseAST(scriptCalc.code, { sourceType: 'module', ecmaVersion: 2020 })
|
|
568
|
+
// export function main() { ... }
|
|
569
|
+
const declarationBody = (
|
|
570
|
+
(program.body[0] as ExportNamedDeclaration).declaration as FunctionDeclaration
|
|
571
|
+
)?.body
|
|
572
|
+
code = escodegen.generate(declarationBody)
|
|
573
|
+
} catch (e) {
|
|
574
|
+
code = scriptCalc.code || ''
|
|
575
|
+
}
|
|
448
576
|
calc.script_config = {
|
|
449
577
|
note: scriptCalc.note,
|
|
450
|
-
code
|
|
578
|
+
code,
|
|
451
579
|
enable_async: scriptCalc.enableAsync,
|
|
452
580
|
inputs: scriptCalc.inputs.reduce((acc, input) => {
|
|
453
581
|
acc[input.data().id] = input.key
|
|
@@ -466,21 +594,30 @@ export const compile = (app: Application) => {
|
|
|
466
594
|
error: scriptCalc.error?.().id,
|
|
467
595
|
}
|
|
468
596
|
|
|
469
|
-
Object.assign(
|
|
470
|
-
|
|
471
|
-
|
|
597
|
+
Object.assign(
|
|
598
|
+
calc,
|
|
599
|
+
generateCalulationMap(calc.script_config, {
|
|
600
|
+
snapshotMode: process.env.BRICKS_SNAPSHOT_MODE === '1',
|
|
601
|
+
}),
|
|
602
|
+
)
|
|
472
603
|
}
|
|
473
604
|
map[dataCalc.id] = calc
|
|
474
605
|
return map
|
|
475
606
|
}, {}),
|
|
476
|
-
action_map: subspace.actions ||
|
|
607
|
+
action_map: subspace.actions || undefined,
|
|
477
608
|
event_map: compileEvents('', subspace.events || {}),
|
|
609
|
+
routing: subspace.dataRouting.reduce((acc, data) => {
|
|
610
|
+
acc[data.id] = { enabled_routing: true }
|
|
611
|
+
return acc
|
|
612
|
+
}, {}),
|
|
613
|
+
...compileModule(subspace),
|
|
478
614
|
}
|
|
479
615
|
return subspaceMap
|
|
480
616
|
}, {}),
|
|
481
617
|
root_subspace_id: app.rootSubspace.id,
|
|
482
618
|
fonts: app.fonts,
|
|
483
619
|
...compileApplicationSettings(app.settings),
|
|
620
|
+
test_map: app.metadata?.TEMP_test_map || {},
|
|
484
621
|
}
|
|
485
622
|
return config
|
|
486
623
|
}
|
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.test11",
|
|
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`
|