Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Syncing shared styles #4

Closed
arronhunt opened this issue Nov 28, 2017 · 1 comment
Closed

Syncing shared styles #4

arronhunt opened this issue Nov 28, 2017 · 1 comment

Comments

@arronhunt
Copy link

I'm writing a small script to update a shared style and apply it to all layers that inherit it. Currently I can update the shared style, but I'm not quite sure how to "sync" it to all layers.

I see there's an UpdateStyles plugin, but that takes styles from an external document and applies them to another. I want to update shared styles within a document and then update all layers that use it.

@oscarotero
Copy link
Owner

If I understand correctly, you have updated the shared styles and want to apply these changes to all layers using this style, right?

You can do something like this: https://github.com/oscarotero/node-sketch/blob/master/plugins/UpdateStyles.js#L29 removing the code related with the new shared styles replacement. For example:

//Iterate with the sharedStyles
sketch.sharedStyles.forEach(sharedStyle => {

    //Update the referencies
    sketch.pages.forEach(page => {
        page
            .getAll(
                'style',
                style =>
                    style.sharedObjectID === sharedStyle.do_objectID
            )
            .forEach(style => style.applySharedStyle(newSharedStyle));
    });
});

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants