oscarotero / node-sketch

💎 Javascript library to manipulate sketch files
https://oscarotero.github.io/node-sketch/
MIT License
304 stars 23 forks source link

Preview is not updated after saving #28

Closed wholcman closed 4 years ago

wholcman commented 4 years ago

I'm trying to update text layers of sketch files dynamically like below.

const sketch = await ns.read(mySketchFile);
const page = sketch.pages[0].layers[0];
let my_layer = _.find(page.layers, { name: 'my_layer' });
my_layer.attributedString.string = myDataLayer;
sketch.save(myNewSketchFilePath)

The preview of the new sketch file exported is never updated as if updates have not been taken. I have to manually open the sketch file, save it and now the preview will be OK. You can see the issue in the demo replace-styles in the repo

Any ideas ?

oscarotero commented 4 years ago

The preview images are generated automatically by sketch (the app) when save the file. This library cannot update these images because it require to render the document to generate them. The only thing that can do is exporting the images with sketch.exportPreviews('path/to/export/').

wholcman commented 4 years ago

If I export by running sketch.exportPreviews('path/to/export/') after having updated a attributedString, the exports are not good. Do you know this issue ?!

The only solution found is to use directly the CLI sketchtool.

oscarotero commented 4 years ago

Yes, this library does not re-generate the previews after any change, only can export the previews existing currently in the file.