Fix eval response unwrapping and export_jsx page selection

- eval CLI was typing rpc result as {ok, result} but the bridge
  already unwraps to the inner value — use rpc<unknown> directly
- export_jsx defaults to current page children, not first page
- Fix import ordering in server.ts (doc comment above imports)
This commit is contained in:
Danila Poyarkov 2026-03-07 20:51:53 +03:00
parent b6c922e335
commit 2b525b816b
2 changed files with 7 additions and 6 deletions

View file

@ -41,12 +41,12 @@ export default defineCommand({
}
if (isAppMode(args.file)) {
const response = await rpc<{ ok: boolean; result?: unknown; error?: string }>('eval', { code })
if (!args.quiet && response.result !== undefined) {
const result = await rpc<unknown>('eval', { code })
if (!args.quiet && result !== undefined && result !== null) {
if (args.json || !process.stdout.isTTY) {
console.log(JSON.stringify(response.result, null, 2))
console.log(JSON.stringify(result, null, 2))
} else {
console.log(response.result)
console.log(result)
}
}
return

View file

@ -1,4 +1,3 @@
import { makeFigmaFromStore } from '@/automation/figma-factory'
/**
* Browser-side automation handler.
*
@ -15,6 +14,7 @@ import {
sceneNodeToJSX
} from '@open-pencil/core'
import { makeFigmaFromStore } from '@/automation/figma-factory'
import type { EditorStore } from '@/stores/editor'
import type { ExportFormat } from '@open-pencil/core'
@ -107,7 +107,8 @@ export function connectAutomation(getStore: () => EditorStore) {
if (command === 'export_jsx') {
const jsxArgs = args as { nodeIds?: string[]; style?: string } | undefined
const style = (jsxArgs?.style ?? 'openpencil') as 'openpencil' | 'tailwind'
const nodeIds = jsxArgs?.nodeIds ?? store.graph.getPages()[0]?.childIds ?? []
const currentPage = store.graph.getNode(store.state.currentPageId)
const nodeIds = jsxArgs?.nodeIds ?? currentPage?.childIds ?? []
const jsx =
nodeIds.length === 1
? sceneNodeToJSX(nodeIds[0], store.graph, style)