@fugood/bricks-project 2.21.0-beta.14.test9 → 2.21.0-beta.16-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/api/instance.ts +2 -2
- package/compile/index.ts +64 -10
- package/index.ts +1 -1
- package/package.json +2 -3
- package/tools/deploy.ts +14 -3
- package/tools/preview-main.mjs +3 -0
- package/tools/preview.ts +2 -1
- package/tools/pull.ts +28 -16
- package/types/bricks.ts +114 -89
- package/types/canvas.ts +1 -0
- package/types/common.ts +2 -2
- package/types/data.ts +19 -8
- package/types/generators.ts +142 -142
- package/types/subspace.ts +9 -1
- package/types/system.ts +54 -54
- package/utils/data.ts +27 -1
package/api/instance.ts
CHANGED
|
@@ -64,7 +64,7 @@ export const deployApp = async (
|
|
|
64
64
|
stage: Stage,
|
|
65
65
|
appId: string,
|
|
66
66
|
config: Config,
|
|
67
|
-
lastCommitId
|
|
67
|
+
lastCommitId?: string,
|
|
68
68
|
) => {
|
|
69
69
|
const app = await pullApp(stage, appId)
|
|
70
70
|
if (app.config?.bricks_project_last_commit_id === lastCommitId)
|
|
@@ -135,7 +135,7 @@ export const deployModule = async (
|
|
|
135
135
|
stage: Stage,
|
|
136
136
|
modId: string,
|
|
137
137
|
config: Config,
|
|
138
|
-
lastCommitId
|
|
138
|
+
lastCommitId?: string,
|
|
139
139
|
) => {
|
|
140
140
|
const mod = await pullModule(stage, modId)
|
|
141
141
|
if (mod.config?.bricks_project_last_commit_id === lastCommitId)
|
package/compile/index.ts
CHANGED
|
@@ -7,6 +7,7 @@ import { templateActionNameMap } from './action-name-map'
|
|
|
7
7
|
import type {
|
|
8
8
|
Application,
|
|
9
9
|
Data,
|
|
10
|
+
DataAssetKind,
|
|
10
11
|
Animation,
|
|
11
12
|
AnimationDef,
|
|
12
13
|
AnimationComposeDef,
|
|
@@ -98,23 +99,27 @@ const compileEvents = (
|
|
|
98
99
|
if (Object.hasOwn(action, 'params')) {
|
|
99
100
|
const actionDef = action as ActionWithParams
|
|
100
101
|
;(actionDef.params || []).forEach(({ input, value, mapping }) => {
|
|
101
|
-
|
|
102
|
+
const param = {
|
|
102
103
|
[camelCase ? 'inputToReceiver' : 'input_to_receiver']: handlerTemplateKey
|
|
103
104
|
? compileActionParam(handlerTemplateKey, action.__actionName, input)
|
|
104
105
|
: input,
|
|
105
|
-
[camelCase ? 'resultFromSender' : 'result_from_sender']:
|
|
106
|
-
|
|
107
|
-
}
|
|
106
|
+
[camelCase ? 'resultFromSender' : 'result_from_sender']:
|
|
107
|
+
mapping || compileProperty(value),
|
|
108
|
+
}
|
|
109
|
+
if (mapping) param[camelCase ? 'resultDataMapping' : 'result_data_mapping'] = true
|
|
110
|
+
parameterList.push(param)
|
|
108
111
|
})
|
|
109
112
|
} else if (Object.hasOwn(action, 'dataParams')) {
|
|
110
113
|
const actionDef = action as ActionWithDataParams
|
|
111
114
|
;(actionDef.dataParams || []).forEach(({ input, value, mapping }) => {
|
|
112
115
|
if (!input) return
|
|
113
|
-
|
|
116
|
+
const param = {
|
|
114
117
|
[camelCase ? 'inputToReceiver' : 'input_to_receiver']: input().id,
|
|
115
|
-
[camelCase ? 'resultFromSender' : 'result_from_sender']:
|
|
116
|
-
|
|
117
|
-
}
|
|
118
|
+
[camelCase ? 'resultFromSender' : 'result_from_sender']:
|
|
119
|
+
mapping || compileProperty(value),
|
|
120
|
+
}
|
|
121
|
+
if (mapping) param[camelCase ? 'resultDataMapping' : 'result_data_mapping'] = true
|
|
122
|
+
parameterList.push(param)
|
|
118
123
|
})
|
|
119
124
|
}
|
|
120
125
|
return {
|
|
@@ -199,9 +204,37 @@ const compileFrame = (frame: Canvas['items'][number]['frame']) => ({
|
|
|
199
204
|
render_out_of_viewport: frame.renderOutOfViewport,
|
|
200
205
|
})
|
|
201
206
|
|
|
207
|
+
const preloadTypes = [
|
|
208
|
+
'media-resource-image',
|
|
209
|
+
'media-resource-video',
|
|
210
|
+
'media-resource-audio',
|
|
211
|
+
'media-resource-file',
|
|
212
|
+
'lottie-file-uri',
|
|
213
|
+
'ggml-model-asset',
|
|
214
|
+
'gguf-model-asset',
|
|
215
|
+
'binary-asset',
|
|
216
|
+
]
|
|
217
|
+
|
|
202
218
|
const compileKind = (kind: Data['kind']) => {
|
|
203
219
|
const { type, ...rest } = kind || {}
|
|
204
220
|
if (!type) return {}
|
|
221
|
+
if (preloadTypes.includes(type)) {
|
|
222
|
+
const { preload, metadata } = kind as DataAssetKind
|
|
223
|
+
const result: any = { kind: type, ...rest }
|
|
224
|
+
if (preload) {
|
|
225
|
+
result.preload = {
|
|
226
|
+
type: preload.type,
|
|
227
|
+
hashType: preload.hashType,
|
|
228
|
+
}
|
|
229
|
+
if (preload.hashType) result.preload[preload.hashType] = preload.hash
|
|
230
|
+
}
|
|
231
|
+
// Handle metadata
|
|
232
|
+
if (type === 'gguf-model-asset') {
|
|
233
|
+
result._hfRepoInfo = metadata?.hfRepoInfo
|
|
234
|
+
}
|
|
235
|
+
return result
|
|
236
|
+
}
|
|
237
|
+
|
|
205
238
|
return { kind: type, ...rest }
|
|
206
239
|
}
|
|
207
240
|
|
|
@@ -240,13 +273,26 @@ const compileModule = (subspace: Subspace) => {
|
|
|
240
273
|
}
|
|
241
274
|
}
|
|
242
275
|
|
|
243
|
-
export const compile = (app: Application) => {
|
|
276
|
+
export const compile = async (app: Application) => {
|
|
277
|
+
await new Promise((resolve) => setImmediate(resolve, 0))
|
|
244
278
|
const config = {
|
|
245
279
|
title: app.name,
|
|
246
280
|
subspace_map: app.subspaces.reduce((subspaceMap, subspace) => {
|
|
247
281
|
subspaceMap[subspace.id] = {
|
|
248
282
|
title: subspace.title,
|
|
249
283
|
description: subspace.description,
|
|
284
|
+
_expanded: subspace.unexpanded
|
|
285
|
+
? {
|
|
286
|
+
brick: !subspace.unexpanded.brick,
|
|
287
|
+
generator: !subspace.unexpanded.generator,
|
|
288
|
+
canvas: subspace.unexpanded.canvas?.reduce((acc, canvas) => {
|
|
289
|
+
acc[canvas.id] = canvas?.id ? false : true
|
|
290
|
+
return acc
|
|
291
|
+
}, {}),
|
|
292
|
+
property_bank: !subspace.unexpanded.data,
|
|
293
|
+
property_bank_calc: !subspace.unexpanded.dataCalculation,
|
|
294
|
+
}
|
|
295
|
+
: undefined,
|
|
250
296
|
layout: {
|
|
251
297
|
width: subspace.layout?.width,
|
|
252
298
|
height: subspace.layout?.height,
|
|
@@ -289,6 +335,7 @@ export const compile = (app: Application) => {
|
|
|
289
335
|
brickId: itemBrick.brickId,
|
|
290
336
|
brickIdPrefix: itemBrick.brickIdPrefix,
|
|
291
337
|
templateKey: itemBrick.templateKey,
|
|
338
|
+
frame: itemBrick.frame,
|
|
292
339
|
property: compileProperty(itemBrick.property),
|
|
293
340
|
propertyMapping: itemBrick.propertyMapping,
|
|
294
341
|
animation: compileAnimations(itemBrick.templateKey, itemBrick.animation || {}),
|
|
@@ -382,6 +429,7 @@ export const compile = (app: Application) => {
|
|
|
382
429
|
? { brick_id: (item.item as () => Brick)()?.id }
|
|
383
430
|
: { subspace_id: item.item }),
|
|
384
431
|
frame: compileFrame(item.frame),
|
|
432
|
+
hidden: item.hidden,
|
|
385
433
|
})),
|
|
386
434
|
}
|
|
387
435
|
return map
|
|
@@ -564,7 +612,13 @@ export const compile = (app: Application) => {
|
|
|
564
612
|
const declarationBody = (
|
|
565
613
|
(program.body[0] as ExportNamedDeclaration).declaration as FunctionDeclaration
|
|
566
614
|
)?.body
|
|
567
|
-
code = escodegen.generate(declarationBody
|
|
615
|
+
code = escodegen.generate(declarationBody, {
|
|
616
|
+
format: {
|
|
617
|
+
indent: { style: ' ' },
|
|
618
|
+
semicolons: false,
|
|
619
|
+
},
|
|
620
|
+
comment: true,
|
|
621
|
+
})
|
|
568
622
|
} catch (e) {
|
|
569
623
|
code = scriptCalc.code || ''
|
|
570
624
|
}
|
package/index.ts
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fugood/bricks-project",
|
|
3
|
-
"version": "2.21.0-beta.
|
|
3
|
+
"version": "2.21.0-beta.16-1",
|
|
4
4
|
"main": "index.ts",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"build": "node scripts/build.js"
|
|
@@ -12,6 +12,5 @@
|
|
|
12
12
|
"escodegen": "^2.1.0",
|
|
13
13
|
"lodash": "^4.17.4",
|
|
14
14
|
"uuid": "^8.3.1"
|
|
15
|
-
}
|
|
16
|
-
"devDependencies": {}
|
|
15
|
+
}
|
|
17
16
|
}
|
package/tools/deploy.ts
CHANGED
|
@@ -3,10 +3,21 @@ import { deployApp, deployModule } from '../api'
|
|
|
3
3
|
|
|
4
4
|
const cwd = process.cwd()
|
|
5
5
|
|
|
6
|
-
const
|
|
7
|
-
|
|
6
|
+
const { exitCode } = await $`cd ${cwd} && git status`.nothrow()
|
|
7
|
+
const isGitRepo = exitCode === 0
|
|
8
|
+
|
|
9
|
+
let commitId = ''
|
|
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
|
+
|
|
15
|
+
commitId = (await $`cd ${cwd} && git rev-parse HEAD`.text()).trim()
|
|
16
|
+
} else {
|
|
17
|
+
const confirmContinue = prompt('No git repository found, continue? (y/n)')
|
|
18
|
+
if (confirmContinue !== 'y') throw new Error('Deployment cancelled')
|
|
19
|
+
}
|
|
8
20
|
|
|
9
|
-
const commitId = (await $`cd ${cwd} && git rev-parse HEAD`.text()).trim()
|
|
10
21
|
const app = await Bun.file(`${cwd}/application.json`).json()
|
|
11
22
|
const stage = app.stage || 'production'
|
|
12
23
|
const config = await Bun.file(`${cwd}/.bricks/build/application-config.json`).json()
|
package/tools/preview-main.mjs
CHANGED
|
@@ -20,6 +20,7 @@ if (!previewUrl) throw new Error(`Invalid BRICKS_STAGE: ${stage}`)
|
|
|
20
20
|
|
|
21
21
|
app.on('ready', () => {
|
|
22
22
|
const mainWindow = new BrowserWindow({ width: 1280, height: 768 })
|
|
23
|
+
mainWindow.setBackgroundColor('#333')
|
|
23
24
|
mainWindow.loadURL(previewUrl)
|
|
24
25
|
|
|
25
26
|
const sendConfig = () => {
|
|
@@ -35,6 +36,8 @@ app.on('ready', () => {
|
|
|
35
36
|
|
|
36
37
|
mainWindow.webContents.once('dom-ready', sendConfig)
|
|
37
38
|
|
|
39
|
+
mainWindow.on('close', () => app.quit())
|
|
40
|
+
|
|
38
41
|
watchFile(
|
|
39
42
|
`${cwd}/.bricks/build/application-config.json`,
|
|
40
43
|
{
|
package/tools/preview.ts
CHANGED
|
@@ -27,7 +27,7 @@ const compileDebounced = debounce(compile, 500)
|
|
|
27
27
|
|
|
28
28
|
const cwd = process.cwd()
|
|
29
29
|
|
|
30
|
-
watch(`${cwd}/subspaces`, { recursive: true }, async (event, filename) => {
|
|
30
|
+
const watcher = watch(`${cwd}/subspaces`, { recursive: true }, async (event, filename) => {
|
|
31
31
|
console.log(`Detected ${event} in ${filename}`)
|
|
32
32
|
compileDebounced()
|
|
33
33
|
})
|
|
@@ -35,3 +35,4 @@ watch(`${cwd}/subspaces`, { recursive: true }, async (event, filename) => {
|
|
|
35
35
|
const app = await Bun.file(`${cwd}/application.json`).json()
|
|
36
36
|
|
|
37
37
|
await $`BRICKS_STAGE=${app.stage || 'production'} bunx electron ${__dirname}/preview-main.mjs`
|
|
38
|
+
watcher.close()
|
package/tools/pull.ts
CHANGED
|
@@ -15,24 +15,34 @@ const { files, lastCommitId } =
|
|
|
15
15
|
? await pullModuleProject(stage, app.id)
|
|
16
16
|
: await pullApplicationProject(stage, app.id)
|
|
17
17
|
|
|
18
|
-
const
|
|
19
|
-
|
|
20
|
-
.match(/^[a-f0-9]{40}$/)
|
|
18
|
+
const { exitCode } = await $`cd ${cwd} && git status`.nothrow()
|
|
19
|
+
const isGitRepo = exitCode === 0
|
|
21
20
|
|
|
22
|
-
|
|
21
|
+
let useMain = false
|
|
22
|
+
if (isGitRepo) {
|
|
23
|
+
const found = (await $`cd ${cwd} && git rev-list -1 ${lastCommitId}`.nothrow().text())
|
|
24
|
+
.trim()
|
|
25
|
+
.match(/^[a-f0-9]{40}$/)
|
|
23
26
|
|
|
24
|
-
|
|
27
|
+
const commitId = (await $`cd ${cwd} && git rev-parse HEAD`.text()).trim()
|
|
25
28
|
|
|
26
|
-
|
|
29
|
+
if (commitId === lastCommitId) throw new Error('Commit not changed')
|
|
27
30
|
|
|
28
|
-
|
|
31
|
+
const branchName = 'BRICKS_PROJECT_try-pull-application'
|
|
29
32
|
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
+
await $`cd ${cwd} && git branch -D ${branchName}`.nothrow()
|
|
34
|
+
|
|
35
|
+
if (found) {
|
|
36
|
+
await $`cd ${cwd} && git checkout -b ${branchName} ${lastCommitId}`.nothrow()
|
|
37
|
+
} else {
|
|
38
|
+
await $`cd ${cwd} && git checkout -b ${branchName}`
|
|
39
|
+
useMain = true
|
|
40
|
+
}
|
|
33
41
|
} else {
|
|
34
|
-
|
|
35
|
-
|
|
42
|
+
const confirmContinue = prompt(
|
|
43
|
+
'No git repository found, so it will not be safe to pull, continue? (y/n)',
|
|
44
|
+
)
|
|
45
|
+
if (confirmContinue !== 'y') throw new Error('Pull cancelled')
|
|
36
46
|
}
|
|
37
47
|
|
|
38
48
|
await Promise.all(
|
|
@@ -44,8 +54,10 @@ await Promise.all(
|
|
|
44
54
|
),
|
|
45
55
|
)
|
|
46
56
|
|
|
47
|
-
|
|
48
|
-
await $`cd ${cwd} && git
|
|
49
|
-
|
|
50
|
-
|
|
57
|
+
if (isGitRepo) {
|
|
58
|
+
await $`cd ${cwd} && git add .`
|
|
59
|
+
await $`cd ${cwd} && git commit -m 'Apply ${app.name} file changes'`
|
|
60
|
+
if (!useMain) {
|
|
61
|
+
await $`cd ${cwd} && git merge main`
|
|
62
|
+
}
|
|
51
63
|
}
|