Files
image-workbench-desktop/scripts/ctx-menu-audit.js
T
qiqi 375a3b2c0d
Verify (Gitea) / gate (build · unit · facts) (push) Failing after 3m27s
docs(ctx-menu): 修正「替代入口」表述——工具栏也隐藏了 promptlib/style-source
我上一版文档写「提示词模板/样式节点需要时走工具栏插件菜单」,这是错的:
工具栏⊕菜单由 app.js 的 PLUGIN_TOOLBAR_HIDE = { promptlib: true, 'style-source': true } 按插件整体隐藏,
实际只剩 相册 / 网页 / 便利贴(与用户实测截图一致)。

- docs/standards/ctx-menu.md:新增 §3「两条独立的隐藏机制(别混)」表格(工具栏按插件、右键按入口),
  并修正排除名单里的替代入口说明
- scripts/ctx-menu-audit.js:补三条断言——PLUGIN_TOOLBAR_HIDE 存在且含 promptlib / style-source,
  防止工具栏那一侧被悄悄删掉
2026-11-27 23:05:28 +08:00

35 lines
2.3 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
'use strict'
// 右键菜单守卫(v3.26.109):插件会自动往菜单里注入节点类型与命令,宿主的排除名单一旦被
// 顺手删掉,菜单就会悄悄变回一长串用不到的入口(2026-11-27 刚按使用频率精简过一轮)。
// 这里做静态断言:名单常量在、两项过滤在、关键 id 在名单里。文档见 docs/standards/ctx-menu.md。
const fs = require('fs')
const path = require('path')
const app = fs.readFileSync(path.join(__dirname, '..', 'app.js'), 'utf8')
let fail = 0
const check = (name, cond, hint) => {
if (cond) { console.log(' PASS ' + name); return }
fail++
console.error(' FAIL ' + name + (hint ? ' —— ' + hint : ''))
}
console.log('ctx-menu: 右键菜单排除名单与过滤点')
check('CTX_SKIP_VARIANTS 名单存在', /const CTX_SKIP_VARIANTS = \[/.test(app), 'app.js 顶部应保留该常量(见 docs/standards/ctx-menu.md)')
check('CTX_SKIP_COMMANDS 名单存在', /const CTX_SKIP_COMMANDS = \[/.test(app))
check('插件节点过滤已应用', app.indexOf('pluginNodeVariants.filter((v) => !ctxSkippedVariant(v))') >= 0, '插件节点渲染处必须过滤')
check('插件命令过滤已应用', app.indexOf('wPluginCommands.filter((c) => !ctxSkippedCommand(c))') >= 0, '插件命令渲染处必须过滤')
const variants = (/const CTX_SKIP_VARIANTS = \[([^\]]*)\]/.exec(app) || [])[1] || ''
const commands = (/const CTX_SKIP_COMMANDS = \[([^\]]*)\]/.exec(app) || [])[1] || ''
for (const id of ['ptpl', 'style']) check('变体名单含 ' + id, variants.indexOf("'" + id + "'") >= 0)
for (const id of ['image-annotate', 'image-vectorize', 'collect-selected']) check('命令名单含 ' + id, commands.indexOf("'" + id + "'") >= 0)
// 工具栏侧:整个插件不进 ⊕ 菜单(PROMPTLIB / style-source)。两侧机制独立,都要守住。
const toolbarHide = (/const PLUGIN_TOOLBAR_HIDE = \{([^}]*)\}/.exec(app) || [])[1] || ''
check('PLUGIN_TOOLBAR_HIDE 存在', toolbarHide.length > 0, '工具栏插件菜单的隐藏名单')
check('工具栏隐藏 promptlib', toolbarHide.indexOf('promptlib') >= 0)
check('工具栏隐藏 style-source', toolbarHide.indexOf('style-source') >= 0)
if (fail) { console.error('ctx-menu-audit: ' + fail + ' 项失败'); process.exit(1) }
console.log('ctx-menu-audit: 通过')