@open-pencil/cli
Advanced tools
| import { defineCommand } from 'citty' | ||
| import { rpc } from '../app-client' | ||
| import { bold, entity, fmtList, formatType, printError } from '../format' | ||
| interface SelectionNode { | ||
| id: string | ||
| name: string | ||
| type: string | ||
| width: number | ||
| height: number | ||
| xpath: string | null | ||
| } | ||
| export default defineCommand({ | ||
| meta: { description: 'Get current selection from the running app' }, | ||
| args: { | ||
| json: { type: 'boolean', description: 'Output as JSON' } | ||
| }, | ||
| async run({ args }) { | ||
| try { | ||
| const nodes = await rpc<SelectionNode[]>('selection') | ||
| if (args.json) { | ||
| console.log(JSON.stringify(nodes, null, 2)) | ||
| return | ||
| } | ||
| if (nodes.length === 0) { | ||
| console.log('\n No nodes selected.\n') | ||
| return | ||
| } | ||
| console.log('') | ||
| console.log(bold(` ${nodes.length} selected node${nodes.length !== 1 ? 's' : ''}`)) | ||
| console.log('') | ||
| console.log( | ||
| fmtList( | ||
| nodes.map((n) => ({ | ||
| header: entity(formatType(n.type), n.name, n.id), | ||
| details: { | ||
| size: `${n.width}×${n.height}`, | ||
| ...(n.xpath ? { xpath: n.xpath } : {}) | ||
| } | ||
| })) | ||
| ) | ||
| ) | ||
| console.log('') | ||
| } catch (error) { | ||
| printError(error) | ||
| process.exit(1) | ||
| } | ||
| } | ||
| }) |
+2
-2
| { | ||
| "name": "@open-pencil/cli", | ||
| "version": "0.11.6", | ||
| "version": "0.11.7", | ||
| "license": "MIT", | ||
@@ -18,3 +18,3 @@ "type": "module", | ||
| "dependencies": { | ||
| "@open-pencil/core": "^0.11.5", | ||
| "@open-pencil/core": "^0.11.7", | ||
| "agentfmt": "^0.1.3", | ||
@@ -21,0 +21,0 @@ "canvaskit-wasm": "^0.40.0", |
@@ -27,11 +27,3 @@ import { defineCommand } from 'citty' | ||
| meta: { | ||
| description: `Query nodes using XPath selectors | ||
| Examples: | ||
| open-pencil query file.fig "//FRAME" # All frames | ||
| open-pencil query file.fig "//FRAME[@width < 300]" # Frames narrower than 300px | ||
| open-pencil query file.fig "//COMPONENT[starts-with(@name, 'Button')]" # Components starting with Button | ||
| open-pencil query file.fig "//SECTION/FRAME" # Direct frame children of sections | ||
| open-pencil query file.fig "//SECTION//TEXT" # All text inside sections | ||
| open-pencil query file.fig "//*[@cornerRadius > 0]" # Any node with corner radius` | ||
| description: 'Query nodes using XPath selectors' | ||
| }, | ||
@@ -38,0 +30,0 @@ args: { |
+2
-0
@@ -15,2 +15,3 @@ #!/usr/bin/env bun | ||
| import query from './commands/query' | ||
| import selection from './commands/selection' | ||
| import tree from './commands/tree' | ||
@@ -39,2 +40,3 @@ import variables from './commands/variables' | ||
| pages, | ||
| selection, | ||
| tree, | ||
@@ -41,0 +43,0 @@ variables |
54207
1.41%23
4.55%1570
2.82%Updated