דלגו לתוכן

Exporter SDK

המייצא הוא קבוצה של פונקציות טהורות מעל DrawtonomySnapshot. הוספת פורמט יעד חדשה היא עצמאית: מודול חדש, כמה בדיקות ו-hook UI אופציונלי.

עמוד זה הוא התמצאות מהירה. המדריך המלא — ארכיטקטורה, API, דפוסי בדיקה, בדיקות ויזואליות של esmini — נמצא במאגר הציבורי:

מדריך מפתח המייצא (日本語)

Terminal window
git clone https://github.com/kosuke55/drawtonomy.git
cd drawtonomy
pnpm install
cd packages/drawtonomy-sdk
pnpm exec vitest exporter # watch mode
packages/drawtonomy-sdk/src/exporter/my-format.ts
import type { DrawtonomySnapshot } from '../types'
export function exportToMyFormat(snapshot: DrawtonomySnapshot): string {
// Walk shapes, emit your format.
return ''
}
packages/drawtonomy-sdk/__tests__/exporter/my-format.test.ts
import { describe, it, expect } from 'vitest'
import { exportToMyFormat } from '../../src/exporter/my-format'
import { createSnapshot, createLane } from '../../src/index'
describe('my-format exporter', () => {
it('emits expected payload for a single lane', () => {
const snapshot = createSnapshot([createLane(/* ... */)])
expect(exportToMyFormat(snapshot)).toContain('<expected/>')
})
})

שימוש בסצנה אמיתית כ-fixture

Section titled “שימוש בסצנה אמיתית כ-fixture”

קבצי drawtonomy.svg עושים הלוך-ושוב דרך ה-SDK, כך שאתם יכולים לכתוב סצנה בעורך ולהשתמש בה כקלט בדיקת רגרסיה:

import { readFileSync } from 'node:fs'
import { parseDrawtonomySvg } from '@drawtonomy/sdk'
const svg = readFileSync('./fixtures/my-scene.drawtonomy.svg', 'utf-8')
const snapshot = parseDrawtonomySvg(svg)!