Home

Awesome

<p align="center"> <img src="https://raw.githubusercontent.com/omaralbeik/SketchGen/master/Assets/logo.svg?sanitize=true" title="SketchGen"> </p> <p align="center">SketchGen is a command line tool written in Swift that generates source code from sketch files.</p>

Features

tl;dr

SketchGen + Example/styles.sketch + Example/templates = Example/generated

After installation

git clone git@github.com:omaralbeik/SketchGen.git
cd SketchGen

sketchgen generate -s Example/styles.sketch ~/Desktop/Output Example/templates -v

open ~/Desktop/Output

Check generated source code in Desktop/Output

Installation

Homebrew (recommended)

brew tap omaralbeik/formulae
brew install sketchgen

Mint

mint install omaralbeik/SketchGen

Make

git clone https://github.com/omaralbeik/SketchGen.git
cd SketchGen
make install

Swift Package Manager

Use as CLI

git clone https://github.com/omaralbeik/SketchGen.git
cd SketchGen
swift run sketchgen

Use as dependency

Add the following to your Package.swift file's dependencies:

.package(url: "https://github.com/omaralbeik/SketchGen.git", from: "0.1.0"),

And then import wherever needed: import SketchGen

Usage

Parse a Sketch file

sketchkit parse <.sketch file path> <destination path>

# Example:
## Parse a a file named styles.sketch in Desktop and create a context.json in Desktop
sketchkit parse ~/Desktop/styles.sketch ~/Desktop

Generate source code

From .sketch file

sketchkit generate -s <.sketch file path> <destination path> <templates folder path>

# Example:
## Parse a file named styles.sketch in Desktop and create source code
## in Desktop/generated, using templates in /Desktop/templates folder:
sketchkit generate -s ~/Desktop/styles.sketch ~/Desktop/generated ~/Desktop/templates

From pre-generated context.json file

sketchkit generate -c <context.json file path> <destination path> <templates folder path>

# Example:
## Parse a context file named context.json in Desktop and create source code
## in Desktop/generated, using templates in /Desktop/templates folder:
sketchkit generate -c ~/Desktop/context.json ~/Desktop/generated ~/Desktop/templates

Flags

-v--verboseLog tech details for nerds
-h--helpShow help information

A word about conventions in your Sketch file

SketchGen expect the followingin your Sketch file:

Layer TypePrefixExamples of Valid Names
Colorgen_color_gen_color_primary, gen_color_dark_blue
Shadowgen_shadow_gen_shadow_small, gen_shadow_extra_large
Fontgen_font_gen_font_body, gen_font_heading_1
Bordergen_border_gen_border_small, gen_border_extra_large
Radiusgen_radius_gen_radius_small, gen_radius_extra_large

See Example/styles.sketch for an example.

Source code templates

Templates are written in Stencil templating language.

On top of Stencil's built-in filters, snakecased and camelcased filters are added for more flexible source code generation.

See Example/templates for examples for Swift, ObjC, CSS, and XML templates.

Attributions

This tool is powered by

Thanks

License

SketchGen is released under the MIT license. See LICENSE for more information.