@fugood/bricks-project 2.22.0-beta.0 → 2.22.0-beta.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/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.1",
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": "c55f6effe15a6c481e6fc1147f8bff0c747169ef"
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'
@@ -42,6 +58,20 @@ app.on('ready', () => {
42
58
  mainWindow.webContents.executeJavaScript(
43
59
  `window.postMessage(JSON.stringify(${JSON.stringify(payload)}))`,
44
60
  )
61
+ if (takeScreenshotConfig) {
62
+ const { delay, width, height, path, closeAfter } = takeScreenshotConfig
63
+ setTimeout(() => {
64
+ console.log('Taking screenshot')
65
+ mainWindow.webContents.capturePage({ width, height }).then((image) => {
66
+ console.log('Writing screenshot to', path)
67
+ writeFile(path, image.toPNG())
68
+ if (closeAfter) {
69
+ console.log('Closing app')
70
+ app.quit()
71
+ }
72
+ })
73
+ }, delay)
74
+ }
45
75
  }
46
76
 
47
77
  mainWindow.webContents.once('dom-ready', sendConfig)
package/tools/preview.ts CHANGED
@@ -6,12 +6,13 @@ 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-delay': { type: 'string' },
12
+ 'screenshot-width': { type: 'string' },
13
+ 'screenshot-height': { type: 'string' },
14
+ 'screenshot-path': { type: 'string' },
15
+ 'screenshot-close-after': { type: 'boolean' },
15
16
  },
16
17
  strict: true,
17
18
  allowPositionals: true,
@@ -37,11 +38,22 @@ const watcher = watch(`${cwd}/subspaces`, { recursive: true }, async (event, fil
37
38
 
38
39
  const app = await Bun.file(`${cwd}/application.json`).json()
39
40
 
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`
41
+ let args: string[] = []
42
+ if (values['clear-cache']) args.push('--clear-cache')
43
+
44
+ if (values['screenshot-delay'] || values['screenshot-close-after']) {
45
+ args.push(`--take-screenshot`)
46
+ args.push(
47
+ JSON.stringify({
48
+ delay: Number(values['take-screenshot-delay']) || 1000,
49
+ width: Number(values['screenshot-width']) || 1920,
50
+ height: Number(values['screenshot-height']) || 1080,
51
+ path: values['screenshot-path'] || `${cwd}/screenshot.png`,
52
+ closeAfter: values['take-screenshot-close-after'] ?? true,
53
+ }),
54
+ )
45
55
  }
46
56
 
57
+ await $`BRICKS_STAGE=${app.stage || 'production'} bunx --bun electron ${__dirname}/preview-main.mjs ${args}`
58
+
47
59
  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 */