Browse Source

修改结点文件结构

yichael 2 months ago
parent
commit
037ca0a9fa
29 changed files with 99 additions and 14 deletions
  1. 85 0
      doc/ef-compiler新增结点说明.md
  2. 0 0
      nodejs/ef-compiler/actions/adb-parser.js
  3. 0 0
      nodejs/ef-compiler/actions/delay-parser.js
  4. 0 0
      nodejs/ef-compiler/actions/echo-parser.js
  5. 0 0
      nodejs/ef-compiler/actions/for-parser.js
  6. 0 0
      nodejs/ef-compiler/actions/fun-parser.js
  7. 0 0
      nodejs/ef-compiler/actions/fun/chat/chat-history.js
  8. 0 0
      nodejs/ef-compiler/actions/fun/chat/ocr-chat.js
  9. 0 0
      nodejs/ef-compiler/actions/fun/chat/read-last-message.js
  10. 0 0
      nodejs/ef-compiler/actions/fun/chat/smart-chat-append.js
  11. 0 0
      nodejs/ef-compiler/actions/fun/img-bounding-box-location.js
  12. 1 1
      nodejs/ef-compiler/actions/fun/img-center-point-location.js
  13. 2 2
      nodejs/ef-compiler/actions/fun/img-cropping.js
  14. 0 0
      nodejs/ef-compiler/actions/fun/read-txt.js
  15. 0 0
      nodejs/ef-compiler/actions/fun/save-txt.js
  16. 0 0
      nodejs/ef-compiler/actions/fun/string-reg-location.js
  17. 0 0
      nodejs/ef-compiler/actions/if-parser.js
  18. 0 0
      nodejs/ef-compiler/actions/log-parser.js
  19. 0 0
      nodejs/ef-compiler/actions/random-parser.js
  20. 0 0
      nodejs/ef-compiler/actions/schedule-parser.js
  21. 0 0
      nodejs/ef-compiler/actions/set-parser.js
  22. 0 0
      nodejs/ef-compiler/actions/try-parser.js
  23. 0 0
      nodejs/ef-compiler/actions/while-parser.js
  24. 10 10
      nodejs/ef-compiler/ef-compiler.js
  25. 0 0
      nodejs/ef-compiler/expression-evaluator.js
  26. 0 0
      nodejs/ef-compiler/runtime-api.js
  27. 0 0
      nodejs/ef-compiler/sequence-runner.js
  28. 0 0
      nodejs/ef-compiler/workflow-json-parser.js
  29. 1 1
      static/device_list.json

+ 85 - 0
doc/ef-compiler新增结点说明.md

@@ -0,0 +1,85 @@
+# ef-compiler 新增结点说明
+
+---
+
+## 一、action 下添加结点
+
+在 `nodejs/ef-compiler/actions/` 下新建 `hello-parser.js`:
+
+```js
+const types = ['hello']
+
+function parse(action, parseContext) {
+  const parsed = { type: 'hello', value: action.value || '' }
+  return Object.assign({}, action, parsed)
+}
+
+async function execute(action, ctx) {
+  const msg = action.value ? String(action.value) : 'hello'
+  if (ctx.logMessage) await ctx.logMessage('[hello] ' + msg, ctx.folderPath)
+  return { success: true }
+}
+
+module.exports = { types, parse, execute }
+```
+
+在 `workflow-json-parser.js` 里:`actionModules` 加 `require('./actions/hello-parser.js')`;要中文名则在 `getActionName` 的 `typeNames` 加 `'hello': '打招呼'`。
+
+工作流 JSON:`{ "type": "hello", "value": "世界" }`
+
+---
+
+## 二、fun 下添加结点
+
+以添加 `test-fun` 为例,共 5 步(都在 `fun-parser.js` 里改,除了第 1 步)。
+
+**1. 实现**  
+在 `nodejs/ef-compiler/actions/fun/` 下新建 `test-fun.js`:
+
+```js
+async function executeTestFun() {
+  return { success: true, value: 'ok' }
+}
+module.exports = { executeTestFun }
+```
+
+**2. 登记**  
+脚本:`nodejs/ef-compiler/actions/fun-parser.js`  
+约第 6~14 行,在 `FUN_REGISTRY_TYPES` 数组里加 `'test-fun'`(可加在 `'string-press',` 后)。
+
+**3. 解析**  
+脚本:`fun-parser.js`  
+约第 34~118 行,在 `parse()` 的 `switch (action.type)` 里、`default:` 之前加:
+
+```js
+case 'test-fun':
+  parsed.variable = action.outVars?.[0] ? extractVarName(action.outVars[0]) : extractVarName(action.variable)
+  break
+```
+
+**4. 挂载**  
+脚本:`fun-parser.js`  
+约第 183~189 行,在 `get()` 的 `case 'io':` 的 mod 对象里加一行(例如在 `executeSaveTxt` 那行后面):  
+`executeTestFun: require(path.join(funcDir, 'test-fun.js')).executeTestFun`。(funcDir 已指向 `actions/fun`)
+
+**5. 执行**  
+脚本:`fun-parser.js`  
+约第 229 行起,在 `run()` 的 `switch (actionType)` 里加:
+
+```js
+case 'test-fun': {
+  const { executeTestFun } = get(funcDir, 'io')
+  const result = await executeTestFun()
+  if (!result.success) return result
+  const varName = action.outVars?.[0] ? extractVarName(action.outVars[0]) : extractVarName(action.variable)
+  if (varName && result.value != null) variableContext[varName] = String(result.value)
+  await logOutVars(action, variableContext, folderPath)
+  return { success: true }
+}
+```
+
+**显示名(可选)**  
+脚本:`nodejs/ef-compiler/workflow-json-parser.js`  
+约第 48~84 行,在 `getActionName` 的 `typeNames` 对象里加 `'test-fun': '测试'`。
+
+工作流里写:`{ "type": "test-fun", "variable": "out" }` 即可。

+ 0 - 0
nodejs/ef-compiler/components/actions/adb-parser.js → nodejs/ef-compiler/actions/adb-parser.js


+ 0 - 0
nodejs/ef-compiler/components/actions/delay-parser.js → nodejs/ef-compiler/actions/delay-parser.js


+ 0 - 0
nodejs/ef-compiler/components/actions/echo-parser.js → nodejs/ef-compiler/actions/echo-parser.js


+ 0 - 0
nodejs/ef-compiler/components/actions/for-parser.js → nodejs/ef-compiler/actions/for-parser.js


+ 0 - 0
nodejs/ef-compiler/components/actions/fun-parser.js → nodejs/ef-compiler/actions/fun-parser.js


+ 0 - 0
nodejs/ef-compiler/fun/chat/chat-history.js → nodejs/ef-compiler/actions/fun/chat/chat-history.js


+ 0 - 0
nodejs/ef-compiler/fun/chat/ocr-chat.js → nodejs/ef-compiler/actions/fun/chat/ocr-chat.js


+ 0 - 0
nodejs/ef-compiler/fun/chat/read-last-message.js → nodejs/ef-compiler/actions/fun/chat/read-last-message.js


+ 0 - 0
nodejs/ef-compiler/fun/chat/smart-chat-append.js → nodejs/ef-compiler/actions/fun/chat/smart-chat-append.js


+ 0 - 0
nodejs/ef-compiler/fun/img-bounding-box-location.js → nodejs/ef-compiler/actions/fun/img-bounding-box-location.js


+ 1 - 1
nodejs/ef-compiler/fun/img-center-point-location.js → nodejs/ef-compiler/actions/fun/img-center-point-location.js

@@ -10,7 +10,7 @@ const { spawnSync } = require('child_process')
 
 const configPath = process.env.STATIC_ROOT
   ? path.join(path.dirname(process.env.STATIC_ROOT), 'configs', 'config.js')
-  : path.join(__dirname, '..', '..', '..', 'configs', 'config.js')
+  : path.join(__dirname, '..', '..', '..', '..', 'configs', 'config.js')
 const projectRoot = path.dirname(path.dirname(path.resolve(configPath)))
 const config = fs.existsSync(configPath) ? require(configPath) : {}
 const imageMatchScriptPath = path.join(projectRoot, 'python', 'scripts', 'image-match.py')

+ 2 - 2
nodejs/ef-compiler/fun/img-cropping.js → nodejs/ef-compiler/actions/fun/img-cropping.js

@@ -6,12 +6,12 @@
 const path = require('path')
 const fs = require('fs')
 const { spawnSync } = require('child_process')
-const { captureScreenshot } = require('../../adb/adb-screencap.js')
+const { captureScreenshot } = require('../../../adb/adb-screencap.js')
 
 const tagName = 'img-cropping'
 const configPath = process.env.STATIC_ROOT
   ? path.join(path.dirname(process.env.STATIC_ROOT), 'configs', 'config.js')
-  : path.join(__dirname, '..', '..', '..', 'configs', 'config.js')
+  : path.join(__dirname, '..', '..', '..', '..', 'configs', 'config.js')
 const projectRoot = path.dirname(path.dirname(path.resolve(configPath)))
 const config = fs.existsSync(configPath) ? require(configPath) : {}
 const imgCropScriptPath = path.join(projectRoot, 'python', 'scripts', 'img-crop.py')

+ 0 - 0
nodejs/ef-compiler/fun/read-txt.js → nodejs/ef-compiler/actions/fun/read-txt.js


+ 0 - 0
nodejs/ef-compiler/fun/save-txt.js → nodejs/ef-compiler/actions/fun/save-txt.js


+ 0 - 0
nodejs/ef-compiler/fun/string-reg-location.js → nodejs/ef-compiler/actions/fun/string-reg-location.js


+ 0 - 0
nodejs/ef-compiler/components/actions/if-parser.js → nodejs/ef-compiler/actions/if-parser.js


+ 0 - 0
nodejs/ef-compiler/components/actions/log-parser.js → nodejs/ef-compiler/actions/log-parser.js


+ 0 - 0
nodejs/ef-compiler/components/actions/random-parser.js → nodejs/ef-compiler/actions/random-parser.js


+ 0 - 0
nodejs/ef-compiler/components/actions/schedule-parser.js → nodejs/ef-compiler/actions/schedule-parser.js


+ 0 - 0
nodejs/ef-compiler/components/actions/set-parser.js → nodejs/ef-compiler/actions/set-parser.js


+ 0 - 0
nodejs/ef-compiler/components/actions/try-parser.js → nodejs/ef-compiler/actions/try-parser.js


+ 0 - 0
nodejs/ef-compiler/components/actions/while-parser.js → nodejs/ef-compiler/actions/while-parser.js


+ 10 - 10
nodejs/ef-compiler/ef-compiler.js

@@ -25,23 +25,23 @@ if (fs.existsSync(configPath)) {
     }
   } catch (e) {}
 }
-const funcDir = path.join(__dirname, 'fun')
+const funcDir = path.join(__dirname, 'actions', 'fun')
 const DEFAULT_STEP_INTERVAL = 1000
 const DEFAULT_SCROLL_DISTANCE = 100
 const compilerConfig = { projectRoot, funcDir, adbInteractPath, nodeExePath, DEFAULT_STEP_INTERVAL, DEFAULT_SCROLL_DISTANCE }
 
 // --- 依赖 ---
-const setParser = require('./components/actions/set-parser.js')
-const expressionEvaluator = require('./components/expression-evaluator.js')
-const runtimeApi = require('./components/runtime-api.js')
-const workflowJsonParser = require('./components/workflow-json-parser.js')
-const sequenceRunner = require('./components/sequence-runner.js')
-const actions = require('./components/actions/fun-parser.js')
+const setParser = require('./actions/set-parser.js')
+const expressionEvaluator = require('./expression-evaluator.js')
+const runtimeApi = require('./runtime-api.js')
+const workflowJsonParser = require('./workflow-json-parser.js')
+const sequenceRunner = require('./sequence-runner.js')
+const actions = require('./actions/fun-parser.js')
 
 // --- 功能模块(fun 目录)与运行时 API ---
-const { matchImageAndGetCoordinate } = require('./fun/img-center-point-location.js')
-const { readTextFile } = require('./fun/read-txt.js')
-const { writeTextFile } = require('./fun/save-txt.js')
+const { matchImageAndGetCoordinate } = require('./actions/fun/img-center-point-location.js')
+const { readTextFile } = require('./actions/fun/read-txt.js')
+const { writeTextFile } = require('./actions/fun/save-txt.js')
 
 const electronAPI = runtimeApi.createElectronAPI({ matchImageAndGetCoordinate, readTextFile, writeTextFile }, compilerConfig)
 

+ 0 - 0
nodejs/ef-compiler/components/expression-evaluator.js → nodejs/ef-compiler/expression-evaluator.js


+ 0 - 0
nodejs/ef-compiler/components/runtime-api.js → nodejs/ef-compiler/runtime-api.js


+ 0 - 0
nodejs/ef-compiler/components/sequence-runner.js → nodejs/ef-compiler/sequence-runner.js


+ 0 - 0
nodejs/ef-compiler/components/workflow-json-parser.js → nodejs/ef-compiler/workflow-json-parser.js


+ 1 - 1
static/device_list.json

@@ -1,5 +1,5 @@
 {
   "devices": [
-    "192.168.0.107"
+    "192.168.42.129"
   ]
 }