Giter Club home page Giter Club logo

sketch-plugin-boilerplate's Introduction

Image



Sketch Plugin Boilerplate

The Sketch Plugin Boilerplate is targeted at JS Developers, who want to create awesome plugins for Sketch, but don't want to have to go through all the Obj C frustrations to be able to do more complex stuff, like building GUIs, handling HTTP requests, etc.

I tried to use as little Obj C as possible, again, this is supposed to be a helpful starting point for JS developers.


This is meant as a starting point, so clone the repo, modify anything and everything to your needs and build an awesome Sketch plugin


Why

Sketch is awesome. And they provided us an awesome API to develop plugins. But as a JS Developer, there are still many things that are quiet hard to achieve. The main problem I keep hearing of is the ability to build custom user interfaces (GUIs), which requires some knowledge of how web views work in Obj C, how you can communicate with them and then a lot of boilerplate.

This repo should make it easier and faster to start new projects :)

Getting started

# Change to plugin folder
cd ~/Library/Application Support/com.bohemiancoding.sketch3/Plugins/

# Clone repo (as .sketchplugin!)
git clone https://github.com/julianburr/sketch-plugin-boilerplate.git sketch-plugin-boilerplate.sketchplugin
cd sketch-plugin-boilerplate.sketchplugin

# Install dependecies
yarn install

# ...and create a first build
yarn build

... and you are ready to go :)

Commands / Scripts

# Build and watch plugin (๐Ÿ”ฅ, no need to run build every time to see changes in Sketch!)
yarn start

# Build and watch webview(s) in browser
yarn start:webview

# Compile everything into correct folder structure to use it in Sketch
yarn build

# Run eslint --fix on the source directory
yarn lint-fix

# Run Jest tests (needs Sketch / sketchtool installed locally)
yarn test

For the rest, see package.json

Folder structure

Why is the folder structure as it is

The build structure follows Sketch's guidelines of how your plugin has to be structured. This makes development so much easier. All you have to do is to create the repo in your Sketch plugin folder (usually ~/Library/Application Support/com.bohemiancoding.sketch3/Plugins/) and start coding. The watch and build scripts automatically put everything in the right place so you see the changes immediately in Sketch :)

โ””โ”€โ”€โ”€ /__tests__ # Jest tests and assets (e.g. Sketch files, etc) that are used for test scenarios
โ””โ”€โ”€โ”€ /config # Here you will find all necessary configurations, feel free to adjust them to your needs! :)
โ”‚
โ””โ”€โ”€โ”€ /Contents  # This is the build folder that Sketch reads
โ”‚    โ””โ”€โ”€โ”€ /Resources  # Assets, frameworks, etc.
โ”‚    โ””โ”€โ”€โ”€ /Sketch  # plugin.js and manifest.json have to be here
โ”‚    
โ””โ”€โ”€โ”€ /scripts  # The npm scripts, also feel free to change to your needs, this is a boilerplate, not an end product!
โ”‚    โ””โ”€โ”€โ”€ /plugin  # For `yarn *:plugin` scripts
โ”‚    โ””โ”€โ”€โ”€ /webview
โ”‚    
โ””โ”€โ”€โ”€ /src  # Source code, split into the different parts of your plugin
โ”‚    โ””โ”€โ”€โ”€ /framework  # Any xcode cocoa frameworks you want to load into your plugin
โ”‚    โ””โ”€โ”€โ”€ /plugin  # The plugins JS source code
โ”‚    โ”‚    โ””โ”€โ”€โ”€ index.js  # By default, this will be used to bundle your production plugin.js file
โ”‚    โ””โ”€โ”€โ”€ /webview  # The source for possible web views
โ”‚    
โ””โ”€โ”€โ”€ package.json  # By default, the version of your package.json will be copied into the plugins manifest.json

Documentation

In progress

Roadmap / Todos

  • Create useful documentation (integrated into a simple github.io page)
  • Create tutorials for JS developers to get started with Sketch plugins
  • Implement testing (Jest?) - Note: using sketchtool for accessing Sketch files and running plugin commands, however using own util functions, since the node package does not seem to be maintained anymore (currently at version 39.x)
  • Migrate the webview build from webpack to rollup, so we only have one build system to care about
  • Re-Implement fetch polyfill (see master before merge for old solution with cocoa framework and plugin action handler)
  • Try to get rid of cocoa framework if feasable

About Testing

Testing is a bit of a question mark for Sketch plugins at the moment, as it's not that easy to unit test your plugin commands in the Sketch enviroment. I am currently working on a util library / plugin that lets you run and test Sketch commands with Jest or any similar JS unit testing framework. If you are interested, just hit me up, happy to share my progress on this and collaborate.

sketch-plugin-boilerplate's People

Contributors

julianburr avatar kaelig avatar peerjollux avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

sketch-plugin-boilerplate's Issues

Issue with build (.git related)

The build doesn't complete properly the first time because the frameworks directory is missing.

Perhaps you could add an empty hidden file (e.g. .foo) so that frameworks will be uploaded with the directory?

Quick-fix for anyone cloning is just to create frameworks directory locally (ie. in ~sketch-plugin-boilerplate/src/).

No effect for watch

Hello! In Mac OS Catalina, sketch version 59.1. When I use yarn start,there is no effect when I change something.
Please help me. Thank you!

Getting user input using 'require('sketch/ui')'

Hey @julianburr , I'm having trouble using the provided Sketch API reference to get a user input within sketch. I want to do something like this:

var UI = require('sketch/ui');
const response = UI.getStringFromUser("Enter a string", 'e.g. hello');

but when I run yarn build on the boilerplate, I get this error on build:

ModuleNotFoundError: Module not found: Error: Can't resolve 'sketch/ui'

Any suggestions would be much appreciated!!

How to inspect panel and/or window DOM via safari

This is such an awesome repo!

I'm having trouble inspecting the DOM and seeing any console errors for a panel/window. I can inspect the application via safari but it doesn't have the elements panel.

Any help would be greatly appreciated!

Thanks in advance,
Jono

yarn start:webview fails to compile

First of all, great boilerplate!

But I'm having a issue when I try start the webview via yarn. I get the following error:

$ node scripts/start-webview.js
Failed to compile.
Cannot read property 'indexOf' of undefined
error Command failed with exit code 1

Do you have any idea how to fix this? #5

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.