-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(sketch): add sketch package with color generation
- Loading branch information
Showing
4 changed files
with
125 additions
and
49 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,29 @@ | ||
## Usage | ||
|
||
- `yarn skpm:link` to link | ||
- `yarn develop` | ||
- `yarn skpm log -f` to tail logs | ||
- https://developer.sketch.com/guides/plugin-bundles/ | ||
- When removing layers, start at th e end as the indices get reordered each time | ||
a layer is removed | ||
# @carbon/sketch | ||
|
||
## Developing | ||
|
||
When working with this package, you will need to follow a couple of steps to get | ||
started. It's important that you have Sketch installed on your system before | ||
attempting any of these steps. | ||
|
||
1. Run `cd packages/sketch` to go into the package folder | ||
2. Run `yarn build` to build out the initial plugin | ||
3. Run `yarn skpm:link` to link the plugin to your Sketch plugin folder | ||
|
||
Afterwards, you can continue development by running `yarn develop`. | ||
|
||
## References | ||
|
||
- [API Reference](https://developer.sketch.com/reference/api) for the `sketch` | ||
module | ||
- [`Sketch-Headers`](https://github.com/abynim/Sketch-Headers) to determine | ||
methods on internal objects | ||
- [Plugin bundle guide](https://developer.sketch.com/guides/plugin-bundles/) for | ||
structuring a plugin and its menus | ||
|
||
## Tips & Tricks | ||
|
||
- Use `yarn skpm log -f` to tail logs from the Sketch plugin. Useful if you want | ||
to debug using `console.log` | ||
- When removing layers, start at th end as the indices get reordered each time a | ||
layer is removed |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
{ | ||
"name": "sketch", | ||
"name": "@carbon/sketch", | ||
"private": true, | ||
"version": "10.2.0", | ||
"license": "Apache-2.0", | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
/** | ||
* Copyright IBM Corp. 2018, 2018 | ||
* | ||
* This source code is licensed under the Apache-2.0 license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
import { Page } from 'sketch/dom'; | ||
|
||
/** | ||
* Find or create a page for the given document context and page name | ||
* @param {SketchContext} context | ||
* @param {string} pageName | ||
* @return {MSPage} | ||
*/ | ||
export function findOrCreatePage(context, pageName) { | ||
let [page] = Array.from(context.document.pages()).filter(page => { | ||
return '' + page.name() === pageName; | ||
}); | ||
|
||
if (!page) { | ||
page = new Page({ | ||
name: pageName, | ||
parent: context.document, | ||
}); | ||
} | ||
|
||
clearPage(page); | ||
page.selected = true; | ||
|
||
return page; | ||
} | ||
|
||
/** | ||
* Clear all the layers for a given page. | ||
* @param {MSPage} page | ||
* @return {MSPage} | ||
*/ | ||
export function clearPage(page) { | ||
if (!Array.isArray(page.layers) && page.layers().count() > 0) { | ||
for (let i = page.layers().count() - 1; i >= 0; i--) { | ||
const layer = page.layers().objectAtIndex(i); | ||
layer.removeFromParent(); | ||
} | ||
} | ||
return page; | ||
} |