mirror of
https://github.com/Comfy-Org/ComfyUI_frontend.git
synced 2026-01-26 19:09:52 +00:00
Fix widget label extraction (#2737)
This commit is contained in:
@@ -7,7 +7,7 @@ const config: PlaywrightTestConfig = {
|
|||||||
headless: true
|
headless: true
|
||||||
},
|
},
|
||||||
reporter: 'list',
|
reporter: 'list',
|
||||||
timeout: 10000,
|
timeout: 60000,
|
||||||
testMatch: /collect-i18n-.*\.ts/
|
testMatch: /collect-i18n-.*\.ts/
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -2,13 +2,20 @@ import * as fs from 'fs'
|
|||||||
|
|
||||||
import { comfyPageFixture as test } from '../browser_tests/fixtures/ComfyPage'
|
import { comfyPageFixture as test } from '../browser_tests/fixtures/ComfyPage'
|
||||||
import type { ComfyApi } from '../src/scripts/api'
|
import type { ComfyApi } from '../src/scripts/api'
|
||||||
import { ComfyInputsSpec, ComfyNodeDefImpl } from '../src/stores/nodeDefStore'
|
import { ComfyNodeDefImpl } from '../src/stores/nodeDefStore'
|
||||||
import { normalizeI18nKey } from '../src/utils/formatUtil'
|
import { normalizeI18nKey } from '../src/utils/formatUtil'
|
||||||
|
|
||||||
const localePath = './src/locales/en/main.json'
|
const localePath = './src/locales/en/main.json'
|
||||||
const nodeDefsPath = './src/locales/en/nodeDefs.json'
|
const nodeDefsPath = './src/locales/en/nodeDefs.json'
|
||||||
|
|
||||||
test('collect-i18n-node-defs', async ({ comfyPage }) => {
|
test('collect-i18n-node-defs', async ({ comfyPage }) => {
|
||||||
|
// Mock view route
|
||||||
|
comfyPage.page.route('**/view**', async (route) => {
|
||||||
|
await route.fulfill({
|
||||||
|
body: JSON.stringify({})
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
const nodeDefs: ComfyNodeDefImpl[] = Object.values(
|
const nodeDefs: ComfyNodeDefImpl[] = Object.values(
|
||||||
await comfyPage.page.evaluate(async () => {
|
await comfyPage.page.evaluate(async () => {
|
||||||
const api = window['app'].api as ComfyApi
|
const api = window['app'].api as ComfyApi
|
||||||
@@ -40,57 +47,46 @@ test('collect-i18n-node-defs', async ({ comfyPage }) => {
|
|||||||
const nodeLabels = {}
|
const nodeLabels = {}
|
||||||
|
|
||||||
for (const nodeDef of nodeDefs) {
|
for (const nodeDef of nodeDefs) {
|
||||||
const labels = await comfyPage.page.evaluate(async (def) => {
|
const inputNames = [
|
||||||
try {
|
...Object.values(nodeDef.inputs?.optional ?? {}),
|
||||||
// Create and add node to graph
|
...Object.values(nodeDef.inputs?.required ?? {})
|
||||||
const node = window['LiteGraph'].createNode(
|
]
|
||||||
def.name,
|
.filter((input) => input?.name)
|
||||||
def.display_name
|
.map((input) => input.name)
|
||||||
)
|
|
||||||
window['app'].graph.add(node)
|
|
||||||
|
|
||||||
// Get node instance and check for widgets
|
if (!inputNames.length) continue
|
||||||
const nodeInstance = window['app'].graph.getNodeById(node.id)
|
|
||||||
if (!nodeInstance?.widgets) return {}
|
|
||||||
|
|
||||||
const getAllInputNames = (inputs: ComfyInputsSpec) => {
|
try {
|
||||||
return [
|
const widgetsMappings = await comfyPage.page.evaluate(
|
||||||
...Object.values(inputs?.optional ?? {}),
|
(args) => {
|
||||||
...Object.values(inputs?.required ?? {})
|
const [nodeName, displayName, inputNames] = args
|
||||||
]
|
const node = window['LiteGraph'].createNode(nodeName, displayName)
|
||||||
.filter((input) => input && input.name !== undefined)
|
if (!node.widgets?.length) return {}
|
||||||
.map((input) => input.name)
|
return Object.fromEntries(
|
||||||
}
|
node.widgets
|
||||||
|
.filter((w) => w?.name && !inputNames.includes(w.name))
|
||||||
|
.map((w) => [w.name, w.label])
|
||||||
|
)
|
||||||
|
},
|
||||||
|
[nodeDef.name, nodeDef.display_name, inputNames]
|
||||||
|
)
|
||||||
|
|
||||||
// Get input names for comparison
|
// Format runtime widgets
|
||||||
const nodeInputNames = getAllInputNames(def.inputs)
|
const runtimeWidgets = Object.fromEntries(
|
||||||
|
Object.entries(widgetsMappings)
|
||||||
// Collect runtime-generated widget labels
|
|
||||||
const labels = {}
|
|
||||||
for (const widget of nodeInstance.widgets) {
|
|
||||||
if (!widget?.name) continue
|
|
||||||
const isRuntimeGenerated = !nodeInputNames.includes(widget.name)
|
|
||||||
if (isRuntimeGenerated) {
|
|
||||||
console.warn(widget.label)
|
|
||||||
const label = widget.label ?? widget.name
|
|
||||||
labels[widget.name] = label
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return labels
|
|
||||||
} finally {
|
|
||||||
// Cleanup
|
|
||||||
window['app'].graph.clear()
|
|
||||||
}
|
|
||||||
}, nodeDef)
|
|
||||||
|
|
||||||
// Format and store labels if any were found
|
|
||||||
if (Object.keys(labels ?? {}).length > 0) {
|
|
||||||
nodeLabels[nodeDef.name] = Object.fromEntries(
|
|
||||||
Object.entries(labels)
|
|
||||||
.sort((a, b) => a[0].localeCompare(b[0]))
|
.sort((a, b) => a[0].localeCompare(b[0]))
|
||||||
.map(([key, value]) => [normalizeI18nKey(key), { name: value }])
|
.map(([key, value]) => [normalizeI18nKey(key), { name: value }])
|
||||||
)
|
)
|
||||||
|
|
||||||
|
if (Object.keys(runtimeWidgets).length > 0) {
|
||||||
|
nodeLabels[nodeDef.name] = runtimeWidgets
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
console.error(
|
||||||
|
`Failed to extract widgets from ${nodeDef.name}: ${error}`
|
||||||
|
)
|
||||||
|
} finally {
|
||||||
|
await comfyPage.nextFrame()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user