@fugood/bricks-project 2.21.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.
@@ -62,6 +62,26 @@ export const templateActionNameMap = {
62
62
  height: 'TAKE_SCREENSHOT_HEIGHT',
63
63
  saveProperty: 'TAKE_SCREENSHOT_SAVE_PROPERTY',
64
64
  },
65
+ STORAGE_SET: {
66
+ storageType: 'STORAGE_TYPE',
67
+ storageScope: 'STORAGE_SCOPE',
68
+ storageKey: 'STORAGE_KEY',
69
+ storageValue: 'STORAGE_VALUE',
70
+ },
71
+ STORAGE_RETRIEVE: {
72
+ storageType: 'STORAGE_TYPE',
73
+ storageScope: 'STORAGE_SCOPE',
74
+ storageKey: 'STORAGE_KEY',
75
+ result: 'STORAGE_RETRIEVE_RESULT',
76
+ defaultValue: 'STORAGE_RETRIEVE_DEFAULT_VALUE',
77
+ skipIfNotFound: 'STORAGE_RETRIEVE_SKIP_IF_NOT_FOUND',
78
+ },
79
+ STORAGE_DELETE: {
80
+ storageType: 'STORAGE_TYPE',
81
+ storageScope: 'STORAGE_SCOPE',
82
+ storageKey: 'STORAGE_KEY',
83
+ all: 'STORAGE_DELETE_ALL',
84
+ },
65
85
  CHANNEL_SUBSCRIBE: {
66
86
  key: 'CHANNEL_SUBSCRIBE_KEY',
67
87
  type: 'CHANNEL_SUBSCRIBE_TYPE',
package/compile/index.ts CHANGED
@@ -4,6 +4,7 @@ import type { ExportNamedDeclaration, FunctionDeclaration } from 'acorn'
4
4
  import escodegen from 'escodegen'
5
5
  import { generateCalulationMap } from './util'
6
6
  import { templateActionNameMap } from './action-name-map'
7
+ import { templateEventPropsMap } from '../utils/event-props'
7
8
  import type {
8
9
  Application,
9
10
  Data,
@@ -52,6 +53,17 @@ const compileProperty = (property, errorReference: string, result = {}) => {
52
53
  return property
53
54
  }
54
55
 
56
+ const compileEventActionValue = (templateKey, eventKey, value, errorReference) => {
57
+ const tmplEventProperties = templateEventPropsMap[templateKey]
58
+ const props = tmplEventProperties?.[eventKey]
59
+ if (!props) return compileProperty(value, errorReference)
60
+ if (props.includes(value)) return value
61
+ if (value?.startsWith(templateKey)) {
62
+ console.warn(`[Warning] Value start with template key but there is no event property: ${value} ${errorReference}`)
63
+ }
64
+ return compileProperty(value, errorReference)
65
+ }
66
+
55
67
  const convertOutletKey = (templateKey: string, key: string) => {
56
68
  return `${templateKey}_${_.snakeCase(key).toUpperCase()}`
57
69
  }
@@ -128,7 +140,7 @@ const compileEvents = (
128
140
  ? compileActionParam(handlerTemplateKey, action.__actionName, input)
129
141
  : input,
130
142
  [camelCase ? 'resultFromSender' : 'result_from_sender']:
131
- mapping || compileProperty(value, errorReference),
143
+ mapping || compileEventActionValue(handlerTemplateKey, key, value, errorReference),
132
144
  }
133
145
  if (mapping) param[camelCase ? 'resultDataMapping' : 'result_data_mapping'] = true
134
146
  parameterList.push(param)
@@ -140,7 +152,7 @@ const compileEvents = (
140
152
  const param = {
141
153
  [camelCase ? 'inputToReceiver' : 'input_to_receiver']: input().id,
142
154
  [camelCase ? 'resultFromSender' : 'result_from_sender']:
143
- mapping || compileProperty(value, errorReference),
155
+ mapping || compileEventActionValue(handlerTemplateKey, key, value, errorReference),
144
156
  }
145
157
  if (mapping) param[camelCase ? 'resultDataMapping' : 'result_data_mapping'] = true
146
158
  parameterList.push(param)
package/index.ts CHANGED
@@ -3,3 +3,4 @@ export type * from './types'
3
3
  export { makeId } from './utils/id'
4
4
  export { generateDataCalculationMapEditorInfo } from './utils/calc'
5
5
  export { linkData, useSystemData, createCanvasIdRef } from './utils/data'
6
+ export { templateEventPropsMap } from './utils/event-props'
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fugood/bricks-project",
3
- "version": "2.21.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": "7198652cb0d8217f36d88a755542300321dd2d74"
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()