Last active
June 13, 2017 12:30
-
-
Save MrPeak/8ddd419bdb77fb9a3bf3b850a6d52927 to your computer and use it in GitHub Desktop.
Revisions
-
MrPeak renamed this gist
Jun 13, 2017 . 1 changed file with 0 additions and 0 deletions.There are no files selected for viewing
File renamed without changes. -
MrPeak created this gist
May 22, 2017 .There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,36 @@ const fs = require('fs'); // lib to read and write to the zip const JSZip = require('jszip'); fs.readFile('Untitled3.sketch', function(err, data) { if(err) throw err; JSZip.loadAsync(data).then(function(zip) { // zip contains a json file that describes all the directory & files in the zip file // read the top level page // hardcoding page because im lazy ;) const pagePath = Object.keys(zip.files)[1]; zip.file(pagePath) .async('string') .then(function(str) { const json = JSON.parse(str); // grab the first layer which in my case is a text layer const text = json.layers[0]; text.name = 'Changing the layer name'; // write the page json back to the file in the zip zip.file(pagePath, JSON.stringify(json)) // override the original file zip .generateNodeStream({ type:'nodebuffer', streamFiles:true }) .pipe(fs.createWriteStream('Untitled3.sketch')) .on('finish', () => { console.log('yay saved file. Open me in sketch to see the changes'); }); }); }); });