Skip to content

Instantly share code, notes, and snippets.

@RyanParsley
Created May 4, 2015 21:22
Show Gist options
  • Select an option

  • Save RyanParsley/a30725b474ef6dee33bf to your computer and use it in GitHub Desktop.

Select an option

Save RyanParsley/a30725b474ef6dee33bf to your computer and use it in GitHub Desktop.
Parsing Sketch dumped json
var fs = require('fs');
var _ = require('lodash');
var filename = './dump.json';
var obj = JSON.parse(fs.readFileSync(filename, 'utf8'));
var layerStyles = obj.layerStyles.objects['<items>'];
// Write css file from layer styles
var styleName = '',
color = '',
styles = '';
for (var style in layerStyles){
styleName = obj.layerStyles.objects['<items>'][style].name;
if ( styleName.lastIndexOf('Color', 0) === 0){
color = obj.layerStyles.objects['<items>'][style].value.fills['<items>'][0].color.value;
styles += styleName +': '+ color + '\n';
}
}
fs.writeFile('color.css', styles, function(err) {
'use strict';
if(err) {
return console.log(err);
}
console.log('The css file was saved!');
});
// end writing css file from layer styles
// Write css file from text styles
var textStyles = obj.layerTextStyles.objects['<items>'];
var styleName = '',
fontFamily = '',
styles = '';
for (var style in textStyles){
styleName = obj.layerTextStyles.objects['<items>'][style].name;
fontFamily = obj.layerTextStyles.objects['<items>'][style].value.textStyle.NSFont.attributes.NSFontNameAttribute;
styles += styleName +' { font-family: '+ fontFamily + ';}\n';
}
fs.writeFile('font.css', styles, function(err) {
'use strict';
if(err) {
return console.log(err);
}
console.log('The css file was saved!');
});
// end writing css file from text styles
console.log(obj.currentPageIndex);
console.log('style', obj.layerStyles.objects['<items>'][0].name);
console.log('color', obj.layerStyles.objects['<items>'][0].value.fills['<items>'][0].color.value);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment