@fugood/bricks-project 2.22.0-beta.0 → 2.22.0-beta.2

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fugood/bricks-project",
3
- "version": "2.22.0-beta.0",
3
+ "version": "2.22.0-beta.2",
4
4
  "main": "index.ts",
5
5
  "scripts": {
6
6
  "build": "node scripts/build.js"
@@ -13,5 +13,5 @@
13
13
  "lodash": "^4.17.4",
14
14
  "uuid": "^8.3.1"
15
15
  },
16
- "gitHead": "43f9ee596a089c0e7fa511c0d9d25251cde09d5f"
16
+ "gitHead": "a230efafdd33bc1dd02ed6397cf5741b318e172f"
17
17
  }
@@ -1,6 +1,6 @@
1
1
  // eslint-disable-next-line import/no-extraneous-dependencies
2
2
  import { app, BrowserWindow } from 'electron'
3
- import { readFile } from 'fs/promises'
3
+ import { readFile, writeFile } from 'fs/promises'
4
4
  import { watchFile } from 'fs'
5
5
  import { parseArgs } from 'util'
6
6
 
@@ -8,6 +8,7 @@ const { values } = parseArgs({
8
8
  args: process.argv,
9
9
  options: {
10
10
  'clear-cache': { type: 'boolean' },
11
+ 'take-screenshot': { type: 'string' },
11
12
  },
12
13
  strict: true,
13
14
  allowPositionals: true,
@@ -15,6 +16,21 @@ const { values } = parseArgs({
15
16
 
16
17
  const cwd = process.cwd()
17
18
 
19
+ let takeScreenshotConfig = null
20
+ try {
21
+ if (values['take-screenshot']) {
22
+ takeScreenshotConfig = JSON.parse(values['take-screenshot'])
23
+ if (!takeScreenshotConfig.path) takeScreenshotConfig.path = `${cwd}/screenshot.png`
24
+ if (!takeScreenshotConfig.width) takeScreenshotConfig.width = 1280
25
+ if (!takeScreenshotConfig.height) takeScreenshotConfig.height = 768
26
+ if (!takeScreenshotConfig.delay) takeScreenshotConfig.delay = 1000
27
+ }
28
+ } catch (e) {
29
+ console.error('Invalid take-screenshot config', e)
30
+ // eslint-disable-next-line unicorn/no-process-exit
31
+ process.exit(1)
32
+ }
33
+
18
34
  let config = JSON.parse(await readFile(`${cwd}/.bricks/build/application-config.json`))
19
35
 
20
36
  const stage = process.env.BRICKS_STAGE || 'production'
@@ -29,7 +45,9 @@ const previewUrl = previewUrlMap[stage]
29
45
  if (!previewUrl) throw new Error(`Invalid BRICKS_STAGE: ${stage}`)
30
46
 
31
47
  app.on('ready', () => {
32
- const mainWindow = new BrowserWindow({ width: 1280, height: 768 })
48
+ let show = true
49
+ if (takeScreenshotConfig?.headless) show = false
50
+ const mainWindow = new BrowserWindow({ width: 1280, height: 768, show })
33
51
  mainWindow.setBackgroundColor('#333')
34
52
  mainWindow.loadURL(previewUrl)
35
53
 
@@ -42,6 +60,20 @@ app.on('ready', () => {
42
60
  mainWindow.webContents.executeJavaScript(
43
61
  `window.postMessage(JSON.stringify(${JSON.stringify(payload)}))`,
44
62
  )
63
+ if (takeScreenshotConfig) {
64
+ const { delay, width, height, path, closeAfter } = takeScreenshotConfig
65
+ setTimeout(() => {
66
+ console.log('Taking screenshot')
67
+ mainWindow.webContents.capturePage({ width, height }).then((image) => {
68
+ console.log('Writing screenshot to', path)
69
+ writeFile(path, image.toPNG())
70
+ if (closeAfter) {
71
+ console.log('Closing app')
72
+ app.quit()
73
+ }
74
+ })
75
+ }, delay)
76
+ }
45
77
  }
46
78
 
47
79
  mainWindow.webContents.once('dom-ready', sendConfig)
package/tools/preview.ts CHANGED
@@ -6,12 +6,15 @@ import { debounce } from 'lodash'
6
6
  const { values } = parseArgs({
7
7
  args: Bun.argv,
8
8
  options: {
9
- 'skip-typecheck': {
10
- type: 'boolean',
11
- },
12
- 'clear-cache': {
13
- type: 'boolean',
14
- },
9
+ 'skip-typecheck': { type: 'boolean' },
10
+ 'clear-cache': { type: 'boolean' },
11
+ 'screenshot': { type: 'boolean' },
12
+ 'screenshot-delay': { type: 'string' },
13
+ 'screenshot-width': { type: 'string' },
14
+ 'screenshot-height': { type: 'string' },
15
+ 'screenshot-path': { type: 'string' },
16
+ 'screenshot-close-after': { type: 'boolean' },
17
+ 'screenshot-headless': { type: 'boolean' },
15
18
  },
16
19
  strict: true,
17
20
  allowPositionals: true,
@@ -37,11 +40,23 @@ const watcher = watch(`${cwd}/subspaces`, { recursive: true }, async (event, fil
37
40
 
38
41
  const app = await Bun.file(`${cwd}/application.json`).json()
39
42
 
40
-
41
- if (values['clear-cache']) {
42
- await $`BRICKS_STAGE=${app.stage || 'production'} bunx --bun electron ${__dirname}/preview-main.mjs --clear-cache`
43
- } else {
44
- await $`BRICKS_STAGE=${app.stage || 'production'} bunx --bun electron ${__dirname}/preview-main.mjs`
43
+ let args: string[] = []
44
+ if (values['clear-cache']) args.push('--clear-cache')
45
+
46
+ if (values['screenshot']) {
47
+ args.push(`--take-screenshot`)
48
+ args.push(
49
+ JSON.stringify({
50
+ delay: Number(values['screenshot-delay']) || 1000,
51
+ width: Number(values['screenshot-width']) || 1920,
52
+ height: Number(values['screenshot-height']) || 1080,
53
+ path: values['screenshot-path'] || `${cwd}/screenshot.png`,
54
+ closeAfter: values['screenshot-close-after'] ?? true,
55
+ headless: values['screenshot-headless'] ?? true,
56
+ }),
57
+ )
45
58
  }
46
59
 
60
+ await $`BRICKS_STAGE=${app.stage || 'production'} bunx --bun electron ${__dirname}/preview-main.mjs ${args}`
61
+
47
62
  watcher.close()
@@ -3183,6 +3183,7 @@ Default property:
3183
3183
  "cameraType": "back",
3184
3184
  "cameraPosition": "top",
3185
3185
  "selectColumns": 3,
3186
+ "selectAutoColumns": true,
3186
3187
  "sizeFactor": 1,
3187
3188
  "containerBackgroundColor": "#ffffff",
3188
3189
  "titleColor": "#000000",
@@ -3447,6 +3448,8 @@ Default property:
3447
3448
  doneButtonText?: string | DataLink
3448
3449
  /* Select columns */
3449
3450
  selectColumns?: number | DataLink
3451
+ /* Select auto calculate columns */
3452
+ selectAutoColumns?: boolean | DataLink
3450
3453
  /* Fixed model width, default is auto */
3451
3454
  fixedModelWidth?: number | DataLink
3452
3455
  /* Fixed model height, default is auto */
@@ -221,10 +221,6 @@ export const templateEventPropsMap = {
221
221
  'BRICK_GENERATIVE_MEDIA_ERROR', // type: string
222
222
  ],
223
223
  },
224
- BRICK_CHART_LINE: {},
225
- BRICK_CHART_BAR: {},
226
- BRICK_CHART_PIE: {},
227
- BRICK_CHART_PROGRESS: {},
228
224
  GENERATOR_TICK: {
229
225
  ticking: [
230
226
  'GENERATOR_TICK_COUNTDOWN', // type: number
@@ -332,7 +328,6 @@ export const templateEventPropsMap = {
332
328
  'GENERATOR_FILE_LIST_PATHS', // type: array
333
329
  ],
334
330
  },
335
- GENERATOR_URL_FILE_SYNC: {},
336
331
  GENERATOR_MEDIA_FLOW: {
337
332
  fetchError: [
338
333
  'GENERATOR_MEDIA_FLOW_ERROR', // type: string
@@ -548,11 +543,6 @@ export const templateEventPropsMap = {
548
543
  'GENERATOR_WEBRTC_TEXT_MESSAGE', // type: string
549
544
  ],
550
545
  },
551
- GENERATOR_TENSORFLOW_INFERENCE: {
552
- onError: [
553
- 'GENERATOR_TENSORFLOW_INFERENCE_ERROR_MESSAGE', // type: string
554
- ],
555
- },
556
546
  GENERATOR_WEB_CRAWLER: {},
557
547
  GENERATOR_SOUND_RECORDER: {
558
548
  chunk: [
@@ -563,11 +553,6 @@ export const templateEventPropsMap = {
563
553
  ],
564
554
  },
565
555
  GENERATOR_BLE_PERIPHERAL: {},
566
- GENERATOR_PROMPT: {
567
- onError: [
568
- 'GENERATOR_PROMPT_ERROR_MESSAGE', // type: string
569
- ],
570
- },
571
556
  GENERATOR_QUESTION: {
572
557
  onError: [
573
558
  'GENERATOR_QUESTION_ERROR_MESSAGE', // type: string