diff --git a/README.md b/README.md index 7ddba98..cc94c9f 100644 --- a/README.md +++ b/README.md @@ -127,6 +127,12 @@ Additionally, if you wish to run the plugin every time it is built: npm run start ``` +You may need to update your Sketch defaults to always reload plugins: + +```bash +defaults write com.bohemiancoding.sketch3 AlwaysReloadScript -bool YES +``` + ### Custom Configuration #### Babel @@ -169,4 +175,3 @@ skpm log ``` The `-f` option causes `skpm log` to not stop when the end of logs is reached, but rather to wait for additional data to be appended to the input - diff --git a/interactive-export.sketchplugin/Contents/Sketch/attribute-export.js b/interactive-export.sketchplugin/Contents/Sketch/attribute-export.js index 7269d66..32b544d 100644 --- a/interactive-export.sketchplugin/Contents/Sketch/attribute-export.js +++ b/interactive-export.sketchplugin/Contents/Sketch/attribute-export.js @@ -70,10 +70,7 @@ var exports = /************************************************************************/ /******/ ([ /* 0 */ -/***/ (function(module, exports, __webpack_require__) { - -"use strict"; - +/***/ (function(module, exports) { Object.defineProperty(exports, "__esModule", { value: true @@ -81,6 +78,8 @@ Object.defineProperty(exports, "__esModule", { exports['default'] = function (context) {}; +var writeNonConflictingFile = false; // TODO: Use plugin settings here + function saveJSON(obj, filePath) { obj = JSON.parse(JSON.stringify(obj)); var data = NSJSONSerialization.dataWithJSONObject_options_error(obj, NSJSONWritingPrettyPrinted, nil), @@ -97,6 +96,14 @@ function getClassFromName(name) { return name.split('.').slice(1).join(' '); } +function buildNonConflictingPath(path) { + var splitParts = path.split('\\').pop().split('/'); + var pathToFile = splitParts.slice(0, splitParts.length - 1).join('/'); + var filenameParts = splitParts.pop().split('.'); + var newFileName = filenameParts.slice(0, -2).concat([filenameParts[filenameParts.length - 2] + "_attribute_export", filenameParts[filenameParts.length - 1]]).join('.'); + return pathToFile + '/' + newFileName; +} + function onExportSlices(context) { var exp = context.actionContext.exports; var document = context.actionContext.document; @@ -139,7 +146,13 @@ function onExportSlices(context) { }); svgString = svgString.replace(/svg width\=\"\d+px" height\=\"\d+px"/, 'svg '); - NSString.stringWithString(svgString).writeToFile_atomically_encoding_error(path, true, NSUTF8StringEncoding, nil); + + var svgAsNsString = NSString.stringWithFormat("%@", svgString); + if (writeNonConflictingFile) { + svgAsNsString.writeToFile_atomically(buildNonConflictingPath(path), true); + } else { + svgAsNsString.writeToFile_atomically(path, true); + } } } } diff --git a/interactive-export.sketchplugin/Contents/Sketch/manifest.json b/interactive-export.sketchplugin/Contents/Sketch/manifest.json index 25609a6..df2d50c 100644 --- a/interactive-export.sketchplugin/Contents/Sketch/manifest.json +++ b/interactive-export.sketchplugin/Contents/Sketch/manifest.json @@ -1,5 +1,5 @@ { - "version": "1.0.1", + "version": "1.0.2", "icon": "icon.png", "commands": [ { diff --git a/package.json b/package.json index fe525fa..40b2dfd 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "interactive-export", - "version": "0.1.1", + "version": "0.1.2", "engines": { "sketch": ">=3.0" }, diff --git a/src/attribute-export.js b/src/attribute-export.js index 9519025..3317dbc 100644 --- a/src/attribute-export.js +++ b/src/attribute-export.js @@ -1,3 +1,4 @@ +var writeNonConflictingFile = false; // TODO: Use plugin settings here function saveJSON(obj, filePath) { obj = JSON.parse(JSON.stringify(obj)); @@ -15,6 +16,14 @@ function getClassFromName(name) { return name.split('.').slice(1).join(' '); } +function buildNonConflictingPath(path) { + const splitParts = path.split('\\').pop().split('/') + const pathToFile = splitParts.slice(0, splitParts.length - 1).join('/') + const filenameParts = splitParts.pop().split('.'); + const newFileName = filenameParts.slice(0, -2).concat([filenameParts[filenameParts.length - 2] + "_attribute_export", filenameParts[filenameParts.length - 1]]).join('.') + return pathToFile + '/' + newFileName; +} + function onExportSlices(context) { const exp = context.actionContext.exports; const document = context.actionContext.document; @@ -55,7 +64,13 @@ function onExportSlices(context) { }) svgString = svgString.replace(/svg width\=\"\d+px" height\=\"\d+px"/, 'svg '); - NSString.stringWithString(svgString).writeToFile_atomically_encoding_error(path, true, NSUTF8StringEncoding, nil); + + const svgAsNsString = NSString.stringWithFormat("%@", svgString); + if (writeNonConflictingFile) { + svgAsNsString.writeToFile_atomically(buildNonConflictingPath(path), true); + } else { + svgAsNsString.writeToFile_atomically(path, true); + } } } diff --git a/src/manifest.json b/src/manifest.json index f01c62e..d7a7100 100644 --- a/src/manifest.json +++ b/src/manifest.json @@ -1,7 +1,7 @@ { - "version": "1.0.1", + "version": "1.0.2", "icon": "icon.png", "commands" : [ {