How wuba/picasso works
Main components
• Sketch Plugin Host
– Sketch App (runs the plugin via SKPM)
– Plugin Manifest & Entry (webpack.skpm.config.js, src/manifest.json, src/index.js)
• Plugin UI / WebView
– resources/webview.html, .js, .css
– Presents options: selected/all artboards, target code type
• Plugin Controller & Orchestration
– src/index.js, src/parseArtboard/*, src/handleImage/*
– Receives UI commands, loads artboard JSON, filters layers, handles images
• Transformation Monorepo Packages (picasso-package/packages/*)
– parse (picasso-parse): transforms Sketch JSON into an intermediate DSL
– group (picasso-group): merges/organizes layer groups
– DSL definitions (picasso-dsl): exposes UI/Style/Structure components
– code generation (picasso-trans): turns DSL into Web/RN/weapp code
– browser integration (picasso-code / picasso-code-browser): loads transformations in-browser for preview
– Sketch DSL bindings (sketch-dsl): Sketch-specific data structures
• Output artifacts
– Generated source code (Web HTML/CSS/SCSS, WXSS/WXML, JSX/StyleSheet)
– Downloaded or copied back into UI
Relationships and data flow
• User triggers action in Sketch → UI WebView
• WebView → Plugin Controller
– Passes “artboard JSON + target type”
• Controller calls parseArtboard → intermediate representation (raw nodes + style metadata)
• Sequential pipeline through packages:
parse → layout → group → DSL assembly → code transform
• Final code returned to UI → written to disk or clipboard
Architectural patterns
• Monorepo (Lerna) managing loosely‐coupled packages
• Pipeline pattern: each package handles a stage in the transform
• Plugin pattern: SKPM + WebView for UI/host integration
• Adapter layers: sketch-dsl adapts Sketch JSON into a uniform DSL; picasso-trans adapts DSL into target language
Technologies & frameworks
• Node.js, SKPM (Sketch Plugin Manager), Webpack
• TypeScript for packages (tsconfig.json in each)
• JavaScript for plugin core (src/**/*.js)
• Lerna (monorepo)
• Web UI: plain HTML/JS/CSS loaded by Sketch
Detail is critical
• Packages from picasso-package/packages as individual pipeline stages
• Where resources fit (UI assets) and where top‐level src/handleImage and src/parseArtboard reside in orchestration
• File watchers / build (npm start, npm run build) as side notes if desired
[Sketch App]
↓
[Plugin WebView (resources/webview.html/js/css)]
↓ “command(targetType, artboardJSON)”
[Plugin Controller (src/index.js + parseArtboard + handleImage)]
↓ artboard JSON
┌───────────────────────────────────────────────────────────────┐
│ Transformation Pipeline (picasso-package) │
│ ┌───────────┐ ┌──────────────┐ ┌────────────┐ │
│ │ picasso- │→ │ picasso- │→ │ picasso- │→ ... │
│ │ parse │ │ layout │ │ group │ │
│ └───────────┘ └──────────────┘ └────────────┘ │
│ ↓ intermediate DSL │
│ ┌──────────────┐ ┌───────────────┐ │
│ │ picasso-dsl │ →│ picasso-trans │ │
│ └──────────────┘ └───────────────┘ │
└───────────────────────────────────────────────────────────────┘
↓ generated code (HTML/CSS/SCSS, WXML/WXSS, JSX/Style)
[Output: files saved / clipboard / UI display]