Last active
November 15, 2018 14:36
-
-
Save bomberstudios/eefc4d576957c95b0d151fb50082435a to your computer and use it in GitHub Desktop.
UPDATE: Please use https://github.com/mathieudutour/sketch-file since this script was just a quick proof of concept and is not very futureproof. If you still decide to go ahead, this script will create a new, blank Sketch file, with proper UUIDs so you don't get a conflict creating multiple libraries from the same blank file)
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 characters
#!/usr/bin/env ruby | |
# Generate empty .sketch file, with brand new UUID | |
require 'fileutils' | |
DOC_UUID = `uuidgen`.strip | |
PAGE_UUID = `uuidgen`.strip | |
DOCUMENT_JSON = <<~HEREDOC | |
{ | |
"_class": "document", | |
"do_objectID": "#{DOC_UUID}", | |
"assets": { | |
"_class": "assetCollection", | |
"colors": [ | |
], | |
"gradients": [ | |
], | |
"imageCollection": { | |
"_class": "imageCollection", | |
"images": { | |
} | |
}, | |
"images": [ | |
] | |
}, | |
"colorSpace": 0, | |
"currentPageIndex": 0, | |
"foreignLayerStyles": [ | |
], | |
"foreignSymbols": [ | |
], | |
"foreignTextStyles": [ | |
], | |
"layerStyles": { | |
"_class": "sharedStyleContainer", | |
"objects": [ | |
] | |
}, | |
"layerSymbols": { | |
"_class": "symbolContainer", | |
"objects": [ | |
] | |
}, | |
"layerTextStyles": { | |
"_class": "sharedTextStyleContainer", | |
"objects": [ | |
] | |
}, | |
"pages": [ | |
{ | |
"_class": "MSJSONFileReference", | |
"_ref_class": "MSImmutablePage", | |
"_ref": "pages/#{PAGE_UUID}" | |
} | |
] | |
} | |
HEREDOC | |
META_JSON = <<~HEREDOC | |
{ | |
"commit": "120f488f43e85cae5c74eeae99d970dcf7fe443d", | |
"pagesAndArtboards": { | |
"#{PAGE_UUID}": { | |
"name": "Page 1", | |
"artboards": { | |
} | |
} | |
}, | |
"version": 105, | |
"fonts": [ | |
], | |
"compatibilityVersion": 99, | |
"app": "com.bohemiancoding.sketch3", | |
"autosaved": 0, | |
"variant": "NONAPPSTORE", | |
"created": { | |
"commit": "120f488f43e85cae5c74eeae99d970dcf7fe443d", | |
"appVersion": "51.2", | |
"build": 57519, | |
"app": "com.bohemiancoding.sketch3", | |
"compatibilityVersion": 99, | |
"version": 105, | |
"variant": "NONAPPSTORE" | |
}, | |
"saveHistory": [ | |
"NONAPPSTORE.57519" | |
], | |
"appVersion": "51.2", | |
"build": 57519 | |
} | |
HEREDOC | |
USER_JSON = <<~HEREDOC | |
{ | |
"document": { | |
"pageListHeight": 110 | |
}, | |
"#{PAGE_UUID}": { | |
"scrollOrigin": "{26, 26}", | |
"zoomValue": 1 | |
} | |
} | |
HEREDOC | |
PAGE_JSON = <<~HEREDOC | |
{ | |
"_class": "page", | |
"do_objectID": "#{PAGE_UUID}", | |
"booleanOperation": -1, | |
"exportOptions": { | |
"_class": "exportOptions", | |
"exportFormats": [ | |
], | |
"includedLayerIds": [ | |
], | |
"layerOptions": 0, | |
"shouldTrim": false | |
}, | |
"frame": { | |
"_class": "rect", | |
"constrainProportions": false, | |
"height": 0, | |
"width": 0, | |
"x": 0, | |
"y": 0 | |
}, | |
"isFixedToViewport": false, | |
"isFlippedHorizontal": false, | |
"isFlippedVertical": false, | |
"isLocked": false, | |
"isVisible": true, | |
"layerListExpandedType": 0, | |
"name": "Page 1", | |
"nameIsFixed": false, | |
"resizingConstraint": 63, | |
"resizingType": 0, | |
"rotation": 0, | |
"shouldBreakMaskChain": false, | |
"style": { | |
"_class": "style", | |
"endMarkerType": 0, | |
"miterLimit": 10, | |
"startMarkerType": 0, | |
"windingRule": 1 | |
}, | |
"hasClickThrough": true, | |
"layers": [ | |
], | |
"horizontalRulerData": { | |
"_class": "rulerData", | |
"base": 0, | |
"guides": [ | |
] | |
}, | |
"includeInCloudUpload": true, | |
"verticalRulerData": { | |
"_class": "rulerData", | |
"base": 0, | |
"guides": [ | |
] | |
} | |
} | |
HEREDOC | |
File.open("document.json", "w") { |file| file << DOCUMENT_JSON } | |
File.open("meta.json", "w") { |file| file << META_JSON } | |
File.open("user.json", "w") { |file| file << USER_JSON } | |
FileUtils.mkdir_p("pages") | |
File.open("pages/#{PAGE_UUID}.json", "w") { |file| file << PAGE_JSON } | |
%x(zip blank.sketch -r pages document.json meta.json user.json) | |
%x(rm -r pages document.json meta.json user.json) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment