├── LICENSE ├── README.md └── sketch-export-generator.sketchplugin └── Contents └── Sketch ├── export.js ├── handler.js └── manifest.json /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2015 Kang Chen (kangchen.me, satoriwild.com) 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | Sketch Export Generator 2 | ============================= 3 | 4 | ![alt text](http://philippehong.com/download/SketchExportGenerator.png "Logo Sketch Export Generator") 5 | 6 | A simple plugin for Sketch to generate export in iOS and Android with shortcuts. 7 | 8 | Update : 29/07/16 9 | 10 | Support Sketch 48.2 11 | 12 | Installation 13 | ------------ 14 | 15 | 1. Download the latest plugin by cloning this repo 16 | 17 | 2. Unzip it and open the `Sketch-export-generator.sketchplugin` file. 18 | 19 | Usage 20 | ----- 21 | 22 | ![alt text](http://philippehong.com/download/sketchgeneratorexport.gif "Logo Sketch Export Generator") 23 | 24 | 1. Select layers. 25 | 26 | 2. Tap the shortcut "Shift + Option + Command + E" or go to the menu: Plugins > Sketch Export Generator > Add iOS and Android Exports 27 | 28 | 29 | License 30 | ------- 31 | 32 | **Sketch Export Sizes Generator** is under MIT license. See the LICENSE file for more info. 33 | 34 | Author 35 | ------ 36 | 37 | Proudly made by [Philippe Hong](http://philippehong.com) and [Kang Chen](http://Kangchen.me) 38 | -------------------------------------------------------------------------------- /sketch-export-generator.sketchplugin/Contents/Sketch/export.js: -------------------------------------------------------------------------------- 1 | // The MIT License (MIT) 2 | // 3 | // Copyright (c) 2015 Philippe Hong (www.philippehong.com) & Kang Chen (kangchen.me, www.satoriwild.com) 4 | // 5 | // Permission is hereby granted, free of charge, to any person obtaining a copy 6 | // of this software and associated documentation files (the "Software"), to deal 7 | // in the Software without restriction, including without limitation the rights 8 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | // copies of the Software, and to permit persons to whom the Software is 10 | // furnished to do so, subject to the following conditions: 11 | // 12 | // The above copyright notice and this permission notice shall be included in all 13 | // copies or substantial portions of the Software. 14 | // 15 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | // SOFTWARE. 22 | 23 | var SIZES = []; // e.g. [16, 32, 128, 256, 512] 24 | var SCALES = []; 25 | 26 | function setScale(scales) { 27 | SCALES = scales; 28 | } 29 | 30 | function prepareExportSizes(layer, format) { 31 | 32 | var sizes = layer.exportOptions().exportFormats(); 33 | layer.exportOptions().removeAllExportFormats(); 34 | 35 | SCALES.forEach(function(scale) { 36 | addExportSize(layer, scale.size, scale.suffix, format); 37 | }); 38 | 39 | // add and remove a new export size to refresh UI 40 | layer.exportOptions().addExportFormat(); 41 | layer.exportOptions().removeExportFormat(layer.exportOptions().exportFormats().objectAtIndex(layer.exportOptions().exportFormats().count() -1)); 42 | } 43 | 44 | 45 | function addExportSize(layer, scale, suffix, format) { 46 | 47 | if ( !format || typeof(format) == "undefined") { 48 | format = "png"; 49 | } 50 | 51 | var size = layer.exportOptions().addExportFormat(); 52 | 53 | size.setName(suffix); 54 | 55 | size.setScale(scale); 56 | 57 | size.fileFormat = format; 58 | 59 | log(size.fileFormat); 60 | } 61 | 62 | function runExportIOS(context) { 63 | runExport(context); 64 | } 65 | 66 | function runExportAndroid(context) { 67 | runExport(context); 68 | } 69 | 70 | function runExportPDF(context) { 71 | runExport(context, "pdf"); 72 | } 73 | 74 | function runExportSVG(context) { 75 | runExport(context, "svg"); 76 | } 77 | 78 | 79 | function runExport(context, format) { 80 | 81 | var selectedLayers = context.selection; 82 | var selectedCount = selectedLayers.count(); 83 | 84 | if (selectedCount == 0) { 85 | //log('No layers are selected.'); 86 | return; 87 | } 88 | 89 | // use this if you want to override default scales for IOS and Android 90 | //prompt(); 91 | for (var i = 0; i < selectedCount; i++) { 92 | var layer = selectedLayers[i]; 93 | if (i != 0) { 94 | log(""); 95 | } 96 | prepareExportSizes(layer, format); 97 | } 98 | 99 | context.api().selectedDocument.selectedLayers.clear(); 100 | log("\nDone set export and cleared selection"); 101 | } -------------------------------------------------------------------------------- /sketch-export-generator.sketchplugin/Contents/Sketch/handler.js: -------------------------------------------------------------------------------- 1 | 2 | @import 'export.js' 3 | 4 | var exportIOS = function(context) { 5 | //setScale([1,2,3]); 6 | setScale([ 7 | {size: 1, suffix: ""}, 8 | {size: 2, suffix: "@2x"}, 9 | {size: 3, suffix: "@3x"} 10 | ]) 11 | 12 | runExportIOS(context); 13 | 14 | context.document.showMessage("iOS Exports added"); 15 | } 16 | 17 | var exportAndroid = function(context) { 18 | /* 19 | mdpi = ~160dpi = 1×, or 100% 20 | hdpi = ~240dpi = 1.5×, or 150% 21 | xhdpi = ~320dpi = 2×, or 200% 22 | xxhdpi = ~480dpi = 3×, or 300% 23 | xxxhdpi = ~640dpi = 4×, or 400% 24 | */ 25 | //setScale([1,1.5,2,3]); 26 | 27 | setScale([ 28 | {size: 1, suffix: "-mdpi"}, 29 | {size: 1.5, suffix: "-hdpi"}, 30 | {size: 2, suffix: "-xhdpi"}, 31 | {size: 3, suffix: "-xxhdpi"}, 32 | {size: 4, suffix: "-xxxhdpi"} 33 | ]) 34 | runExportAndroid(context); 35 | context.document.showMessage("Android Exports added"); 36 | } 37 | 38 | var exportAll = function(context) { 39 | 40 | setScale([ 41 | {size: 1, suffix: ""}, 42 | {size: 2, suffix: "@2x"}, 43 | {size: 3, suffix: "@3x"}, 44 | {size: 1, suffix: "-mdpi"}, 45 | {size: 1.5, suffix: "-hdpi"}, 46 | {size: 2, suffix: "-xhdpi"}, 47 | {size: 3, suffix: "-xxhdpi"}, 48 | {size: 4, suffix: "-xxxhdpi"} 49 | ]) 50 | runExport(context); 51 | context.document.showMessage("iOS and Android Exports added"); 52 | } 53 | 54 | var exportPDF = function(context) { 55 | setScale([ 56 | {size: 1, suffix: ""}, 57 | ]) 58 | 59 | runExportPDF(context); 60 | context.document.showMessage("PDF Export added"); 61 | } 62 | 63 | var exportSVG = function(context) { 64 | setScale([ 65 | {size: 1, suffix: ""}, 66 | ]) 67 | runExportSVG(context); 68 | context.document.showMessage("SVG Export added"); 69 | } 70 | 71 | var clear = function(context) { 72 | 73 | runClear(context); 74 | context.document.showMessage("Exports cleared"); 75 | } 76 | -------------------------------------------------------------------------------- /sketch-export-generator.sketchplugin/Contents/Sketch/manifest.json: -------------------------------------------------------------------------------- 1 | { 2 | "author" : "Philippe Hong, Kang Chen", 3 | "commands" : [ 4 | { 5 | "script" : "handler.js", 6 | "handler" : "exportIOS", 7 | "shortcut" : "option shift cmd i", 8 | "name" : "Add iOS Exports", 9 | "identifier" : "exportIOS" 10 | }, 11 | { 12 | "script" : "handler.js", 13 | "handler" : "exportAndroid", 14 | "shortcut" : "option shift cmd a", 15 | "name" : "Add Android Exports", 16 | "identifier" : "exportAndroid" 17 | }, 18 | { 19 | "script" : "handler.js", 20 | "handler" : "exportAll", 21 | "shortcut" : "option shift cmd e", 22 | "name" : "Add iOS and Android Exports", 23 | "identifier" : "exportAll" 24 | }, 25 | { 26 | "script" : "handler.js", 27 | "handler" : "exportPDF", 28 | "shortcut" : "option shift cmd p", 29 | "name" : "Add PDF Exports", 30 | "identifier" : "exportPDF" 31 | }, 32 | { 33 | "script" : "handler.js", 34 | "handler" : "exportSVG", 35 | "shortcut" : "option shift cmd g", 36 | "name" : "Add SVG Exports", 37 | "identifier" : "exportSVG" 38 | }, 39 | { 40 | "script" : "handler.js", 41 | "handler" : "clear", 42 | "shortcut" : "option shift cmd c", 43 | "name" : "Clear Exports", 44 | "identifier" : "clear" 45 | } 46 | ], 47 | "menu" : { 48 | "items" : [ 49 | "exportIOS", 50 | "exportAndroid", 51 | "exportAll", 52 | "exportPDF", 53 | "exportSVG", 54 | "clear" 55 | ] 56 | }, 57 | "identifier" : "me.kangchen.export-scale-generator", 58 | "version" : "1.1.1", 59 | "description" : "A simple plugin to add iOS and Android exports with shortcut.", 60 | "authorEmail" : "me@philippehong.com", 61 | "name" : "Sketch Export Generator" 62 | } 63 | --------------------------------------------------------------------------------