'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: 通过')